POV-Ray : Newsgroups : povray.programming : targa files Server Time
21 Dec 2024 20:18:55 EST (-0500)
  targa files (Message 1 to 2 of 2)  
From: Anthony D  Baye
Subject: targa files
Date: 9 May 2007 12:25:02
Message: <web.4641f5aef5584801a7a033310@news.povray.org>
Can anybody tell me how to positively identify a targa file other than by
it's extension?

Reading the specification, there are a number of things I can look at, but
there are no "Magic numbers" or format identifiers in the 1.0 spec that I
can see.  The 2.0 spec contains an ID block in the footer, but I haven't
yet run into any files using this spec.

Any help you can provide would be appreciated.


Regards,

ADB


Post a reply to this message

From: Warp
Subject: Re: targa files
Date: 9 May 2007 12:49:32
Message: <4641fb9c@news.povray.org>
Anthony D. Baye <Sha### [at] spamnomorehotmailcom> wrote:
> Can anybody tell me how to positively identify a targa file other than by
> it's extension?

  You can make an "educated guess" by examining the first 18 bytes of
the file (ie. its header).

  For instance, (I'm indexing starting with 0 here) byte 1 should usually
have the value of 0 or 1. If it has anything else it's either not a tga
or a non-standard one.
  Byte 2 should have one of these values: 0, 1, 2, 3, 9, 10, 11, 32 or 33.
If it has anything else, it's probably not a standard tga.
  If byte 1 was 1, then byte 7 should be 16, 24 or 32.
  The two-byte words at byte 12 and 14 should look reasonable width and
height values. Eg. 0 would probably be a suspicious value. You could also
check that the file size is large enough to really contain that many pixels
(with the specified bit depth), unless it's a compressed image (which was
specified at byte 2), in which case it becomes more complicated to check.
  Byte 16 should be 16, 24 or 32.
  The three lowest bits of byte 17 should form 0, 1 or 8.

  If you want to build a heuristical algorithm, you could give each
successful test above a point, and if a file passes it with full points
there's a really high probability it's a genuine tga file. If one or two
tests fail, then you either have to make additional tests or decide at
random. If most tests fail, it's most probably not a tga file.

  If you want to increase the probability of a correct positive guess,
you could proceed to interpret the actual image data. You could check
that it contains at least as many pixels as the header states (you'll
have to decompress if the header states that it's compressed), and if
the header claims it's a paletted image, you can check that there are
enough values in the file for those too.
  Obviously if the file doesn't contain enough data for it to contain
the full image (even though the header seemed to be one of a tga), then
it's either a broken tga or not a tga at all.

  Note, however, that you probably can't deduce anything if the file is
larger than necessary because it may well be that some programs attach
additional non-standard data to the end of the file.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.