Chromium Code Reviews| Index: media/filters/jpeg_parser.h |
| diff --git a/media/filters/jpeg_parser.h b/media/filters/jpeg_parser.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3f74a7d7fadf5e394ca985cac87e13892083953a |
| --- /dev/null |
| +++ b/media/filters/jpeg_parser.h |
| @@ -0,0 +1,101 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
|
xhwang
2015/01/12 18:08:58
2015?
kcwu
2015/01/13 14:57:01
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +// |
| +#ifndef MEDIA_FILTERS_JPEG_PARSER_H_ |
| +#define MEDIA_FILTERS_JPEG_PARSER_H_ |
| + |
| +#include <stdint.h> |
| +#include "base/macros.h" |
| +#include "media/base/media_export.h" |
| + |
| +namespace media { |
| + |
| +static const size_t kJpegMaxHuffmanTableNum_baseline = 2; |
|
xhwang
2015/01/12 18:08:58
s/_baseline/Baseline
xhwang
2015/01/12 18:08:58
static not needed for consts.
kcwu
2015/01/13 14:57:00
Done.
kcwu
2015/01/13 14:57:01
Done.
|
| +static const size_t kJpegMaxComponents = 4; |
| +static const size_t kJpegMaxQuantizationTableNum = 4; |
| + |
| +// Parsing result of JPEG DHT marker. |
| +struct JpegHuffmanTable { |
| + bool valid; |
| + uint8_t code_length[16]; |
| + uint8_t code_value[256]; |
| +}; |
| + |
| +// Parsing result of JPEG DQT marker. |
| +struct JpegQuantizationTable { |
| + bool valid; |
| + uint8_t value[64]; // baseline only supports 8 bits quantization table |
| +}; |
| + |
| +// Parsing result of a JPEG component. |
| +struct JpegComponent { |
| + uint8_t id; |
| + uint8_t horizontal_sampling_factor; |
| + uint8_t vertical_sampling_factor; |
| + uint8_t quantization_table_selector; |
| +}; |
| + |
| +// Parsing result of JPEG SOS marker. |
| +struct JpegScan { |
| + uint8_t num_components; |
| + struct Component { |
| + uint8_t component_selector; |
| + uint8_t dc_selector; |
| + uint8_t ac_selector; |
| + } components[kJpegMaxComponents]; |
| + const char* data; |
| + size_t data_size; |
| +}; |
| + |
| +struct JpegParseResult { |
| + uint16_t visible_width; |
| + uint16_t visible_height; |
| + uint8_t num_components; |
| + JpegComponent components[kJpegMaxComponents]; |
| + JpegHuffmanTable dc_table[kJpegMaxHuffmanTableNum_baseline]; |
| + JpegHuffmanTable ac_table[kJpegMaxHuffmanTableNum_baseline]; |
| + JpegQuantizationTable q_table[kJpegMaxQuantizationTableNum]; |
| + uint16_t restart_interval; |
| + JpegScan scan; |
| +}; |
| + |
| +// JpegParser parses JPEG header. It's not a full featured JPEG parser |
|
xhwang
2015/01/12 18:08:58
In this case, how about s/JpegParser/JpegHeaderPar
kcwu
2015/01/13 14:57:00
Now I named the function as ParseJpegPicture. Not
|
| +// implememtation. It only parses JPEG baseline sequential process. For |
| +// explanations of each struct and its members, see JPEG specification at |
| +// http://www.w3.org/Graphics/JPEG/itu-t81.pdf. |
| +class MEDIA_EXPORT JpegParser { |
|
xhwang
2015/01/12 18:08:58
It seems we only need a Parse() function which is
kcwu
2015/01/13 14:57:00
Done.
|
| + public: |
| + // Parses JPEG picture in |buffer| with |length|. Returns true iff header is |
| + // valid and JPEG baseline sequential process is present. If parsed |
| + // successfully, |result| is the parsed result. |
| + static bool Parse(const uint8_t* buffer, |
| + size_t length, |
| + JpegParseResult* result); |
| + |
| + private: |
| + static bool ParseSOF(const char* buffer, |
|
xhwang
2015/01/12 18:08:58
Can you hide all these functions in the .cc file?
kcwu
2015/01/13 14:57:01
Done.
|
| + size_t length, |
| + JpegParseResult* result); |
| + static bool ParseDQT(const char* buffer, |
| + size_t length, |
| + JpegParseResult* result); |
| + static bool ParseDHT(const char* buffer, |
| + size_t length, |
| + JpegParseResult* result); |
| + static bool ParseDRI(const char* buffer, |
| + size_t length, |
| + JpegParseResult* result); |
| + static bool ParseSOS(const char* buffer, |
| + size_t length, |
| + JpegParseResult* result); |
| + static bool ParseSOI(const char* buffer, |
| + size_t length, |
| + JpegParseResult* result); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(JpegParser); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_FILTERS_JPEG_PARSER_H_ |