diff options
author | Jerry Jiang <jerryjiang1128@gmail.com> | 2017-02-01 23:23:04 -0800 |
---|---|---|
committer | Rostislav Pehlivanov <atomnuker@gmail.com> | 2017-02-08 13:59:53 +0000 |
commit | 884506dfe2e29a5b2bd2905ca4f17e277e32acb1 (patch) | |
tree | efac020fcd29af2670ddbf40faff5edb5ddf718e /libavcodec/mjpegenc.h | |
parent | 2d453188c2303da641dafb048dc1806790526dfd (diff) | |
download | ffmpeg-884506dfe2e29a5b2bd2905ca4f17e277e32acb1.tar.gz |
Implement optimal huffman encoding for (M)JPEG.
> seems to break
> make fate-vsynth1-mjpeg-444
Fixed.
Diffstat (limited to 'libavcodec/mjpegenc.h')
-rw-r--r-- | libavcodec/mjpegenc.h | 68 |
1 files changed, 59 insertions, 9 deletions
diff --git a/libavcodec/mjpegenc.h b/libavcodec/mjpegenc.h index 60cd56677f..577fa1fec6 100644 --- a/libavcodec/mjpegenc.h +++ b/libavcodec/mjpegenc.h @@ -39,18 +39,67 @@ #include "mpegvideo.h" #include "put_bits.h" +/** + * Buffer of JPEG frame data. + * + * Optimal Huffman table generation requires the frame data to be loaded into + * a buffer so that the tables can be computed. + * There are at most mb_width*mb_height*12*64 of these per frame. + */ +typedef struct MJpegHuffmanCode { + // 0=DC lum, 1=DC chrom, 2=AC lum, 3=AC chrom + uint8_t table_id; ///< The Huffman table id associated with the data. + uint8_t code; ///< The exponent. + uint16_t mant; ///< The mantissa. +} MJpegHuffmanCode; + +/** + * Holds JPEG frame data and Huffman table data. + */ typedef struct MJpegContext { - uint8_t huff_size_dc_luminance[12]; //FIXME use array [3] instead of lumi / chroma, for easier addressing - uint16_t huff_code_dc_luminance[12]; - uint8_t huff_size_dc_chrominance[12]; - uint16_t huff_code_dc_chrominance[12]; + //FIXME use array [3] instead of lumi / chroma, for easier addressing + uint8_t huff_size_dc_luminance[12]; ///< DC luminance Huffman table size. + uint16_t huff_code_dc_luminance[12]; ///< DC luminance Huffman table codes. + uint8_t huff_size_dc_chrominance[12]; ///< DC chrominance Huffman table size. + uint16_t huff_code_dc_chrominance[12]; ///< DC chrominance Huffman table codes. + + uint8_t huff_size_ac_luminance[256]; ///< AC luminance Huffman table size. + uint16_t huff_code_ac_luminance[256]; ///< AC luminance Huffman table codes. + uint8_t huff_size_ac_chrominance[256]; ///< AC chrominance Huffman table size. + uint16_t huff_code_ac_chrominance[256]; ///< AC chrominance Huffman table codes. - uint8_t huff_size_ac_luminance[256]; - uint16_t huff_code_ac_luminance[256]; - uint8_t huff_size_ac_chrominance[256]; - uint16_t huff_code_ac_chrominance[256]; + /** Storage for AC luminance VLC (in MpegEncContext) */ + uint8_t uni_ac_vlc_len[64 * 64 * 2]; + /** Storage for AC chrominance VLC (in MpegEncContext) */ + uint8_t uni_chroma_ac_vlc_len[64 * 64 * 2]; + + // Default DC tables have exactly 12 values + uint8_t bits_dc_luminance[17]; ///< DC luminance Huffman bits. + uint8_t val_dc_luminance[12]; ///< DC luminance Huffman values. + uint8_t bits_dc_chrominance[17]; ///< DC chrominance Huffman bits. + uint8_t val_dc_chrominance[12]; ///< DC chrominance Huffman values. + + // 8-bit JPEG has max 256 values + uint8_t bits_ac_luminance[17]; ///< AC luminance Huffman bits. + uint8_t val_ac_luminance[256]; ///< AC luminance Huffman values. + uint8_t bits_ac_chrominance[17]; ///< AC chrominance Huffman bits. + uint8_t val_ac_chrominance[256]; ///< AC chrominance Huffman values. + + unsigned int huff_capacity; ///< Size of the buffer, in entries. + size_t huff_ncode; ///< Number of current entries in the buffer. + MJpegHuffmanCode *huff_buffer; ///< Buffer for Huffman code values. + int error; ///< Error code. } MJpegContext; +/** + * Enum for the Huffman encoding strategy. + */ +enum HuffmanTableOption { + HUFFMAN_TABLE_DEFAULT = 0, ///< Use the default Huffman tables. + HUFFMAN_TABLE_OPTIMAL = 1, ///< Compute and use optimal Huffman tables. + NB_HUFFMAN_TABLE_OPTION = 2 +}; + static inline void put_marker(PutBitContext *p, enum JpegMarker code) { put_bits(p, 8, 0xff); @@ -58,7 +107,8 @@ static inline void put_marker(PutBitContext *p, enum JpegMarker code) } int ff_mjpeg_encode_init(MpegEncContext *s); +void ff_mjpeg_encode_picture_frame(MpegEncContext *s); void ff_mjpeg_encode_close(MpegEncContext *s); -void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64]); +int ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64]); #endif /* AVCODEC_MJPEGENC_H */ |