Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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. | |
| 4 // | |
| 5 #ifndef MEDIA_FILTERS_JPEG_PARSER_H_ | |
| 6 #define MEDIA_FILTERS_JPEG_PARSER_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 #include "base/macros.h" | |
| 10 #include "media/base/media_export.h" | |
| 11 | |
| 12 namespace media { | |
| 13 | |
| 14 const size_t kJpegMaxHuffmanTableNumBaseline = 2; | |
| 15 const size_t kJpegMaxComponents = 4; | |
| 16 const size_t kJpegMaxQuantizationTableNum = 4; | |
| 17 | |
| 18 // Parsing result of JPEG DHT marker. | |
| 19 struct JpegHuffmanTable { | |
| 20 bool valid; | |
| 21 uint8_t code_length[16]; | |
| 22 uint8_t code_value[256]; | |
| 23 }; | |
| 24 | |
| 25 // Parsing result of JPEG DQT marker. | |
| 26 struct JpegQuantizationTable { | |
| 27 bool valid; | |
| 28 uint8_t value[64]; // baseline only supports 8 bits quantization table | |
| 29 }; | |
| 30 | |
| 31 // Parsing result of a JPEG component. | |
| 32 struct JpegComponent { | |
| 33 uint8_t id; | |
| 34 uint8_t horizontal_sampling_factor; | |
| 35 uint8_t vertical_sampling_factor; | |
| 36 uint8_t quantization_table_selector; | |
| 37 }; | |
| 38 | |
| 39 // Parsing result of a JPEG SOF marker. | |
| 40 struct JpegFrameHeader { | |
| 41 uint16_t visible_width; | |
| 42 uint16_t visible_height; | |
| 43 uint8_t num_components; | |
| 44 JpegComponent components[kJpegMaxComponents]; | |
| 45 }; | |
| 46 | |
| 47 // Parsing result of JPEG SOS marker. | |
| 48 struct JpegScanHeader { | |
| 49 uint8_t num_components; | |
| 50 struct Component { | |
| 51 uint8_t component_selector; | |
| 52 uint8_t dc_selector; | |
| 53 uint8_t ac_selector; | |
| 54 } components[kJpegMaxComponents]; | |
| 55 }; | |
| 56 | |
| 57 struct JpegParseResult { | |
| 58 JpegFrameHeader frame_header; | |
| 59 JpegHuffmanTable dc_table[kJpegMaxHuffmanTableNumBaseline]; | |
| 60 JpegHuffmanTable ac_table[kJpegMaxHuffmanTableNumBaseline]; | |
| 61 JpegQuantizationTable q_table[kJpegMaxQuantizationTableNum]; | |
| 62 uint16_t restart_interval; | |
| 63 JpegScanHeader scan; | |
| 64 const char* data; | |
| 65 size_t data_size; | |
| 66 }; | |
| 67 | |
| 68 // Parses JPEG picture in |buffer| with |length|. Returns true iff header is | |
| 69 // valid and JPEG baseline sequential process is present. If parsed | |
| 70 // successfully, |result| is the parsed result. | |
| 71 // It's not a full featured JPEG parser implememtation. It only parses JPEG | |
| 72 // baseline sequential process. For explanations of each struct and its | |
| 73 // members, see JPEG specification at | |
| 74 // http://www.w3.org/Graphics/JPEG/itu-t81.pdf. | |
| 75 bool ParseJpegPicture(const uint8_t* buffer, | |
|
xhwang
2015/01/13 17:07:14
You need MEDIA_EXPORT to use it in the unittest.
kcwu
2015/01/14 06:22:46
Done.
| |
| 76 size_t length, | |
| 77 JpegParseResult* result); | |
| 78 | |
| 79 } // namespace media | |
| 80 | |
| 81 #endif // MEDIA_FILTERS_JPEG_PARSER_H_ | |
| OLD | NEW |