Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_PARSER_H_ | |
| 6 #define CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_PARSER_H_ | |
| 7 | |
| 8 #include "base/big_endian.h" | |
| 9 #include "base/macros.h" | |
| 10 #include "content/common/content_export.h" | |
| 11 #include "ui/gfx/geometry/size.h" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 static const size_t kJpegMaxHuffmanTableNum_baseline = 2; | |
| 16 static const size_t kJpegMaxComponents = 4; | |
| 17 static const size_t kJpegMaxQuantizationTableNum = 4; | |
| 18 | |
| 19 // Parsing result of JPEG DHT marker. | |
| 20 struct JpegHuffmanTable { | |
| 21 bool valid; | |
| 22 uint8_t code_length[16]; | |
| 23 uint8_t code_value[256]; | |
| 24 }; | |
| 25 | |
| 26 // Parsing result of JPEG DQT marker. | |
| 27 struct JpegQuantizationTable { | |
| 28 bool valid; | |
| 29 uint8_t value[64]; // only support 8 bits quantization table for baseline | |
| 30 }; | |
| 31 | |
| 32 // Parsing result of a JPEG component. | |
| 33 struct JpegComponent { | |
| 34 uint8_t id; | |
| 35 uint8_t horizontal_sampling_factor; | |
| 36 uint8_t vertical_sampling_factor; | |
| 37 uint8_t quantization_table_selector; | |
| 38 }; | |
| 39 | |
| 40 // Parsing result of JPEG SOS marker. | |
| 41 struct JpegScan { | |
| 42 uint8_t num_components; | |
| 43 struct Component { | |
| 44 uint8_t component_selector; | |
| 45 uint8_t dc_selector; | |
| 46 uint8_t ac_selector; | |
| 47 } components[kJpegMaxComponents]; | |
| 48 const uint8_t* data; | |
| 49 size_t data_size; | |
| 50 }; | |
| 51 | |
| 52 struct JpegParseResult { | |
| 53 JpegParseResult(); | |
| 54 gfx::Size visible_size; | |
| 55 uint8_t num_components; | |
| 56 JpegComponent components[kJpegMaxComponents]; | |
| 57 JpegHuffmanTable dc_table[kJpegMaxHuffmanTableNum_baseline]; | |
| 58 JpegHuffmanTable ac_table[kJpegMaxHuffmanTableNum_baseline]; | |
| 59 JpegQuantizationTable q_table[kJpegMaxQuantizationTableNum]; | |
| 60 uint16_t restart_interval; | |
| 61 JpegScan scan; | |
| 62 }; | |
| 63 | |
| 64 // JpegParser parses JPEG header. It's not a full featured JPEG parser | |
| 65 // implememtation. It only parses JPEG baseline sequential process. For | |
| 66 // explanations of each struct and its members, see JPEG specification at | |
| 67 // http://www.w3.org/Graphics/JPEG/itu-t81.pdf. | |
| 68 class CONTENT_EXPORT JpegParser { | |
| 69 public: | |
| 70 JpegParser(); | |
|
Owen Lin
2014/12/29 09:03:20
If all members are static, why we need constructor
| |
| 71 ~JpegParser(); | |
| 72 | |
| 73 // Parses JPEG picture in |buffer| with |length|. Returns true iff header is | |
| 74 // valid and supported JPEG baseline sequential process. If parsed | |
| 75 // successfully, |result| is the parsed result. | |
| 76 static bool Parse(const uint8_t* buffer, | |
| 77 size_t length, | |
| 78 JpegParseResult* result); | |
| 79 | |
| 80 private: | |
| 81 static bool ParseSOF(const char* buffer, | |
| 82 size_t length, | |
| 83 JpegParseResult* result); | |
| 84 static bool ParseDQT(const char* buffer, | |
| 85 size_t length, | |
| 86 JpegParseResult* result); | |
| 87 static bool ParseDHT(const char* buffer, | |
| 88 size_t length, | |
| 89 JpegParseResult* result); | |
| 90 static bool ParseDRI(const char* buffer, | |
| 91 size_t length, | |
| 92 JpegParseResult* result); | |
| 93 static bool ParseSOS(const char* buffer, | |
| 94 size_t length, | |
| 95 JpegParseResult* result); | |
| 96 static bool ParseSOI(const char* buffer, | |
| 97 size_t length, | |
| 98 JpegParseResult* result); | |
| 99 | |
| 100 DISALLOW_COPY_AND_ASSIGN(JpegParser); | |
| 101 }; | |
| 102 | |
| 103 } // namespace content | |
| 104 | |
| 105 #endif // CONTENT_COMMON_GPU_MEDIA_VAAPI_JPEG_PARSER_H_ | |
| OLD | NEW |