소스 검색

Use VIPS_META_BITS_PER_SAMPLE image header instead of palette-bit-depth when available

DarthSim 1 년 전
부모
커밋
157843ccb3
4개의 변경된 파일22개의 추가작업 그리고 11개의 파일을 삭제
  1. 1 1
      processing/watermark.go
  2. 17 8
      vips/vips.c
  3. 2 2
      vips/vips.go
  4. 2 0
      vips/vips.h

+ 1 - 1
processing/watermark.go

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

+ 17 - 8
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;

+ 2 - 2
vips/vips.go

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

+ 2 - 0
vips/vips.h

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