add vips_image_hasalpha()

This commit is contained in:
John Cupitt 2016-10-31 11:14:27 +00:00
parent 87928d4eba
commit 3f1f950bff
4 changed files with 23 additions and 3 deletions

View File

@ -3,6 +3,7 @@
- added tiff save to buffer
- added dzsave save to buffer (zip only)
- revise header get/set functions
- added vips_image_hasalpha()
18/10/16 started 8.4.3
- fix error detection in gif_close, thanks aaron42net

View File

@ -473,6 +473,7 @@ int vips_image_encode( VipsImage *in, VipsImage **out, VipsCoding coding );
gboolean vips_image_isMSBfirst( VipsImage *image );
gboolean vips_image_isfile( VipsImage *image );
gboolean vips_image_ispartial( VipsImage *image );
gboolean vips_image_hasalpha( VipsImage *image );
VipsImage *vips_image_copy_memory( VipsImage *image );
int vips_image_wio_input( VipsImage *image );

View File

@ -10,6 +10,8 @@
* - add vips_image_new_from_memory_copy()
* 10/6/16
* - vips_image_write() does not ref input for non-partial images
* 29/10/16
* - add vips_image_hasalpha()
*/
/*
@ -2775,6 +2777,24 @@ vips_image_ispartial( VipsImage *image )
return( 0 );
}
/**
* vips_image_hasalpha:
* @image: image to check
*
* libvips assumes an image has an alpha if it has two bands (ie. it is a
* monochrome image with an extra band), if it has four bands (unless it's been
* tagged as CMYK), or if it has more than four bands.
*
* Return %TRUE if @image has an alpha channel.
*/
gboolean
vips_image_hasalpha( VipsImage *image )
{
return( image->Bands == 2 ||
(image->Bands == 4 && image->Type != VIPS_INTERPRETATION_CMYK) ||
image->Bands > 4 );
}
/**
* vips_image_write_prepare:
* @image: image to prepare

View File

@ -432,9 +432,7 @@ thumbnail_shrink( VipsObject *process, VipsImage *in )
* https://github.com/jcupitt/libvips/issues/291
*/
have_premultiplied = FALSE;
if( in->Bands == 2 ||
(in->Bands == 4 && in->Type != VIPS_INTERPRETATION_CMYK) ||
in->Bands == 5 ) {
if( vips_image_hasalpha( in ) ) {
vips_info( "vipsthumbnail", "premultiplying alpha" );
if( vips_premultiply( in, &t[3], NULL ) )
return( NULL );