mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-02-12 11:46:10 +02:00
Use VIPS_META_BITS_PER_SAMPLE image header instead of palette-bit-depth when available
This commit is contained in:
parent
3048c30e1e
commit
157843ccb3
@ -69,7 +69,7 @@ func prepareWatermark(wm *vips.Image, wmData *imagedata.ImageData, opts *options
|
||||
}
|
||||
}
|
||||
|
||||
wm.RemoveHeader("palette-bit-depth")
|
||||
wm.RemoveBitsPerSampleHeader()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
25
vips/vips.c
25
vips/vips.c
@ -15,6 +15,10 @@
|
||||
#define VIPS_GIF_RESOLUTION_LIMITED \
|
||||
(VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION <= 12)
|
||||
|
||||
#ifndef VIPS_META_BITS_PER_SAMPLE
|
||||
#define VIPS_META_BITS_PER_SAMPLE "palette-bit-depth"
|
||||
#endif
|
||||
|
||||
int
|
||||
vips_initialize() {
|
||||
return vips_init("imgproxy");
|
||||
@ -134,17 +138,22 @@ vips_get_orientation(VipsImage *image) {
|
||||
}
|
||||
|
||||
int
|
||||
vips_get_palette_bit_depth(VipsImage *image) {
|
||||
int palette_bit_depth;
|
||||
vips_get_bits_per_sample(VipsImage *image) {
|
||||
int bits_per_sample;
|
||||
|
||||
if (
|
||||
vips_image_get_typeof(image, "palette-bit-depth") == G_TYPE_INT &&
|
||||
vips_image_get_int(image, "palette-bit-depth", &palette_bit_depth) == 0
|
||||
) return palette_bit_depth;
|
||||
vips_image_get_typeof(image, VIPS_META_BITS_PER_SAMPLE) == G_TYPE_INT &&
|
||||
vips_image_get_int(image, VIPS_META_BITS_PER_SAMPLE, &bits_per_sample) == 0
|
||||
) return bits_per_sample;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
vips_remove_bits_per_sample(VipsImage *image) {
|
||||
vips_image_remove(image, VIPS_META_BITS_PER_SAMPLE);
|
||||
}
|
||||
|
||||
VipsBandFormat
|
||||
vips_band_format(VipsImage *in) {
|
||||
return in->BandFmt;
|
||||
@ -610,7 +619,7 @@ vips_strip(VipsImage *in, VipsImage **out, int keep_exif_copyright) {
|
||||
|
||||
if (
|
||||
(strcmp(name, VIPS_META_ICC_NAME) == 0) ||
|
||||
(strcmp(name, "palette-bit-depth") == 0) ||
|
||||
(strcmp(name, VIPS_META_BITS_PER_SAMPLE) == 0) ||
|
||||
(strcmp(name, "width") == 0) ||
|
||||
(strcmp(name, "height") == 0) ||
|
||||
(strcmp(name, "bands") == 0) ||
|
||||
@ -664,8 +673,8 @@ vips_pngsave_go(VipsImage *in, void **buf, size_t *len, int interlace, int quant
|
||||
else if (colors > 4) bitdepth = 4;
|
||||
else if (colors > 2) bitdepth = 2;
|
||||
} else {
|
||||
bitdepth = vips_get_palette_bit_depth(in);
|
||||
if (bitdepth) {
|
||||
bitdepth = vips_get_bits_per_sample(in);
|
||||
if (bitdepth && bitdepth <= 8) {
|
||||
if (bitdepth > 4) bitdepth = 8;
|
||||
else if (bitdepth > 2) bitdepth = 4;
|
||||
quantize = 1;
|
||||
|
@ -482,8 +482,8 @@ func (img *Image) SetBlob(name string, value []byte) {
|
||||
C.vips_image_set_blob_copy(img.VipsImage, cachedCString(name), unsafe.Pointer(&value[0]), C.size_t(len(value)))
|
||||
}
|
||||
|
||||
func (img *Image) RemoveHeader(name string) {
|
||||
C.vips_image_remove(img.VipsImage, cachedCString(name))
|
||||
func (img *Image) RemoveBitsPerSampleHeader() {
|
||||
C.vips_remove_bits_per_sample(img.VipsImage)
|
||||
}
|
||||
|
||||
func (img *Image) CastUchar() error {
|
||||
|
@ -28,6 +28,8 @@ void vips_strip_meta(VipsImage *image);
|
||||
|
||||
VipsBandFormat vips_band_format(VipsImage *in);
|
||||
|
||||
void vips_remove_bits_per_sample(VipsImage * image);
|
||||
|
||||
gboolean vips_is_animated(VipsImage * in);
|
||||
|
||||
int vips_image_get_array_int_go(VipsImage *image, const char *name, int **out, int *n);
|
||||
|
Loading…
x
Reference in New Issue
Block a user