libtgaloader
Описание
Lightweight TGA loader
Языки
- C80,9%
- CMake19,1%
TGA Loader v0.1
Description of the TGALoader library
TGALoader is a lightweight library for TGA images manipulation. Here are main capabilities and restrictions of this library.
TGA Loader has some advantages:
- Load TGA uncompressed images.
- Extract TGA header.
- Can flip image vertically for OpenGL usage.
- Can save RGB/RGBA images.
- Licensed under the GNU Lesser General Public License v3 (LGPLv3).
Also TGA Loader has some restrictions
- Can not load palette images.
- Can not load RLE compressed images.
- Can not read X-TARGA additional fields.
The main purpose of this library is to give simple interface to load textures and images for OpenGL-based applications. It is also can be used to save OpenGL framebuffer for debug purposes.
Library interface
There are some new types, that defined by this library.
This type is an enumerator for all TGALoader error codes. Here is the table of values such type variable can have:
| Name | Description |
|---|---|
| 0 - No error. |
| TGA file is missing or can not be read. |
| File or stream is not a TGA image. |
| Can not allocate memory. |
| Image is empty, i.e. there is no image data. |
| TGA format not supported by this version. |
This type will contains TGA file header when TGA image will be loaded. Here it's fields:
| Name | Type | Description |
|---|---|---|
| | Length of the TGA image description string. |
| | Color type. Can be one of values. |
| | Image map type. Can be one of values. |
| | Color map descriptor. Has type. |
| | Image type descriptor. Has type. |
This type describes the color map of the TGA image. It can have one of the follows values:
| Name | Description |
|---|---|
| There is no colom map. |
| Color map is exists. |
This type describes the image type of the TGA image, and can hold one of values below:
| Name | Description |
|---|---|
| TGA has no image (why this value can be used?) |
| Color mapped image data. |
| True color image data (RGB). |
| Grayscale image data. |
| Color mapped image data with RLE compression. |
| True color image data with RLE compression. |
| Grayscale image data with RLE compression. |
This is the color map description structure.
| Name | Type | Description |
|---|---|---|
| | Index of the first entry in color map table. |
| | Number of the entries in color map table. |
| | Size of the color map entry. |
This is the image description structure.
| Name | Type | Description |
|---|---|---|
| | X origin position in the image. |
| | Y origin position in the image. |
| | Width of the image. |
| | Height of the image. |
| | Number of bits in the pixel. |
| | Some additional bitfields of image descriptor. |
The TGALoader has function interface bellow.
This function allows to load TGA image from memory image, pointed by
. Size of the buffer is passed through argument
in bytes. After successful loading of the image will contain
header of the TGA file with full image description, will point
to image array, and will be returned.
You should not allocate memory for image array, pointed by .
Function do this automatically. Image will be loaded from upper left corner
in any case of image origin position. To flip it vertically, just pass
as argument.
Use to free any data, pointed by argument after
successful image loading.
This function allows to load TGA image from file and works same as
function.
This function free memory, previously allocated by or
. Just pass pointer to the array.
This function is used to save any pixel array to the TGA file. All you have
to do is determine size of the image ( and ), pixel
size in bytes (can be 1, 2, 3 or 4), provide data array in
argument and determine output file by it's .
If argument is out of range, or is zero, or
or is zero, will return error.
function extract module version in N.N.N.N form,
where N is a number of version component. Version string will be copied into
with null symbol at the end. To prevent buffer overflow
argument must contain length of the buffer. Version strings are typically short
(for example 0.2.0.1); callers should pass the buffer length in
to avoid overflow.