writeImageToFile param now used by CImageWriterPNG for compression level

A bit annoying that it kinda has the opposite meaning for png and jpg compression for same parameter (png compression goes up, jpg goes down).
Also unfortunate we chose u32 instead of int here or we could at least use the usual zlib value range for png.
But I think it still won't mess up in many cases. Defaults (value 0) stay the same as before.
And setting a jpg range <= 10 is rarely done and even if so it just changes png sizes a bit now if people use writer for both. 
People just have to be careful now when they override defaults for png and then also write jpg - but can't help it.
And it's too  useful to not have this - this can massively change the write-speed for png's (like up to 3 times faster with no compression on my system).

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6570 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien
2023-11-13 14:53:44 +00:00
parent 3fa020d03c
commit 8bf9cf5471
4 changed files with 16 additions and 5 deletions

View File

@ -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)