1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
//! Image format constants: magic numbers, headers, markers, and tags
//!
//! Centralizes all format-specific constants used across image parsers
//! for maintainability and consistency.
// ============================================================================
// Format Signatures / Magic Numbers
// ============================================================================
/// JPEG Start of Image (SOI) marker
pub const JPEG_SOI: & = &;
/// PNG signature (first 8 bytes)
pub const PNG_SIGNATURE: & = &;
/// `GIF87a` signature
pub const GIF87A_SIGNATURE: & = b"GIF87a";
/// `GIF89a` signature
pub const GIF89A_SIGNATURE: & = b"GIF89a";
/// WebP RIFF signature (bytes 0-3)
pub const WEBP_RIFF: & = b"RIFF";
/// WebP format identifier (bytes 8-11)
pub const WEBP_FORMAT: & = b"WEBP";
/// BMP signature (bytes 0-1)
pub const BMP_SIGNATURE: & = b"BM";
/// TIFF little-endian signature (bytes 0-1)
pub const TIFF_LE_SIGNATURE: & = b"II";
/// TIFF big-endian signature (bytes 0-1)
pub const TIFF_BE_SIGNATURE: & = b"MM";
/// TIFF version number (should be 42, bytes 2-3)
pub const TIFF_VERSION: u16 = 42;
// ============================================================================
// JPEG Markers
// ============================================================================
/// JPEG End of Image (EOI) marker
pub const JPEG_EOI: u8 = 0xD9;
/// JPEG Restart markers (RST0-RST7)
pub const JPEG_RST_START: u8 = 0xD0;
pub const JPEG_RST_END: u8 = 0xD7;
/// JPEG Temporary marker
pub const JPEG_TEM: u8 = 0x01;
/// JPEG Start of Frame (SOF) markers
/// These indicate the start of frame data and contain image dimensions
pub const JPEG_SOF_MARKERS: & = &;
// ============================================================================
// PNG Chunk Types
// ============================================================================
/// PNG IHDR chunk type (Image Header)
pub const PNG_IHDR: & = b"IHDR";
// ============================================================================
// WebP Chunk Types
// ============================================================================
/// WebP VP8 chunk type (lossy)
pub const WEBP_VP8: & = b"VP8 ";
/// WebP VP8L chunk type (lossless)
pub const WEBP_VP8L: & = b"VP8L";
/// WebP VP8X chunk type (extended)
pub const WEBP_VP8X: & = b"VP8X";
/// WebP alpha channel flag bit mask (bit 4 of flags byte)
pub const WEBP_ALPHA_FLAG: u8 = 0x10;
// ============================================================================
// TIFF Tags
// ============================================================================
/// TIFF tag: `BitsPerSample` (258 / 0x0102)
pub const TIFF_TAG_BITS_PER_SAMPLE: u16 = 258;
/// TIFF tag: Compression (259 / 0x0103)
/// Note: Currently not used - compression extraction returns "TIFF" as placeholder
pub const TIFF_TAG_COMPRESSION: u16 = 259;
/// TIFF tag: `PhotometricInterpretation` (262 / 0x0106)
pub const TIFF_TAG_PHOTOMETRIC_INTERPRETATION: u16 = 262;
/// TIFF IFD entry type: SHORT (16-bit)
pub const TIFF_TYPE_SHORT: u16 = 3;
/// TIFF IFD entry type: LONG (32-bit)
pub const TIFF_TYPE_LONG: u16 = 4;
// ============================================================================
// TIFF PhotometricInterpretation Values
// ============================================================================
/// TIFF `PhotometricInterpretation`: `WhiteIsZero` (grayscale, inverted)
pub const TIFF_PHOTOMETRIC_WHITE_IS_ZERO: u32 = 0;
/// TIFF `PhotometricInterpretation`: `BlackIsZero` (grayscale)
pub const TIFF_PHOTOMETRIC_BLACK_IS_ZERO: u32 = 1;
/// TIFF `PhotometricInterpretation`: RGB
pub const TIFF_PHOTOMETRIC_RGB: u32 = 2;
/// TIFF `PhotometricInterpretation`: Palette color (indexed)
pub const TIFF_PHOTOMETRIC_PALETTE: u32 = 3;
/// TIFF `PhotometricInterpretation`: Transparency mask
pub const TIFF_PHOTOMETRIC_MASK: u32 = 4;
/// TIFF `PhotometricInterpretation`: CMYK
pub const TIFF_PHOTOMETRIC_CMYK: u32 = 5;
/// TIFF `PhotometricInterpretation`: YCbCr (typically converted to RGB for display)
pub const TIFF_PHOTOMETRIC_YCBCR: u32 = 6;
/// TIFF `PhotometricInterpretation`: CIE L*a*b*
pub const TIFF_PHOTOMETRIC_CIELAB: u32 = 8;
// ============================================================================
// BMP Compression Constants
// ============================================================================
/// BMP compression: `BI_RGB` (no compression)
pub const BMP_COMPRESSION_RGB: u32 = 0;
/// BMP compression: `BI_RLE8` (8-bit RLE)
pub const BMP_COMPRESSION_RLE8: u32 = 1;
/// BMP compression: `BI_RLE4` (4-bit RLE)
pub const BMP_COMPRESSION_RLE4: u32 = 2;
/// BMP compression: `BI_BITFIELDS` (bit fields)
pub const BMP_COMPRESSION_BITFIELDS: u32 = 3;
/// BMP compression: `BI_JPEG` (JPEG compression)
pub const BMP_COMPRESSION_JPEG: u32 = 4;
/// BMP compression: `BI_PNG` (PNG compression)
pub const BMP_COMPRESSION_PNG: u32 = 5;
// ============================================================================
// Color Type Names
// ============================================================================
/// Color type: 8-bit RGB (3 channels, 24-bit total)
pub const COLOR_TYPE_RGB8: &str = "Rgb8";
/// Color type: 8-bit RGBA (4 channels, 32-bit total)
pub const COLOR_TYPE_RGBA8: &str = "Rgba8";
/// Color type: 8-bit grayscale (1 channel, 8-bit total)
pub const COLOR_TYPE_L8: &str = "L8";
/// Color type: 8-bit grayscale with alpha (2 channels, 16-bit total)
pub const COLOR_TYPE_LA8: &str = "La8";
/// Color type: 8-bit CMYK (4 channels, 32-bit total)
pub const COLOR_TYPE_CMYK8: &str = "Cmyk8";
/// Color type: 8-bit indexed/palette color
pub const COLOR_TYPE_INDEXED8: &str = "Indexed8";
/// Color type: 4-bit indexed/palette color
pub const COLOR_TYPE_INDEXED4: &str = "Indexed4";
/// Color type: 1-bit indexed/palette color
pub const COLOR_TYPE_INDEXED1: &str = "Indexed1";
/// Color type: 16-bit RGB (typically 5-6-5 format)
pub const COLOR_TYPE_RGB16: &str = "Rgb16";
/// Color type: 16-bit grayscale
pub const COLOR_TYPE_L16: &str = "L16";
/// Color type: 16-bit grayscale with alpha
pub const COLOR_TYPE_LA16: &str = "La16";
/// Color type: 16-bit RGBA
pub const COLOR_TYPE_RGBA16: &str = "Rgba16";
/// Color type: Grayscale (generic, used in JPEG)
pub const COLOR_TYPE_GRAYSCALE: &str = "Grayscale";
// ============================================================================
// Chroma Subsampling Names (JPEG)
// ============================================================================
/// Chroma subsampling: 4:4:4 (no subsampling, full chroma resolution)
/// Y: 1x1, Cb: 1x1, Cr: 1x1
pub const SUBSAMPLING_444: &str = "4:4:4";
/// Chroma subsampling: 4:2:2 (horizontal subsampling)
/// Y: 2x1, Cb: 1x1, Cr: 1x1
pub const SUBSAMPLING_422: &str = "4:2:2";
/// Chroma subsampling: 4:2:0 (horizontal and vertical subsampling)
/// Y: 2x2, Cb: 1x1, Cr: 1x1
pub const SUBSAMPLING_420: &str = "4:2:0";
/// Chroma subsampling: 4:1:1 (heavy horizontal subsampling)
/// Y: 4x1, Cb: 1x1, Cr: 1x1
pub const SUBSAMPLING_411: &str = "4:1:1";
/// Chroma subsampling: Unknown (for unrecognized patterns)
pub const SUBSAMPLING_UNKNOWN: &str = "Unknown";
// ============================================================================
// Helper Functions
// ============================================================================
/// Check if a byte is a JPEG SOF marker
/// Check if a byte is a JPEG restart marker (RST0-RST7)
/// Check if data starts with JPEG SOI marker
/// Check if data starts with PNG signature
/// Check if data starts with GIF signature (`GIF87a` or `GIF89a`)
/// Check if data starts with WebP signature
/// Check if data starts with BMP signature
/// Check if data starts with TIFF signature (little-endian or big-endian)