Browse Source

Preserve GIF bit-per-sample

DarthSim 1 year ago
parent
commit
39c436e527
2 changed files with 6 additions and 1 deletions
  1. 3 0
      CHANGELOG.md
  2. 3 1
      vips/vips.c

+ 3 - 0
CHANGELOG.md

@@ -4,6 +4,9 @@
 ### Add
 - Add `IMGPROXY_URL_REPLACEMENTS` config.
 
+### Change
+- Preserve GIF's bit-per-sample.
+
 ## [3.17.0] - 2023-05-10
 ### Add
 - Add `process_resident_memory_bytes`, `process_virtual_memory_bytes`, `go_memstats_sys_bytes`, `go_memstats_heap_idle_bytes`, `go_memstats_heap_inuse_bytes`, `go_goroutines`, `go_threads`, `buffer_default_size_bytes`, `buffer_max_size_bytes`, and `buffer_size_bytes` metrics to OpenTelemetry.

+ 3 - 1
vips/vips.c

@@ -712,7 +712,9 @@ vips_webpsave_go(VipsImage *in, void **buf, size_t *len, int quality) {
 int
 vips_gifsave_go(VipsImage *in, void **buf, size_t *len) {
 #if VIPS_SUPPORT_GIFSAVE
-  return vips_gifsave_buffer(in, buf, len, NULL);
+  int bitdepth = vips_get_bits_per_sample(in);
+  if (bitdepth <= 0 || bitdepth > 8 ) bitdepth = 8;
+  return vips_gifsave_buffer(in, buf, len, "bitdepth", bitdepth, NULL);
 #else
   vips_error("vips_gifsave_go", "Saving GIF is not supported (libvips 8.12+ reuired)");
   return 1;