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

Read and write X11 bitmap images. More...

Collaboration diagram for XBM:

XBM Reading

gdImagePtr gdImageCreateFromXbm (FILE *in)
 Create an image from XBM data in a stdio stream.
 

XBM Writing

void gdImageXbmCtx (gdImagePtr image, char *file_name, int fg, gdIOCtxPtr out)
 Write an image to an IO context in X11 bitmap format.
 

Detailed Description

Read and write X11 bitmap images.

XBM support reads X11 bitmap data from an open stdio stream and writes XBM text to a gd IO context. XBM images are 1-bit images stored as C source-style data, and gd maps them to palette images when reading. The reader returns a new image owned by the caller; the writer borrows both the image and output context for the duration of the call.

FILE *in;
gdImagePtr im;
gdIOCtxPtr out;
in = fopen("icon.xbm", "rb");
if (in == NULL) {
return 1;
}
fclose(in);
if (im == NULL) {
return 1;
}
out = gdNewFileCtx(stdout);
if (out == NULL) {
gdImageDestroy(im);
return 1;
}
gdImageXbmCtx(im, "icon.xbm", 1, out);
out->gd_free(out);
gdImageDestroy(im);
void gdImageXbmCtx(gdImagePtr image, char *file_name, int fg, gdIOCtxPtr out)
Write an image to an IO context in X11 bitmap format.
gdImagePtr gdImageCreateFromXbm(FILE *in)
Create an image from XBM data in a stdio stream.
Definition gd_xbm.c:23
gdIOCtxPtr gdNewFileCtx(FILE *)
Creates a new I/O context for reading/writing to a file.
Definition gd_io_file.c:50
Write an image as JPEG data to a gdIOCtx.

Function Documentation

◆ gdImageCreateFromXbm()

gdImagePtr gdImageCreateFromXbm ( FILE *  in)

Create an image from XBM data in a stdio stream.

gdImageCreateFromXbm() rewinds in before reading and does not close it. X11 XBM data with char arrays and X10 XBM data with short arrays are supported. On success, the returned image is owned by the caller and must be destroyed with gdImageDestroy.

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

◆ gdImageXbmCtx()

void gdImageXbmCtx ( gdImagePtr  image,
char *  file_name,
int  fg,
gdIOCtxPtr  out 
)

Write an image to an IO context in X11 bitmap format.

gdImageXbmCtx() does not close out. The image and output context are borrowed for the duration of the call. Pixels whose color index equals fg are written as set bits; all other pixels are written as unset bits.

Parameters
imageThe image to write.
file_namePrefix for the generated XBM C identifiers. Path components, a trailing .xbm extension, and unsupported identifier characters are normalized before writing.
fgForeground color index to write as set bits.
outThe output IO context.