mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-06 22:18:15 +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
|
||||
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.bfSize := SizeOf(Header) + ASize;
|
||||
{$ELSE}
|
||||
Header.bfType := $424d;
|
||||
Header.bfSize := swap(SizeOf(Header) + ASize);
|
||||
{$ENDIF}
|
||||
//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));
|
||||
try
|
||||
inherited LoadFromStream(S, Header.bfSize);
|
||||
inherited LoadFromStream(S, SizeOf(Header) + ASize);
|
||||
finally
|
||||
S.Free;
|
||||
end;
|
||||
|
@ -5047,13 +5047,21 @@ end;
|
||||
function TLazReaderBMP.InternalCheck(Stream: TStream): boolean;
|
||||
var
|
||||
BFH: TBitMapFileHeader;
|
||||
offbits: DWORD;
|
||||
begin
|
||||
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)
|
||||
then FDataOffset := Stream.Position + BFH.bfOffBits - SizeOf(BFH);
|
||||
then begin
|
||||
offbits := BFH.bfOffBits;
|
||||
FDataOffset := Stream.Position + LEtoN(offbits) - SizeOf(BFH)
|
||||
end
|
||||
end;
|
||||
|
||||
procedure TLazReaderBMP.InternalReadHead;
|
||||
|
Loading…
Reference in New Issue
Block a user