POV-Ray : Newsgroups : povray.general : hacking TARGA the easy way : Re: hacking TARGA the easy way Server Time
9 Aug 2024 03:23:01 EDT (-0400)
  Re: hacking TARGA the easy way  
From: Jon A  Cruz
Date: 29 Aug 2000 12:27:26
Message: <39ABE4AE.D6B4D7D0@geocities.com>
Christoph Hormann wrote:

> Warp wrote:
> >
> >   The raw targa file format outputted by povray is extremely simple. It has
> > 18 bytes of header data at the beginning and then the image follows as raw
> > data. I don't remember which pair of 16 bits of the header data tells the
> > dimensions of the image but that should be easy to discover (either by
> > lookin it up in some spec or by examining the header directly with a
> > hex editor (and knowing the dimensions of the image)).
> >
>
> As i already posted in p.b.i some time ago, the tga header has the following
> form (pascal/delphi syntax):
>
>    T_TGA_header = packed record
>     ID_size: Byte;            { ID-Field                   }
>     Palette: Byte;            { 1= Palette exists          }
>     Typ: Byte;                { Type (Mono, Color, compr.) }
>     Pal_index: Word;
>     Pal_size: Word;
>     Pal_entry_size: Byte;
>     Lx    : Word;
>     Ly    : Word;
>     cX    : Word;             { Width                      }
>     cY    : Word;             { Height                     }
>     Bppix : Byte;             { Bits per Pixel - 1, 8, 24  }
>     Image_des: Byte;          { Image Descriptor Flag      }
>    end;
>
> If Palette is 1 this if followed by a 3x256 byte palette of rgb triples.
> Otherwise only the raw data array is appended (RLE compression in some cases,
> but that should not be neccessary here).

Just a few minor clarifications from the specs:

In this usage, Word is 2 bytes and stored in little-endian (Intel) format.

ID-Field is the number of bytes in the image ID field. Could be up to 255,
although 0 (no id string) is most common.

The Image ID (if present) comes after the 18 byte header and before the color
map. If this value is not zero, the not skipping that many bytes will mess up
your read.

The values for type are:
    0 - no image data
    1 - uncompressed color mapped
    2 - uncompressed true color
    3 - uncompressed black & white
    9 - RLE color mapped
    10 - RLE true color
    11 - RLE black & white

Pal_entry_size is in bits per entry. often 15, 16, 24 or 32.

The palette is not always 3x256. It is # of entries times entry size in bytes.
Or
((Pal_entry_size + 7) >> 3) * Pal_size

Lx and Ly are the offset of the start position of the image. (i.e. the place to
start drawing the image if it's a sprite). Usually this can be ignored.

The Image Descriptor Flag is broken into three parts, one of which is unused.
bits 3-0 are the # of bits for the alpha channel.
bits 4-5 are the image orgin
bits 6-7 are unused.

If bit 4 is set, the image data starts on the right, if bit 4 is clear, the
image data starts on the left.
If bit 5 is set, the image data starts at the top, if bit 5 is clear, the image
data starts at the bottom.


Post a reply to this message

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