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_lib.h"
13 #include "gif_hash.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 RunningCode. */
45       MaxCode1,    /* 1 bigger than max. possible code, in RunningBits bits. */
46       LastCode,    /* The code before the current code. */
47       CrntCode,    /* Current algorithm code. */
48       StackPtr,    /* For character stack (see below). */
49       CrntShiftState;    /* Number of bits in CrntShiftDWord. */
50     unsigned long CrntShiftDWord;   /* For bytes decomposition into codes. */
51     unsigned long PixelCount;   /* Number of pixels in image. */
52     FILE *File;    /* File as stream. */
53     InputFunc Read;     /* function to read gif input (TVT) */
54     OutputFunc Write;   /* function to write gif output (MRB) */
55     GifByteType Buf[256];   /* Compressed input is buffered here. */
56     GifByteType Stack[LZ_MAX_CODE]; /* Decoded pixels are stacked here. */
57     GifByteType Suffix[LZ_MAX_CODE + 1];    /* So we can trace the codes. */
58     GifPrefixType Prefix[LZ_MAX_CODE + 1];
59     GifHashTableType *HashTable;
60     bool gif89;
61 } GifFilePrivateType;
62 
63 #ifndef HAVE_REALLOCARRAY
64 extern void *openbsd_reallocarray(void *optr, size_t nmemb, size_t size);
65 #define reallocarray openbsd_reallocarray
66 #endif
67 
68 #endif /* _GIF_LIB_PRIVATE_H */
69 
70 /* end */
71