Speed up JPEG encoding using Alchemy
Posted on June 21, 2009
Few weeks ago Thibault Imbert published an optimized version of Adobes JPGEncoder. And it rocks! However, if you may have very big-size bitmaps it takes too much time to encode images. For example: A bitmap with a size of 2000px x 1500px takes 22 sec. (BTW: Adobes version 30 sec.!!)
Today I came across to a post by Manfred Weber, which points to a discussion at Adobes Alchemy forum. There you will find a great solution published by metalbot for encoding JPEGs using Alchemy. It's based on a C library for JPEG image compression by IJG and it's pretty fast (2,7 sec. for 2000 px x 1500px ) !!! Check out the example:
Click the image to see the live example. Feel free to post a comment about your your results!
Download Full Source
I have changed the original C code a little bit
for manipulating the quality of an encoded image as well. It's just one line added to
// line 78 jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
as3_jpeg_wrapper.swc located within the
*.zip is recompiled for using this feature in
your Flex project via
as3_jpeg_wrapper.write_jpeg_file(baSource, WIDTH, HEIGHT, 3, 2, quality);
Full source of the Flex based example above: AlchemyJPEGEncoderFlexExample.zip
BTW: You will find the original source of all C based classes published by metalbot here.
I struggled around to set up Alchemy and to recompile the IJG library and the "as3_jpeg_wrapper.swc". To avoid this, here are some tips:
- Instruction for set up Alchemy by Lee Felarca (zeropointnine). Best instruction I've found so far for set up Alchemy.
- Recompiling the SWC of metalbot's source following its "README.txt" and using its "Makefile" failed: To avoid this issue, after compiling the C library of jpegsrc you have to move the following files to $ALCHEMY_HOME/jpeg/ as well: "jconfig.h", "jmorecfg.h" and "jpeglib.h". Check out the comment by notnick here
There is another great test for encoding images using Alchemy by Mateusz Malczak, which includes an asynchrounous example as well: Alchemy - asynchronous jpeg encoding Thanks to xoestudio for pointing to this via twitter! [UPDATE]
Have fun ;)