Sunday, August 21, 2005

PNG support in Flash Player 8

Yes, you have probably heard about it and maybe already tried dynamically loading PNG images in Flash Player 8 using MovieClip.loadMovie(). But did you know why this was not implemented in previous releases? Sounds like an obvious feature request doesn't it? Two words: Code size. libpng, which is the most frequently used developer library for handling png files, is about 150KB of code. No one was able to find a good reason to give up as much code size for this feature alone.

At the beginning of the development of Flash Player 8 we heard the constant mantra from users: "We want PNG support!". With our answer usually being: "It's too big, won't happen!" The situation became so bad that we had an mailing list thread going on this subject which quickly became the most passionate I had seen. There was no way around it this time around, we had to find a way to include it.

After looking at the W3C PNG spec I realized that the key was to ditch libpng and rewrite a PNG loader from scratch. It was much easier than I thought and due to the excellent PNG test suite the QA impact was minimal. Since we already had zlib in the Flash Player I was able to reduce the code size of the PNG loader to less than 4KB including all of the features the standard requires and a couple more. All of that in less than a week of work. Neat, isn't it? It's always great to see that small efforts can pay back big time for users.

And please, keep on using the Feature Request page on the Macromedia web site. It really works and we look at all the requests. Without it the PNG support would not have happened. The feedback from this page unlike some of you might think does not go into the trash or /dev/null but to an email list developers and QA people subscribe to (I am not sure how we can make the Flash Player produce blue pills though, so we run some heavy duty spam filters on it ;-)

Update: If you are familiar with the PNG file format here are the chunk types we currently fully support:

IHDR Image header
IDAT Image data
PLTE Palette information
tRNS Transparency extension
gAMA Image gamma
IEND End of stream

And here are the chunk types we do NOT support (According to the PNG 1.2 specification these are truely optional and not required for displaying PNG files):

cHRM Primary chromaticities
sRGB Standard RGB color space
iCCP Embedded ICC profile
tEXt Textual data
zTXt Compressed textual data
iTXt International textual data
bKGD Background color
pHYs Physical pixel dimensions
sBIT Significant bits
sPLT Suggested palette
hIST Palette histogram
tIME Image last-modification time

8 Comments:

Blogger diviner said...

Hi
very nice and interesting content, thank you,
See Persian Diviner in IRAN with ADS Flash

Sunday, August 21, 2005 6:27:00 PM  
Blogger stefan said...

turic -

thank you so much for your posts. i really really enjoy them.

keep up the good work.

stef

Sunday, August 21, 2005 7:38:00 PM  
Blogger Daniel Wabyick said...

Does the Flash player have zlib *deflate* in there by chance? If so is it accessible?

Monday, August 22, 2005 8:27:00 AM  
Blogger Lance said...

This is a great feature the PNG format. Is the JPEG200 standard a possibility as well? I work with medical image formats. The DICOM medical image standard adopted jpeg2000 in 2001. Is the decoder for a jp2 so big that it can't be put into the player? I noticed it is an import option in fireworks. thanks in advance/

Monday, January 09, 2006 2:06:00 PM  
Anonymous Anonymous said...

Its a great new. Do you have a solution to export transparent PNG from flash player without usoing server side scripts

Saturday, August 12, 2006 6:27:00 AM  
Blogger semateos said...

Do you have any suggestions on what kind of PNG compression flash will accept? Have been trying to export png images using imagemagick and load them on the fly in flash - currently only works by turning compression off in imagemagick which makes the files large and slow to download. Any advise at all would be huge as I've been looking a long time and there is very little info out there.

Thanks,
Sam

Thursday, April 26, 2007 10:35:00 AM  
Blogger Tinic Uro said...

semateos,

Imagemagick is known to create corrupt PNG files which do not conform to the spec. It has to do with the way they handle zlib compressed data, the compressed buffer is one byte short.

The Flash Player is very strict for security reasons, will never try to display corrupt files.

Thursday, April 26, 2007 12:03:00 PM  
Anonymous Anonymous said...

Hello. There seem to be some bug (feature ?) with the way transparency is handled in PNGs, take a look here http://flashmove.com/forum/showthread.php?t=31727 for example. Can you explain this behavior, please?

Tuesday, September 11, 2007 9:51:00 PM  

Post a Comment

<< Home