vipsthumbnail uses vips_premultiply()
This commit is contained in:
parent
65778237a9
commit
25bf910f21
@ -2,6 +2,7 @@
|
|||||||
- add vips_premultiply(), vips_unpremultiply()
|
- add vips_premultiply(), vips_unpremultiply()
|
||||||
- change the alpha range rules for vips_flatten() to match vips_premultiply()
|
- change the alpha range rules for vips_flatten() to match vips_premultiply()
|
||||||
- vipsthumbnail uses vips_resize() rather than its own code
|
- vipsthumbnail uses vips_resize() rather than its own code
|
||||||
|
- vipsthumbnail uses vips_premultiply() for better alpha quality
|
||||||
|
|
||||||
4/5/15 started 8.0.2
|
4/5/15 started 8.0.2
|
||||||
- fix a refcount error in C++ wrapper, thanks huskier
|
- fix a refcount error in C++ wrapper, thanks huskier
|
||||||
|
1
TODO
1
TODO
@ -1,3 +1,4 @@
|
|||||||
|
- get vipsthumbnail to use vips_premultiply() etc
|
||||||
|
|
||||||
- are the mosaic functions calling vips_fastcor()? it must be very slow
|
- are the mosaic functions calling vips_fastcor()? it must be very slow
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@
|
|||||||
* - rename -o as -f, keep -o as a hidden flag
|
* - rename -o as -f, keep -o as a hidden flag
|
||||||
* 9/5/15
|
* 9/5/15
|
||||||
* - use vips_resize() instead of our own code
|
* - use vips_resize() instead of our own code
|
||||||
|
* - premultiply alpha
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
@ -346,12 +347,15 @@ thumbnail_shrink( VipsObject *process, VipsImage *in,
|
|||||||
*/
|
*/
|
||||||
gboolean have_imported;
|
gboolean have_imported;
|
||||||
|
|
||||||
int shrink;
|
/* TRUE if we've premultiplied and need to unpremultiply.
|
||||||
double residual;
|
*/
|
||||||
int tile_width;
|
gboolean have_premultiplied;
|
||||||
int tile_height;
|
|
||||||
int nlines;
|
/* Sniff the incoming image and try to guess what the alpha max is.
|
||||||
double sigma;
|
*/
|
||||||
|
double max_alpha;
|
||||||
|
|
||||||
|
double shrink;
|
||||||
|
|
||||||
/* RAD needs special unpacking.
|
/* RAD needs special unpacking.
|
||||||
*/
|
*/
|
||||||
@ -365,6 +369,12 @@ 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
|
||||||
@ -409,17 +419,42 @@ thumbnail_shrink( VipsObject *process, VipsImage *in,
|
|||||||
return( NULL );
|
return( NULL );
|
||||||
in = t[2];
|
in = t[2];
|
||||||
|
|
||||||
shrink = calculate_shrink( in );
|
/* If there's an alpha, we have to premultiply before shrinking. See
|
||||||
|
* https://github.com/jcupitt/libvips/issues/291
|
||||||
vips_info( "vipsthumbnail", "resize by %d", shrink );
|
*/
|
||||||
vips_info( "vipsthumbnail", "%s interpolation",
|
have_premultiplied = FALSE;
|
||||||
VIPS_OBJECT_GET_CLASS( interp )->nickname );
|
if( in->Bands == 2 ||
|
||||||
|
(in->Bands == 4 && in->Type != VIPS_INTERPRETATION_CMYK) ||
|
||||||
if( vips_resize( in, &t[3], 1.0 / shrink,
|
in->Bands == 5 ) {
|
||||||
"interpolate", interp,
|
vips_info( "vipsthumbnail", "premultiplying alpha" );
|
||||||
|
if( vips_premultiply( in, &t[3],
|
||||||
|
"max_alpha", max_alpha,
|
||||||
NULL ) )
|
NULL ) )
|
||||||
return( NULL );
|
return( NULL );
|
||||||
in = t[3];
|
in = t[3];
|
||||||
|
have_premultiplied = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
shrink = calculate_shrink( in );
|
||||||
|
|
||||||
|
vips_info( "vipsthumbnail", "shrink by %g", shrink );
|
||||||
|
vips_info( "vipsthumbnail", "%s interpolation",
|
||||||
|
VIPS_OBJECT_GET_CLASS( interp )->nickname );
|
||||||
|
|
||||||
|
if( vips_resize( in, &t[4], 1.0 / shrink,
|
||||||
|
"interpolate", interp,
|
||||||
|
NULL ) )
|
||||||
|
return( NULL );
|
||||||
|
in = t[4];
|
||||||
|
|
||||||
|
if( have_premultiplied ) {
|
||||||
|
vips_info( "vipsthumbnail", "unpremultiplying alpha" );
|
||||||
|
if( vips_unpremultiply( in, &t[5],
|
||||||
|
"max_alpha", max_alpha,
|
||||||
|
NULL ) )
|
||||||
|
return( NULL );
|
||||||
|
in = t[5];
|
||||||
|
}
|
||||||
|
|
||||||
/* Colour management.
|
/* Colour management.
|
||||||
*
|
*
|
||||||
@ -500,8 +535,7 @@ thumbnail_shrink( VipsObject *process, VipsImage *in,
|
|||||||
/* If we are upsampling, don't sharpen, since nearest looks dumb
|
/* If we are upsampling, don't sharpen, since nearest looks dumb
|
||||||
* sharpened.
|
* sharpened.
|
||||||
*/
|
*/
|
||||||
if( shrink >= 1 &&
|
if( shrink > 1.0 &&
|
||||||
residual <= 1.0 &&
|
|
||||||
sharpen ) {
|
sharpen ) {
|
||||||
vips_info( "vipsthumbnail", "sharpening thumbnail" );
|
vips_info( "vipsthumbnail", "sharpening thumbnail" );
|
||||||
if( vips_conv( in, &t[8], sharpen, NULL ) )
|
if( vips_conv( in, &t[8], sharpen, NULL ) )
|
||||||
|
Loading…
Reference in New Issue
Block a user