From 21a7c308a6dbd1de40d15a80cbe8f0acdf18a123 Mon Sep 17 00:00:00 2001 From: Nicolae Vartolomei Date: Mon, 12 Sep 2016 13:33:25 +0300 Subject: [PATCH] fix(flatten): fix flattening with background for 16bit transparent pngs --- vips.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vips.h b/vips.h index e3dc1c8..52895ef 100644 --- a/vips.h +++ b/vips.h @@ -244,11 +244,21 @@ vips_webpsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int qual ); } +int +vips_is_16bit (VipsInterpretation interpretation) { + return interpretation == VIPS_INTERPRETATION_RGB16 || interpretation == VIPS_INTERPRETATION_GREY16; +} + int vips_flatten_background_brigde(VipsImage *in, VipsImage **out, double background[3]) { + background[0] *= 256; + background[1] *= 256; + background[2] *= 256; + VipsArrayDouble *vipsBackground = vips_array_double_new(background, 3); return vips_flatten(in, out, "background", vipsBackground, + "max_alpha", vips_is_16bit(in->Type) ? 65535.0 : 255.0, NULL ); }