xref: /aosp_15_r20/external/giflib/gif_lib_private.h (revision 324bb76b8d05e2a05aa88511fff61cf3f9ca5892)
1 /****************************************************************************
2 
3 gif_lib_private.h - internal giflib routines and structures
4 
5 SPDX-License-Identifier: MIT
6 
7 ****************************************************************************/
8 
9 #ifndef _GIF_LIB_PRIVATE_H
10 #define _GIF_LIB_PRIVATE_H
11 
12 #include "gif_hash.h"
13 #include "gif_lib.h"
14 
15 #ifndef SIZE_MAX
16 #define SIZE_MAX UINTPTR_MAX
17 #endif
18 
19 #define EXTENSION_INTRODUCER 0x21
20 #define DESCRIPTOR_INTRODUCER 0x2c
21 #define TERMINATOR_INTRODUCER 0x3b
22 
23 #define LZ_MAX_CODE 4095 /* Biggest code possible in 12 bits. */
24 #define LZ_BITS 12
25 
26 #define FLUSH_OUTPUT 4096 /* Impossible code, to signal flush. */
27 #define FIRST_CODE 4097   /* Impossible code, to signal first. */
28 #define NO_SUCH_CODE 4098 /* Impossible code, to signal empty. */
29 
30 #define FILE_STATE_WRITE 0x01
31 #define FILE_STATE_SCREEN 0x02
32 #define FILE_STATE_IMAGE 0x04
33 #define FILE_STATE_READ 0x08
34 
35 #define IS_READABLE(Private) (Private->FileState & FILE_STATE_READ)
36 #define IS_WRITEABLE(Private) (Private->FileState & FILE_STATE_WRITE)
37 
38 typedef struct GifFilePrivateType {
39 	GifWord FileState, FileHandle, /* Where all this data goes to! */
40 	    BitsPerPixel, /* Bits per pixel (Codes uses at least this + 1). */
41 	    ClearCode,    /* The CLEAR LZ code. */
42 	    EOFCode,      /* The EOF LZ code. */
43 	    RunningCode,  /* The next code algorithm can generate. */
44 	    RunningBits,  /* The number of bits required to represent
45 	                     RunningCode. */
46 	    MaxCode1, /* 1 bigger than max. possible code, in RunningBits bits.
47 	               */
48 	    LastCode, /* The code before the current code. */
49 	    CrntCode, /* Current algorithm code. */
50 	    StackPtr, /* For character stack (see below). */
51 	    CrntShiftState;           /* Number of bits in CrntShiftDWord. */
52 	unsigned long CrntShiftDWord; /* For bytes decomposition into codes. */
53 	unsigned long PixelCount;     /* Number of pixels in image. */
54 	FILE *File;                   /* File as stream. */
55 	InputFunc Read;               /* function to read gif input (TVT) */
56 	OutputFunc Write;             /* function to write gif output (MRB) */
57 	GifByteType Buf[256];         /* Compressed input is buffered here. */
58 	GifByteType Stack[LZ_MAX_CODE]; /* Decoded pixels are stacked here. */
59 	GifByteType Suffix[LZ_MAX_CODE + 1]; /* So we can trace the codes. */
60 	GifPrefixType Prefix[LZ_MAX_CODE + 1];
61 	GifHashTableType *HashTable;
62 	bool gif89;
63 } GifFilePrivateType;
64 
65 #ifndef HAVE_REALLOCARRAY
66 extern void *openbsd_reallocarray(void *optr, size_t nmemb, size_t size);
67 #define reallocarray openbsd_reallocarray
68 #endif
69 
70 #endif /* _GIF_LIB_PRIVATE_H */
71 
72 /* end */
73