torchcodec 1.0.0__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. torchcodec/__init__.py +50 -0
  2. torchcodec/_core/AVIOContextHolder.cpp +85 -0
  3. torchcodec/_core/AVIOContextHolder.h +44 -0
  4. torchcodec/_core/AudioCommon.cpp +101 -0
  5. torchcodec/_core/AudioCommon.h +48 -0
  6. torchcodec/_core/AudioConverter.cpp +130 -0
  7. torchcodec/_core/AudioConverter.h +59 -0
  8. torchcodec/_core/BetaCudaDeviceInterface.cpp +1635 -0
  9. torchcodec/_core/BetaCudaDeviceInterface.h +364 -0
  10. torchcodec/_core/CMakeLists.txt +661 -0
  11. torchcodec/_core/CUDACommon.cpp +129 -0
  12. torchcodec/_core/CUDACommon.h +115 -0
  13. torchcodec/_core/Cache.h +126 -0
  14. torchcodec/_core/CodecParameters.cpp +98 -0
  15. torchcodec/_core/CodecParameters.h +59 -0
  16. torchcodec/_core/ColorConverter.cpp +92 -0
  17. torchcodec/_core/ColorConverter.h +40 -0
  18. torchcodec/_core/CpuDeviceInterface.cpp +654 -0
  19. torchcodec/_core/CpuDeviceInterface.h +153 -0
  20. torchcodec/_core/CudaDeviceInterface.cpp +519 -0
  21. torchcodec/_core/CudaDeviceInterface.h +92 -0
  22. torchcodec/_core/DecodeAvif.cpp +284 -0
  23. torchcodec/_core/DecodeAvif.h +28 -0
  24. torchcodec/_core/DecodeGif.cpp +488 -0
  25. torchcodec/_core/DecodeGif.h +32 -0
  26. torchcodec/_core/DecodeHeic.cpp +306 -0
  27. torchcodec/_core/DecodeHeic.h +18 -0
  28. torchcodec/_core/DecodeJpeg.cpp +489 -0
  29. torchcodec/_core/DecodeJpeg.h +17 -0
  30. torchcodec/_core/DecodeJpegCuda.cpp +638 -0
  31. torchcodec/_core/DecodeJpegCuda.h +92 -0
  32. torchcodec/_core/DecodePng.cpp +569 -0
  33. torchcodec/_core/DecodePng.h +31 -0
  34. torchcodec/_core/DecodeWebp.cpp +238 -0
  35. torchcodec/_core/DecodeWebp.h +17 -0
  36. torchcodec/_core/Demuxer.cpp +415 -0
  37. torchcodec/_core/Demuxer.h +158 -0
  38. torchcodec/_core/DeviceInterface.cpp +152 -0
  39. torchcodec/_core/DeviceInterface.h +255 -0
  40. torchcodec/_core/EncodeJpeg.cpp +223 -0
  41. torchcodec/_core/EncodeJpeg.h +19 -0
  42. torchcodec/_core/EncodeJpegCuda.cpp +272 -0
  43. torchcodec/_core/EncodeJpegCuda.h +56 -0
  44. torchcodec/_core/EncodePng.cpp +207 -0
  45. torchcodec/_core/EncodePng.h +19 -0
  46. torchcodec/_core/Encoder.cpp +1023 -0
  47. torchcodec/_core/Encoder.h +144 -0
  48. torchcodec/_core/Exif.h +241 -0
  49. torchcodec/_core/FFMPEGCommon.cpp +1159 -0
  50. torchcodec/_core/FFMPEGCommon.h +506 -0
  51. torchcodec/_core/FileIO.cpp +78 -0
  52. torchcodec/_core/FileIO.h +34 -0
  53. torchcodec/_core/FileLikeIO.cpp +76 -0
  54. torchcodec/_core/FileLikeIO.h +68 -0
  55. torchcodec/_core/FilterGraph.cpp +211 -0
  56. torchcodec/_core/FilterGraph.h +59 -0
  57. torchcodec/_core/Frame.cpp +75 -0
  58. torchcodec/_core/Frame.h +76 -0
  59. torchcodec/_core/IOInterface.h +44 -0
  60. torchcodec/_core/ImageCommon.h +113 -0
  61. torchcodec/_core/Logging.cpp +42 -0
  62. torchcodec/_core/Logging.h +38 -0
  63. torchcodec/_core/Metadata.cpp +312 -0
  64. torchcodec/_core/Metadata.h +115 -0
  65. torchcodec/_core/NVCUVIDRuntimeLoader.cpp +324 -0
  66. torchcodec/_core/NVCUVIDRuntimeLoader.h +14 -0
  67. torchcodec/_core/NVDECCache.cpp +111 -0
  68. torchcodec/_core/NVDECCache.h +136 -0
  69. torchcodec/_core/NVDECCacheConfig.cpp +61 -0
  70. torchcodec/_core/NVDECCacheConfig.h +30 -0
  71. torchcodec/_core/PacketDecoder.cpp +358 -0
  72. torchcodec/_core/PacketDecoder.h +140 -0
  73. torchcodec/_core/SingleStreamDecoder.cpp +1856 -0
  74. torchcodec/_core/SingleStreamDecoder.h +424 -0
  75. torchcodec/_core/StableABICompat.h +213 -0
  76. torchcodec/_core/StreamOptions.h +93 -0
  77. torchcodec/_core/SwScale.cpp +124 -0
  78. torchcodec/_core/SwScale.h +67 -0
  79. torchcodec/_core/TensorIO.cpp +136 -0
  80. torchcodec/_core/TensorIO.h +53 -0
  81. torchcodec/_core/Transform.cpp +207 -0
  82. torchcodec/_core/Transform.h +125 -0
  83. torchcodec/_core/ValidationUtils.cpp +65 -0
  84. torchcodec/_core/ValidationUtils.h +29 -0
  85. torchcodec/_core/WavDecoder.cpp +494 -0
  86. torchcodec/_core/WavDecoder.h +73 -0
  87. torchcodec/_core/__init__.py +45 -0
  88. torchcodec/_core/_decoder_utils.py +258 -0
  89. torchcodec/_core/_ffmpeg_op_names.py +95 -0
  90. torchcodec/_core/_ffmpeg_ops.py +699 -0
  91. torchcodec/_core/_file_like.py +221 -0
  92. torchcodec/_core/_metadata.py +402 -0
  93. torchcodec/_core/color_conversion.cpp +316 -0
  94. torchcodec/_core/color_conversion.cu +391 -0
  95. torchcodec/_core/color_conversion.h +150 -0
  96. torchcodec/_core/custom_ops.cpp +2438 -0
  97. torchcodec/_core/fetch_and_expose_non_gpl_ffmpeg_libs.cmake +192 -0
  98. torchcodec/_core/fetch_avif_from_s3.cmake +81 -0
  99. torchcodec/_core/giflib/README +28 -0
  100. torchcodec/_core/giflib/dgif_lib.c +1313 -0
  101. torchcodec/_core/giflib/gif_hash.c +129 -0
  102. torchcodec/_core/giflib/gif_hash.h +43 -0
  103. torchcodec/_core/giflib/gif_lib.h +292 -0
  104. torchcodec/_core/giflib/gif_lib_private.h +73 -0
  105. torchcodec/_core/giflib/gifalloc.c +426 -0
  106. torchcodec/_core/giflib/openbsd-reallocarray.c +74 -0
  107. torchcodec/_core/heic_custom_ops.cpp +20 -0
  108. torchcodec/_core/image_custom_ops.cpp +137 -0
  109. torchcodec/_core/nvcuvid_include/cuviddec.h +1374 -0
  110. torchcodec/_core/nvcuvid_include/nvcuvid.h +610 -0
  111. torchcodec/_core/ops.py +103 -0
  112. torchcodec/_core/sources.bzl +113 -0
  113. torchcodec/_frame.py +146 -0
  114. torchcodec/_internally_replaced_utils.py +129 -0
  115. torchcodec/_logging.py +59 -0
  116. torchcodec/decoders/__init__.py +50 -0
  117. torchcodec/decoders/_audio_decoder.py +183 -0
  118. torchcodec/decoders/_blocks/__init__.py +48 -0
  119. torchcodec/decoders/_blocks/_audio_converter.py +155 -0
  120. torchcodec/decoders/_blocks/_codec_parameters.py +229 -0
  121. torchcodec/decoders/_blocks/_color_converter.py +107 -0
  122. torchcodec/decoders/_blocks/_demuxer.py +678 -0
  123. torchcodec/decoders/_blocks/_frame.py +577 -0
  124. torchcodec/decoders/_blocks/_helpers.py +53 -0
  125. torchcodec/decoders/_blocks/_packet_decoder.py +357 -0
  126. torchcodec/decoders/_decoder_utils.py +128 -0
  127. torchcodec/decoders/_image_decoders.py +1575 -0
  128. torchcodec/decoders/_video_decoder.py +592 -0
  129. torchcodec/decoders/_wav_decoder.py +131 -0
  130. torchcodec/encoders/__init__.py +4 -0
  131. torchcodec/encoders/_audio_encoder.py +167 -0
  132. torchcodec/encoders/_image_encoders.py +181 -0
  133. torchcodec/encoders/_multi_stream_encoder.py +272 -0
  134. torchcodec/encoders/_video_encoder.py +227 -0
  135. torchcodec/jpeg8.dll +0 -0
  136. torchcodec/libavif.dll +0 -0
  137. torchcodec/libpng16.dll +0 -0
  138. torchcodec/libsharpyuv.dll +0 -0
  139. torchcodec/libtorchcodec_core4.dll +0 -0
  140. torchcodec/libtorchcodec_core5.dll +0 -0
  141. torchcodec/libtorchcodec_core6.dll +0 -0
  142. torchcodec/libtorchcodec_core7.dll +0 -0
  143. torchcodec/libtorchcodec_core8.dll +0 -0
  144. torchcodec/libtorchcodec_core9.dll +0 -0
  145. torchcodec/libtorchcodec_custom_ops4.dll +0 -0
  146. torchcodec/libtorchcodec_custom_ops5.dll +0 -0
  147. torchcodec/libtorchcodec_custom_ops6.dll +0 -0
  148. torchcodec/libtorchcodec_custom_ops7.dll +0 -0
  149. torchcodec/libtorchcodec_custom_ops8.dll +0 -0
  150. torchcodec/libtorchcodec_custom_ops9.dll +0 -0
  151. torchcodec/libtorchcodec_heic.dll +0 -0
  152. torchcodec/libtorchcodec_image.dll +0 -0
  153. torchcodec/libwebp.dll +0 -0
  154. torchcodec/libwebpdecoder.dll +0 -0
  155. torchcodec/libwebpdemux.dll +0 -0
  156. torchcodec/libwebpmux.dll +0 -0
  157. torchcodec/libzstd.dll +0 -0
  158. torchcodec/py.typed +0 -0
  159. torchcodec/samplers/__init__.py +2 -0
  160. torchcodec/samplers/_common.py +83 -0
  161. torchcodec/samplers/_index_based.py +287 -0
  162. torchcodec/samplers/_time_based.py +360 -0
  163. torchcodec/share/cmake/TorchCodec/TorchCodecConfig.cmake +76 -0
  164. torchcodec/share/cmake/TorchCodec/ffmpeg_versions.cmake +128 -0
  165. torchcodec/transforms/__init__.py +12 -0
  166. torchcodec/transforms/_decoder_transforms.py +375 -0
  167. torchcodec/version.py +1 -0
  168. torchcodec/zlib.dll +0 -0
  169. torchcodec-1.0.0.dist-info/METADATA +275 -0
  170. torchcodec-1.0.0.dist-info/RECORD +179 -0
  171. torchcodec-1.0.0.dist-info/WHEEL +5 -0
  172. torchcodec-1.0.0.dist-info/licenses/LICENSE +28 -0
  173. torchcodec-1.0.0.dist-info/licenses/third_party/COPYING.dav1d +23 -0
  174. torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libavif +387 -0
  175. torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libjpeg-turbo +135 -0
  176. torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libpng +134 -0
  177. torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libwebp +30 -0
  178. torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.libyuv +29 -0
  179. torchcodec-1.0.0.dist-info/licenses/third_party/LICENSE.zlib +22 -0
@@ -0,0 +1,129 @@
1
+ // @nolint (improperly imported third-party code)
2
+ /*****************************************************************************
3
+
4
+ gif_hash.c -- module to support the following operations:
5
+
6
+ 1. InitHashTable - initialize hash table.
7
+ 2. ClearHashTable - clear the hash table to an empty state.
8
+ 2. InsertHashTable - insert one item into data structure.
9
+ 3. ExistsHashTable - test if item exists in data structure.
10
+
11
+ This module is used to hash the GIF codes during encoding.
12
+
13
+ *****************************************************************************/
14
+ // SPDX-License-Identifier: MIT
15
+ // SPDX-File-Copyright-Txt: (C) Copyright 1989 Gershon Elber
16
+
17
+ #include <fcntl.h>
18
+ #include <stdint.h>
19
+ #include <stdio.h>
20
+ #include <stdlib.h>
21
+ #include <string.h>
22
+
23
+ #include "gif_hash.h"
24
+ #include "gif_lib.h"
25
+ #include "gif_lib_private.h"
26
+
27
+ /* #define DEBUG_HIT_RATE Debug number of misses per hash Insert/Exists. */
28
+
29
+ #ifdef DEBUG_HIT_RATE
30
+ static long NumberOfTests = 0, NumberOfMisses = 0;
31
+ #endif /* DEBUG_HIT_RATE */
32
+
33
+ static int KeyItem(uint32_t Item);
34
+
35
+ /******************************************************************************
36
+ Initialize HashTable - allocate the memory needed and clear it. *
37
+ ******************************************************************************/
38
+ GifHashTableType *_InitHashTable(void) {
39
+ GifHashTableType *HashTable;
40
+
41
+ if ((HashTable = (GifHashTableType *)malloc(
42
+ sizeof(GifHashTableType))) == NULL) {
43
+ return NULL;
44
+ }
45
+
46
+ _ClearHashTable(HashTable);
47
+
48
+ return HashTable;
49
+ }
50
+
51
+ /******************************************************************************
52
+ Routine to clear the HashTable to an empty state. *
53
+ This part is a little machine depended. Use the commented part otherwise. *
54
+ ******************************************************************************/
55
+ void _ClearHashTable(GifHashTableType *HashTable) {
56
+ memset(HashTable->HTable, 0xFF, HT_SIZE * sizeof(uint32_t));
57
+ }
58
+
59
+ /******************************************************************************
60
+ Routine to insert a new Item into the HashTable. The data is assumed to be *
61
+ new one. *
62
+ ******************************************************************************/
63
+ void _InsertHashTable(GifHashTableType *HashTable, uint32_t Key, int Code) {
64
+ int HKey = KeyItem(Key);
65
+ uint32_t *HTable = HashTable->HTable;
66
+
67
+ #ifdef DEBUG_HIT_RATE
68
+ NumberOfTests++;
69
+ NumberOfMisses++;
70
+ #endif /* DEBUG_HIT_RATE */
71
+
72
+ while (HT_GET_KEY(HTable[HKey]) != 0xFFFFFL) {
73
+ #ifdef DEBUG_HIT_RATE
74
+ NumberOfMisses++;
75
+ #endif /* DEBUG_HIT_RATE */
76
+ HKey = (HKey + 1) & HT_KEY_MASK;
77
+ }
78
+ HTable[HKey] = HT_PUT_KEY(Key) | HT_PUT_CODE(Code);
79
+ }
80
+
81
+ /******************************************************************************
82
+ Routine to test if given Key exists in HashTable and if so returns its code *
83
+ Returns the Code if key was found, -1 if not. *
84
+ ******************************************************************************/
85
+ int _ExistsHashTable(GifHashTableType *HashTable, uint32_t Key) {
86
+ int HKey = KeyItem(Key);
87
+ uint32_t *HTable = HashTable->HTable, HTKey;
88
+
89
+ #ifdef DEBUG_HIT_RATE
90
+ NumberOfTests++;
91
+ NumberOfMisses++;
92
+ #endif /* DEBUG_HIT_RATE */
93
+
94
+ while ((HTKey = HT_GET_KEY(HTable[HKey])) != 0xFFFFFL) {
95
+ #ifdef DEBUG_HIT_RATE
96
+ NumberOfMisses++;
97
+ #endif /* DEBUG_HIT_RATE */
98
+ if (Key == HTKey) {
99
+ return HT_GET_CODE(HTable[HKey]);
100
+ }
101
+ HKey = (HKey + 1) & HT_KEY_MASK;
102
+ }
103
+
104
+ return -1;
105
+ }
106
+
107
+ /******************************************************************************
108
+ Routine to generate an HKey for the hashtable out of the given unique key. *
109
+ The given Key is assumed to be 20 bits as follows: lower 8 bits are the *
110
+ new postfix character, while the upper 12 bits are the prefix code. *
111
+ Because the average hit ratio is only 2 (2 hash references per entry), *
112
+ evaluating more complex keys (such as twin prime keys) does not worth it! *
113
+ ******************************************************************************/
114
+ static int KeyItem(uint32_t Item) {
115
+ return ((Item >> 12) ^ Item) & HT_KEY_MASK;
116
+ }
117
+
118
+ #ifdef DEBUG_HIT_RATE
119
+ /******************************************************************************
120
+ Debugging routine to print the hit ratio - number of times the hash table *
121
+ was tested per operation. This routine was used to test the KeyItem routine *
122
+ ******************************************************************************/
123
+ void HashTablePrintHitRatio(void) {
124
+ printf("Hash Table Hit Ratio is %ld/%ld = %ld%%.\n", NumberOfMisses,
125
+ NumberOfTests, NumberOfMisses * 100 / NumberOfTests);
126
+ }
127
+ #endif /* DEBUG_HIT_RATE */
128
+
129
+ /* end */
@@ -0,0 +1,43 @@
1
+ // @nolint (improperly imported third-party code)
2
+ /******************************************************************************
3
+
4
+ gif_hash.h - magfic constants and declarations for GIF LZW
5
+
6
+ ******************************************************************************/
7
+ // SPDX-License-Identifier: MIT
8
+
9
+ #ifndef _GIF_HASH_H_
10
+ #define _GIF_HASH_H_
11
+
12
+ #ifndef _WIN32
13
+ #include <unistd.h>
14
+ #endif /* _WIN32 */
15
+ #include <stdint.h>
16
+
17
+ #define HT_SIZE 8192 /* 12bits = 4096 or twice as big! */
18
+ #define HT_KEY_MASK 0x1FFF /* 13bits keys */
19
+ #define HT_KEY_NUM_BITS 13 /* 13bits keys */
20
+ #define HT_MAX_KEY 8191 /* 13bits - 1, maximal code possible */
21
+ #define HT_MAX_CODE 4095 /* Biggest code possible in 12 bits. */
22
+
23
+ /* The 32 bits of the long are divided into two parts for the key & code: */
24
+ /* 1. The code is 12 bits as our compression algorithm is limited to 12bits */
25
+ /* 2. The key is 12 bits Prefix code + 8 bit new char or 20 bits. */
26
+ /* The key is the upper 20 bits. The code is the lower 12. */
27
+ #define HT_GET_KEY(l) (l >> 12)
28
+ #define HT_GET_CODE(l) (l & 0x0FFF)
29
+ #define HT_PUT_KEY(l) (l << 12)
30
+ #define HT_PUT_CODE(l) (l & 0x0FFF)
31
+
32
+ typedef struct GifHashTableType {
33
+ uint32_t HTable[HT_SIZE];
34
+ } GifHashTableType;
35
+
36
+ GifHashTableType *_InitHashTable(void);
37
+ void _ClearHashTable(GifHashTableType *HashTable);
38
+ void _InsertHashTable(GifHashTableType *HashTable, uint32_t Key, int Code);
39
+ int _ExistsHashTable(GifHashTableType *HashTable, uint32_t Key);
40
+
41
+ #endif /* _GIF_HASH_H_ */
42
+
43
+ /* end */
@@ -0,0 +1,292 @@
1
+ // @nolint (improperly imported third-party code)
2
+ /******************************************************************************
3
+
4
+ gif_lib.h - service library for decoding and encoding GIF images
5
+
6
+ SPDX-License-Identifier: MIT
7
+
8
+ *****************************************************************************/
9
+
10
+ #ifndef _GIF_LIB_H_
11
+ #define _GIF_LIB_H_ 1
12
+
13
+ #ifdef __cplusplus
14
+ extern "C" {
15
+ #endif /* __cplusplus */
16
+
17
+ #define GIFLIB_MAJOR 5
18
+ #define GIFLIB_MINOR 2
19
+ #define GIFLIB_RELEASE 2
20
+
21
+ #define GIF_ERROR 0
22
+ #define GIF_OK 1
23
+
24
+ #include <stdbool.h>
25
+ #include <stddef.h>
26
+
27
+ #define GIF_STAMP "GIFVER" /* First chars in file - GIF stamp. */
28
+ #define GIF_STAMP_LEN sizeof(GIF_STAMP) - 1
29
+ #define GIF_VERSION_POS 3 /* Version first character in stamp. */
30
+ #define GIF87_STAMP "GIF87a" /* First chars in file - GIF stamp. */
31
+ #define GIF89_STAMP "GIF89a" /* First chars in file - GIF stamp. */
32
+
33
+ typedef unsigned char GifPixelType;
34
+ typedef unsigned char *GifRowType;
35
+ typedef unsigned char GifByteType;
36
+ typedef unsigned int GifPrefixType;
37
+ typedef int GifWord;
38
+
39
+ typedef struct GifColorType {
40
+ GifByteType Red, Green, Blue;
41
+ } GifColorType;
42
+
43
+ typedef struct ColorMapObject {
44
+ int ColorCount;
45
+ int BitsPerPixel;
46
+ bool SortFlag;
47
+ GifColorType *Colors; /* on malloc(3) heap */
48
+ } ColorMapObject;
49
+
50
+ typedef struct GifImageDesc {
51
+ GifWord Left, Top, Width, Height; /* Current image dimensions. */
52
+ bool Interlace; /* Sequential/Interlaced lines. */
53
+ ColorMapObject *ColorMap; /* The local color map */
54
+ } GifImageDesc;
55
+
56
+ typedef struct ExtensionBlock {
57
+ int ByteCount;
58
+ GifByteType *Bytes; /* on malloc(3) heap */
59
+ int Function; /* The block function code */
60
+ #define CONTINUE_EXT_FUNC_CODE 0x00 /* continuation subblock */
61
+ #define COMMENT_EXT_FUNC_CODE 0xfe /* comment */
62
+ #define GRAPHICS_EXT_FUNC_CODE 0xf9 /* graphics control (GIF89) */
63
+ #define PLAINTEXT_EXT_FUNC_CODE 0x01 /* plaintext */
64
+ #define APPLICATION_EXT_FUNC_CODE 0xff /* application block (GIF89) */
65
+ } ExtensionBlock;
66
+
67
+ typedef struct SavedImage {
68
+ GifImageDesc ImageDesc;
69
+ GifByteType *RasterBits; /* on malloc(3) heap */
70
+ int ExtensionBlockCount; /* Count of extensions before image */
71
+ ExtensionBlock *ExtensionBlocks; /* Extensions before image */
72
+ } SavedImage;
73
+
74
+ typedef struct GifFileType {
75
+ GifWord SWidth, SHeight; /* Size of virtual canvas */
76
+ GifWord SColorResolution; /* How many colors can we generate? */
77
+ GifWord SBackGroundColor; /* Background color for virtual canvas */
78
+ GifByteType AspectByte; /* Used to compute pixel aspect ratio */
79
+ ColorMapObject *SColorMap; /* Global colormap, NULL if nonexistent. */
80
+ int ImageCount; /* Number of current image (both APIs) */
81
+ GifImageDesc Image; /* Current image (low-level API) */
82
+ SavedImage *SavedImages; /* Image sequence (high-level API) */
83
+ int ExtensionBlockCount; /* Count extensions past last image */
84
+ ExtensionBlock *ExtensionBlocks; /* Extensions past last image */
85
+ int Error; /* Last error condition reported */
86
+ void *UserData; /* hook to attach user data (TVT) */
87
+ void *Private; /* Don't mess with this! */
88
+ } GifFileType;
89
+
90
+ #define GIF_ASPECT_RATIO(n) ((n) + 15.0 / 64.0)
91
+
92
+ typedef enum {
93
+ UNDEFINED_RECORD_TYPE,
94
+ SCREEN_DESC_RECORD_TYPE,
95
+ IMAGE_DESC_RECORD_TYPE, /* Begin with ',' */
96
+ EXTENSION_RECORD_TYPE, /* Begin with '!' */
97
+ TERMINATE_RECORD_TYPE /* Begin with ';' */
98
+ } GifRecordType;
99
+
100
+ /* func type to read gif data from arbitrary sources (TVT) */
101
+ typedef int (*InputFunc)(GifFileType *, GifByteType *, int);
102
+
103
+ /* func type to write gif data to arbitrary targets.
104
+ * Returns count of bytes written. (MRB)
105
+ */
106
+ typedef int (*OutputFunc)(GifFileType *, const GifByteType *, int);
107
+
108
+ /******************************************************************************
109
+ GIF89 structures
110
+ ******************************************************************************/
111
+
112
+ typedef struct GraphicsControlBlock {
113
+ int DisposalMode;
114
+ #define DISPOSAL_UNSPECIFIED 0 /* No disposal specified. */
115
+ #define DISPOSE_DO_NOT 1 /* Leave image in place */
116
+ #define DISPOSE_BACKGROUND 2 /* Set area too background color */
117
+ #define DISPOSE_PREVIOUS 3 /* Restore to previous content */
118
+ bool UserInputFlag; /* User confirmation required before disposal */
119
+ int DelayTime; /* pre-display delay in 0.01sec units */
120
+ int TransparentColor; /* Palette index for transparency, -1 if none */
121
+ #define NO_TRANSPARENT_COLOR -1
122
+ } GraphicsControlBlock;
123
+
124
+ /******************************************************************************
125
+ GIF encoding routines
126
+ ******************************************************************************/
127
+
128
+ /* Main entry points */
129
+ GifFileType *EGifOpenFileName(const char *GifFileName,
130
+ const bool GifTestExistence, int *Error);
131
+ GifFileType *EGifOpenFileHandle(const int GifFileHandle, int *Error);
132
+ GifFileType *EGifOpen(void *userPtr, OutputFunc writeFunc, int *Error);
133
+ int EGifSpew(GifFileType *GifFile);
134
+ const char *EGifGetGifVersion(GifFileType *GifFile); /* new in 5.x */
135
+ int EGifCloseFile(GifFileType *GifFile, int *ErrorCode);
136
+
137
+ #define E_GIF_SUCCEEDED 0
138
+ #define E_GIF_ERR_OPEN_FAILED 1 /* And EGif possible errors. */
139
+ #define E_GIF_ERR_WRITE_FAILED 2
140
+ #define E_GIF_ERR_HAS_SCRN_DSCR 3
141
+ #define E_GIF_ERR_HAS_IMAG_DSCR 4
142
+ #define E_GIF_ERR_NO_COLOR_MAP 5
143
+ #define E_GIF_ERR_DATA_TOO_BIG 6
144
+ #define E_GIF_ERR_NOT_ENOUGH_MEM 7
145
+ #define E_GIF_ERR_DISK_IS_FULL 8
146
+ #define E_GIF_ERR_CLOSE_FAILED 9
147
+ #define E_GIF_ERR_NOT_WRITEABLE 10
148
+
149
+ /* These are legacy. You probably do not want to call them directly */
150
+ int EGifPutScreenDesc(GifFileType *GifFile, const int GifWidth,
151
+ const int GifHeight, const int GifColorRes,
152
+ const int GifBackGround,
153
+ const ColorMapObject *GifColorMap);
154
+ int EGifPutImageDesc(GifFileType *GifFile, const int GifLeft, const int GifTop,
155
+ const int GifWidth, const int GifHeight,
156
+ const bool GifInterlace,
157
+ const ColorMapObject *GifColorMap);
158
+ void EGifSetGifVersion(GifFileType *GifFile, const bool gif89);
159
+ int EGifPutLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
160
+ int EGifPutPixel(GifFileType *GifFile, const GifPixelType GifPixel);
161
+ int EGifPutComment(GifFileType *GifFile, const char *GifComment);
162
+ int EGifPutExtensionLeader(GifFileType *GifFile, const int GifExtCode);
163
+ int EGifPutExtensionBlock(GifFileType *GifFile, const int GifExtLen,
164
+ const void *GifExtension);
165
+ int EGifPutExtensionTrailer(GifFileType *GifFile);
166
+ int EGifPutExtension(GifFileType *GifFile, const int GifExtCode,
167
+ const int GifExtLen, const void *GifExtension);
168
+ int EGifPutCode(GifFileType *GifFile, int GifCodeSize,
169
+ const GifByteType *GifCodeBlock);
170
+ int EGifPutCodeNext(GifFileType *GifFile, const GifByteType *GifCodeBlock);
171
+
172
+ /******************************************************************************
173
+ GIF decoding routines
174
+ ******************************************************************************/
175
+
176
+ /* Main entry points */
177
+ GifFileType *DGifOpenFileName(const char *GifFileName, int *Error);
178
+ GifFileType *DGifOpenFileHandle(int GifFileHandle, int *Error);
179
+ int DGifSlurp(GifFileType *GifFile);
180
+ GifFileType *DGifOpen(void *userPtr, InputFunc readFunc,
181
+ int *Error); /* new one (TVT) */
182
+ int DGifCloseFile(GifFileType *GifFile, int *ErrorCode);
183
+
184
+ #define D_GIF_SUCCEEDED 0
185
+ #define D_GIF_ERR_OPEN_FAILED 101 /* And DGif possible errors. */
186
+ #define D_GIF_ERR_READ_FAILED 102
187
+ #define D_GIF_ERR_NOT_GIF_FILE 103
188
+ #define D_GIF_ERR_NO_SCRN_DSCR 104
189
+ #define D_GIF_ERR_NO_IMAG_DSCR 105
190
+ #define D_GIF_ERR_NO_COLOR_MAP 106
191
+ #define D_GIF_ERR_WRONG_RECORD 107
192
+ #define D_GIF_ERR_DATA_TOO_BIG 108
193
+ #define D_GIF_ERR_NOT_ENOUGH_MEM 109
194
+ #define D_GIF_ERR_CLOSE_FAILED 110
195
+ #define D_GIF_ERR_NOT_READABLE 111
196
+ #define D_GIF_ERR_IMAGE_DEFECT 112
197
+ #define D_GIF_ERR_EOF_TOO_SOON 113
198
+
199
+ /* These are legacy. You probably do not want to call them directly */
200
+ int DGifGetScreenDesc(GifFileType *GifFile);
201
+ int DGifGetRecordType(GifFileType *GifFile, GifRecordType *GifType);
202
+ int DGifGetImageHeader(GifFileType *GifFile);
203
+ int DGifGetImageDesc(GifFileType *GifFile);
204
+ int DGifGetLine(GifFileType *GifFile, GifPixelType *GifLine, int GifLineLen);
205
+ int DGifGetPixel(GifFileType *GifFile, GifPixelType GifPixel);
206
+ int DGifGetExtension(GifFileType *GifFile, int *GifExtCode,
207
+ GifByteType **GifExtension);
208
+ int DGifGetExtensionNext(GifFileType *GifFile, GifByteType **GifExtension);
209
+ int DGifGetCode(GifFileType *GifFile, int *GifCodeSize,
210
+ GifByteType **GifCodeBlock);
211
+ int DGifGetCodeNext(GifFileType *GifFile, GifByteType **GifCodeBlock);
212
+ int DGifGetLZCodes(GifFileType *GifFile, int *GifCode);
213
+ const char *DGifGetGifVersion(GifFileType *GifFile);
214
+
215
+ /******************************************************************************
216
+ Error handling and reporting.
217
+ ******************************************************************************/
218
+ extern const char *GifErrorString(int ErrorCode); /* new in 2012 - ESR */
219
+
220
+ /*****************************************************************************
221
+ it g in core.
222
+ ******************************************************************************/
223
+
224
+ /******************************************************************************
225
+ Color map handling from gif_alloc.c
226
+ ******************************************************************************/
227
+
228
+ extern ColorMapObject *GifMakeMapObject(int ColorCount,
229
+ const GifColorType *ColorMap);
230
+ extern void GifFreeMapObject(ColorMapObject *Object);
231
+ extern ColorMapObject *GifUnionColorMap(const ColorMapObject *ColorIn1,
232
+ const ColorMapObject *ColorIn2,
233
+ GifPixelType ColorTransIn2[]);
234
+ extern int GifBitSize(int n);
235
+
236
+ /******************************************************************************
237
+ Support for the in-core structures allocation (slurp mode).
238
+ ******************************************************************************/
239
+
240
+ extern void GifApplyTranslation(SavedImage *Image,
241
+ const GifPixelType Translation[]);
242
+ extern int GifAddExtensionBlock(int *ExtensionBlock_Count,
243
+ ExtensionBlock **ExtensionBlocks, int Function,
244
+ unsigned int Len, unsigned char ExtData[]);
245
+ extern void GifFreeExtensions(int *ExtensionBlock_Count,
246
+ ExtensionBlock **ExtensionBlocks);
247
+ extern SavedImage *GifMakeSavedImage(GifFileType *GifFile,
248
+ const SavedImage *CopyFrom);
249
+ extern void GifFreeSavedImages(GifFileType *GifFile);
250
+
251
+ /******************************************************************************
252
+ 5.x functions for GIF89 graphics control blocks
253
+ ******************************************************************************/
254
+
255
+ int DGifExtensionToGCB(const size_t GifExtensionLength,
256
+ const GifByteType *GifExtension,
257
+ GraphicsControlBlock *GCB);
258
+ size_t EGifGCBToExtension(const GraphicsControlBlock *GCB,
259
+ GifByteType *GifExtension);
260
+
261
+ int DGifSavedExtensionToGCB(GifFileType *GifFile, int ImageIndex,
262
+ GraphicsControlBlock *GCB);
263
+ int EGifGCBToSavedExtension(const GraphicsControlBlock *GCB,
264
+ GifFileType *GifFile, int ImageIndex);
265
+
266
+ /******************************************************************************
267
+ The library's internal utility font
268
+ ******************************************************************************/
269
+
270
+ #define GIF_FONT_WIDTH 8
271
+ #define GIF_FONT_HEIGHT 8
272
+ extern const unsigned char GifAsciiTable8x8[][GIF_FONT_WIDTH];
273
+
274
+ extern void GifDrawText8x8(SavedImage *Image, const int x, const int y,
275
+ const char *legend, const int color);
276
+
277
+ extern void GifDrawBox(SavedImage *Image, const int x, const int y, const int w,
278
+ const int d, const int color);
279
+
280
+ extern void GifDrawRectangle(SavedImage *Image, const int x, const int y,
281
+ const int w, const int d, const int color);
282
+
283
+ extern void GifDrawBoxedText8x8(SavedImage *Image, const int x, const int y,
284
+ const char *legend, const int border,
285
+ const int bg, const int fg);
286
+
287
+ #ifdef __cplusplus
288
+ }
289
+ #endif /* __cplusplus */
290
+ #endif /* _GIF_LIB_H */
291
+
292
+ /* end */
@@ -0,0 +1,73 @@
1
+ // @nolint (improperly imported third-party code)
2
+ /****************************************************************************
3
+
4
+ gif_lib_private.h - internal giflib routines and structures
5
+
6
+ SPDX-License-Identifier: MIT
7
+
8
+ ****************************************************************************/
9
+
10
+ #ifndef _GIF_LIB_PRIVATE_H
11
+ #define _GIF_LIB_PRIVATE_H
12
+
13
+ #include "gif_hash.h"
14
+ #include "gif_lib.h"
15
+
16
+ #ifndef SIZE_MAX
17
+ #define SIZE_MAX UINTPTR_MAX
18
+ #endif
19
+
20
+ #define EXTENSION_INTRODUCER 0x21
21
+ #define DESCRIPTOR_INTRODUCER 0x2c
22
+ #define TERMINATOR_INTRODUCER 0x3b
23
+
24
+ #define LZ_MAX_CODE 4095 /* Biggest code possible in 12 bits. */
25
+ #define LZ_BITS 12
26
+
27
+ #define FLUSH_OUTPUT 4096 /* Impossible code, to signal flush. */
28
+ #define FIRST_CODE 4097 /* Impossible code, to signal first. */
29
+ #define NO_SUCH_CODE 4098 /* Impossible code, to signal empty. */
30
+
31
+ #define FILE_STATE_WRITE 0x01
32
+ #define FILE_STATE_SCREEN 0x02
33
+ #define FILE_STATE_IMAGE 0x04
34
+ #define FILE_STATE_READ 0x08
35
+
36
+ #define IS_READABLE(Private) (Private->FileState & FILE_STATE_READ)
37
+ #define IS_WRITEABLE(Private) (Private->FileState & FILE_STATE_WRITE)
38
+
39
+ typedef struct GifFilePrivateType {
40
+ GifWord FileState, FileHandle, /* Where all this data goes to! */
41
+ BitsPerPixel, /* Bits per pixel (Codes uses at least this + 1). */
42
+ ClearCode, /* The CLEAR LZ code. */
43
+ EOFCode, /* The EOF LZ code. */
44
+ RunningCode, /* The next code algorithm can generate. */
45
+ RunningBits, /* The number of bits required to represent
46
+ RunningCode. */
47
+ MaxCode1, /* 1 bigger than max. possible code, in RunningBits bits.
48
+ */
49
+ LastCode, /* The code before the current code. */
50
+ CrntCode, /* Current algorithm code. */
51
+ StackPtr, /* For character stack (see below). */
52
+ CrntShiftState; /* Number of bits in CrntShiftDWord. */
53
+ unsigned long CrntShiftDWord; /* For bytes decomposition into codes. */
54
+ unsigned long PixelCount; /* Number of pixels in image. */
55
+ FILE *File; /* File as stream. */
56
+ InputFunc Read; /* function to read gif input (TVT) */
57
+ OutputFunc Write; /* function to write gif output (MRB) */
58
+ GifByteType Buf[256]; /* Compressed input is buffered here. */
59
+ GifByteType Stack[LZ_MAX_CODE]; /* Decoded pixels are stacked here. */
60
+ GifByteType Suffix[LZ_MAX_CODE + 1]; /* So we can trace the codes. */
61
+ GifPrefixType Prefix[LZ_MAX_CODE + 1];
62
+ GifHashTableType *HashTable;
63
+ bool gif89;
64
+ } GifFilePrivateType;
65
+
66
+ #ifndef HAVE_REALLOCARRAY
67
+ extern void *openbsd_reallocarray(void *optr, size_t nmemb, size_t size);
68
+ #define reallocarray openbsd_reallocarray
69
+ #endif
70
+
71
+ #endif /* _GIF_LIB_PRIVATE_H */
72
+
73
+ /* end */