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 | #if !defined(_WIN32) || !defined(_MSC_VER) |
16 | #include <unistd.h> |
17 | #define posix_open open |
18 | #define posix_close close |
19 | #define posix_fdopen fdopen |
20 | #define posix_unlink unlink |
21 | #endif |
22 | |
23 | #ifdef _WIN32 |
24 | #include <io.h> |
25 | #ifdef _MSC_VER |
26 | #define posix_open _open |
27 | #define posix_close _close |
28 | #define posix_fdopen _fdopen |
29 | #define posix_unlink _unlink |
30 | #endif |
31 | #else |
32 | #include <sys/types.h> |
33 | #endif /* _WIN32 */ |
34 | #include <sys/stat.h> |
35 | |
36 | #ifndef SIZE_MAX |
37 | #define SIZE_MAX UINTPTR_MAX |
38 | #endif |
39 | |
40 | #define EXTENSION_INTRODUCER 0x21 |
41 | #define DESCRIPTOR_INTRODUCER 0x2c |
42 | #define TERMINATOR_INTRODUCER 0x3b |
43 | |
44 | #define LZ_MAX_CODE 4095 /* Biggest code possible in 12 bits. */ |
45 | #define LZ_BITS 12 |
46 | |
47 | #define FLUSH_OUTPUT 4096 /* Impossible code, to signal flush. */ |
48 | #define FIRST_CODE 4097 /* Impossible code, to signal first. */ |
49 | #define NO_SUCH_CODE 4098 /* Impossible code, to signal empty. */ |
50 | |
51 | #define FILE_STATE_WRITE 0x01 |
52 | #define FILE_STATE_SCREEN 0x02 |
53 | #define FILE_STATE_IMAGE 0x04 |
54 | #define FILE_STATE_READ 0x08 |
55 | |
56 | #define IS_READABLE(Private) (Private->FileState & FILE_STATE_READ) |
57 | #define IS_WRITEABLE(Private) (Private->FileState & FILE_STATE_WRITE) |
58 | |
59 | typedef struct GifFilePrivateType { |
60 | GifWord FileState, FileHandle, /* Where all this data goes to! */ |
61 | BitsPerPixel, /* Bits per pixel (Codes uses at least this + 1). */ |
62 | ClearCode, /* The CLEAR LZ code. */ |
63 | EOFCode, /* The EOF LZ code. */ |
64 | RunningCode, /* The next code algorithm can generate. */ |
65 | RunningBits, /* The number of bits required to represent RunningCode. */ |
66 | MaxCode1, /* 1 bigger than max. possible code, in RunningBits bits. */ |
67 | LastCode, /* The code before the current code. */ |
68 | CrntCode, /* Current algorithm code. */ |
69 | StackPtr, /* For character stack (see below). */ |
70 | CrntShiftState; /* Number of bits in CrntShiftDWord. */ |
71 | unsigned long CrntShiftDWord; /* For bytes decomposition into codes. */ |
72 | unsigned long PixelCount; /* Number of pixels in image. */ |
73 | FILE *File; /* File as stream. */ |
74 | InputFunc Read; /* function to read gif input (TVT) */ |
75 | OutputFunc Write; /* function to write gif output (MRB) */ |
76 | GifByteType Buf[256]; /* Compressed input is buffered here. */ |
77 | GifByteType Stack[LZ_MAX_CODE]; /* Decoded pixels are stacked here. */ |
78 | GifByteType Suffix[LZ_MAX_CODE + 1]; /* So we can trace the codes. */ |
79 | GifPrefixType Prefix[LZ_MAX_CODE + 1]; |
80 | GifHashTableType *HashTable; |
81 | bool gif89; |
82 | } GifFilePrivateType; |
83 | |
84 | #ifndef HAVE_REALLOCARRAY |
85 | extern void *openbsd_reallocarray(void *optr, size_t nmemb, size_t size); |
86 | #define reallocarray openbsd_reallocarray |
87 | #endif |
88 | |
89 | #endif /* _GIF_LIB_PRIVATE_H */ |
90 | |
91 | /* end */ |
92 | |