Episode 190: JPEG and PNG, what’s in it?

190Download the Video! (36:10 68.8MB)

Download the Companion File! (4.6MB)

The last episode was for absolute beginners, this one is for Geeks. I try to explain (and understand on the way) how images are stored in PNG and JPEG files. PNG (pronounced “PING”) does this lossless, the image can be retrieved in the same quality as the original. PNG works wonders with graphics with a lot of lines and clear colour areas, comics and logos for example, but it creates monster files out of photos and similar images. JPEG looses details, aquires artefacts and generally mangles the image. But it has so beautifully small files and the losses are in most cases invisible – except in the area where PNG is good. So both have their niche to live in.

How is this done? I try to explain this without the math, using analogies, plaing with GIMP to reenact some stages and reducing the complexity a lot. If you want to know the exact facts, read up in Wikipedia, which was also my source of information, or look for other sources. I hope that I never crossed the border between simplification and telling wrong stuff – but I am really not sure. The math is really over my head, last time I had to tackle such a level a Pentax ME Super was still a new camera model. I am happy about any comments that improve my understanding – and all other comments too.

The TOC

00:00:00 Intro
00:02:22 Basics about digital images – pixel, RGB
00:05:25 Storing the colour values in the computer
00:06:24 Palettes for reducing the image size
00:06:50 Run length encoding as simple compression method
00:07:20 PNG, JPG and a WARNING
00:08:44 The PNG format
00:10:12 HexDump and structure of a PNG image
00:13:32 Compression in PNG
00:15:15 PNG is suitable for …
00:16:26 JPG analysed – file structure
00:18:13 First stage: Change the colour model to YCbCr
00:18:54 Decomposing an image to YCbCr in GIMP
00:20:32 Reduce the colours
00:22:20 Testing the concept with GIMP
00:26:17 Splicing into blocks and DCT
00:28:41 quantization
00:29:53 Summary
00:31:20 Testing the compression
00:35:19 Final words
00:36:10 End of video

Creative Commons License
Meet the GIMP Video Podcast by Rolf Steinort is licensed under a Creative Commons Attribution 3.0 Unported License.
Permissions beyond the scope of this license may be available at http://meetthegimp.org.

13 thoughts on “Episode 190: JPEG and PNG, what’s in it?

  1. Really interesting episode, and carefully explained. It really make me want to come back for more. πŸ™‚

    /klesus

    P.S.
    Didn’t you have a donation button on here before πŸ˜‰

    • Thanks! Part two will be simply saving different stuff in different formats and then comparing everything that is comparable. πŸ˜‰

  2. Rolf,
    This is again a very interesting episode. I’m afraid you lost me at the Fourier stuff. I never understood this stuff at the Fachhochschule anyway πŸ™‚
    Looking forward to the next episode.

    Wim

  3. Great episode…

    While I was aware of the generation operation theory of JPEG, I never quite understood the DCT part… And now I sortof do πŸ™‚

    Progressive JPEG now makes a lot more sense, as it probably just means the DCT “levels” are encoded in an interleaved way into the file (rough detail to fine detail).

    Also, you briefly mentioned the last step, lossless (Huffman) compression, there is a small detail as I understand where either a predefined (static) Huffman table is used, which works fairly well. Or the optimized mode, which a dynamic (specific to each image) Huffman table is calculated, which is benefical for larger images.
    The main caveat seems to be that the predefined Huffman table is not encoded into the resulting JPEG, whereas the optimized Huffman table is, so in that case data is being added, to get higher compression ratios. Which is why optimized JPEGs can be larger on smaller files than non-optimized JPEGs, where the added Huffman table adds more data that can be reclaimed from improved compression on the small image.

    • I should get my shovel out and dig a bit deeper. πŸ˜‰

      Thanks for these pointers, I’ll do the research and include an update into the next show.

  4. Pingback: Links 15/4/2013: Underwater Linux, More Android Phones | Techrights

Anything to add from your side of the computer?

This site uses Akismet to reduce spam. Learn how your comment data is processed.