layout fixes for tga sniff

This commit is contained in:
John Cupitt 2021-11-14 04:09:23 +00:00
parent b3ff4d9ed6
commit fef024061f

View File

@ -52,14 +52,15 @@
#if defined(HAVE_MAGICK6) || defined(HAVE_MAGICK7)
/* ImageMagick can't detect some formats, like ICO and TGA, by examining the contents --
* ico.c and tga.c simply do not have recognisers.
/* ImageMagick can't detect some formats, like ICO and TGA, by examining the
* contents -- ico.c and tga.c simply do not have recognisers.
*
* For these formats, do the detection ourselves.
* Return an IM format specifier, or NULL to let IM do the detection.
*
* For sniffing TGAs, we check that there is at least enough room for the header and that
* the preamble contains valid values:
* For sniffing TGAs, we check that there is at least enough room for the
* header and that the preamble contains valid values:
*
* -----------------------------------------------------------
* |0x00 | 0-255 idlength, skip |
* |0x01 | 0-1, color map present |
@ -80,16 +81,18 @@ magick_sniff( const unsigned char *bytes, size_t length )
bytes[2] == 1 &&
bytes[3] == 0 )
return( "ICO" );
if( length >= 18 &&
(bytes[1] == 0 || bytes[1] == 1) && (
bytes[2] == 0 ||
bytes[2] == 1 ||
bytes[2] == 2 ||
bytes[2] == 3 ||
bytes[2] == 9 ||
bytes[2] == 10 ||
bytes[2] == 11) )
return( "TGA" );
if( length >= 18 &&
(bytes[1] == 0 ||
bytes[1] == 1) &&
(bytes[2] == 0 ||
bytes[2] == 1 ||
bytes[2] == 2 ||
bytes[2] == 3 ||
bytes[2] == 9 ||
bytes[2] == 10 ||
bytes[2] == 11) )
return( "TGA" );
return( NULL );
}