mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-02-07 11:36:25 +02:00
Fix PNG quantization with vips 8.10+
This commit is contained in:
parent
c7fcb9b94f
commit
7e4ae9d0ce
22
vips.c
22
vips.c
@ -1,5 +1,6 @@
|
|||||||
#include "vips.h"
|
#include "vips.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
#define VIPS_SUPPORT_SMARTCROP \
|
#define VIPS_SUPPORT_SMARTCROP \
|
||||||
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 5))
|
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 5))
|
||||||
@ -43,6 +44,9 @@
|
|||||||
#define VIPS_SUPPORT_FIND_TRIM \
|
#define VIPS_SUPPORT_FIND_TRIM \
|
||||||
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 6))
|
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 6))
|
||||||
|
|
||||||
|
#define VIPS_SUPPORT_PNG_BITDEPTH \
|
||||||
|
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 10))
|
||||||
|
|
||||||
#define EXIF_ORIENTATION "exif-ifd0-Orientation"
|
#define EXIF_ORIENTATION "exif-ifd0-Orientation"
|
||||||
|
|
||||||
#if (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 8))
|
#if (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 8))
|
||||||
@ -642,15 +646,29 @@ vips_jpegsave_go(VipsImage *in, void **buf, size_t *len, int quality, int interl
|
|||||||
|
|
||||||
int
|
int
|
||||||
vips_pngsave_go(VipsImage *in, void **buf, size_t *len, int interlace, int quantize, int colors) {
|
vips_pngsave_go(VipsImage *in, void **buf, size_t *len, int interlace, int quantize, int colors) {
|
||||||
|
if (!quantize)
|
||||||
|
return vips_pngsave_buffer(
|
||||||
|
in, buf, len,
|
||||||
|
"filter", VIPS_FOREIGN_PNG_FILTER_NONE,
|
||||||
|
"interlace", interlace,
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
int bitdepth = ceil(log2(colors));
|
||||||
|
|
||||||
return vips_pngsave_buffer(
|
return vips_pngsave_buffer(
|
||||||
in, buf, len,
|
in, buf, len,
|
||||||
"filter", VIPS_FOREIGN_PNG_FILTER_NONE,
|
"filter", VIPS_FOREIGN_PNG_FILTER_NONE,
|
||||||
"interlace", interlace,
|
"interlace", interlace,
|
||||||
#if VIPS_SUPPORT_PNG_QUANTIZATION
|
#if VIPS_SUPPORT_PNG_BITDEPTH
|
||||||
|
"palette", quantize,
|
||||||
|
"bitdepth", bitdepth,
|
||||||
|
#elif VIPS_SUPPORT_PNG_QUANTIZATION // VIPS_SUPPORT_PNG_BITDEPTH
|
||||||
"palette", quantize,
|
"palette", quantize,
|
||||||
"colours", colors,
|
"colours", colors,
|
||||||
#endif // VIPS_SUPPORT_PNG_QUANTIZATION
|
#endif // VIPS_SUPPORT_PNG_QUANTIZATION
|
||||||
NULL);
|
NULL
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user