Use palette-bit-depth for palette bitdepth instead of VIPS_META_BITS_PER_SAMPLE

This commit is contained in:
DarthSim
2023-11-13 20:26:58 +03:00
parent 33bbfd0ed9
commit 07528dbecf
4 changed files with 15 additions and 16 deletions

View File

@@ -69,7 +69,7 @@ func prepareWatermark(wm *vips.Image, wmData *imagedata.ImageData, opts *options
} }
} }
wm.RemoveBitsPerSampleHeader() wm.RemovePaletteBitDepth()
return nil return nil
} }

View File

@@ -18,9 +18,7 @@
#define VIPS_SCRGB_ALPHA_FIXED \ #define VIPS_SCRGB_ALPHA_FIXED \
(VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 15)) (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 15))
#ifndef VIPS_META_BITS_PER_SAMPLE #define VIPS_META_PALETTE_BITS_DEPTH "palette-bit-depth"
#define VIPS_META_BITS_PER_SAMPLE "palette-bit-depth"
#endif
int int
vips_initialize() vips_initialize()
@@ -273,22 +271,22 @@ vips_get_orientation(VipsImage *image)
} }
int int
vips_get_bits_per_sample(VipsImage *image) vips_get_palette_bit_depth(VipsImage *image)
{ {
int bits_per_sample; int palette_bit_depth;
if ( if (
vips_image_get_typeof(image, VIPS_META_BITS_PER_SAMPLE) == G_TYPE_INT && vips_image_get_typeof(image, VIPS_META_PALETTE_BITS_DEPTH) == G_TYPE_INT &&
vips_image_get_int(image, VIPS_META_BITS_PER_SAMPLE, &bits_per_sample) == 0) vips_image_get_int(image, VIPS_META_PALETTE_BITS_DEPTH, &palette_bit_depth) == 0)
return bits_per_sample; return palette_bit_depth;
return 0; return 0;
} }
void void
vips_remove_bits_per_sample(VipsImage *image) vips_remove_palette_bit_depth(VipsImage *image)
{ {
vips_image_remove(image, VIPS_META_BITS_PER_SAMPLE); vips_image_remove(image, VIPS_META_PALETTE_BITS_DEPTH);
} }
VipsBandFormat VipsBandFormat
@@ -790,6 +788,7 @@ vips_strip(VipsImage *in, VipsImage **out, int keep_exif_copyright)
if ( if (
(strcmp(name, VIPS_META_ICC_NAME) == 0) || (strcmp(name, VIPS_META_ICC_NAME) == 0) ||
(strcmp(name, VIPS_META_BITS_PER_SAMPLE) == 0) || (strcmp(name, VIPS_META_BITS_PER_SAMPLE) == 0) ||
(strcmp(name, VIPS_META_PALETTE_BITS_DEPTH) == 0) ||
(strcmp(name, "width") == 0) || (strcmp(name, "width") == 0) ||
(strcmp(name, "height") == 0) || (strcmp(name, "height") == 0) ||
(strcmp(name, "bands") == 0) || (strcmp(name, "bands") == 0) ||
@@ -848,7 +847,7 @@ vips_pngsave_go(VipsImage *in, void **buf, size_t *len, int interlace, int quant
bitdepth = 2; bitdepth = 2;
} }
else { else {
bitdepth = vips_get_bits_per_sample(in); bitdepth = vips_get_palette_bit_depth(in);
if (bitdepth && bitdepth <= 8) { if (bitdepth && bitdepth <= 8) {
if (bitdepth > 4) if (bitdepth > 4)
bitdepth = 8; bitdepth = 8;
@@ -888,7 +887,7 @@ int
vips_gifsave_go(VipsImage *in, void **buf, size_t *len) vips_gifsave_go(VipsImage *in, void **buf, size_t *len)
{ {
#if VIPS_SUPPORT_GIFSAVE #if VIPS_SUPPORT_GIFSAVE
int bitdepth = vips_get_bits_per_sample(in); int bitdepth = vips_get_palette_bit_depth(in);
if (bitdepth <= 0 || bitdepth > 8) if (bitdepth <= 0 || bitdepth > 8)
bitdepth = 8; bitdepth = 8;
return vips_gifsave_buffer(in, buf, len, "bitdepth", bitdepth, NULL); return vips_gifsave_buffer(in, buf, len, "bitdepth", bitdepth, NULL);

View File

@@ -553,8 +553,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))) C.vips_image_set_blob_copy(img.VipsImage, cachedCString(name), unsafe.Pointer(&value[0]), C.size_t(len(value)))
} }
func (img *Image) RemoveBitsPerSampleHeader() { func (img *Image) RemovePaletteBitDepth() {
C.vips_remove_bits_per_sample(img.VipsImage) C.vips_remove_palette_bit_depth(img.VipsImage)
} }
func (img *Image) CastUchar() error { func (img *Image) CastUchar() error {

View File

@@ -32,7 +32,7 @@ void vips_strip_meta(VipsImage *image);
VipsBandFormat vips_band_format(VipsImage *in); VipsBandFormat vips_band_format(VipsImage *in);
void vips_remove_bits_per_sample(VipsImage *image); void vips_remove_palette_bit_depth(VipsImage *image);
gboolean vips_is_animated(VipsImage *in); gboolean vips_is_animated(VipsImage *in);