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"
14 const size_t kJpegMaxHuffmanTableNumBaseline
= 2;
15 const size_t kJpegMaxComponents
= 4;
16 const size_t kJpegMaxQuantizationTableNum
= 4;
18 // Parsing result of JPEG DHT marker.
19 struct JpegHuffmanTable
{
21 uint8_t code_length
[16];
22 uint8_t code_value
[256];
25 // Parsing result of JPEG DQT marker.
26 struct JpegQuantizationTable
{
28 uint8_t value
[64]; // baseline only supports 8 bits quantization table
31 // Parsing result of a JPEG component.
32 struct JpegComponent
{
34 uint8_t horizontal_sampling_factor
;
35 uint8_t vertical_sampling_factor
;
36 uint8_t quantization_table_selector
;
39 // Parsing result of a JPEG SOF marker.
40 struct JpegFrameHeader
{
41 uint16_t visible_width
;
42 uint16_t visible_height
;
44 uint16_t coded_height
;
45 uint8_t num_components
;
46 JpegComponent components
[kJpegMaxComponents
];
49 // Parsing result of JPEG SOS marker.
50 struct JpegScanHeader
{
51 uint8_t num_components
;
53 uint8_t component_selector
;
56 } components
[kJpegMaxComponents
];
59 struct JpegParseResult
{
60 JpegFrameHeader frame_header
;
61 JpegHuffmanTable dc_table
[kJpegMaxHuffmanTableNumBaseline
];
62 JpegHuffmanTable ac_table
[kJpegMaxHuffmanTableNumBaseline
];
63 JpegQuantizationTable q_table
[kJpegMaxQuantizationTableNum
];
64 uint16_t restart_interval
;
70 // Parses JPEG picture in |buffer| with |length|. Returns true iff header is
71 // valid and JPEG baseline sequential process is present. If parsed
72 // successfully, |result| is the parsed result.
73 // It's not a full featured JPEG parser implememtation. It only parses JPEG
74 // baseline sequential process. For explanations of each struct and its
75 // members, see JPEG specification at
76 // http://www.w3.org/Graphics/JPEG/itu-t81.pdf.
77 MEDIA_EXPORT
bool ParseJpegPicture(const uint8_t* buffer
,
79 JpegParseResult
* result
);
83 #endif // MEDIA_FILTERS_JPEG_PARSER_H_