"Fossies" - the Fresh Open Source Software Archive

Member "libgd-2.3.2/docs/naturaldocs/html/files/gd_gd-c.html" (5 Mar 2021, 23394 Bytes) of package /linux/www/libgd-2.3.2.tar.gz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the project site itself.

GD IO

Read and write GD images.

The GD image format is a proprietary image format of libgd.  It has to be regarded as being obsolete, and should only be used for development and testing purposes.

Structure of a GD image file

  • file header
  • color header (either truecolor or palette)
  • image data

All numbers are stored in big-endian format.  Note that all GD output is done in the GD 2.x format (not to be confused with the GD2 format), but input may also be in the GD 1.x format.

GD 1.x file header structure

width1 word
height1 word

GD 1.x color header (palette only)

count1 byte (the number of used palette colors)
transparent1 word (257 signals no transparency)
palette256×3 bytes (RGB triplets)

GD 2.x file header structure

signature1 word (“\xFF\xFE” for truecolor, “\xFF\xFF” for palette)
width1 word
height1 word

GD 2.x truecolor image color header

truecolor1 byte (always “\001”)
transparent1 dword (ARGB color); “\377\377\377\377” means that no transparent color is set

GD 2.x palette image color header

truecolor1 byte (always “\0”)
count1 word (the number of used palette colors)
transparent1 dword (palette index); “\377\377\377\377” means that no transparent color is set
palette256 dwords (RGBA colors)

Image data

Sequential pixel data; row-major from top to bottom, left to right:

  • 1 byte per pixel for palette images
  • 1 dword (ARGB) per pixel for truecolor images
Summary
GD IORead and write GD images.
Functions
gdImageCreateFromGdgdImageCreateFromGd is called to load images from gd format files.
gdImageCreateFromGdPtr
gdImageCreateFromGdCtxReads in a GD image via a gdIOCtx struct.
gdImageGd
gdImageGdPtr

Functions

gdImageCreateFromGd

gdImagePtr gdImageCreateFromGd (FILE *inFile)

gdImageCreateFromGd is called to load images from gd format files.  Invoke gdImageCreateFromGd with an already opened pointer to a file containing the desired image in the gd file format, which is specific to gd and intended for very fast loading.  (It is not intended for compression; for compression, use PNG or JPEG.)

gdImageCreateFromGd returns a gdImagePtr to the new image, or NULL if unable to load the image (most often because the file is corrupt or does not contain a gd format image).  gdImageCreateFromGd does not close the file.  You can inspect the sx and sy members of the image to determine its size.  The image must eventually be destroyed using gdImageDestroy.

Variants

gdImageCreateFromGdPtr creates an image from GD data (i.e. the contents of a GD file) already in memory.

gdImageCreateFromGdCtx reads in an image using the functions in a gdIOCtx struct.

Parameters

infileThe input FILE pointer

Returns

A pointer to the new image or NULL if an error occurred.

Example

gdImagePtr im;
FILE *in;
in = fopen("mygd.gd", "rb");
im = gdImageCreateFromGd(in);
fclose(in);
// ... Use the image ...
gdImageDestroy(im);

gdImageCreateFromGdPtr

gdImagePtr gdImageCreateFromGdPtr (int size,
void *data)

Parameters

sizesize of GD data in bytes.
dataGD data (i.e. contents of a GIF file).

Reads in GD data from memory.  See gdImageCreateFromGd.

gdImageCreateFromGdCtx

gdImagePtr gdImageCreateFromGdCtx (gdIOCtxPtr in)

Reads in a GD image via a gdIOCtx struct.  See gdImageCreateFromGd.

gdImageGd

void gdImageGd (gdImagePtr im,
FILE *outFile)

gdImageGdPtr

void * gdImageGdPtr (gdImagePtr im,
int *size)
gdImagePtr gdImageCreateFromGd (FILE *inFile)
gdImageCreateFromGd is called to load images from gd format files.
gdImagePtr gdImageCreateFromGdPtr (int size,
void *data)
gdImagePtr gdImageCreateFromGdCtx (gdIOCtxPtr in)
Reads in a GD image via a gdIOCtx struct.
gdIOCtx structures hold function pointers for doing image IO.
void gdImageGd (gdImagePtr im,
FILE *outFile)
void * gdImageGdPtr (gdImagePtr im,
int *size)
The data structure in which gd stores images.
void gdImageDestroy (gdImagePtr im)
gdImageDestroy is used to free the memory associated with an image.
Close