diff --git a/ChangeLog b/ChangeLog index b0c342c9..015e2746 100644 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,7 @@ - allow nested [] in CLI args - restore BandFmt on unpremultiply in vipsthumbnail - better python detection and build [Felix Bünemann] +- max-alpha defaults to 65535 for RGB16/GREY16 18/5/16 started 8.3.2 - more robust vips image reading diff --git a/libvips/conversion/flatten.c b/libvips/conversion/flatten.c index 486515d3..9c86de62 100644 --- a/libvips/conversion/flatten.c +++ b/libvips/conversion/flatten.c @@ -7,6 +7,8 @@ * - better rounding * 9/5/15 * - add max_alpha to match vips_premultiply() etc. + * 25/5/16 + * - max_alpha defaults to 65535 for RGB16/GREY16 */ /* @@ -320,6 +322,14 @@ vips_flatten_build( VipsObject *object ) conversion->out->Bands -= 1; + /* Is max-alpha unset? Default to the correct value for this + * interpretation. + */ + if( !vips_object_argument_isset( object, "max_alpha" ) ) + if( in->Type == VIPS_INTERPRETATION_GREY16 || + in->Type == VIPS_INTERPRETATION_RGB16 ) + flatten->max_alpha = 65535; + /* Is the background black? We have a special path for this. */ black = TRUE; @@ -421,9 +431,9 @@ vips_flatten_init( VipsFlatten *flatten ) * Non-complex images only. * @background defaults to zero (black). * - * @max_alpha has the default value 255. You will need to set this to 65535 - * for images with a 16-bit alpha, or perhaps 1.0 for images with a float - * alpha. + * @max_alpha has the default value 255, or 65535 for images tagged as + * #VIPS_INTERPRETATION_RGB16 or + * #VIPS_INTERPRETATION_GREY16. * * Useful for flattening PNG images to RGB. * diff --git a/libvips/conversion/premultiply.c b/libvips/conversion/premultiply.c index 7923100e..3999e6c9 100644 --- a/libvips/conversion/premultiply.c +++ b/libvips/conversion/premultiply.c @@ -5,6 +5,8 @@ * * 11/4/16 Lovell * - fix RGBA path + * 25/5/16 + * - max_alpha defaults to 65535 for RGB16/GREY16 */ /* @@ -214,6 +216,14 @@ vips_premultiply_build( VipsObject *object ) VIPS_DEMAND_STYLE_THINSTRIP, in, NULL ) ) return( -1 ); + /* Is max-alpha unset? Default to the correct value for this + * interpretation. + */ + if( !vips_object_argument_isset( object, "max_alpha" ) ) + if( in->Type == VIPS_INTERPRETATION_GREY16 || + in->Type == VIPS_INTERPRETATION_RGB16 ) + premultiply->max_alpha = 65535; + if( in->BandFmt == VIPS_FORMAT_DOUBLE ) conversion->out->BandFmt = VIPS_FORMAT_DOUBLE; else @@ -294,9 +304,9 @@ vips_premultiply_init( VipsPremultiply *premultiply ) * #VIPS_FORMAT_FLOAT unless the input format is #VIPS_FORMAT_DOUBLE, in which * case the output is double as well. * - * @max_alpha has the default value 255. You will need to set this to 65535 - * for images with a 16-bit alpha, or perhaps 1.0 for images with a float - * alpha. + * @max_alpha has the default value 255, or 65535 for images tagged as + * #VIPS_INTERPRETATION_RGB16 or + * #VIPS_INTERPRETATION_GREY16. * * Non-complex images only. * diff --git a/libvips/conversion/unpremultiply.c b/libvips/conversion/unpremultiply.c index c7857c02..39623bab 100644 --- a/libvips/conversion/unpremultiply.c +++ b/libvips/conversion/unpremultiply.c @@ -3,6 +3,8 @@ * Author: John Cupitt * Written on: 7/5/15 * + * 25/5/16 + * - max_alpha defaults to 65535 for RGB16/GREY16 */ /* @@ -223,6 +225,14 @@ vips_unpremultiply_build( VipsObject *object ) VIPS_DEMAND_STYLE_THINSTRIP, in, NULL ) ) return( -1 ); + /* Is max-alpha unset? Default to the correct value for this + * interpretation. + */ + if( !vips_object_argument_isset( object, "max_alpha" ) ) + if( in->Type == VIPS_INTERPRETATION_GREY16 || + in->Type == VIPS_INTERPRETATION_RGB16 ) + unpremultiply->max_alpha = 65535; + if( in->BandFmt == VIPS_FORMAT_DOUBLE ) conversion->out->BandFmt = VIPS_FORMAT_DOUBLE; else @@ -307,9 +317,9 @@ vips_unpremultiply_init( VipsUnpremultiply *unpremultiply ) * #VIPS_FORMAT_FLOAT unless the input format is #VIPS_FORMAT_DOUBLE, in which * case the output is double as well. * - * @max_alpha has the default value 255. You will need to set this to 65535 - * for images with a 16-bit alpha, or perhaps 1.0 for images with a float - * alpha. + * @max_alpha has the default value 255, or 65535 for images tagged as + * #VIPS_INTERPRETATION_RGB16 or + * #VIPS_INTERPRETATION_GREY16. * * Non-complex images only. * diff --git a/libvips/foreign/foreign.c b/libvips/foreign/foreign.c index e51d2b17..0f8f05d2 100644 --- a/libvips/foreign/foreign.c +++ b/libvips/foreign/foreign.c @@ -12,6 +12,8 @@ * - fix conversion to 16-bit RGB, thanks John * 18/6/15 * - forward progress signals from load + * 23/5/16 + * - remove max-alpha stuff, this is now automatic */ /* @@ -1214,9 +1216,6 @@ vips_foreign_convert_saveable( VipsForeignSave *save ) if( vips_flatten( in, &out, "background", save->background, - "max_alpha", - in->BandFmt == VIPS_FORMAT_USHORT ? - 65535.0 : 255.0, NULL ) ) { g_object_unref( in ); return( -1 ); diff --git a/tools/vipsthumbnail.c b/tools/vipsthumbnail.c index 9949846d..23b53dea 100644 --- a/tools/vipsthumbnail.c +++ b/tools/vipsthumbnail.c @@ -79,6 +79,8 @@ * - deprecate sharpen and interpolate * 6/5/16 * - restore BandFmt after unpremultiply + * 23/5/16 + * - no need to guess max-alpha now premultiply does this for us */ #ifdef HAVE_CONFIG_H @@ -367,10 +369,6 @@ thumbnail_shrink( VipsObject *process, VipsImage *in ) gboolean have_premultiplied; VipsBandFormat unpremultiplied_format; - /* Sniff the incoming image and try to guess what the alpha max is. - */ - double max_alpha; - double shrink; /* RAD needs special unpacking. @@ -385,12 +383,6 @@ thumbnail_shrink( VipsObject *process, VipsImage *in ) in = t[0]; } - /* Try to guess what the maximum alpha might be. - */ - max_alpha = 255; - if( in->BandFmt == VIPS_FORMAT_USHORT ) - max_alpha = 65535; - /* In linear mode, we import right at the start. * * We also have to import the whole image if it's CMYK, since @@ -443,9 +435,7 @@ thumbnail_shrink( VipsObject *process, VipsImage *in ) (in->Bands == 4 && in->Type != VIPS_INTERPRETATION_CMYK) || in->Bands == 5 ) { vips_info( "vipsthumbnail", "premultiplying alpha" ); - if( vips_premultiply( in, &t[3], - "max_alpha", max_alpha, - NULL ) ) + if( vips_premultiply( in, &t[3], NULL ) ) return( NULL ); have_premultiplied = TRUE; @@ -465,9 +455,7 @@ thumbnail_shrink( VipsObject *process, VipsImage *in ) if( have_premultiplied ) { vips_info( "vipsthumbnail", "unpremultiplying alpha" ); - if( vips_unpremultiply( in, &t[5], - "max_alpha", max_alpha, - NULL ) || + if( vips_unpremultiply( in, &t[5], NULL ) || vips_cast( t[5], &t[6], unpremultiplied_format, NULL ) ) return( NULL ); in = t[6];