From 4bcbcbbf49c7c64f032fab32d6827a508ecf4173 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Thu, 23 Feb 2017 20:05:35 +0000 Subject: [PATCH] try to fix IM load of ico files 8-bit ico files were being reported at 32-bit, because we used the ->depth field to get pixel depth try using GetImageChannelDepth() instead, who knows, it might work see https://github.com/jcupitt/php-vips/issues/34 --- libvips/foreign/magick2vips.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/libvips/foreign/magick2vips.c b/libvips/foreign/magick2vips.c index 4fd466e1..f0fa26aa 100644 --- a/libvips/foreign/magick2vips.c +++ b/libvips/foreign/magick2vips.c @@ -53,6 +53,8 @@ * - fix @page with graphicsmagick * 25/11/16 * - remove @all_frames, add @n + * 23/2/17 + * - try using GetImageChannelDepth() instead of ->depth */ /* @@ -304,6 +306,7 @@ parse_header( Read *read ) VipsImage *im = read->im; Image *image = read->image; + int depth; Image *p; int i; @@ -332,28 +335,33 @@ parse_header( Read *read ) if( (im->Bands = get_bands( image )) < 0 ) return( -1 ); - /* Depth can be 'fractional'. You'd think we should use + /* Depth can be 'fractional'. + * + * You'd think we should use * GetImageDepth() but that seems unreliable. 16-bit mono DICOM images * are reported as depth 1, for example. + * + * Try GetImageChannelDepth(), maybe that works. */ + depth = GetImageChannelDepth( image, AllChannels, &image->exception ); im->BandFmt = -1; - if( image->depth >= 1 && image->depth <= 8 ) + if( depth >= 1 && depth <= 8 ) im->BandFmt = VIPS_FORMAT_UCHAR; - if( image->depth >= 9 && image->depth <= 16 ) + if( depth >= 9 && depth <= 16 ) im->BandFmt = VIPS_FORMAT_USHORT; #ifdef UseHDRI - if( image->depth == 32 ) + if( depth == 32 ) im->BandFmt = VIPS_FORMAT_FLOAT; - if( image->depth == 64 ) + if( depth == 64 ) im->BandFmt = VIPS_FORMAT_DOUBLE; #else /*!UseHDRI*/ - if( image->depth == 32 ) + if( depth == 32 ) im->BandFmt = VIPS_FORMAT_UINT; #endif /*UseHDRI*/ if( im->BandFmt == -1 ) { vips_error( "magick2vips", _( "unsupported bit depth %d" ), - (int) image->depth ); + (int) depth ); return( -1 ); }