Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#10372 closed enhancement (fixed)

Add several wxIMAGE_OPTION_PNG_xxx to reduce the size of PNG files created by wxImage::SaveFile()

Reported by: pandu Owned by: frm
Priority: normal Milestone:
Component: base Version: stable-latest
Keywords: wxPNGHandler Cc:
Blocked By: Blocking:
Patch: yes

Description

I'm developing a document-scanning application that outputs gray scale images sized about 1200 x 1700 pixels. Naturally I expect PNG to encode that kind of images with the smallest file size, but wxImage gives smaller JPG than PNG. That's weird so I tried optipng (http://optipng.sourceforge.net/) and found out that the "optimized" PNGs are 25%-30% smaller than those outputted by wxPNGHandler. Optipng also gives information about the libpng parameters used to create those PNGs. I modified wxPNGHandler so my program can tell it (via wxImage::SetOption) about the parameters.

Changed files are:
\include\wx\imagpng.h --- #defined some new wxIMAGE_OPTION_PNG_XXX constants
\src\common\imagpng.cpp --- implement new options by calling matching libpng functions
\interface\wx\image.h --- updated documentation to describe the new options
\samples\image\image.cpp --- updated sample app to test the effect of the new options

The new wxImage options are: (=> translated to libpng call:)
wxIMAGE_OPTION_PNG_FILTER => png_set_filter
wxIMAGE_OPTION_PNG_COMPRESSION_LEVEL => png_set_compression_level
wxIMAGE_OPTION_PNG_COMPRESSION_MEM_LEVEL => png_set_compression_mem_level
wxIMAGE_OPTION_PNG_COMPRESSION_STRATEGY => png_set_compression_strategy
wxIMAGE_OPTION_PNG_COMPRESSION_BUFFER_SIZE => png_set_compression_buffer_size

The libpng call is made only if its corresponding option presents (via wxImage::HasOption).
The calls are made before png_set_IHDR (in conformance with libpng.txt guide).

Attachments (1)

smallpng.diff download (6.3 KB) - added by pandu 12 years ago.

Download all attachments as: .zip

Change History (8)

Changed 12 years ago by pandu

comment:1 Changed 12 years ago by frm

  • Owner set to frm
  • Status changed from new to accepted

seems really a great patch!
I'm compiling my patched wx now...

comment:2 Changed 12 years ago by FM

  • Resolution set to fixed
  • Status changed from accepted to closed

(In [58103]) add some wxIMAGE_OPTION_PNG_xxx options to wxImage and wxPNGHandler to allow the user to set the desired compression level (closes #10372)

comment:3 follow-up: Changed 12 years ago by frm

I've made some small modifications and enhanced a bits the docs... thanks for the patch!

comment:4 in reply to: ↑ 3 Changed 12 years ago by pandu

Thanks for accepting and improving my patch, hope it would be useful for other people too.

comment:5 Changed 11 years ago by frm

Hi pandu,

I'm adding an entry to the changelog about this patch: what's your real name so that I can give you credit?

comment:6 follow-up: Changed 11 years ago by pandu

Wow that's cool!
My name is Perdana Panduwana, I'm from Indonesia

And frm stands for...?

comment:7 in reply to: ↑ 6 Changed 11 years ago by frm

Replying to pandu:

Wow that's cool!
My name is Perdana Panduwana, I'm from Indonesia

ok, I've added it to the changelog; see r58960

And frm stands for...?

Francesco Montorsi

Thanks for the patch!

Note: See TracTickets for help on using tickets.