LibTargaWrapperDocumentation

TargaImage - Documentation

September 10, 2007

TargaImage is a C++ class wrapper for the LibTarga library.

Get the files here:

IMPORTANT. TargaImage treats the upper-left hand corner of a Targa image as location (0,0), whileLibTarga (and TGA files) treats the lower-left hand corner as (0,0). TargaImage loads the image array left to right from top to bottom. TargaImage always stores pixels in premultiplied RGBA format internally but writes out TGA files in non-premultiplied RGBA format.

Note: All constructors of TargaImage are private. Images can only be created by calling the static functions blankImage and readImage. That way we'll never get any invalid images (either accidentally or intentionally).

 

Constructors / Destructor

TargaImage(const unsigned int width, const int height, const unsigned char* pixels); 
Constructs an image with the specified width, height and pixel values. Note that this constructor is private. If you want to create an image, use the static functions blankImage and readImage instead.

TargaImage(); 
This null constructor is private and should never be called.

~TargaImage(); 
Destructor. Frees up the memory allocated for the image data.

 

Methods

static TargaImage* blankImage(const unsigned int width, const unsigned int height); 
Returns the pointer to an empty image with specified width and height. All pixels have their RGBA values set to 0.

static TargaImage* readImage(const char* filename); 
Reads an image from a file and returns a pointer to the image. If the read was unsuccessful, a NULL pointer is returned. To get the error message (if any), use the error handling routines in LibTarga.

int write(const char* filename) const; 
Writes the image to a file. The output file always uses 4 bytes per pixel (i.e. format = TGA_TRUECOLOR_32). Returns 1 if successful and 0 otherwise. To get the error message (if any), use the error handling routines in LibTarga.

TargaImage* clone() const; 
Returns a deep copy of the image, i.e. changing the pixels of the copy would not affect the pixels of the original image.

void flip(); 
Flips the image upside down.

void fillAlpha(const unsigned char value); 
Sets the alpha values of all pixels to a specific value.

unsigned int width() const; 
Returns the width of the image.

unsigned int height() const; 
Returns the height of the image.

unsigned char* pixels() const; 
Returns the pixel values of the image.