Skip to content

Commit

Permalink
layout fixes for tga sniff
Browse files Browse the repository at this point in the history
  • Loading branch information
jcupitt committed Nov 14, 2021
1 parent b3ff4d9 commit fef0240
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions libvips/foreign/magick.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand All @@ -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 );
}
Expand Down

0 comments on commit fef0240

Please sign in to comment.