better max_alpha default

it used to default to 255, now it sniff the interpretation and defaults to
65535 for RGB16 and GREY16

see https://github.com/jcupitt/libvips/issues/449
This commit is contained in:
John Cupitt 2016-05-23 12:18:39 +01:00
parent 445d419efb
commit dbbd2850a1
6 changed files with 46 additions and 28 deletions

View File

@ -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

View File

@ -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.
*

View File

@ -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.
*

View File

@ -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.
*

View File

@ -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 );

View File

@ -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];