forked from old/legacy-imlib2
png loader now pays head to images "quality" tag, just like the jpeg loader.
Now, the png lib takes values 1-9 for compression. I decided to standardise loaders on a 1-100 quality value, and do some sums in the loader to convert to 1-9 compression. That was you can set quality and not care what file format is used. Sound reasonable? SVN revision: 3772
This commit is contained in:
parent
ed96b0c6ff
commit
d1227691a0
|
@ -277,6 +277,8 @@ save (ImlibImage *im, ImlibProgressFunction progress,
|
|||
png_color_8 sig_bit;
|
||||
int pl = 0;
|
||||
char pper = 0;
|
||||
ImlibImageTag *tag;
|
||||
int quality = 75, compression;
|
||||
|
||||
f = fopen(im->file, "wb");
|
||||
if (!f)
|
||||
|
@ -325,6 +327,19 @@ save (ImlibImage *im, ImlibProgressFunction progress,
|
|||
sig_bit.blue = 8;
|
||||
sig_bit.alpha = 8;
|
||||
png_set_sBIT(png_ptr, info_ptr, &sig_bit);
|
||||
/* compression */
|
||||
tag = __imlib_GetTag(im, "quality");
|
||||
if (tag)
|
||||
quality = tag->val;
|
||||
if (quality < 10)
|
||||
quality = 10;
|
||||
if (quality > 99)
|
||||
quality = 99;
|
||||
/* translate to png-relevant value */
|
||||
quality = quality / 10;
|
||||
compression = 10 - quality;
|
||||
/* should be 1-9 now */
|
||||
png_set_compression_level(png_ptr, compression);
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
png_set_shift(png_ptr, &sig_bit);
|
||||
png_set_packing(png_ptr);
|
||||
|
|
Loading…
Reference in New Issue