Just as the topic name suggests, I'm asking you how a computer reads picture files. As in .png, .bmp, .jpg, and .gif. I'm just wondering. I looked it up on google, but I couldn't find anything that was clear to me.
They use libraries (such as libpng and libjpeg) to do the hard part for them, then they just copy the image to the screen. You could look at the source code for those libraries to see how they decompress and read the image data.
Is this the source?

http://sourceforge.net/projects/libpng/files/
I was wondering how computers did that too. Thanks you souvik, I now understand it a little better Smile
BMP is the easiest one, because it doesn't do any compression. The bytes for the image are stored sequentially, alternating red, green, and blue, and the bytes can then be directly copied to the screen. For compressed types such as JPG and PNG, the data must first be decompressed before it can be shown on the screen. JPG uses lossy compression, which means that the reconstructed image isn't exactly the image that was compressed (but it's close). PNG is lossless, so even though it compresses the picture, when it is decompressed it is identical to the original.
KermMartian wrote:
BMP is the easiest one, because it doesn't do any compression. The bytes for the image are stored sequentially, alternating red, green, and blue, and the bytes can then be directly copied to the screen. For compressed types such as JPG and PNG, the data must first be decompressed before it can be shown on the screen. JPG uses lossy compression, which means that the reconstructed image isn't exactly the image that was compressed (but it's close). PNG is lossless, so even though it compresses the picture, when it is decompressed it is identical to the original.

I would say that the raw Portable Pixmap (PPM) format is even easier than BMP to decode, as it has only one pixel format (red/green/blue, 8 or 16 bits per channel). BMP has several different pixel formats and depths to worry about when decoding, eg 1-bit monochrome, 4-, or 8-bit indexed; 16-, 24-, or 32- bit high/true color; etc. BMP can also be RLE compressed. Plus BMP's are stored "upside down", meaning the bottom row of pixels is stored first in the file.

Then there's also the ASCII PPM format, which is the same as the raw PPM format, but the values are stored in plain text, which makes it easier to edit in a text editor or with a programming language that doesn't easily support binary data. The only downside is that an ASCII PPM file is larger than a raw PPM file.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement