diff --git a/changes.txt b/changes.txt index 950e088d..1e862545 100644 --- a/changes.txt +++ b/changes.txt @@ -1,6 +1,7 @@ -------------------------- Changes in 1.9 (not yet released) +- CImageWriterPNG now also supports the writeImageToFile param to allow setting compressing level. 0 stays default, 1-10 for range increasing compression level. - Add io::IUserData which can be set in SMaterial to make it easer passing additional material values to shaders - Add lens shift support for the camera and the perspective projection functions - TGA loader no longer reduces 24&32 bit TGA's with palettes to 16 bit. Thanks @erlehmann for report: https://irrlicht.sourceforge.io/forum/viewtopic.php?t=52925 diff --git a/include/IVideoDriver.h b/include/IVideoDriver.h index ef8ac253..5581dd4e 100644 --- a/include/IVideoDriver.h +++ b/include/IVideoDriver.h @@ -1208,8 +1208,10 @@ namespace video for writing the image. \param image Image to write. \param filename Name of the file to write. - \param param Control parameter for the backend (e.g. compression - level). + \param param Control parameter for the backend. Meaning depends on format: + 0 is always some default + For jpg it's otherwise the quality level in range 1-100 (0=default is 75) + For png it's the compression level in range 1-10 (0=default is converted to Z_DEFAULT_COMPRESSION) \return True on successful write. */ virtual bool writeImageToFile(IImage* image, const io::path& filename, u32 param = 0) = 0; @@ -1219,8 +1221,10 @@ namespace video \param image Image to write. \param file An already open io::IWriteFile object. The name will be used to determine the appropriate image writer to use. - \param param Control parameter for the backend (e.g. compression - level). + \param param Control parameter for the backend. Meaning depends on format: + 0 is always some default + For jpg it's otherwise the quality level in range 1-100 (0=default is 75) + For png it's the compression level in range 1-10 (0=default is converted to Z_DEFAULT_COMPRESSION) \return True on successful write. */ virtual bool writeImageToFile(IImage* image, io::IWriteFile* file, u32 param =0) =0; diff --git a/source/Irrlicht/CImageWriterPNG.cpp b/source/Irrlicht/CImageWriterPNG.cpp index 6dc1e6ff..100b56c3 100644 --- a/source/Irrlicht/CImageWriterPNG.cpp +++ b/source/Irrlicht/CImageWriterPNG.cpp @@ -87,6 +87,12 @@ bool CImageWriterPNG::writeImage(io::IWriteFile* file, IImage* image,u32 param) return false; } + // Set compression level + // Sadly Irrlicht used param=0 as default and an u32 type + // So to avoid breaking downward compatibility we keep 0 as default (which is -1 in zlib) and subtract 1 from param to everything into zlib range + if (param <= 10) // Z_BEST_COMPRESSION is 9 - values above have so far no meaning + png_set_compression_level(png_ptr, (int)param-1); + // Allocate the png info struct png_infop info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) diff --git a/tests/tests-last-passed-at.txt b/tests/tests-last-passed-at.txt index 75518824..7a936a53 100644 --- a/tests/tests-last-passed-at.txt +++ b/tests/tests-last-passed-at.txt @@ -1,4 +1,4 @@ Tests finished. 72 tests of 72 passed. Compiled as DEBUG -Test suite pass at GMT Tue Nov 07 15:09:58 2023 +Test suite pass at GMT Mon Nov 13 14:43:47 2023