Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
/ GR32PNG Public archive

Commit

Permalink
Improved decompression (thanks to Vismanto)
Browse files Browse the repository at this point in the history
  • Loading branch information
CWBudde committed Nov 21, 2018
1 parent de1f039 commit 7bc3e68
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions GR32_PortableNetworkGraphic.pas
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ interface
uses
Classes, Graphics, SysUtils,
{$IFDEF FPC} ZBase, ZDeflate, ZInflate; {$ELSE}
{$IFDEF ZLibEx}ZLibEx, ZLibExApi; {$ELSE}zlib; {$ENDIF} {$ENDIF}
{$IFDEF ZLibEx}ZLibEx, ZLibExApi; {$ELSE}
{$IFDEF COMPILERRX2_UP} System.zlib; {$ELSE} zlib;
{$ENDIF}{$ENDIF}{$ENDIF}

type
{$A1}
Expand Down Expand Up @@ -1424,12 +1426,14 @@ procedure ZDecompress(Data: Pointer; Size: Integer; const Output: TStream); over

GetMem(TempBuffer, CBufferSize);
try
while ZStreamRecord.avail_in > 0 do
ZResult := Z_OK;

while (ZStreamRecord.avail_in > 0) and (ZResult = Z_OK) do
begin
ZStreamRecord.next_out := TempBuffer;
ZStreamRecord.avail_out := CBufferSize;

inflate(ZStreamRecord, Z_NO_FLUSH);
ZResult := inflate(ZStreamRecord, Z_NO_FLUSH);

Output.Write(TempBuffer^, CBufferSize - ZStreamRecord.avail_out);
end;
Expand Down

0 comments on commit 7bc3e68

Please sign in to comment.