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:
parent
445d419efb
commit
dbbd2850a1
@ -7,6 +7,7 @@
|
|||||||
- allow nested [] in CLI args
|
- allow nested [] in CLI args
|
||||||
- restore BandFmt on unpremultiply in vipsthumbnail
|
- restore BandFmt on unpremultiply in vipsthumbnail
|
||||||
- better python detection and build [Felix Bünemann]
|
- better python detection and build [Felix Bünemann]
|
||||||
|
- max-alpha defaults to 65535 for RGB16/GREY16
|
||||||
|
|
||||||
18/5/16 started 8.3.2
|
18/5/16 started 8.3.2
|
||||||
- more robust vips image reading
|
- more robust vips image reading
|
||||||
|
@ -7,6 +7,8 @@
|
|||||||
* - better rounding
|
* - better rounding
|
||||||
* 9/5/15
|
* 9/5/15
|
||||||
* - add max_alpha to match vips_premultiply() etc.
|
* - 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;
|
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.
|
/* Is the background black? We have a special path for this.
|
||||||
*/
|
*/
|
||||||
black = TRUE;
|
black = TRUE;
|
||||||
@ -421,9 +431,9 @@ vips_flatten_init( VipsFlatten *flatten )
|
|||||||
* Non-complex images only.
|
* Non-complex images only.
|
||||||
* @background defaults to zero (black).
|
* @background defaults to zero (black).
|
||||||
*
|
*
|
||||||
* @max_alpha has the default value 255. You will need to set this to 65535
|
* @max_alpha has the default value 255, or 65535 for images tagged as
|
||||||
* for images with a 16-bit alpha, or perhaps 1.0 for images with a float
|
* #VIPS_INTERPRETATION_RGB16 or
|
||||||
* alpha.
|
* #VIPS_INTERPRETATION_GREY16.
|
||||||
*
|
*
|
||||||
* Useful for flattening PNG images to RGB.
|
* Useful for flattening PNG images to RGB.
|
||||||
*
|
*
|
||||||
|
@ -5,6 +5,8 @@
|
|||||||
*
|
*
|
||||||
* 11/4/16 Lovell
|
* 11/4/16 Lovell
|
||||||
* - fix RGBA path
|
* - 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 ) )
|
VIPS_DEMAND_STYLE_THINSTRIP, in, NULL ) )
|
||||||
return( -1 );
|
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 )
|
if( in->BandFmt == VIPS_FORMAT_DOUBLE )
|
||||||
conversion->out->BandFmt = VIPS_FORMAT_DOUBLE;
|
conversion->out->BandFmt = VIPS_FORMAT_DOUBLE;
|
||||||
else
|
else
|
||||||
@ -294,9 +304,9 @@ vips_premultiply_init( VipsPremultiply *premultiply )
|
|||||||
* #VIPS_FORMAT_FLOAT unless the input format is #VIPS_FORMAT_DOUBLE, in which
|
* #VIPS_FORMAT_FLOAT unless the input format is #VIPS_FORMAT_DOUBLE, in which
|
||||||
* case the output is double as well.
|
* case the output is double as well.
|
||||||
*
|
*
|
||||||
* @max_alpha has the default value 255. You will need to set this to 65535
|
* @max_alpha has the default value 255, or 65535 for images tagged as
|
||||||
* for images with a 16-bit alpha, or perhaps 1.0 for images with a float
|
* #VIPS_INTERPRETATION_RGB16 or
|
||||||
* alpha.
|
* #VIPS_INTERPRETATION_GREY16.
|
||||||
*
|
*
|
||||||
* Non-complex images only.
|
* Non-complex images only.
|
||||||
*
|
*
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
* Author: John Cupitt
|
* Author: John Cupitt
|
||||||
* Written on: 7/5/15
|
* 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 ) )
|
VIPS_DEMAND_STYLE_THINSTRIP, in, NULL ) )
|
||||||
return( -1 );
|
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 )
|
if( in->BandFmt == VIPS_FORMAT_DOUBLE )
|
||||||
conversion->out->BandFmt = VIPS_FORMAT_DOUBLE;
|
conversion->out->BandFmt = VIPS_FORMAT_DOUBLE;
|
||||||
else
|
else
|
||||||
@ -307,9 +317,9 @@ vips_unpremultiply_init( VipsUnpremultiply *unpremultiply )
|
|||||||
* #VIPS_FORMAT_FLOAT unless the input format is #VIPS_FORMAT_DOUBLE, in which
|
* #VIPS_FORMAT_FLOAT unless the input format is #VIPS_FORMAT_DOUBLE, in which
|
||||||
* case the output is double as well.
|
* case the output is double as well.
|
||||||
*
|
*
|
||||||
* @max_alpha has the default value 255. You will need to set this to 65535
|
* @max_alpha has the default value 255, or 65535 for images tagged as
|
||||||
* for images with a 16-bit alpha, or perhaps 1.0 for images with a float
|
* #VIPS_INTERPRETATION_RGB16 or
|
||||||
* alpha.
|
* #VIPS_INTERPRETATION_GREY16.
|
||||||
*
|
*
|
||||||
* Non-complex images only.
|
* Non-complex images only.
|
||||||
*
|
*
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
* - fix conversion to 16-bit RGB, thanks John
|
* - fix conversion to 16-bit RGB, thanks John
|
||||||
* 18/6/15
|
* 18/6/15
|
||||||
* - forward progress signals from load
|
* - 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,
|
if( vips_flatten( in, &out,
|
||||||
"background", save->background,
|
"background", save->background,
|
||||||
"max_alpha",
|
|
||||||
in->BandFmt == VIPS_FORMAT_USHORT ?
|
|
||||||
65535.0 : 255.0,
|
|
||||||
NULL ) ) {
|
NULL ) ) {
|
||||||
g_object_unref( in );
|
g_object_unref( in );
|
||||||
return( -1 );
|
return( -1 );
|
||||||
|
@ -79,6 +79,8 @@
|
|||||||
* - deprecate sharpen and interpolate
|
* - deprecate sharpen and interpolate
|
||||||
* 6/5/16
|
* 6/5/16
|
||||||
* - restore BandFmt after unpremultiply
|
* - restore BandFmt after unpremultiply
|
||||||
|
* 23/5/16
|
||||||
|
* - no need to guess max-alpha now premultiply does this for us
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
@ -367,10 +369,6 @@ thumbnail_shrink( VipsObject *process, VipsImage *in )
|
|||||||
gboolean have_premultiplied;
|
gboolean have_premultiplied;
|
||||||
VipsBandFormat unpremultiplied_format;
|
VipsBandFormat unpremultiplied_format;
|
||||||
|
|
||||||
/* Sniff the incoming image and try to guess what the alpha max is.
|
|
||||||
*/
|
|
||||||
double max_alpha;
|
|
||||||
|
|
||||||
double shrink;
|
double shrink;
|
||||||
|
|
||||||
/* RAD needs special unpacking.
|
/* RAD needs special unpacking.
|
||||||
@ -385,12 +383,6 @@ thumbnail_shrink( VipsObject *process, VipsImage *in )
|
|||||||
in = t[0];
|
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.
|
/* In linear mode, we import right at the start.
|
||||||
*
|
*
|
||||||
* We also have to import the whole image if it's CMYK, since
|
* 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 == 4 && in->Type != VIPS_INTERPRETATION_CMYK) ||
|
||||||
in->Bands == 5 ) {
|
in->Bands == 5 ) {
|
||||||
vips_info( "vipsthumbnail", "premultiplying alpha" );
|
vips_info( "vipsthumbnail", "premultiplying alpha" );
|
||||||
if( vips_premultiply( in, &t[3],
|
if( vips_premultiply( in, &t[3], NULL ) )
|
||||||
"max_alpha", max_alpha,
|
|
||||||
NULL ) )
|
|
||||||
return( NULL );
|
return( NULL );
|
||||||
have_premultiplied = TRUE;
|
have_premultiplied = TRUE;
|
||||||
|
|
||||||
@ -465,9 +455,7 @@ thumbnail_shrink( VipsObject *process, VipsImage *in )
|
|||||||
|
|
||||||
if( have_premultiplied ) {
|
if( have_premultiplied ) {
|
||||||
vips_info( "vipsthumbnail", "unpremultiplying alpha" );
|
vips_info( "vipsthumbnail", "unpremultiplying alpha" );
|
||||||
if( vips_unpremultiply( in, &t[5],
|
if( vips_unpremultiply( in, &t[5], NULL ) ||
|
||||||
"max_alpha", max_alpha,
|
|
||||||
NULL ) ||
|
|
||||||
vips_cast( t[5], &t[6], unpremultiplied_format, NULL ) )
|
vips_cast( t[5], &t[6], unpremultiplied_format, NULL ) )
|
||||||
return( NULL );
|
return( NULL );
|
||||||
in = t[6];
|
in = t[6];
|
||||||
|
Loading…
Reference in New Issue
Block a user