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..d56419c2acf726cf3b45ce7254ae39f964e30de3 |
--- /dev/null |
+++ b/media/filters/jpeg_parser.h |
@@ -0,0 +1,105 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
wuchengli
2015/01/05 07:32:55
Can you explain why we are not using ffmpeg/libavc
kcwu
2015/01/05 08:50:50
ffmpeg/libavcodec/mjpeg_parser.c only scans for be
|
+// found in the LICENSE file. |
+// |
+#ifndef MEDIA_FILTERS_JPEG_PARSER_H_ |
+#define MEDIA_FILTERS_JPEG_PARSER_H_ |
+ |
+#include "base/big_endian.h" |
wuchengli
2015/01/05 07:32:55
Move this to jpeg_parser.cc?
kcwu
2015/01/05 08:50:51
Done.
|
+#include "base/macros.h" |
+#include "media/base/media_export.h" |
+#include "ui/gfx/geometry/size.h" |
+ |
+namespace media { |
+ |
+static const size_t kJpegMaxHuffmanTableNum_baseline = 2; |
+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]; // only support 8 bits quantization table for baseline |
+}; |
+ |
+// 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 uint8_t* data; |
+ size_t data_size; |
+}; |
+ |
+struct JpegParseResult { |
+ JpegParseResult(); |
wuchengli
2015/01/05 07:32:55
Do we need the constructor?
kcwu
2015/01/05 08:50:50
gfx::Size is not plain data structure, thus it nee
wuchengli
2015/01/05 08:57:13
I wouldn't use gfx::Size because it brings ui/gfx
|
+ gfx::Size visible_size; |
+ 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 |
+// 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 { |
+ public: |
+ JpegParser(); |
+ ~JpegParser(); |
+ |
+ // Parses JPEG picture in |buffer| with |length|. Returns true iff header is |
+ // valid and supported JPEG baseline sequential process. If parsed |
wuchengli
2015/01/05 07:32:55
"supported" sounds strange. s/supported JPEG basel
kcwu
2015/01/05 08:50:50
Done.
|
+ // 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, |
+ 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_ |