1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
|
Function TGLZBitmapBMPImage.GetHeaderRedMask: LongWord;
Begin
if FHeaderType>= bmpht_WindowsV2 then
begin
Case FHeaderType Of
bmpht_WindowsV2: Result := LEToN(FInfoHeader.WindowsV2.biRedMask);
bmpht_WindowsV3: Result := LEToN(FInfoHeader.WindowsV3.biRedMask);
bmpht_WindowsV4: Result := LEToN(FInfoHeader.WindowsV4.biRedMask);
bmpht_WindowsV5: Result := LEToN(FInfoHeader.WindowsV5.biRedMask);
End;
end
else
begin
{$ifdef ENDIAN_BIG}
Result := $0000FF00;
{$else}
Result :=$00FF0000;
{$endif}
end;
End;
Function TGLZBitmapBMPImage.GetHeaderGreenMask: LongWord;
Begin
if FHeaderType>= bmpht_WindowsV2 then
begin
Case FHeaderType Of
bmpht_WindowsV2: Result := LEToN(FInfoHeader.WindowsV2.biGreenMask);
bmpht_WindowsV3: Result := LEToN(FInfoHeader.WindowsV3.biGreenMask);
bmpht_WindowsV4: Result := LEToN(FInfoHeader.WindowsV4.biGreenMask);
bmpht_WindowsV5: Result := LEToN(FInfoHeader.WindowsV5.biGreenMask);
End;
end
else
begin
{$ifdef ENDIAN_BIG}
Result := $00FF0000;
{$else}
Result := $0000FF00;
{$endif}
end;
End;
Function TGLZBitmapBMPImage.GetHeaderBlueMask: LongWord;
Begin
if FHeaderType>= bmpht_WindowsV2 then
begin
Case FHeaderType Of
bmpht_WindowsV2: Result := LEToN(FInfoHeader.WindowsV2.biBlueMask);
bmpht_WindowsV3: Result := LEToN(FInfoHeader.WindowsV3.biBlueMask);
bmpht_WindowsV4: Result := LEToN(FInfoHeader.WindowsV4.biBlueMask);
bmpht_WindowsV5: Result := LEToN(FInfoHeader.WindowsV5.biBlueMask);
End;
end
else
begin
{$ifdef ENDIAN_BIG}
Result := $00FF0000;
{$else}
Result := $000000FF;
{$endif}
end;
End;
Function TGLZBitmapBMPImage.GetHeaderAlphaMask: LongWord;
Begin
if FHeaderType>= bmpht_WindowsV3 then
begin
Case FHeaderType Of
bmpht_WindowsV3: Result := LEToN(FInfoHeader.WindowsV3.biAlphaMask);
bmpht_WindowsV4: Result := LEToN(FInfoHeader.WindowsV4.biAlphaMask);
bmpht_WindowsV5: Result := LEToN(FInfoHeader.WindowsV5.biAlphaMask);
Else Result:=0
End;
end
else
begin
{$ifdef ENDIAN_BIG}
Result := $000000FF;
{$else}
Result := $FF000000;
{$endif}
end;
End;
...
function TGLZBitmapBMPImage.ReadImageProperties:Boolean;
function GetMaskShift(AMask: LongWord): ShortInt;
begin
Result := 0;
while ((AMask and (1 shl Result)) = 0) and (Result < 32) do inc(Result);
// if result = 32 then result:=0;
end;
function GetMaskSize(AMask: LongWord; AShift:ShortInt): Byte;
begin
Result := 0;
while (AShift + Result < 32) and ((AMask and (1 shl (AShift + Result))) <> 0) do Inc(Result);
end;
begin
...
{ On a récupéré nos informations, on met à jour le RawImage. de TGLZBitmap
On charge la palette de couleur si besoins
On initialise quelques variables utiles pour la lecture des données suivant
le "PixelFormat"
}
With RawImage do
begin
UsedColors:=GetHeaderUsedColors;
UsePalette:=False;
With Description do
begin
// Le decalage par defaut pour le bitfield est le format de couleur (A)RGB
(*RedShift := 16;
GreenShift := 8;
BlueShift := 24;
AlphaShift :=0;RedMaskSize := 8;
GreenMaskSize := 8;// Taille de valeur en Bit
BlueMaskSize := 8;
AlphaMaskSize := 8;*)
// On Initialise le format de couleur gràce au "masque"
// Format couleur par Defaut pour le BitField : ARGB
RedMask := GetHeaderRedMask;
GreenMask := GetHeaderGreenMask;
BlueMask := GetHeaderBlueMask;
RedShift := GetMaskShift(RedMask); //ShiftCount(RedMask);
GreenShift := GetMaskShift(GreenMask);
BlueShift := GetMaskShift(BlueMask);
RedMaskSize := GetMaskSize(RedMask,RedShift);
GreenMaskSize := GetMaskSize(GreenMask,GreenShift);
BlueMaskSize := GetMaskSize(BlueMask,BlueShift);
AlphaMask := 0; //GetMaskSize(AlphaMask);
AlphaShift := 0;
AlphaMaskSize :=0;
if FHeaderType>bmpht_WindowsV2 then
begin
AlphaMask := GetHeaderAlphaMask;
AlphaShift := GetMaskShift(AlphaMask);
AlphaMaskSize := GetMaskSize(AlphaMask,AlphaShift);
end
else
begin // En-tête Version 1, on initialise avec la valeur par defaut
if BitCount = 32 then
begin
{$ifdef ENDIAN_BIG}
AlphaMask := := $000000FF;
{$else}
AlphaMask := $FF000000;
{$endif}
AlphaShift := GetMaskShift(AlphaMask);
AlphaMaskSize := GetMaskSize(AlphaMask,AlphaShift);
end;
end;
end;
...
FRowSize:=ComputeBytesPerLine(bmpWidth, bitCount, bleDWordBoundary);
Case bitCount of
...
32:
begin
Description.ColorFormat:=cfBGRA;
if Not(Compression=BMP_COMPRESSION_NONE) and not(Compression=BMP_COMPRESSION_BITF) then
begin
ShowMessage('Bad Compression');
Result:=False;
end;
if Description.AlphaMaskSize > 0 then
begin
// Le Mask Alpha cache-t-il une autre composante de la couleur
if (Description.RedMask or Description.GreenMask or Description.BlueMask) and Description.AlphaMask <> 0 then
begin
Description.AlphaMask := 0;
Description.AlphaShift := 0;
Description.AlphaMaskSize := 0;
end;
end;
// La taille du masque alpha est 0,. C'est un format 24bits.
if Description.AlphaMaskSize = 0 then
begin
//Description.ColorFormat:=cfBGR;
BitCount:=24;//
Description.AlphaMask := $FF000000;
Description.AlphaShift := 0;//GetMaskShift(Description.AlphaMask);
// if Description.AlphaShift = 24 then Description.AlphaShift := 0;
end;
end;
end;
procedure TGLZBitmapBMPImage.LoadFromMemory();
var
YY,Y : Integer;
X:Integer;
DstColor: TGLZColor;
SrcPtr : PLongWord;
DstLine : PGLZColor;
SrcColor :LongWord;
LineBuffer : PByte;
function ExpandColor(Value: LongWord): TGLZColor;
var
tmpr, tmpg, tmpb, tmpa: LongWord;
begin
tmpr := value and RawImage.Description.RedMask;
tmpg := value and RawImage.Description.GreenMask;
tmpb := value and RawImage.Description.BlueMask;
tmpa := value and RawImage.Description.AlphaMask;
Result.Alpha := 255;
if RawImage.Description.RedShift < 0 then
Result.Red := byte(tmpr shl (-RawImage.Description.RedShift))
else
Result.Red := byte(tmpr shr RawImage.Description.RedbitShift);
if RawImage.Description.GreenShift < 0 then
Result.Green := byte(tmpg shl (-RawImage.Description.GreenShift))
else
Result.Green := byte(tmpg shr RawImage.Description.GreenShift);
if RawImage.Description.BluebitShift < 0 then
Result.Blue := byte(tmpb shl (-RawImage.Description.BlueShift))
else
Result.Blue := byte(tmpb shr RawImage.Description.BlueShift);
if RawImage.Description.AlphaMaskSize>0 then
begin
if RawImage.Description.AlphaShift < 0 then
Result.Alpha := byte(tmpa shl (-RawImage.Description.AlphaShift))
else
Result.Alpha := byte(tmpa shr RawImage.Description.AlphaShift);
end;
end;
begin
// On initialise les dimensions de notre bitmap
SetSize(bmpWidth, bmpHeight);
Case RawImage.Description.PixelFormat of
...
pf32Bits: // Pas de compression, formats couleurs suivant "BitField" sinon RGBA
begin
LineBuffer:=nil;
ReallocMem(LineBuffer,FRowSize);
Y:=0;
repeat
Memory.Read(LineBuffer^,FRowSize);
if TopDown then YY:=Y else YY:=MaxHeight-Y;
if (Compression = BMP_COMPRESSION_BITF) then //LineDecodeBITFIELD32
begin
DstLine:=GetScanLine(YY);
SrcPtr := PLongWord(LineBuffer);
For X:=0 to MaxWidth do
begin
SrcColor:=(SrcPtr+X)^;
DstColor := ExpandColor(SrcColor);
if (FHeaderType<bmpht_WindowsV3) then DstColor.Alpha:=255;
DstLine^:=DstColor;
Inc(DstLine);
end;
end else LineDecodeBGRA32(LineBuffer,YY,false);
Inc(Y);
Until (Y>MaxHeight);
ReAllocMem(LineBuffer, 0);
FreeMem(LineBuffer);
LineBuffer:=nil;
end;
end;
end; |
Partager