Browse Source

* Fix for 16-bit PNGs (bug 19209)

git-svn-id: trunk@22141 -
michael 13 years ago
parent
commit
1beea17ed2
1 changed files with 9 additions and 10 deletions
  1. 9 10
      packages/fcl-image/src/fpreadpng.pp

+ 9 - 10
packages/fcl-image/src/fpreadpng.pp

@@ -404,22 +404,21 @@ function TFPReaderPNG.CalcColor: TColorData;
 var cd : longword;
 var cd : longword;
     r : word;
     r : word;
     b : byte;
     b : byte;
+    tmp : pbytearray;
 begin
 begin
   if UsingBitGroup = 0 then
   if UsingBitGroup = 0 then
     begin
     begin
     Databytes := 0;
     Databytes := 0;
     if Header.BitDepth = 16 then
     if Header.BitDepth = 16 then
       begin
       begin
-      r := 1;
-      while (r < ByteWidth) do
-        begin
-        b := FCurrentLine^[Dataindex+r];
-        FCurrentLine^[Dataindex+r] := FCurrentLine^[Dataindex+r-1];
-        FCurrentLine^[Dataindex+r-1] := b;
-        inc (r,2);
-        end;
-      end;
-    move (FCurrentLine^[DataIndex], Databytes, bytewidth);
+       getmem(tmp, bytewidth);
+       fillchar(tmp^, bytewidth, 0);
+       for r:=0 to bytewidth-2 do
+        tmp^[r+1]:=FCurrentLine^[Dataindex+r];
+       move (tmp^[0], Databytes, bytewidth);
+       freemem(tmp);
+      end
+    else move (FCurrentLine^[DataIndex], Databytes, bytewidth);
     {$IFDEF ENDIAN_BIG}
     {$IFDEF ENDIAN_BIG}
     Databytes:=swap(Databytes);
     Databytes:=swap(Databytes);
     {$ENDIF}
     {$ENDIF}