Compression ratios of files
Ben Bullock <[email protected]> Sun, 3 Jan 2021 18:17:48 +0900
| Newsgroups | gmane.comp.graphics.png.devel |
|---|---|
| Message-ID | <CAN5Y6m8pXvw1B9aA9U3Cyze7ZoconzkpUydKVW0jwbwKQGVS7w@mail.gmail.com> |
I've started a new Perl module related more to the image part of the PNG,
which is released as a "Development release" here:
https://metacpan.org/release/BKB/Image-PNG-Util-0.00_01
I have been trying it out on some images and I'd like to ask some questions
about the PNG compression of files.
Taking the following image as an example:
https://i.redd.it/bb8fwzmhwv861.png
which was posted to reddit:
https://www.reddit.com/r/wholesomememes/comments/koucrm/higher_quality_happiness/
the image is of colour type PNG_COLOR_TYPE_RGBA, but its alpha channel is
completely opaque (check the software above), and all its pixels are grey
(again this can be proved with the above software).
My question is, why does removing the alpha channel or changing rgb to grey
in the image result in a drastic reduction in image size? With the above
software, we get
[ben@mikan] {18:07 45} ipuex 506 $ ls -l
total 1060
-rw-r--r-- 1 ben ben 315 Jan 3 10:27 alphard.pl
-rw-r--r-- 1 ben ben 207484 Jan 2 21:26 bb8fwzmhwv861-gray.png
-rw-r--r-- 1 ben ben 162752 Jan 3 11:29 bb8fwzmhwv861-noalpha-gray.png
-rw-r--r-- 1 ben ben 336651 Jan 3 11:28 bb8fwzmhwv861-noalpha.png
-rw-r--r-- 1 ben ben 365237 Jan 2 18:01 bb8fwzmhwv861.png
Here without the alpha channel, which consists of repetitive 0xFF every
fourth byte, we get 336651 bytes as opposed to 365237 with the alpha
included, and with all the bytes changed to greyscale, we get 207484 bytes,
which is just reducing triplets of identical RGB values to a single grey
value. Putting RGB to grey and zapping the alpha together, the image size
is reduced by more than half, and yet all we have done is to remove
extraordinarily repetitive information which it seems a compression
algorithm might have been able to remove easily.
Thanks for any insights.
_______________________________________________
png-mng-implement mailing list
png-mng-implement-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/png-mng-implement