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