Page 1 of 1

PureZIP_UnpackMemory

Posted: Tue Sep 27, 2011 5:41 pm
by JHPJHP
Hi,

I'm trying to compress an image I have encoded using Base64 (saved to a database), then uncompress it at a later date. Modifying the PureZIP_PackMemory example... lets just say that I don't know a lot about assigning strings to memory address' :)

In the following example, the top REMed out string works, but the larger string only produces +++++

Thank you for any insite, your expertise is appreciated:

Code: Select all

;PackData.s = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"

;size reduced for readability
PackData.s = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAoHBwgHBgoICAgLCgoLDhgQDg0NDh0VFhEYIx8lJCIfIiEmKzcvJik0KSEiMEExNDk7Pj4+JS5ESUM8SDc9Pjv/2wBDAQoCw4"
SourceLength = Len(PackData)
Debug SourceLength
Debug PackData

*SourceMemoryID = AllocateMemory(SourceLength)
PokeS(*SourceMemoryID, PackData, SourceLength)
DestinationLength = SourceLength + (SourceLength * 0.01) + 12
*DestinationMemoryID = AllocateMemory(DestinationLength)
PureZIP_PackMemory(*SourceMemoryID, SourceLength, *DestinationMemoryID, @DestinationLength)
PackTest.s = Space(DestinationLength)
PackTest = PeekS(*DestinationMemoryID, @DestinationLength)
Debug Len(PackTest)
Debug PackTest

FreeMemory(*SourceMemoryID)
FreeMemory(*DestinationMemoryID)

*SourceMemoryID = AllocateMemory(SourceLength)
PokeS(*SourceMemoryID, PackTest, SourceLength)
DestinationLength = SourceLength + (SourceLength * 0.01) + 12
*DestinationMemoryID = AllocateMemory(DestinationLength)
PureZIP_UnpackMemory(*SourceMemoryID, SourceLength, *DestinationMemoryID, @DestinationLength)
UnpackTest.s = Space(DestinationLength)
UnpackTest = PeekS(*DestinationMemoryID, @DestinationLength)
Debug Len(UnpackTest)
Debug UnpackTest

FreeMemory(*SourceMemoryID)
FreeMemory(*DestinationMemoryID)

Re: PureZIP_UnpackMemory

Posted: Tue Sep 27, 2011 8:55 pm
by JHPJHP
Ahhh it's a moot point - Base64 being an encryption algorithm, won't have enough similarities to make a difference - I'll need to compress the image at the binary level before the base64 conversion...

Included a small fix to the code from the previous post:

Code: Select all

;PackData.s = "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
PackData.s = "The other day I went to the store to buy a bag of milk.  At the store I met an old friend, her name is Susan, she is a good friend - we had coffee together."
SourceLength = Len(PackData)
Debug SourceLength
Debug PackData

*SourceMemoryID = AllocateMemory(SourceLength)
PokeS(*SourceMemoryID, PackData, SourceLength)
DestinationLength = SourceLength + (SourceLength * 0.01) + 12
*DestinationMemoryID = AllocateMemory(DestinationLength)
PureZIP_PackMemory(*SourceMemoryID, SourceLength, *DestinationMemoryID, @DestinationLength)
PackTest.s = Space(DestinationLength)
PackTest = PeekS(*DestinationMemoryID, @DestinationLength)
Debug Len(PackTest)
Debug PackTest

FreeMemory(*SourceMemoryID)
FreeMemory(*DestinationMemoryID)

DestinationLength = SourceLength
*DestinationMemoryID = AllocateMemory(DestinationLength)
SourceLength = Len(PackTest)
*SourceMemoryID = AllocateMemory(SourceLength)
PokeS(*SourceMemoryID, PackTest, SourceLength)
PureZIP_UnpackMemory(*SourceMemoryID, SourceLength, *DestinationMemoryID, @DestinationLength)
UnpackTest.s = Space(DestinationLength)
UnpackTest = PeekS(*DestinationMemoryID, @DestinationLength)
Debug Len(UnpackTest)
Debug UnpackTest

FreeMemory(*SourceMemoryID)
FreeMemory(*DestinationMemoryID)

Re: PureZIP_UnpackMemory

Posted: Wed Sep 28, 2011 7:03 pm
by JHPJHP
Further update...

Using compression on an image SEEMS not to have had much of an effect - it actually gave an unexpected (reverse) result:

Saved a Bitmap image (screenshot) to a NamedPipe
Converted it to JPEG (quality 10)
Resized the image to 25% its original size
[1] not compressed
[2] compressed with PureZIP_PackMemory
[3] compressed with PackMemory (compression level 9)
Encoded it using Base64Encoder
Saved it to a PostgreSQL database (text)

[1] Size: 440232
[2] Size: 444652
[3] Size: 440244

As you can see - not doing any compression (at least with these tests) gave the best result.

Re: PureZIP_UnpackMemory

Posted: Wed Sep 28, 2011 7:49 pm
by Thorium
JHPJHP wrote: As you can see - not doing any compression (at least with these tests) gave the best result.
Not true, you did compress it by converting it to JPEG, even if the quality is set to 10 it still compresses it.
A specialised image compression will be allways better than a general purpose compression.

Re: PureZIP_UnpackMemory

Posted: Wed Oct 05, 2011 3:48 pm
by JHPJHP
For sure, compared to the alternative (leaving it as BMP) - made a world of difference... thanks for the clarification :)