OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 #ifndef MEDIA_FILTERS_JPEG_PARSER_H_ | 5 #ifndef MEDIA_FILTERS_JPEG_PARSER_H_ |
6 #define MEDIA_FILTERS_JPEG_PARSER_H_ | 6 #define MEDIA_FILTERS_JPEG_PARSER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include "media/base/media_export.h" | 10 #include "media/base/media_export.h" |
11 | 11 |
12 namespace media { | 12 namespace media { |
13 | 13 |
14 enum JpegMarker { | 14 enum JpegMarker { |
15 JPEG_SOF0 = 0xC0, // start of frame (baseline) | 15 JPEG_SOF0 = 0xC0, // start of frame (baseline) |
16 JPEG_SOF1 = 0xC1, // start of frame (extended sequential) | 16 JPEG_SOF1 = 0xC1, // start of frame (extended sequential) |
17 JPEG_SOF2 = 0xC2, // start of frame (progressive) | 17 JPEG_SOF2 = 0xC2, // start of frame (progressive) |
18 JPEG_SOF3 = 0xC3, // start of frame (lossless)) | 18 JPEG_SOF3 = 0xC3, // start of frame (lossless)) |
19 JPEG_DHT = 0xC4, // define huffman table | |
19 JPEG_SOF5 = 0xC5, // start of frame (differential, sequential) | 20 JPEG_SOF5 = 0xC5, // start of frame (differential, sequential) |
20 JPEG_SOF6 = 0xC6, // start of frame (differential, progressive) | 21 JPEG_SOF6 = 0xC6, // start of frame (differential, progressive) |
21 JPEG_SOF7 = 0xC7, // start of frame (differential, lossless) | 22 JPEG_SOF7 = 0xC7, // start of frame (differential, lossless) |
22 JPEG_SOF9 = 0xC9, // start of frame (arithmetic coding, extended) | 23 JPEG_SOF9 = 0xC9, // start of frame (arithmetic coding, extended) |
23 JPEG_SOF10 = 0xCA, // start of frame (arithmetic coding, progressive) | 24 JPEG_SOF10 = 0xCA, // start of frame (arithmetic coding, progressive) |
24 JPEG_SOF11 = 0xCB, // start of frame (arithmetic coding, lossless) | 25 JPEG_SOF11 = 0xCB, // start of frame (arithmetic coding, lossless) |
25 JPEG_SOF13 = 0xCD, // start of frame (differential, arithmetic, sequential) | 26 JPEG_SOF13 = 0xCD, // start of frame (differential, arithmetic, sequential) |
26 JPEG_SOF14 = 0xCE, // start of frame (differential, arithmetic, progressive) | 27 JPEG_SOF14 = 0xCE, // start of frame (differential, arithmetic, progressive) |
27 JPEG_SOF15 = 0xCF, // start of frame (differential, arithmetic, lossless) | 28 JPEG_SOF15 = 0xCF, // start of frame (differential, arithmetic, lossless) |
28 JPEG_DHT = 0xC4, // define huffman table | 29 JPEG_RST0 = 0xD0, // restart |
30 JPEG_RST1 = 0xD1, // restart | |
31 JPEG_RST2 = 0xD2, // restart | |
32 JPEG_RST3 = 0xD3, // restart | |
33 JPEG_RST4 = 0xD4, // restart | |
34 JPEG_RST5 = 0xD5, // restart | |
35 JPEG_RST6 = 0xD6, // restart | |
36 JPEG_RST7 = 0xD7, // restart | |
29 JPEG_SOI = 0xD8, // start of image | 37 JPEG_SOI = 0xD8, // start of image |
38 JPEG_EOI = 0xD9, // end of image | |
30 JPEG_SOS = 0xDA, // start of scan | 39 JPEG_SOS = 0xDA, // start of scan |
31 JPEG_DQT = 0xDB, // define quantization table | 40 JPEG_DQT = 0xDB, // define quantization table |
32 JPEG_DRI = 0xDD, // define restart internal | 41 JPEG_DRI = 0xDD, // define restart internal |
33 JPEG_MARKER_PREFIX = 0xFF, // jpeg marker prefix | 42 JPEG_MARKER_PREFIX = 0xFF, // jpeg marker prefix |
34 }; | 43 }; |
35 | 44 |
36 const size_t kJpegMaxHuffmanTableNumBaseline = 2; | 45 const size_t kJpegMaxHuffmanTableNumBaseline = 2; |
37 const size_t kJpegMaxComponents = 4; | 46 const size_t kJpegMaxComponents = 4; |
38 const size_t kJpegMaxQuantizationTableNum = 4; | 47 const size_t kJpegMaxQuantizationTableNum = 4; |
39 | 48 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 }; | 88 }; |
80 | 89 |
81 struct JpegParseResult { | 90 struct JpegParseResult { |
82 JpegFrameHeader frame_header; | 91 JpegFrameHeader frame_header; |
83 JpegHuffmanTable dc_table[kJpegMaxHuffmanTableNumBaseline]; | 92 JpegHuffmanTable dc_table[kJpegMaxHuffmanTableNumBaseline]; |
84 JpegHuffmanTable ac_table[kJpegMaxHuffmanTableNumBaseline]; | 93 JpegHuffmanTable ac_table[kJpegMaxHuffmanTableNumBaseline]; |
85 JpegQuantizationTable q_table[kJpegMaxQuantizationTableNum]; | 94 JpegQuantizationTable q_table[kJpegMaxQuantizationTableNum]; |
86 uint16_t restart_interval; | 95 uint16_t restart_interval; |
87 JpegScanHeader scan; | 96 JpegScanHeader scan; |
88 const char* data; | 97 const char* data; |
98 // The size of compressed data of the first image. | |
89 size_t data_size; | 99 size_t data_size; |
100 // The size of the first entire image including header. | |
101 size_t image_size; | |
90 }; | 102 }; |
91 | 103 |
92 // Parses JPEG picture in |buffer| with |length|. Returns true iff header is | 104 // Parses JPEG picture in |buffer| with |length|. Returns true iff header is |
93 // valid and JPEG baseline sequential process is present. If parsed | 105 // valid and JPEG baseline sequential process is present. If parsed |
94 // successfully, |result| is the parsed result. | 106 // successfully, |result| is the parsed result. |
95 // It's not a full featured JPEG parser implememtation. It only parses JPEG | 107 // It's not a full featured JPEG parser implememtation. It only parses JPEG |
96 // baseline sequential process. For explanations of each struct and its | 108 // baseline sequential process. For explanations of each struct and its |
97 // members, see JPEG specification at | 109 // members, see JPEG specification at |
98 // http://www.w3.org/Graphics/JPEG/itu-t81.pdf. | 110 // http://www.w3.org/Graphics/JPEG/itu-t81.pdf. |
99 MEDIA_EXPORT bool ParseJpegPicture(const uint8_t* buffer, | 111 MEDIA_EXPORT bool ParseJpegPicture(const uint8_t* buffer, |
100 size_t length, | 112 size_t length, |
101 JpegParseResult* result); | 113 JpegParseResult* result); |
102 | 114 |
115 // Parses the first image of JPEG stream in |buffer| with |length|. Returns | |
116 // true iff header is valid and JPEG baseline sequential process is present. | |
117 // If parsed successfully, |result| is the parsed result. | |
118 // It's not a full featured JPEG parser implememtation. It only parses JPEG | |
119 // baseline sequential process. For explanations of each struct and its | |
120 // members, see JPEG specification at | |
kcwu
2015/08/20 09:01:38
How about move the last sentence to the head of th
henryhsu
2015/08/20 09:50:59
Done.
| |
121 // http://www.w3.org/Graphics/JPEG/itu-t81.pdf. | |
122 MEDIA_EXPORT bool ParseJpegStream(const uint8_t* buffer, | |
123 size_t length, | |
124 JpegParseResult* result); | |
125 | |
103 } // namespace media | 126 } // namespace media |
104 | 127 |
105 #endif // MEDIA_FILTERS_JPEG_PARSER_H_ | 128 #endif // MEDIA_FILTERS_JPEG_PARSER_H_ |
OLD | NEW |