Changeset 494 for GraphicTest/Packages/bgrabitmap/bgrareadbmpmiomap.pas
- Timestamp:
- Dec 22, 2016, 8:49:19 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
GraphicTest/Packages/bgrabitmap/bgrareadbmpmiomap.pas
r472 r494 7 7 uses 8 8 Classes, SysUtils, FPimage, BGRABitmapTypes; 9 10 const 11 MioMapMagicValue = 'RL'; 12 MioMapTransparentColor = $F81F; 9 13 10 14 type … … 29 33 end; 30 34 35 function MioMapToBGRA(AColor: Word): TBGRAPixel; 36 function BGRAToMioMap(const AColor: TBGRAPixel): Word; 37 function MioMapToAlpha(AValue: Byte): Byte; 38 function AlphaToMioMap(AValue: Byte): Byte; 39 31 40 implementation 32 41 33 42 uses bufstream; 43 44 function MioMapToBGRA(AColor: Word): TBGRAPixel; 45 begin 46 if AColor = MioMapTransparentColor then 47 result := BGRAPixelTransparent 48 else 49 result := Color16BitToBGRA(AColor); 50 end; 51 52 function BGRAToMioMap(const AColor: TBGRAPixel): Word; 53 begin 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; 61 end; 62 63 function MioMapToAlpha(AValue: Byte): Byte; 64 begin 65 result := AValue*255 div 32; 66 end; 67 68 function AlphaToMioMap(AValue: Byte): Byte; 69 begin 70 result := (AValue*32 + 64) div 255; 71 end; 34 72 35 73 { TBGRAReaderBmpMioMap } … … 41 79 fillchar({%H-}header,sizeof(header),0); 42 80 if stream.Read(header, sizeof(header))<> sizeof(header) then exit; 43 if header.magic <> 'RL'then exit;81 if header.magic <> MioMapMagicValue then exit; 44 82 header.format:= LEtoN(header.format); 45 83 header.width:= LEtoN(header.width); … … 64 102 begin 65 103 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); 72 105 end; 73 106 for i := nbColorsRead to nbColors-1 do … … 78 111 Stream.Read(alphaPalette[0],nbColors); 79 112 for i := 0 to nbColors-1 do 80 if mioPalette[i] <> $F81Fthen81 result[i].alpha := alphaPalette[i]*255 div 32;113 if mioPalette[i] <> MioMapTransparentColor then 114 result[i].alpha := MioMapToAlpha(alphaPalette[i]); 82 115 end; 83 116 end;
Note:
See TracChangeset
for help on using the changeset viewer.