From f09d767c6ec30fff501a1decd25e4277172d727e Mon Sep 17 00:00:00 2001 From: kamgha Date: Thu, 31 Aug 2017 13:03:17 +0200 Subject: [PATCH] pnmimagetypes: introduce png-compression-level PRC variable --- panda/src/pnmimagetypes/config_pnmimagetypes.cxx | 12 ++++++++++-- panda/src/pnmimagetypes/config_pnmimagetypes.h | 1 + panda/src/pnmimagetypes/pnmFileTypePNG.cxx | 4 ++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/panda/src/pnmimagetypes/config_pnmimagetypes.cxx b/panda/src/pnmimagetypes/config_pnmimagetypes.cxx index c498951f3f..2fc23d574a 100644 --- a/panda/src/pnmimagetypes/config_pnmimagetypes.cxx +++ b/panda/src/pnmimagetypes/config_pnmimagetypes.cxx @@ -81,6 +81,7 @@ ConfigVariableInt img_size ("img-size", 0, PRC_DESC("If an IMG file without a header is loaded (e.g. img-header-type " "is set to 'none', this specifies the fixed x y size of the image.")); + ConfigVariableInt jpeg_quality ("jpeg-quality", 95, PRC_DESC("Set this to the quality percentage for writing JPEG files. 95 is " @@ -88,10 +89,17 @@ ConfigVariableInt jpeg_quality "significantly better quality, but do lead to significantly greater " "size).")); +ConfigVariableInt png_compression_level +("png-compression-level", 6, + PRC_DESC("Set this to the desired compression level for writing PNG images. " + "Valid values are 0 (no compression), or 1 (compression, best " + "speed) to 9 (best compression). Default is 6. PNG compression is " + "lossless.")); + ConfigVariableBool png_palette ("png-palette", true, - PRC_DESC("Set this true to allow writing palette-based PNG images when possible.")); - + PRC_DESC("Set this true to allow writing palette-based PNG images when " + "possible.")); ConfigVariableInt bmp_bpp ("bmp-bpp", 0, diff --git a/panda/src/pnmimagetypes/config_pnmimagetypes.h b/panda/src/pnmimagetypes/config_pnmimagetypes.h index dca563a683..95ed9224a5 100644 --- a/panda/src/pnmimagetypes/config_pnmimagetypes.h +++ b/panda/src/pnmimagetypes/config_pnmimagetypes.h @@ -57,6 +57,7 @@ extern ConfigVariableBool tga_grayscale; extern ConfigVariableInt jpeg_quality; +extern ConfigVariableInt png_compression_level; extern ConfigVariableBool png_palette; extern ConfigVariableInt bmp_bpp; diff --git a/panda/src/pnmimagetypes/pnmFileTypePNG.cxx b/panda/src/pnmimagetypes/pnmFileTypePNG.cxx index 49cbc2faba..bf4ab4ac31 100644 --- a/panda/src/pnmimagetypes/pnmFileTypePNG.cxx +++ b/panda/src/pnmimagetypes/pnmFileTypePNG.cxx @@ -526,6 +526,10 @@ write_data(xel *array, xelval *alpha_data) { png_set_write_fn(_png, (void *)this, png_write_data, png_flush_data); + // The compression level corresponds directly to the compression levels for + // zlib. + png_set_compression_level(_png, png_compression_level); + // First, write the header. int true_bit_depth = pm_maxvaltobits(_maxval);