pngcrush and optipng notes

View: New views
13 Messages — Rating Filter:   Alert me  

pngcrush and optipng notes

by Matthias B. :: Rate this Message:

| View Threaded | Show Only this Message

Hi,

A while ago I faced the task of reducing the size of a few hundred
black'n'white RGB images and I'd like to share 2 things I've
noticed:

1) Whenever I've tried it (not just on the above b/w images), pngcrush's
best results were larger than the original images written by Gimp,
despite the fact that Gimp doesn't do brute force. So there seems to be
something fundamental missing in pngcrush. Is pngcrush completely
obsoleted by optipng, which has always given me better results so far
and which is capable of shrinking Gimp's files even further?

2) While optipng recognized that my RGB images were reducible to
grayscale, it missed the opportunity to reduce them to indexed format
to reduce them even further.

Note: I don't usually work with photorealistic images, so all of my
experiences apply only to cartoonish images.

MSB

--
When you order sausage in Germany, prepare for the wurst!


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
png-mng-implement mailing list
png-mng-implement@...
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

Re: pngcrush and optipng notes

by Matthias B. :: Rate this Message:

| View Threaded | Show Only this Message

On Mon, 14 Apr 2008 18:13:47 +0200
"Matthias B." <msbREMOVE-THIS@...> wrote:

> Hi,
>
> A while ago I faced the task of reducing the size of a few hundred
> black'n'white RGB images and I'd like to share 2 things I've
> noticed:

Oops. I didn't mean black'n'white. The images were black on
transparent.

MSB

--
Problems are always simple. It's finding the solutions that is
difficult.


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
png-mng-implement mailing list
png-mng-implement@...
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

Re: pngcrush and optipng notes

by glennrp-2 :: Rate this Message:

| View Threaded | Show Only this Message

At 06:13 PM 4/14/2008 +0200, Matthias B. wrote:

>Hi,
>
>A while ago I faced the task of reducing the size of a few hundred
>black'n'white RGB images and I'd like to share 2 things I've
>noticed:
>
>1) Whenever I've tried it (not just on the above b/w images), pngcrush's
>best results were larger than the original images written by Gimp,
>despite the fact that Gimp doesn't do brute force. So there seems to be
>something fundamental missing in pngcrush. Is pngcrush completely
>obsoleted by optipng, which has always given me better results so far
>and which is capable of shrinking Gimp's files even further?

One thing on my "to do" list for pngcrush (but don't hold your breath
while waiting) is to keep the original IDAT contents if they are
smaller than anything pngcrush can find.

>2) While optipng recognized that my RGB images were reducible to
>grayscale, it missed the opportunity to reduce them to indexed format
>to reduce them even further.

I usually make a first pass with ImageMagick/GraphicsMagick's "convert"
or with pngquant to do that.  Pngquant, however, needs an option to
retain all colors present, and don't do anything if there are more
than 256.

Glenn

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
png-mng-implement mailing list
png-mng-implement@...
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

Re: pngcrush and optipng notes

by Glenn Randers-Pehrson :: Rate this Message:

| View Threaded | Show Only this Message

Matthias, could you send me a few examples?  Preferably ones that are public
domain or open-source licensed.  You can send me a URL or attach them to
an email to glennREMOVE-THISrp at simpleTHIS-TOOsystems.org

Glenn

On Mon, Apr 14, 2008 at 12:17 PM, Matthias B.
<msbREMOVE-THIS@...> wrote:

> On Mon, 14 Apr 2008 18:13:47 +0200
>  "Matthias B." <msbREMOVE-THIS@...> wrote:
>
>  > Hi,
>  >
>  > A while ago I faced the task of reducing the size of a few hundred
>  > black'n'white RGB images and I'd like to share 2 things I've
>  > noticed:
>
>  Oops. I didn't mean black'n'white. The images were black on
>  transparent.
>
>  MSB

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
png-mng-implement mailing list
png-mng-implement@...
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

Re: pngcrush and optipng notes

by Glenn Randers-Pehrson :: Rate this Message:

| View Threaded | Show Only this Message

On Mon, Apr 14, 2008 at 12:13 PM, Matthias B.
<msbREMOVE-THIS@...> wrote:
> Hi,
>
>  A while ago I faced the task of reducing the size of a few hundred
>  black'n'white RGB images and I'd like to share 2 things I've
>  noticed:
>
>  1) Whenever I've tried it (not just on the above b/w images), pngcrush's
>  best results were larger than the original images written by Gimp,

I looked at four example PNGs that Matthias sent me.  In all 4 cases, the
filesize increase was due to pngcrush adding a gAMA chunk (the originals
contain an sRGB chunk but no gAMA).

It is probably a mistake for pngcrush to be adding gAMA without the user
explicitly asking for it.

Glenn

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
png-mng-implement mailing list
png-mng-implement@...
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

Re: pngcrush and optipng notes

by Gerard Juyn :: Rate this Message:

| View Threaded | Show Only this Message

PNG specification V1.2, paragraph 4.2.2.3 states:

> An application that writes the sRGB chunk should also write a
gAMA chunk (and perhaps a cHRM chunk) for compatibility with
applications that do not use the sRGB chunk. <

Looks like pngcrush is trying to "fix" the output of applications that do
not adhere to the aforementioned recommendation.

I believe the "-rem gAMA" parameter would prevent pngcrush from
showing this behavior.


> > Hi,
> >
> >  A while ago I faced the task of reducing the size of a few hundred
> >  black'n'white RGB images and I'd like to share 2 things I've noticed:
> >
> >  1) Whenever I've tried it (not just on the above b/w images),
> >  pngcrush's best results were larger than the original images written
> >  by Gimp,
>
> I looked at four example PNGs that Matthias sent me.  In all 4 cases,
> the filesize increase was due to pngcrush adding a gAMA chunk (the
> originals contain an sRGB chunk but no gAMA).
>
> It is probably a mistake for pngcrush to be adding gAMA without the user
> explicitly asking for it.


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
png-mng-implement mailing list
png-mng-implement@...
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

Re: pngcrush and optipng notes

by John Denker :: Rate this Message:

| View Threaded | Show Only this Message

On 04/20/2008 04:38 AM, Glenn Randers-Pehrson wrote:

> I looked at four example PNGs that Matthias sent me.  In all 4 cases, the
> filesize increase was due to pngcrush adding a gAMA chunk (the originals
> contain an sRGB chunk but no gAMA).
>
> It is probably a mistake for pngcrush to be adding gAMA without the user
> explicitly asking for it.


I'm not so sure about that.

The semantics are clear:

1) A sRGB chunk, if present and recognized, overrides any gAMA chunk.
  http://www.w3.org/TR/PNG/
so the gAMA chunk doesn't do any harm in the normal case (except for
the extra 8 bytes of size).

2) Therefore the interesting case is where the sRGB chunk is present
but not recognized by the decoder.  To cover this case:

   "It is recommended that a PNG encoder that writes the sRGB chunk
    also write a gAMA chunk (and optionally a cHRM chunk)
    for compatibility with decoders that do not use the sRGB chunk."
      http://www.w3.org/TR/PNG/

Tangential remark:  This compatibility will necessarily be imperfect,
because the sRGB transfer function is not well described by power law,
i.e. not well described by any single value of "gamma".

==================================

Bottom line:  It seems that the observed pngcrush behavior is in strict
compliance with recommendations of the PNG spec.

You could perhaps make an argument for deviating from the recommendations
in some cases, but it would be a nontrivial argument, weighing the pros
and cons.


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
png-mng-implement mailing list
png-mng-implement@...
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

Re: pngcrush and optipng notes

by John Denker :: Rate this Message:

| View Threaded | Show Only this Message

On 04/20/2008 05:59 AM, Gerard Juyn wrote:

> I believe the "-rem gAMA" parameter would prevent pngcrush from
> showing this behavior.

It may be helpful to have a new
      --noadd gAMA
parameter (in addition to --rem).

The distinction is that
  --rem unconditionally removes gAMA even if it was present on
   the input, whereas
  --noadd leaves it alone if it was present on the input


The distinction is important in the case where you want to turn
pngcrush loose on a batch of files, some of which have gAMA (but
don't have sRGB) while others have sRGB (but don't have and don't
want gAMA) ... and you don't know _a priori_ which files are in
which category.


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
png-mng-implement mailing list
png-mng-implement@...
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

Re: pngcrush and optipng notes

by glennrp-2 :: Rate this Message:

| View Threaded | Show Only this Message

At 02:59 PM 4/20/2008 +0200, you wrote:
>PNG specification V1.2, paragraph 4.2.2.3 states:
>
>> An application that writes the sRGB chunk should also write a
>gAMA chunk (and perhaps a cHRM chunk) for compatibility with
>applications that do not use the sRGB chunk. <
>
>Looks like pngcrush is trying to "fix" the output of applications that do
>not adhere to the aforementioned recommendation.

It's actually libpng that is inserting gAMA and cHRM within
png_handle_sRGB: the last thing that function does is
png_set_sRGB_gAMA_and_cHRM.

That's probably the right thing to do, except when we are trying to
squeeze the last few bytes out of a PNG file.  Pngcrush needs to
defeat that libpng behavior.

Glenn


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
png-mng-implement mailing list
png-mng-implement@...
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

Re: pngcrush and optipng notes

by Gerard Juyn :: Rate this Message:

| View Threaded | Show Only this Message

True!

In the specified case however I believe the "-rem gAMA" would
suffice as all the images are reportedly without a gAMA chunk (but
with sRGB).

In a generic sense it would certainly make sense to add a "-noadd
gAMA" feature.
Or perhaps simply "-nocmchanges", as in "leave it as is dude" :-)


> > I believe the "-rem gAMA" parameter would prevent pngcrush from
> > showing this behavior.
>
> It may be helpful to have a new
>       --noadd gAMA
> parameter (in addition to --rem).
>
> The distinction is that
>   --rem unconditionally removes gAMA even if it was present on
>    the input, whereas
>   --noadd leaves it alone if it was present on the input
>
>
> The distinction is important in the case where you want to turn
> pngcrush loose on a batch of files, some of which have gAMA (but
> don't have sRGB) while others have sRGB (but don't have and don't
> want gAMA) ... and you don't know _a priori_ which files are in
> which category.


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
png-mng-implement mailing list
png-mng-implement@...
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

Re: pngcrush and optipng notes

by glennrp-2 :: Rate this Message:

| View Threaded | Show Only this Message

At 04:07 PM 4/20/2008 +0200, Gerard Juyn wrote:
>True!
>
>In the specified case however I believe the "-rem gAMA" would
>suffice as all the images are reportedly without a gAMA chunk (but
>with sRGB).
>
>In a generic sense it would certainly make sense to add a "-noadd
>gAMA" feature.
>Or perhaps simply "-nocmchanges", as in "leave it as is dude" :-)

I'm planning to simply make this the default behavior.  If you want
to add a gamma, use -g as currently.  Pngcrush will leave the situation
the same as found in the input (e.g., sRGB alone -> sRGB alone).

GLenn

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
png-mng-implement mailing list
png-mng-implement@...
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

Re: pngcrush and optipng notes

by Adam M. Costello-2 :: Rate this Message:

| View Threaded | Show Only this Message

John Denker <jsd@...> wrote:

> Bottom line:  It seems that the observed pngcrush behavior is in
> strict compliance with recommendations of the PNG spec.
>
> You could perhaps make an argument for deviating from the
> recommendations in some cases, but it would be a nontrivial argument,
> weighing the pros and cons.

Internet Explorer, at least through version 7.0b1, mishandled gAMA,
but not sRGB, so providing sRGB without gAMA was your best bet for
cross-browser compatibility.  I don't know if this has been fixed.

AMC

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
png-mng-implement mailing list
png-mng-implement@...
https://lists.sourceforge.net/lists/listinfo/png-mng-implement

Re: pngcrush and optipng notes

by Cosmin Truta :: Rate this Message:

| View Threaded | Show Only this Message


Hello, everyone,
Long time no "see" ;-)

Matthias, the gray-to-palette reduction has always been missing in
OptiPNG, and that is documented in the user manual. Because of that,
combined with the fact that rgb-to-gray comes ahead of rgb-to-palette,
the former is done instead of the latter, even when the latter is the
better choice.

This limitation will go away in the upcoming version 0.6, which will
have the gray-to-palette reduction implemented.

About the rest of the discussion (adding or not adding gAMA besides
sRGB), my philosophy so far was to keep the metadata intact, and not
add anything except when absolutely necessary (e.g. adding tRNS when
reducing rgba-to-palette, or removing it when there are no transparent
pixels). That will probably change in the future, because I have
received emails from lots of users asking for the possibility to remove
chunks. I haven't done that in version 0.6 yet, but I will have to do
it, eventually.

Best regards,
Cosmin


On Mon, 14 Apr 2008, Matthias B. wrote:

> Hi,
>
> A while ago I faced the task of reducing the size of a few hundred
> black'n'white RGB images and I'd like to share 2 things I've
> noticed:
>
> 1) Whenever I've tried it (not just on the above b/w images), pngcrush's
> best results were larger than the original images written by Gimp,
> despite the fact that Gimp doesn't do brute force. So there seems to be
> something fundamental missing in pngcrush. Is pngcrush completely
> obsoleted by optipng, which has always given me better results so far
> and which is capable of shrinking Gimp's files even further?
>
> 2) While optipng recognized that my RGB images were reducible to
> grayscale, it missed the opportunity to reduce them to indexed format
> to reduce them even further.
>
> Note: I don't usually work with photorealistic images, so all of my
> experiences apply only to cartoonish images.
>
> MSB
>
> --
> When you order sausage in Germany, prepare for the wurst!
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
> Don't miss this year's exciting event. There's still time to save $100.
> Use priority code J8TL2D2.
> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
> _______________________________________________
> png-mng-implement mailing list
> png-mng-implement@...
> https://lists.sourceforge.net/lists/listinfo/png-mng-implement
>

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
png-mng-implement mailing list
png-mng-implement@...
https://lists.sourceforge.net/lists/listinfo/png-mng-implement