NAME

tga.c - implements reading and writing targa files, uses io layer.

SYNOPSIS

io_glue *ig = io_new_fd( fd );
i_img *im   = i_readtga_wiol(ig, -1); // no limit on how much is read
// or 
io_glue *ig = io_new_fd( fd );
return_code = i_writetga_wiol(im, ig); 

DESCRIPTION

tga.c implements the basic functions to read and write portable targa files. It uses the iolayer and needs either a seekable source or an entire memory mapped buffer.

FUNCTION REFERENCE

Some of these functions are internal.

bpp_to_bytes(bpp)

Convert bits per pixel into bytes per pixel

bpp - bits per pixel
bpp_to_channels(bpp)

Convert bits per pixel and the number of attribute bits into channels in the image

bpp - bits per pixel
attr_bit_count - number of attribute bits
color_unpack(buf, bytepp, val)

Unpacks bytes into colour structures, for 2 byte type the first byte coming from the file will actually be GGGBBBBB, and the second will be ARRRRRGG. "A" represents an attribute bit. The 3 byte entry contains 1 byte each of blue, green, and red. The 4 byte entry contains 1 byte each of blue, green, red, and attribute.

buf - pointer to data
bytepp - bytes per pixel
val - pointer to color to store to
color_pack

Packs a colour into an array of bytes, for 2 byte type the first byte will be GGGBBBBB, and the second will be ARRRRRGG. "A" represents an attribute bit. The 3 byte entry contains 1 byte each of blue, green, and red. The 4 byte entry contains 1 byte each of blue, green, red, and attribute.

buf - destination buffer
bitspp - bits per pixel
val - color to pack
find_repeat

Helper function for rle compressor to find the next triple repeat of the same pixel value in buffer.

buf - buffer
length - number of pixel values in buffer
bytepp - number of bytes in a pixel value
find_span

Helper function for rle compressor to find the length of a span where the same pixel value is in the buffer.

buf - buffer
length - number of pixel values in buffer
bytepp - number of bytes in a pixel value
tga_header_unpack(header, headbuf)

Unpacks the header structure into from buffer and stores in the header structure.

header - header structure
headbuf - buffer to unpack from
tga_header_pack(header, headbuf)

Packs header structure into buffer for writing.

header - header structure
headbuf - buffer to pack into
tga_source_read(s, buf, pixels)

Reads pixel number of pixels from source s into buffer buf. Takes care of decompressing the stream if needed.

s - data source 
buf - destination buffer
pixels - number of pixels to put into buffer
tga_dest_write(s, buf, pixels)

Writes pixels from buf to destination s. Takes care of compressing if the destination is compressed.

s - data destination
buf - source buffer
pixels - number of pixels to put write to destination
tga_palette_read(ig, img, bytepp, colourmaplength)

Reads the colormap from a tga file and stores in the paletted image structure.

ig - iolayer data source
img - image structure
bytepp - bytes per pixel
colourmaplength - number of colours in colourmap
tga_palette_write(ig, img, bitspp, colourmaplength)

Stores the colormap of an image in the destination ig.

ig - iolayer data source
img - image structure
bitspp - bits per pixel in colourmap
colourmaplength - number of colours in colourmap
i_readtga_wiol(ig, length)

Read in an image from the iolayer data source and return the image structure to it. Returns NULL on error.

ig     - io_glue object
length - maximum length to read from data source, before closing it -1 
         signifies no limit.
i_writetga_wiol(img, ig)

Writes an image in targa format. Returns 0 on error.

img    - image to store
ig     - io_glue object

AUTHOR

Arnar M. Hrafnkelsson <addi@umich.edu>

SEE ALSO

Imager(3)