DEADSOFTWARE

vampimg endianess fixes
authorDeaDDooMER <deaddoomer@deadsoftware.ru>
Sun, 6 Oct 2019 14:03:22 +0000 (17:03 +0300)
committerDeaDDooMER <deaddoomer@deadsoftware.ru>
Sun, 13 Oct 2019 14:19:20 +0000 (17:19 +0300)
src/lib/vampimg/ImagingTarga.pas
src/lib/vampimg/ImagingUtility.pas

index 66af5f2c8b58b6cfc477f89ab67fbe5ad435a5ee..921f0097fac37bb5ce7e6a15670750c0c9d50002 100644 (file)
@@ -197,6 +197,12 @@ begin
   begin
     // Read targa header
     Read(Handle, @Hdr, SizeOf(Hdr));
+    Hdr.ColorMapOff := LEtoN(Hdr.ColorMapOff);
+    Hdr.ColorMapLength := LEtoN(Hdr.ColorMapLength);
+    Hdr.XOrg := LEtoN(Hdr.XOrg);
+    Hdr.YOrg := LEtoN(Hdr.YOrg);
+    Hdr.Width := LEtoN(Hdr.Width);
+    Hdr.Height := LEtoN(Hdr.Height);
     // Skip image ID info
     Seek(Handle, Hdr.IDLength, smFromCurrent);
     // Determine image format
index c137e1d1386823beaaeefdd0d2aec47e21d5c93e..1fb47dd66f3005112c7056073fa77f3788e6909f 100644 (file)
@@ -1093,6 +1093,8 @@ begin
   Result := PByte(@W)^ = $FF;
 end;
 
+(* Vampimp wrongly use swaps for converting big-endian to little-endian anywhere *)
+{$IF DEFINED(FPC_LITTLE_ENDIAN)}
 function SwapEndianWord(Value: Word): Word;
 {$IF Defined(USE_ASM) and (not Defined(USE_INLINE))}
 asm
@@ -1170,6 +1172,27 @@ begin
   end;
 end;
 {$ENDIF}
+{$ELSEIF DEFINED(FPC_BIG_ENDIAN)}
+function SwapEndianWord(Value: Word): Word;
+begin
+  Result := Value
+end;
+
+procedure SwapEndianWord(P: PWordArray; Count: LongInt);
+begin
+end;
+
+function SwapEndianLongWord(Value: LongWord): LongWord;
+begin
+  Result := Value
+end;
+
+procedure SwapEndianLongWord(P: PLongWord; Count: LongInt);
+begin
+end;
+{$ELSE}
+  {$ERROR Unsupported endianness!}
+{$ENDIF}
 
 type
   TCrcTable = array[Byte] of LongWord;