2 * gstjpegparser.h - JPEG parser
4 * Copyright (C) 2011-2012 Intel Corporation
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1
9 * of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301 USA
22 #ifndef GST_JPEG_PARSER_H
23 #define GST_JPEG_PARSER_H
25 #ifndef GST_USE_UNSTABLE_API
26 # warning "The JPEG parsing library is unstable API and may change in future."
27 # warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
35 * GST_JPEG_MAX_FRAME_COMPONENTS:
37 * Maximum number of image components in a frame (Nf).
39 #define GST_JPEG_MAX_FRAME_COMPONENTS 256
42 * GST_JPEG_MAX_SCAN_COMPONENTS:
44 * Maximum number of image components in a scan (Ns).
46 #define GST_JPEG_MAX_SCAN_COMPONENTS 4
49 * GST_JPEG_MAX_QUANT_ELEMENTS:
51 * Number of elements in the quantization table.
53 #define GST_JPEG_MAX_QUANT_ELEMENTS 64
55 typedef struct _GstJpegQuantTable GstJpegQuantTable;
56 typedef struct _GstJpegQuantTables GstJpegQuantTables;
57 typedef struct _GstJpegHuffmanTable GstJpegHuffmanTable;
58 typedef struct _GstJpegHuffmanTables GstJpegHuffmanTables;
59 typedef struct _GstJpegScanComponent GstJpegScanComponent;
60 typedef struct _GstJpegScanHdr GstJpegScanHdr;
61 typedef struct _GstJpegFrameComponent GstJpegFrameComponent;
62 typedef struct _GstJpegFrameHdr GstJpegFrameHdr;
63 typedef struct _GstJpegMarkerSegment GstJpegMarkerSegment;
67 * @GST_JPEG_MARKER_SOF_MIN: Start of frame min marker code
68 * @GST_JPEG_MARKER_SOF_MAX: Start of frame max marker code
69 * @GST_JPEG_MARKER_DHT: Huffman tabler marker code
70 * @GST_JPEG_MARKER_DAC: Arithmetic coding marker code
71 * @GST_JPEG_MARKER_RST_MIN: Restart interval min marker code
72 * @GST_JPEG_MARKER_RST_MAX: Restart interval max marker code
73 * @GST_JPEG_MARKER_SOI: Start of image marker code
74 * @GST_JPEG_MARKER_EOI: End of image marker code
75 * @GST_JPEG_MARKER_SOS: Start of scan marker code
76 * @GST_JPEG_MARKER_DQT: Define quantization table marker code
77 * @GST_JPEG_MARKER_DNL: Define number of lines marker code
78 * @GST_JPEG_MARKER_DRI: Define restart interval marker code
79 * @GST_JPEG_MARKER_APP_MIN: Application segment min marker code
80 * @GST_JPEG_MARKER_APP_MAX: Application segment max marker code
81 * @GST_JPEG_MARKER_COM: Comment marker code
83 * Indicates the type of JPEG segment.
86 GST_JPEG_MARKER_SOF_MIN = 0xC0,
87 GST_JPEG_MARKER_SOF_MAX = 0xCF,
88 GST_JPEG_MARKER_DHT = 0xC4,
89 GST_JPEG_MARKER_DAC = 0xCC,
90 GST_JPEG_MARKER_RST_MIN = 0xD0,
91 GST_JPEG_MARKER_RST_MAX = 0xD7,
92 GST_JPEG_MARKER_SOI = 0xD8,
93 GST_JPEG_MARKER_EOI = 0xD9,
94 GST_JPEG_MARKER_SOS = 0xDA,
95 GST_JPEG_MARKER_DQT = 0xDB,
96 GST_JPEG_MARKER_DNL = 0xDC,
97 GST_JPEG_MARKER_DRI = 0xDD,
98 GST_JPEG_MARKER_APP_MIN = 0xE0,
99 GST_JPEG_MARKER_APP_MAX = 0xEF,
100 GST_JPEG_MARKER_COM = 0xFE,
105 * @GST_JPEG_PROFILE_BASELINE: Baseline DCT
106 * @GST_JPEG_PROFILE_EXTENDED: Extended sequential DCT
107 * @GST_JPEG_PROFILE_PROGRESSIVE: Progressive DCT
108 * @GST_JPEG_PROFILE_LOSSLESS: Lossless (sequential)
110 * JPEG encoding processes.
113 GST_JPEG_PROFILE_BASELINE = 0x00,
114 GST_JPEG_PROFILE_EXTENDED = 0x01,
115 GST_JPEG_PROFILE_PROGRESSIVE = 0x02,
116 GST_JPEG_PROFILE_LOSSLESS = 0x03,
120 * GstJpegEntropyCodingMode:
121 * @GST_JPEG_ENTROPY_CODING_HUFFMAN: Huffman coding
122 * @GST_JPEG_ENTROPY_CODING_ARITHMETIC: arithmetic coding
124 * JPEG entropy coding mode.
127 GST_JPEG_ENTROPY_CODING_HUFFMAN = 0x00,
128 GST_JPEG_ENTROPY_CODING_ARITHMETIC = 0x08
129 } GstJpegEntropyCodingMode;
133 * @quant_precision: Quantization table element precision (Pq)
134 * @quant_table: Quantization table elements (Qk)
135 * @valid: If the quantization table is valid, which means it has
136 * already been parsed
138 * Quantization table.
140 struct _GstJpegQuantTable
142 guint8 quant_precision;
143 guint16 quant_table[GST_JPEG_MAX_QUANT_ELEMENTS];
148 * GstJpegQuantTables:
149 * @quant_tables: All quantization tables
151 * Helper data structure that holds all quantization tables used to
154 struct _GstJpegQuantTables
156 GstJpegQuantTable quant_tables[GST_JPEG_MAX_SCAN_COMPONENTS];
160 * GstJpegHuffmanTable:
161 * @huf_bits: Number of Huffman codes of length i + 1 (Li)
162 * @huf_vales: Value associated with each Huffman code (Vij)
163 * @valid: If the Huffman table is valid, which means it has already
168 struct _GstJpegHuffmanTable
171 guint8 huf_values[256];
176 * GstJpegHuffmanTables:
177 * @dc_tables: DC Huffman tables
178 * @ac_tables: AC Huffman tables
180 * Helper data structure that holds all AC/DC Huffman tables used to
183 struct _GstJpegHuffmanTables
185 GstJpegHuffmanTable dc_tables[GST_JPEG_MAX_SCAN_COMPONENTS];
186 GstJpegHuffmanTable ac_tables[GST_JPEG_MAX_SCAN_COMPONENTS];
190 * GstJpegScanComponent:
191 * @component_selector: Scan component selector (Csj)
192 * @dc_selector: DC entropy coding table destination selector (Tdj)
193 * @ac_selector: AC entropy coding table destination selector (Taj)
195 * Component-specification parameters.
197 struct _GstJpegScanComponent
199 guint8 component_selector; /* 0 .. 255 */
200 guint8 dc_selector; /* 0 .. 3 */
201 guint8 ac_selector; /* 0 .. 3 */
206 * @num_components: Number of image components in scan (Ns)
207 * @components: Image components
211 struct _GstJpegScanHdr
213 guint8 num_components; /* 1 .. 4 */
214 GstJpegScanComponent components[GST_JPEG_MAX_SCAN_COMPONENTS];
218 * GstJpegFrameComponent:
219 * @identifier: Component identifier (Ci)
220 * @horizontal_factor: Horizontal sampling factor (Hi)
221 * @vertical_factor: Vertical sampling factor (Vi)
222 * @quant_table_selector: Quantization table destination selector (Tqi)
224 * Component-specification parameters.
226 struct _GstJpegFrameComponent
228 guint8 identifier; /* 0 .. 255 */
229 guint8 horizontal_factor; /* 1 .. 4 */
230 guint8 vertical_factor; /* 1 .. 4 */
231 guint8 quant_table_selector; /* 0 .. 3 */
236 * @sample_precision: Sample precision (P)
237 * @height: Number of lines (Y)
238 * @width: Number of samples per line (X)
239 * @num_components: Number of image components in frame (Nf)
240 * @components: Image components
241 * @restart_interval: Number of MCU in the restart interval (Ri)
245 struct _GstJpegFrameHdr
247 guint8 sample_precision; /* 2 .. 16 */
248 guint16 width; /* 1 .. 65535 */
249 guint16 height; /* 0 .. 65535 */
250 guint8 num_components; /* 1 .. 255 */
251 GstJpegFrameComponent components[GST_JPEG_MAX_FRAME_COMPONENTS];
255 * GstJpegMarkerSegment:
256 * @type: The type of the segment that starts at @offset
257 * @offset: The offset to the segment start in bytes. This is the
258 * exact start of the segment, no marker code included
259 * @size: The size in bytes of the segment, or -1 if the end was not
260 * found. It is the exact size of the segment, no marker code included
262 * A structure that contains the type of a segment, its offset and its size.
264 struct _GstJpegMarkerSegment
272 * gst_jpeg_scan_for_marker_code:
273 * @data: The data to parse
274 * @size: The size of @data
275 * @offset: The offset from which to start parsing
277 * Scans the JPEG bitstream contained in @data for the next marker
278 * code. If found, the function returns an offset to the marker code,
279 * including the 0xff prefix code but excluding any extra fill bytes.
281 * Returns: offset to the marker code if found, or -1 if not found.
283 gint gst_jpeg_scan_for_marker_code (const guint8 * data,
289 * @data: The data to parse
290 * @size: The size of @data
291 * @offset: The offset from which to start parsing
293 * Parses the JPEG bitstream contained in @data, and returns the
294 * detected segment as a #GstJpegMarkerSegment.
296 * Returns: TRUE if a packet start code was found.
298 gboolean gst_jpeg_parse (GstJpegMarkerSegment * seg,
304 * gst_jpeg_parse_frame_hdr:
305 * @hdr: (out): The #GstJpegFrameHdr structure to fill in
306 * @data: The data from which to parse the frame header
307 * @size: The size of @data
308 * @offset: The offset in bytes from which to start parsing @data
310 * Parses the @hdr JPEG frame header structure members from @data.
312 * Returns: TRUE if the frame header was correctly parsed.
314 gboolean gst_jpeg_parse_frame_hdr (GstJpegFrameHdr * hdr,
320 * gst_jpeg_parse_scan_hdr:
321 * @hdr: (out): The #GstJpegScanHdr structure to fill in
322 * @data: The data from which to parse the scan header
323 * @size: The size of @data
324 * @offset: The offset in bytes from which to start parsing @data
326 * Parses the @hdr JPEG scan header structure members from @data.
328 * Returns: TRUE if the scan header was correctly parsed
330 gboolean gst_jpeg_parse_scan_hdr (GstJpegScanHdr * hdr,
336 * gst_jpeg_parse_quantization_table:
337 * @quant_tables: (out): The #GstJpegQuantizationTable structure to fill in
338 * @num_quant_tables: The number of allocated quantization tables in @quant_tables
339 * @data: The data from which to parse the quantization table
340 * @size: The size of @data
341 * @offset: The offset in bytes from which to start parsing @data
343 * Parses the JPEG quantization table structure members from @data.
345 * Note: @quant_tables represents the complete set of possible
346 * quantization tables. However, the parser will only write to the
347 * quantization table specified by the table destination identifier
348 * (Tq). While doing so, the @valid flag of the specified quantization
349 * table will also be set to %TRUE.
351 * Returns: TRUE if the quantization table was correctly parsed.
353 gboolean gst_jpeg_parse_quant_table (GstJpegQuantTables *quant_tables,
359 * gst_jpeg_parse_huffman_table:
360 * @huf_tables: (out): The #GstJpegHuffmanTable structure to fill in
361 * @data: The data from which to parse the Huffman table
362 * @size: The size of @data
363 * @offset: The offset in bytes from which to start parsing @data
365 * Parses the JPEG Huffman table structure members from @data.
367 * Note: @huf_tables represents the complete set of possible Huffman
368 * tables. However, the parser will only write to the Huffman table
369 * specified by the table destination identifier (Th). While doing so,
370 * the @valid flag of the specified Huffman table will also be set to
373 * Returns: TRUE if the Huffman table was correctly parsed.
375 gboolean gst_jpeg_parse_huffman_table (GstJpegHuffmanTables *huf_tables,
381 * gst_jpeg_parse_restart_interval:
382 * @interval: (out): The parsed restart interval value
383 * @data: The data from which to parse the restart interval specification
384 * @size: The size of @data
385 * @offset: The offset in bytes from which to start parsing @data
387 * Returns: TRUE if the restart interval value was correctly parsed.
389 gboolean gst_jpeg_parse_restart_interval (guint * interval,
395 * gst_jpeg_get_default_huffman_tables:
396 * @huf_tables: (out): The default DC/AC Huffman tables to fill in
398 * Fills in @huf_tables with the default AC/DC Huffman tables, as
399 * specified by the JPEG standard.
401 void gst_jpeg_get_default_huffman_tables (GstJpegHuffmanTables *huf_tables);
404 * gst_jpeg_get_default_quantization_table:
405 * @quant_tables: (out): The default luma/chroma quant-tables in zigzag mode
407 * Fills in @quant_tables with the default quantization tables, as
408 * specified by the JPEG standard.
410 void gst_jpeg_get_default_quantization_tables (GstJpegQuantTables *quant_tables);
414 #endif /* GST_JPEG_PARSER_H */