mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-07 02:18:20 +02:00
LCL: Fix BMP handling issues in big endian systems. Issue #27719, patch from Mark Morgan Lloyd.
git-svn-id: trunk@48623 -
This commit is contained in:
parent
1c13bee866
commit
d126fb4491
@ -127,18 +127,21 @@ begin
|
|||||||
begin
|
begin
|
||||||
FillChar(Header, SizeOf(Header), 0);
|
FillChar(Header, SizeOf(Header), 0);
|
||||||
|
|
||||||
|
{ Create a BMP header ordered as it would be on disc, noting that if the CPU
|
||||||
|
is big-endian this will be the "wrong way round" for numeric operations. }
|
||||||
|
|
||||||
|
{$IFNDEF ENDIAN_BIG}
|
||||||
Header.bfType := $4d42;
|
Header.bfType := $4d42;
|
||||||
Header.bfSize := SizeOf(Header) + ASize;
|
Header.bfSize := SizeOf(Header) + ASize;
|
||||||
|
{$ELSE}
|
||||||
|
Header.bfType := $424d;
|
||||||
|
Header.bfSize := swap(SizeOf(Header) + ASize);
|
||||||
|
{$ENDIF}
|
||||||
//Header.bfOffBits := 0; //data imediately follows
|
//Header.bfOffBits := 0; //data imediately follows
|
||||||
{$IFDEF ENDIAN_BIG}
|
|
||||||
swap(Header.bfType);
|
|
||||||
swap(Header.bfSize);
|
|
||||||
//swap(Header.bfOffBits);
|
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
S := THeaderStream.Create(AStream, @Header, SizeOf(Header));
|
S := THeaderStream.Create(AStream, @Header, SizeOf(Header));
|
||||||
try
|
try
|
||||||
inherited LoadFromStream(S, Header.bfSize);
|
inherited LoadFromStream(S, SizeOf(Header) + ASize);
|
||||||
finally
|
finally
|
||||||
S.Free;
|
S.Free;
|
||||||
end;
|
end;
|
||||||
|
@ -5047,13 +5047,21 @@ end;
|
|||||||
function TLazReaderBMP.InternalCheck(Stream: TStream): boolean;
|
function TLazReaderBMP.InternalCheck(Stream: TStream): boolean;
|
||||||
var
|
var
|
||||||
BFH: TBitMapFileHeader;
|
BFH: TBitMapFileHeader;
|
||||||
|
offbits: DWORD;
|
||||||
begin
|
begin
|
||||||
Stream.Read(BFH, SizeOf(BFH));
|
Stream.Read(BFH, SizeOf(BFH));
|
||||||
Result := BFH.bfType = BMmagic; // Just check magic number
|
Result := BFH.bfType = LEtoN(BMmagic); // Just check magic number
|
||||||
|
|
||||||
// store the data offset
|
{ Store the data offset. BFH is poorly aligned (dictated by the .bmp file
|
||||||
|
format), which can cause problems for architectures such as SPARC and some
|
||||||
|
ARM implementations which have strict alignment requirements. That is why
|
||||||
|
the code below uses an intermediate variable, rather than a direct call to
|
||||||
|
LEtoN(BFH.bfOffBits) which will try to pass a misaligned parameter. }
|
||||||
if Result and (BFH.bfOffBits <> 0)
|
if Result and (BFH.bfOffBits <> 0)
|
||||||
then FDataOffset := Stream.Position + BFH.bfOffBits - SizeOf(BFH);
|
then begin
|
||||||
|
offbits := BFH.bfOffBits;
|
||||||
|
FDataOffset := Stream.Position + LEtoN(offbits) - SizeOf(BFH)
|
||||||
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TLazReaderBMP.InternalReadHead;
|
procedure TLazReaderBMP.InternalReadHead;
|
||||||
|
Loading…
Reference in New Issue
Block a user