Browse Source

Fix PNG bitdepth

DarthSim 4 years ago
parent
commit
aa6edd13f6
2 changed files with 5 additions and 3 deletions
  1. 4 2
      vips.c
  2. 1 1
      vips.go

+ 4 - 2
vips.c

@@ -1,6 +1,5 @@
 #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))
@@ -654,7 +653,10 @@ vips_pngsave_go(VipsImage *in, void **buf, size_t *len, int interlace, int quant
       NULL
       NULL
     );
     );
 
 
-  int bitdepth = ceil(log2(colors));
+  int bitdepth = 1;
+  if (colors > 16) bitdepth = 8;
+  else if (colors > 4) bitdepth = 4;
+  else if (colors > 2) bitdepth = 2;
 
 
   return vips_pngsave_buffer(
   return vips_pngsave_buffer(
     in, buf, len,
     in, buf, len,

+ 1 - 1
vips.go

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