/**************************************************************************
 *{@C
 *      Copyright:      1988-2024 Paul Obermeier (obermeier@poSoft.de)
 *
 *      Module:         FileFormats
 *      Filename:       FF_ImageTarga.h
 *
 *      Author:         Paul Obermeier
 *
 *      Description:    Functions for reading and writing image files in
 *                      Truevsision's Targa file format.
 *
 *      Additional documentation:
 *                      None.
 *
 **************************************************************************/

#ifndef __FF_IMAGETARGA_H__
#define __FF_IMAGETARGA_H__

#include "UT_Compat.h"

#define str_colormap            "Invalid colormap size (%d)"

/* Supported Targa pixel file format versions */

#define str_int_version "int"
#define str_ext_version "ext"

/* Supported TARGA version numbers */

#define TGA_RGB_uncomp   2
#define TGA_RGB_comp    10

#define TGA_mode_same   0
#define TGA_mode_diff   1

#define TGA_int_magic   7531
#define TGA_hdr_len     18         /* sizeof tgaheader */
#define TGA_iddata_len  (2 + 10*4) /* Magic number + 10 Float32's */

/* Format dependent pixel file descriptor */

typedef struct {
    FILE  *file;        /* File in TARGA format */
    Int32 lastscan,     /* Last scan line read or written */
          nchan,        /* Number of channels (3 or 4) */
          scanrest,     /* Number of pixels belonging to next scanline */
          scanmode;     /* Current compression mode */
    UInt8 *rowbuf;      /* Scanline buffer for reading uncompressed pixel data */
    UInt8 *red,         /* Scanline buffer for red component */
          *green,       /* Scanline buffer for green component */
          *blue,        /* Scanline buffer for blue component */
          *matte;       /* Scanline buffer for matte component */
} tgafile;

/* A Targa header */

typedef struct {
    UInt8 numid;
    UInt8 maptyp;
    UInt8 imgtyp;
    Int16 maporig;
    Int16 mapsize;
    UInt8 mapbits;
    Int16 xorig;
    Int16 yorig;
    Int16 xsize;
    Int16 ysize;
    UInt8 pixsize;
    UInt8 imgdes;
} tgaheader;

/* Functions for reading and writing TARGA pixel files */

extern UT_Bool FF_ImgOpenWriteTarga (const char *, FF_ImgFileDesc *);
extern UT_Bool FF_ImgOpenReadTarga  (const char *, FF_ImgFileDesc *);

#endif /* __FF_IMAGETARGA_H__ */
