Ignore:
Timestamp:
Dec 22, 2016, 8:49:19 PM (8 years ago)
Author:
chronos
Message:
  • Modified: Updated BGRABitmap package.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • GraphicTest/Packages/bgrabitmap/bgrareadbmpmiomap.pas

    r472 r494  
    77uses
    88  Classes, SysUtils, FPimage, BGRABitmapTypes;
     9
     10const
     11  MioMapMagicValue = 'RL';
     12  MioMapTransparentColor = $F81F;
    913
    1014type
     
    2933  end;
    3034
     35function MioMapToBGRA(AColor: Word): TBGRAPixel;
     36function BGRAToMioMap(const AColor: TBGRAPixel): Word;
     37function MioMapToAlpha(AValue: Byte): Byte;
     38function AlphaToMioMap(AValue: Byte): Byte;
     39
    3140implementation
    3241
    3342uses bufstream;
     43
     44function MioMapToBGRA(AColor: Word): TBGRAPixel;
     45begin
     46  if AColor = MioMapTransparentColor then
     47    result := BGRAPixelTransparent
     48  else
     49    result := Color16BitToBGRA(AColor);
     50end;
     51
     52function BGRAToMioMap(const AColor: TBGRAPixel): Word;
     53begin
     54  if AColor.alpha < 7 then
     55    result := MioMapTransparentColor
     56  else
     57  begin
     58    result := BGRAToColor16Bit(AColor);
     59    if result = MioMapTransparentColor then dec(result);
     60  end;
     61end;
     62
     63function MioMapToAlpha(AValue: Byte): Byte;
     64begin
     65  result := AValue*255 div 32;
     66end;
     67
     68function AlphaToMioMap(AValue: Byte): Byte;
     69begin
     70  result := (AValue*32 + 64) div 255;
     71end;
    3472
    3573{ TBGRAReaderBmpMioMap }
     
    4179  fillchar({%H-}header,sizeof(header),0);
    4280  if stream.Read(header, sizeof(header))<> sizeof(header) then exit;
    43   if header.magic <> 'RL' then exit;
     81  if header.magic <> MioMapMagicValue then exit;
    4482  header.format:= LEtoN(header.format);
    4583  header.width:= LEtoN(header.width);
     
    64102  begin
    65103    colorValue := LEtoN(mioPalette[i]);
    66     if colorValue = $F81F then
    67       result[i] := BGRAPixelTransparent
    68     else
    69       result[i] := BGRA(   ((colorValue and $F800) shr 11)*255 div 31,
    70                            ((colorValue and $07e0) shr 5)*255 div 63,
    71                            (colorValue and $001f)*255 div 31);
     104    result[i] := MioMapToBGRA(colorValue);
    72105  end;
    73106  for i := nbColorsRead to nbColors-1 do
     
    78111    Stream.Read(alphaPalette[0],nbColors);
    79112    for i := 0 to nbColors-1 do
    80       if mioPalette[i] <> $F81F then
    81         result[i].alpha := alphaPalette[i]*255 div 32;
     113      if mioPalette[i] <> MioMapTransparentColor then
     114        result[i].alpha := MioMapToAlpha(alphaPalette[i]);
    82115  end;
    83116end;
Note: See TracChangeset for help on using the changeset viewer.