LibGd 2.4.0-dev
GD Graphics library
Loading...
Searching...
No Matches
gd_io.h
1#ifndef GD_IO_H
2#define GD_IO_H 1
3
4#include <stdio.h>
5
6#ifdef __cplusplus
7extern "C" {
8#endif
9
10/*
11 Group: Types
12
13 typedef: gdIOCtx
14
15 gdIOCtx structures hold function pointers for doing image IO.
16
17 Most of the gd functions that read and write files, such as
18 <gdImagePng> also have variants that accept a <gdIOCtx> structure;
19 see <gdImagePngCtx> and <gdImageCreateFromJpegCtx>.
20
21 Those who wish to provide their own custom routines to read and
22 write images can populate a gdIOCtx structure with functions of
23 their own devising to to read and write data. For image reading, the
24 only mandatory functions are getC and getBuf, which must return the
25 number of characters actually read, or a negative value on error or
26 EOF. These functions must read the number of characters requested
27 unless at the end of the file.
28
29 For image writing, the only mandatory functions are putC and putBuf,
30 which return the number of characters written; these functions must
31 write the number of characters requested except in the event of an
32 error. The seek and tell functions are only required in conjunction
33 with the gd2 file format, which supports quick loading of partial
34 images. The gd_free function will not be invoked when calling the
35 standard Ctx functions; it is an implementation convenience when
36 adding new data types to gd. For examples, see gd_png.c, gd_gd2.c,
37 gd_jpeg.c, etc., all of which rely on gdIOCtx to implement the
38 standard image read and write functions.
39
40 > typedef struct gdIOCtx
41 > {
42 > int (*getC)(gdIOCtxPtr);
43 > int (*getBuf)(gdIOCtxPtr, void *, int wanted);
44 >
45 > void (*putC)(gdIOCtxPtr, int);
46 > int (*putBuf)(gdIOCtxPtr, const void *, int wanted);
47 >
48 > // seek must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek!
49 > int (*seek)(gdIOCtxPtr, const int);
50 > long (*tell)(gdIOCtxPtr);
51 >
52 > void (*gd_free)(gdIOCtxPtr);
53 > } gdIOCtx;
54 */
55typedef struct gdIOCtx *gdIOCtxPtr;
56
57typedef struct gdIOCtx {
58 int (*getC)(gdIOCtxPtr);
59 int (*getBuf)(gdIOCtxPtr, void *, int);
60 void (*putC)(gdIOCtxPtr, int);
61 int (*putBuf)(gdIOCtxPtr, const void *, int);
62 /* seek must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! */
63 int (*seek)(gdIOCtxPtr, const int);
64 long (*tell)(gdIOCtxPtr);
65 void (*gd_free)(gdIOCtxPtr);
66 void *data;
67} gdIOCtx;
68
69void gdPutC(const unsigned char c, gdIOCtxPtr ctx);
70int gdPutBuf(const void *, int, gdIOCtxPtr);
71void gdPutWord(int w, gdIOCtxPtr ctx);
72void gdPutInt(int w, gdIOCtxPtr ctx);
73
74int gdGetC(gdIOCtxPtr ctx);
75int gdGetBuf(void *, int, gdIOCtxPtr);
76int gdGetByte(int *result, gdIOCtxPtr ctx);
77int gdGetWord(int *result, gdIOCtxPtr ctx);
78int gdGetWordLSB(signed short int *result, gdIOCtxPtr ctx);
79int gdGetInt(int *result, gdIOCtxPtr ctx);
80int gdGetIntLSB(signed int *result, gdIOCtxPtr ctx);
81
82int gdSeek(gdIOCtxPtr ctx, const int offset);
83long gdTell(gdIOCtxPtr ctx);
84
85#ifdef __cplusplus
86}
87#endif
88
89#endif