Browse Source

Merge branch 'master' into version/3

DarthSim 4 years ago
parent
commit
f744e5c863
2 changed files with 22 additions and 2 deletions
  1. 21 1
      vips.c
  2. 1 1
      vips.go

+ 21 - 1
vips.c

@@ -1,5 +1,6 @@
 #include "vips.h"
 #include "vips.h"
 #include <string.h>
 #include <string.h>
+#include <math.h>
 
 
 #define VIPS_SUPPORT_ARRAY_HEADERS \
 #define VIPS_SUPPORT_ARRAY_HEADERS \
   (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 9))
   (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 9))
@@ -7,6 +8,9 @@
 #define VIPS_SUPPORT_AVIF \
 #define VIPS_SUPPORT_AVIF \
   (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 9))
   (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 9))
 
 
+#define VIPS_SUPPORT_PNG_BITDEPTH \
+  (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 10))
+
 int
 int
 vips_initialize() {
 vips_initialize() {
   return vips_init("imgproxy");
   return vips_init("imgproxy");
@@ -527,13 +531,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_BITDEPTH
+    "palette", quantize,
+    "bitdepth", bitdepth,
+#else // VIPS_SUPPORT_PNG_BITDEPTH
     "palette", quantize,
     "palette", quantize,
     "colours", colors,
     "colours", colors,
-    NULL);
+#endif // VIPS_SUPPORT_PNG_BITDEPTH
+    NULL
+  );
 }
 }
 
 
 int
 int

+ 1 - 1
vips.go

@@ -2,7 +2,7 @@ package main
 
 
 /*
 /*
 #cgo pkg-config: vips
 #cgo pkg-config: vips
-#cgo LDFLAGS: -s -w
+#cgo LDFLAGS: -s -w -lm
 #cgo CFLAGS: -O3
 #cgo CFLAGS: -O3
 #include "vips.h"
 #include "vips.h"
 */
 */