// Copyright 2015 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef MEDIA_PARSERS_JPEG_PARSER_H_ #define MEDIA_PARSERS_JPEG_PARSER_H_ #include <stddef.h> #include <stdint.h> #include "base/containers/span.h" #include "media/base/media_export.h" namespace media { // It's not a full featured JPEG parser implementation. It only parses JPEG // baseline sequential process (invalid or progressive JPEGs should fail but not // crash). For explanations of each struct and its members, see JPEG // specification at http://www.w3.org/Graphics/JPEG/itu-t81.pdf. enum JpegMarker { … }; // JPEG format uses 2 bytes to denote the size of a segment, and the size // includes the 2 bytes used for specifying it. Therefore, maximum data size // allowed is: 65535 - 2 = 65533. constexpr size_t kMaxMarkerSizeAllowed = …; // JPEG header only uses 2 bytes to represent width and height. constexpr int kMaxDimension = …; constexpr size_t kDctSize = …; constexpr size_t kNumDcRunSizeBits = …; constexpr size_t kNumAcRunSizeBits = …; constexpr size_t kNumDcCodeWordsHuffVal = …; constexpr size_t kNumAcCodeWordsHuffVal = …; constexpr size_t kJpegDefaultHeaderSize = …; constexpr size_t kJFIFApp0Size = …; constexpr size_t kJFIFApp1HeaderSize = …; const size_t kJpegMaxHuffmanTableNumBaseline = …; const size_t kJpegMaxComponents = …; const size_t kJpegMaxQuantizationTableNum = …; // Parsing result of JPEG DHT marker. struct JpegHuffmanTable { … }; // K.3.3.1 "Specification of typical tables for DC difference coding" MEDIA_EXPORT extern const JpegHuffmanTable kDefaultDcTable[kJpegMaxHuffmanTableNumBaseline]; // K.3.3.2 "Specification of typical tables for AC coefficient coding" MEDIA_EXPORT extern const JpegHuffmanTable kDefaultAcTable[kJpegMaxHuffmanTableNumBaseline]; // Parsing result of JPEG DQT marker. struct JpegQuantizationTable { … }; MEDIA_EXPORT extern const uint8_t kZigZag8x8[64]; // Table K.1 Luminance quantization table // Table K.2 Chrominance quantization table MEDIA_EXPORT extern const JpegQuantizationTable kDefaultQuantTable[2]; // Parsing result of a JPEG component. struct JpegComponent { … }; // Parsing result of a JPEG SOF marker. struct JpegFrameHeader { … }; // Parsing result of JPEG SOS marker. struct JpegScanHeader { … }; struct JpegParseResult { … }; // 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. MEDIA_EXPORT bool ParseJpegPicture(base::span<const uint8_t> buffer, JpegParseResult* result); // Parses the first image of JPEG stream 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. MEDIA_EXPORT bool ParseJpegStream(base::span<const uint8_t> buffer, JpegParseResult* result); } // namespace media #endif // MEDIA_PARSERS_JPEG_PARSER_H_