Quick Tip: Compression in Flash

While working on one of my projects where I needed compression for transfered data, I hit some very interesting compression libraries. Also the ByteArray class contains compress method, using zlib algorithm in flash player or multiple algorithms in AIR. At the end I decided to use ByteArray.compress() method for encoding vs. PHP gzuncompress for decoding, what works correctly, fast and smooth.

Here is a list of 3rd party compression libraries and other good stuff:

  • AS3 Zip: ActionScript 3 based library for reading and writing zip files
  • FZip: FZip is an Actionscript 3 class library to load, modify and create standard ZIP archives.
  • ASZip: ActionScript 3 library to generate ZIP files
  • LZMA Encoder: AS3 class to compress data using LZMA algorithm.
  • LZMA Decoder: A part of the apparat framework.
  • GZIP: ActionScript GZIP compression library
  • Gzip for HTTPService/URLLoader: Adding Gzip support for Flex/AIR HTTPService/URLLoader
  • airxzip: Zip library for ActionScript3 on AIR

If you know some more, please let me know.

Processing BitmapData.getPixels() With PHP

Have you ever worked with BitmapData.getPixels() method? This method generates a byte array from a rectangular region of pixel data. Writes an unsigned integer (a 32-bit unmultiplied pixel value) for each pixel into the byte array. Thats sounds good, but what is it good for to have a ByteArray full of integers? There is not even a decoder for this format on my backend?!… Well, this format is so cool, and easy to access that you do are able to write your own decoder e.g. in PHP.

The resulting bytes are 32-bit unsigned integers for each pixel represented by AARRGGBB format, followed by another pixels and so on e.g.:

AA RR GG BB:
-- -- -- --
FF FF 00 00
00 00 FF 00

Read the rest of this entry »

Compressing hex string into base64 string

compressLooseWeight

How would you convert / compress 64 character long hex string (0-9a-f) into shortest possible web-safe-char string? (base64 chars is fine) The reverse algorithm must be able to “uncompress” resulting string back into original hex.

I have created p16Top64() compress algorithm and p64Top16() uncompress (reversed) algorithm based on ByteArray class and writeUnsignedInt(), readUnsignedInt() methods. Both p16Top64() and p64Top16() methods are now part of sk.yoz.data.Serialization class. By using p16Top64() method I was able to compress original 64 chars into 44 chars. But, is it possible to compress it into less than 44 char long base64 (0-9a-Z/=) string?

Read the rest of this entry »