GNOME Bugzilla – Bug 133798
Improve magic file format detection for TGA
Last modified: 2007-03-17 19:48:46 UTC
From Debian bug report http://bugs.debian.org/231525 When opening a file with a .tga extension and selecting an Automatic file type, GIMP always thinks it is a Targa file, which can result in an error if the file is just mislabeled and is really in another format. Files with other extensions like .bmp, .png, or .jpg don't have this problem and are automatically detected properly. This bug has been present since at least the 1.2 series.
Does the targa image format have a recognizeable header at all? If not, there's nothing else we can do and this is NOTABUG. Otherwise it's an enhancement request for improving the tga file loader plug-in.
Seems like it; look at /usr/share/misc/file/magic: #------------------------------------------------------------------------------ # images: file(1) magic for image formats (see also "iff") # # originally from jef@helios.ee.lbl.gov (Jef Poskanzer), # additions by janl@ifi.uio.no as well as others. Jan also suggested # merging several one- and two-line files into here. # # little magic: PCX (first byte is 0x0a) # Targa - matches `povray', `ppmtotga' and `xv' outputs # by Philippe De Muyter <phdm@macqel.be> # at 2, byte ImgType must be 1, 2, 3, 9, 10 or 11 # at 1, byte CoMapType must be 1 if ImgType is 1 or 9, 0 otherwise # at 3, leshort Index is 0 for povray, ppmtotga and xv outputs # `xv' recognizes only a subset of the following (RGB with pixelsize = 24) # `tgatoppm' recognizes a superset (Index may be anything) 1 belong&0xfff7ffff 0x01010000 Targa image data - Map >2 byte&8 8 - RLE >12 leshort >0 %hd x >14 leshort >0 %hd 1 belong&0xfff7ffff 0x00020000 Targa image data - RGB >2 byte&8 8 - RLE >12 leshort >0 %hd x >14 leshort >0 %hd 1 belong&0xfff7ffff 0x00030000 Targa image data - Mono >2 byte&8 8 - RLE >12 leshort >0 %hd x >14 leshort >0 %hd
From looking at the code of the plug-in, it doesn't seem to be that easy. As explained in here: http://www.opennet.ru/docs/formats/targa.pdf the file format is optionally identified by a footer and I am afraid GIMP is not prepared for this. What we could do is to add a check for the header (if someone can come up with a check that fits into GIMP's handling of magic file headers) and ignore the footer part. Files not matching the header would then be matched by the extension after all other file magics have been checked.
fixed in svn (r22138): 2007-03-17 Michael Natterer <mitch@gimp.org> * app/file/file-utils.c (file_check_single_magic): alow negative offsets in magics and interpret them as relative to the end of the file. (file_utils_find_proc) (file_check_magic_list): some cleanup. * plug-ins/common/tga.c (query): register the magic string "TRUEVISION-XFILE.\0" 18 bytes before the end of the file. This way, "new style" TGA files are detected regardless of their filename. "old style" TGA files still need the right extension to be treated as TGA. Added "vda", "icb" and "vst" to the list of extensions. Fixes bug #133798.