mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 09:59:20 +02:00
* Use DstBpp instead of SrcDepth when calculating DstLineSize (fixes #0017234)
* Use SrcBytes (=3) for 24Bpp images when RGB indices require a pixel copy git-svn-id: trunk@27376 -
This commit is contained in:
parent
3d961391a4
commit
fd72ca7ff3
@ -614,7 +614,7 @@ var
|
|||||||
SrcPixelPtr, DstPixelPtr: PByte;
|
SrcPixelPtr, DstPixelPtr: PByte;
|
||||||
DstLineSize, SrcLineSize: PtrUInt;
|
DstLineSize, SrcLineSize: PtrUInt;
|
||||||
x, y: Integer;
|
x, y: Integer;
|
||||||
Ridx, Gidx, Bidx, Aidx, Align: Byte;
|
Ridx, Gidx, Bidx, Aidx, Align, SrcBytes, DstBpp: Byte;
|
||||||
begin
|
begin
|
||||||
if (ADesc.BitsPerPixel = 1) and (ADesc.LineEnd = rileWordBoundary)
|
if (ADesc.BitsPerPixel = 1) and (ADesc.LineEnd = rileWordBoundary)
|
||||||
then begin
|
then begin
|
||||||
@ -623,16 +623,19 @@ var
|
|||||||
Exit(ABitmap <> 0);
|
Exit(ABitmap <> 0);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
// for 24 bits images, BPP can be 24 or 32
|
||||||
|
// 32 shouldn't be use since we don't fill the alpha channel
|
||||||
|
|
||||||
|
if ADesc.Depth = 24
|
||||||
|
then DstBpp := 24
|
||||||
|
else DstBpp := ADesc.BitsPerPixel;
|
||||||
|
|
||||||
FillChar(Info, SizeOf(Info), 0);
|
FillChar(Info, SizeOf(Info), 0);
|
||||||
Info.Header.biSize := SizeOf(Info.Header);
|
Info.Header.biSize := SizeOf(Info.Header);
|
||||||
Info.Header.biWidth := ADesc.Width;
|
Info.Header.biWidth := ADesc.Width;
|
||||||
Info.Header.biHeight := -ADesc.Height; // create top to bottom
|
Info.Header.biHeight := -ADesc.Height; // create top to bottom
|
||||||
Info.Header.biPlanes := 1;
|
Info.Header.biPlanes := 1;
|
||||||
// for 24 bits images, BPP can be 24 or 32
|
Info.Header.biBitCount := DstBpp;
|
||||||
// 32 shouldn't be use since we don't fill the alpha channel
|
|
||||||
if ADesc.Depth = 24
|
|
||||||
then Info.Header.biBitCount := 24
|
|
||||||
else Info.Header.biBitCount := ADesc.BitsPerPixel;
|
|
||||||
Info.Header.biCompression := BI_RGB;
|
Info.Header.biCompression := BI_RGB;
|
||||||
{Info.Header.biSizeImage := 0;}
|
{Info.Header.biSizeImage := 0;}
|
||||||
{ first color is black, second color is white, for monochrome bitmap }
|
{ first color is black, second color is white, for monochrome bitmap }
|
||||||
@ -652,7 +655,8 @@ var
|
|||||||
end;
|
end;
|
||||||
if DstLinePtr = nil then Exit(False);
|
if DstLinePtr = nil then Exit(False);
|
||||||
|
|
||||||
DstLineSize := (Windows.MulDiv(ADesc.Depth, ADesc.Width, 8) + 3) and not 3;
|
DstLineSize := Windows.MulDiv(DstBpp, ADesc.Width, 8);
|
||||||
|
// align to DWord
|
||||||
Align := DstLineSize and 3;
|
Align := DstLineSize and 3;
|
||||||
if Align > 0
|
if Align > 0
|
||||||
then Inc(DstLineSize, 4 - Align);
|
then Inc(DstLineSize, 4 - Align);
|
||||||
@ -675,6 +679,7 @@ var
|
|||||||
or (Bidx <> 0) or (Gidx <> 1) or (Ridx <> 2)
|
or (Bidx <> 0) or (Gidx <> 1) or (Ridx <> 2)
|
||||||
then begin
|
then begin
|
||||||
// copy pixels
|
// copy pixels
|
||||||
|
SrcBytes := ADesc.BitsPerPixel div 8;
|
||||||
|
|
||||||
for y := 0 to ADesc.Height - 1 do
|
for y := 0 to ADesc.Height - 1 do
|
||||||
begin
|
begin
|
||||||
@ -687,7 +692,7 @@ var
|
|||||||
DstPixelPtr[2] := SrcPixelPtr[Ridx];
|
DstPixelPtr[2] := SrcPixelPtr[Ridx];
|
||||||
|
|
||||||
Inc(DstPixelPtr, 3); //move to the next dest RGB triple
|
Inc(DstPixelPtr, 3); //move to the next dest RGB triple
|
||||||
Inc(SrcPixelPtr, 4);
|
Inc(SrcPixelPtr, SrcBytes);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Inc(DstLinePtr, DstLineSize);
|
Inc(DstLinePtr, DstLineSize);
|
||||||
|
Loading…
Reference in New Issue
Block a user