1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef MEDIA_FILTERS_JPEG_PARSER_H_
6 #define MEDIA_FILTERS_JPEG_PARSER_H_
10 #include "media/base/media_export.h"
15 JPEG_SOF0
= 0xC0, // start of frame (baseline)
16 JPEG_SOF1
= 0xC1, // start of frame (extended sequential)
17 JPEG_SOF2
= 0xC2, // start of frame (progressive)
18 JPEG_SOF3
= 0xC3, // start of frame (lossless))
19 JPEG_SOF5
= 0xC5, // start of frame (differential, sequential)
20 JPEG_SOF6
= 0xC6, // start of frame (differential, progressive)
21 JPEG_SOF7
= 0xC7, // start of frame (differential, lossless)
22 JPEG_SOF9
= 0xC9, // start of frame (arithmetic coding, extended)
23 JPEG_SOF10
= 0xCA, // start of frame (arithmetic coding, progressive)
24 JPEG_SOF11
= 0xCB, // start of frame (arithmetic coding, lossless)
25 JPEG_SOF13
= 0xCD, // start of frame (differential, arithmetic, sequential)
26 JPEG_SOF14
= 0xCE, // start of frame (differential, arithmetic, progressive)
27 JPEG_SOF15
= 0xCF, // start of frame (differential, arithmetic, lossless)
28 JPEG_DHT
= 0xC4, // define huffman table
29 JPEG_SOI
= 0xD8, // start of image
30 JPEG_SOS
= 0xDA, // start of scan
31 JPEG_DQT
= 0xDB, // define quantization table
32 JPEG_DRI
= 0xDD, // define restart internal
33 JPEG_MARKER_PREFIX
= 0xFF, // jpeg marker prefix
36 const size_t kJpegMaxHuffmanTableNumBaseline
= 2;
37 const size_t kJpegMaxComponents
= 4;
38 const size_t kJpegMaxQuantizationTableNum
= 4;
40 // Parsing result of JPEG DHT marker.
41 struct JpegHuffmanTable
{
43 uint8_t code_length
[16];
44 uint8_t code_value
[256];
47 // Parsing result of JPEG DQT marker.
48 struct JpegQuantizationTable
{
50 uint8_t value
[64]; // baseline only supports 8 bits quantization table
53 // Parsing result of a JPEG component.
54 struct JpegComponent
{
56 uint8_t horizontal_sampling_factor
;
57 uint8_t vertical_sampling_factor
;
58 uint8_t quantization_table_selector
;
61 // Parsing result of a JPEG SOF marker.
62 struct JpegFrameHeader
{
63 uint16_t visible_width
;
64 uint16_t visible_height
;
66 uint16_t coded_height
;
67 uint8_t num_components
;
68 JpegComponent components
[kJpegMaxComponents
];
71 // Parsing result of JPEG SOS marker.
72 struct JpegScanHeader
{
73 uint8_t num_components
;
75 uint8_t component_selector
;
78 } components
[kJpegMaxComponents
];
81 struct JpegParseResult
{
82 JpegFrameHeader frame_header
;
83 JpegHuffmanTable dc_table
[kJpegMaxHuffmanTableNumBaseline
];
84 JpegHuffmanTable ac_table
[kJpegMaxHuffmanTableNumBaseline
];
85 JpegQuantizationTable q_table
[kJpegMaxQuantizationTableNum
];
86 uint16_t restart_interval
;
92 // Parses JPEG picture in |buffer| with |length|. Returns true iff header is
93 // valid and JPEG baseline sequential process is present. If parsed
94 // successfully, |result| is the parsed result.
95 // It's not a full featured JPEG parser implememtation. It only parses JPEG
96 // baseline sequential process. For explanations of each struct and its
97 // members, see JPEG specification at
98 // http://www.w3.org/Graphics/JPEG/itu-t81.pdf.
99 MEDIA_EXPORT
bool ParseJpegPicture(const uint8_t* buffer
,
101 JpegParseResult
* result
);
105 #endif // MEDIA_FILTERS_JPEG_PARSER_H_