-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a fast way to compress/decompress images using SynLZ
Also include the asm variants of SynLZCompress
- Loading branch information
Showing
8 changed files
with
696 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
{ | ||
Author: Raymond van Venetië and Merlijn Wajer | ||
Project: Simba (https://github.com/MerlijnWajer/Simba) | ||
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0) | ||
-------------------------------------------------------------------------- | ||
Compress images fast using SynLZ. | ||
} | ||
unit simba.image_fastcompress; | ||
|
||
{$i simba.inc} | ||
|
||
interface | ||
|
||
uses | ||
Classes, SysUtils, | ||
simba.base, simba.image; | ||
|
||
procedure SimbaImage_FastCompress(Images: TSimbaImageArray; var Data: Pointer; out DataSize: SizeUInt); | ||
function SimbaImage_FastDeCompress(Data: Pointer; DataLen: SizeUInt): TSimbaImageArray; | ||
|
||
implementation | ||
|
||
uses | ||
SynLZ; | ||
|
||
type | ||
PImageHeader = ^TImageHeader; | ||
TImageHeader = packed record | ||
Size: SizeUInt; // compressed size in bytes | ||
Width, Height: Integer; | ||
end; | ||
|
||
procedure SimbaImage_FastCompress(Images: TSimbaImageArray; var Data: Pointer; out DataSize: SizeUInt); | ||
var | ||
TotalSize: SizeUInt; | ||
I: Integer; | ||
Ptr: PByte; | ||
begin | ||
DataSize := 0; | ||
TotalSize := SizeOf(Integer) + (Length(Images) * SizeOf(TImageHeader)); | ||
for I := 0 to High(Images) do | ||
Inc(TotalSize, Images[I].DataSize); | ||
|
||
if (Data = nil) or (MemSize(Data) < SynLZcompressdestlen(TotalSize)) then | ||
ReAllocMem(Data, SynLZcompressdestlen(TotalSize)); | ||
|
||
Ptr := Data; | ||
PInteger(Ptr)^ := Length(Images); | ||
Inc(Ptr, SizeOf(Integer) + (Length(Images) * SizeOf(TImageHeader))); | ||
|
||
for I := 0 to High(Images) do | ||
with PImageHeader(Data + SizeOf(Integer) + (I * SizeOf(TImageHeader)))^ do | ||
begin | ||
Width := Images[I].Width; | ||
Height := Images[I].Height; | ||
Size := SynLZcompress(PByte(Images[I].Data), Images[I].DataSize, Ptr); | ||
Inc(Ptr, Size); | ||
Inc(DataSize, Size); | ||
end; | ||
end; | ||
|
||
function SimbaImage_FastDeCompress(Data: Pointer; DataLen: SizeUInt): TSimbaImageArray; | ||
var | ||
Ptr: PByte; | ||
I: Integer; | ||
begin | ||
Ptr := Data; | ||
SetLength(Result, PInteger(Ptr)^); | ||
Inc(Ptr, SizeOf(Integer) + (Length(Result) * SizeOf(TImageHeader))); | ||
|
||
for I := 0 to High(Result) do | ||
with PImageHeader(Data + SizeOf(Integer) + (I * SizeOf(TImageHeader)))^ do | ||
begin | ||
Result[I] := TSimbaImage.Create(Width, Height); | ||
SynLZdecompress(Ptr, Size, PByte(Result[I].Data)); | ||
Inc(Ptr, Size); | ||
end; | ||
end; | ||
|
||
end. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.