LibGd 2.4.0-dev
GD Graphics library
Loading...
Searching...
No Matches

Read Truevision TGA images. More...

Collaboration diagram for TGA:

TGA Reading

gdImagePtr gdImageCreateFromTga (FILE *fp)
 Create an image from TGA data in a stdio stream.
 
gdImagePtr gdImageCreateFromTgaCtx (gdIOCtxPtr ctx)
 Create an image from TGA data in a gdIOCtx.
 
gdImagePtr gdImageCreateFromTgaPtr (int size, void *data)
 Create an image from a TGA memory buffer.
 

Detailed Description

Read Truevision TGA images.

TGA support is read-only. The reader accepts stdio streams, gdIOCtx streams, and caller-provided memory buffers, and returns a new truecolor gd image. The returned image is owned by the caller and must be destroyed with gdImageDestroy().

GD reads uncompressed and RLE-compressed color-mapped, truecolor, and grayscale TGA images. Supported inputs include 8-bit indexed data with 15-, 16-, 24-, or 32-bit color map entries, 16- and 24-bit truecolor data, 32-bit truecolor data with 8 alpha bits, and 8-bit grayscale data. Image origin flags are applied so the returned gd image has the expected orientation. When decoded alpha is present, alpha saving is enabled on the returned image.

FILE *in;
FILE *out;
gdImagePtr im;
in = fopen("input.tga", "rb");
if (in == NULL) {
return 1;
}
fclose(in);
if (im == NULL) {
return 1;
}
out = fopen("output.png", "wb");
if (out == NULL) {
gdImageDestroy(im);
return 1;
}
gdImagePng(im, out);
fclose(out);
gdImageDestroy(im);
void gdImagePng(gdImagePtr im, FILE *out)
Write an image as PNG data to a stdio file.
Definition gd_png.c:1691
gdImagePtr gdImageCreateFromTga(FILE *fp)
Create an image from TGA data in a stdio stream.
Definition gd_tga.c:42
Write an image as JPEG data to a gdIOCtx.

Function Documentation

◆ gdImageCreateFromTga()

gdImagePtr gdImageCreateFromTga ( FILE *  fp)

Create an image from TGA data in a stdio stream.

gdImageCreateFromTga() borrows fp for the duration of the call and does not close it. On success, the returned image is owned by the caller and must be destroyed with gdImageDestroy().

Parameters
fpPointer to the input FILE stream.
Returns
A newly allocated truecolor image, or NULL on error.

◆ gdImageCreateFromTgaCtx()

gdImagePtr gdImageCreateFromTgaCtx ( gdIOCtxPtr  ctx)

Create an image from TGA data in a gdIOCtx.

gdImageCreateFromTgaCtx() borrows ctx for the duration of the call and does not close it. On success, the returned image is owned by the caller and must be destroyed with gdImageDestroy().

Parameters
ctxPointer to the gdIOCtx input context.
Returns
A newly allocated truecolor image, or NULL on error.

◆ gdImageCreateFromTgaPtr()

gdImagePtr gdImageCreateFromTgaPtr ( int  size,
void *  data 
)

Create an image from a TGA memory buffer.

gdImageCreateFromTgaPtr() borrows data for the duration of the call. The caller retains ownership of the input buffer. On success, the returned image is owned by the caller and must be destroyed with gdImageDestroy().

Parameters
sizeSize of the TGA memory buffer in bytes.
dataPointer to the TGA memory buffer.
Returns
A newly allocated truecolor image, or NULL on error.