FFmpeg
mjpegenc.h
Go to the documentation of this file.
1 /*
2  * MJPEG encoder
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  * Copyright (c) 2003 Alex Beregszaszi
5  * Copyright (c) 2003-2004 Michael Niedermayer
6  *
7  * Support for external huffman table, various fixes (AVID workaround),
8  * aspecting, new decode_frame mechanism and apple mjpeg-b support
9  * by Alex Beregszaszi
10  *
11  * This file is part of FFmpeg.
12  *
13  * FFmpeg is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2.1 of the License, or (at your option) any later version.
17  *
18  * FFmpeg is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  * Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with FFmpeg; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26  */
27 
28 /**
29  * @file
30  * MJPEG encoder.
31  */
32 
33 #ifndef AVCODEC_MJPEGENC_H
34 #define AVCODEC_MJPEGENC_H
35 
36 #include <stdint.h>
37 
38 #include "mjpeg.h"
39 #include "mpegvideo.h"
40 #include "put_bits.h"
41 
42 /**
43  * Buffer of JPEG frame data.
44  *
45  * Optimal Huffman table generation requires the frame data to be loaded into
46  * a buffer so that the tables can be computed.
47  * There are at most mb_width*mb_height*12*64 of these per frame.
48  */
49 typedef struct MJpegHuffmanCode {
50  // 0=DC lum, 1=DC chrom, 2=AC lum, 3=AC chrom
51  uint8_t table_id; ///< The Huffman table id associated with the data.
52  uint8_t code; ///< The exponent.
53  uint16_t mant; ///< The mantissa.
55 
56 /**
57  * Holds JPEG frame data and Huffman table data.
58  */
59 typedef struct MJpegContext {
60  int huffman;
61  /* Force duplication of mjpeg matrices, useful for rtp streaming */
63  //FIXME use array [3] instead of lumi / chroma, for easier addressing
64  uint8_t huff_size_dc_luminance[12]; ///< DC luminance Huffman table size.
65  uint16_t huff_code_dc_luminance[12]; ///< DC luminance Huffman table codes.
66  uint8_t huff_size_dc_chrominance[12]; ///< DC chrominance Huffman table size.
67  uint16_t huff_code_dc_chrominance[12]; ///< DC chrominance Huffman table codes.
68 
69  uint8_t huff_size_ac_luminance[256]; ///< AC luminance Huffman table size.
70  uint16_t huff_code_ac_luminance[256]; ///< AC luminance Huffman table codes.
71  uint8_t huff_size_ac_chrominance[256]; ///< AC chrominance Huffman table size.
72  uint16_t huff_code_ac_chrominance[256]; ///< AC chrominance Huffman table codes.
73 
74  /** Storage for AC luminance VLC (in MpegEncContext) */
75  uint8_t uni_ac_vlc_len[64 * 64 * 2];
76  /** Storage for AC chrominance VLC (in MpegEncContext) */
77  uint8_t uni_chroma_ac_vlc_len[64 * 64 * 2];
78 
79  // Default DC tables have exactly 12 values
80  uint8_t bits_dc_luminance[17]; ///< DC luminance Huffman bits.
81  uint8_t val_dc_luminance[12]; ///< DC luminance Huffman values.
82  uint8_t bits_dc_chrominance[17]; ///< DC chrominance Huffman bits.
83  uint8_t val_dc_chrominance[12]; ///< DC chrominance Huffman values.
84 
85  // 8-bit JPEG has max 256 values
86  uint8_t bits_ac_luminance[17]; ///< AC luminance Huffman bits.
87  uint8_t val_ac_luminance[256]; ///< AC luminance Huffman values.
88  uint8_t bits_ac_chrominance[17]; ///< AC chrominance Huffman bits.
89  uint8_t val_ac_chrominance[256]; ///< AC chrominance Huffman values.
90 
91  size_t huff_ncode; ///< Number of current entries in the buffer.
92  MJpegHuffmanCode *huff_buffer; ///< Buffer for Huffman code values.
93 } MJpegContext;
94 
95 /**
96  * Enum for the Huffman encoding strategy.
97  */
99  HUFFMAN_TABLE_DEFAULT = 0, ///< Use the default Huffman tables.
100  HUFFMAN_TABLE_OPTIMAL = 1, ///< Compute and use optimal Huffman tables.
102 };
103 
104 static inline void put_marker(PutBitContext *p, enum JpegMarker code)
105 {
106  put_bits(p, 8, 0xff);
107  put_bits(p, 8, code);
108 }
109 
112 void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64]);
114 
115 #endif /* AVCODEC_MJPEGENC_H */
mjpeg.h
MJpegContext::uni_ac_vlc_len
uint8_t uni_ac_vlc_len[64 *64 *2]
Storage for AC luminance VLC (in MpegEncContext)
Definition: mjpegenc.h:75
MJpegHuffmanCode
Buffer of JPEG frame data.
Definition: mjpegenc.h:49
MJpegContext::bits_ac_chrominance
uint8_t bits_ac_chrominance[17]
AC chrominance Huffman bits.
Definition: mjpegenc.h:88
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:222
MJpegContext::val_dc_chrominance
uint8_t val_dc_chrominance[12]
DC chrominance Huffman values.
Definition: mjpegenc.h:83
MJpegContext::huffman
int huffman
Definition: mjpegenc.h:60
MJpegHuffmanCode::mant
uint16_t mant
The mantissa.
Definition: mjpegenc.h:53
MJpegContext::huff_code_dc_chrominance
uint16_t huff_code_dc_chrominance[12]
DC chrominance Huffman table codes.
Definition: mjpegenc.h:67
mpegvideo.h
MJpegContext::force_duplicated_matrix
int force_duplicated_matrix
Definition: mjpegenc.h:62
MJpegHuffmanCode::table_id
uint8_t table_id
The Huffman table id associated with the data.
Definition: mjpegenc.h:51
MJpegContext::huff_size_dc_chrominance
uint8_t huff_size_dc_chrominance[12]
DC chrominance Huffman table size.
Definition: mjpegenc.h:66
JpegMarker
JpegMarker
Definition: mjpeg.h:37
ff_mjpeg_encode_init
int ff_mjpeg_encode_init(MpegEncContext *s)
Definition: mjpegenc.c:294
MJpegContext::uni_chroma_ac_vlc_len
uint8_t uni_chroma_ac_vlc_len[64 *64 *2]
Storage for AC chrominance VLC (in MpegEncContext)
Definition: mjpegenc.h:77
ff_mjpeg_amv_encode_picture_header
void ff_mjpeg_amv_encode_picture_header(MpegEncContext *s)
Definition: mjpegenc.c:93
MJpegContext::bits_dc_luminance
uint8_t bits_dc_luminance[17]
DC luminance Huffman bits.
Definition: mjpegenc.h:80
s
#define s(width, name)
Definition: cbs_vp9.c:198
MJpegContext::val_dc_luminance
uint8_t val_dc_luminance[12]
DC luminance Huffman values.
Definition: mjpegenc.h:81
HUFFMAN_TABLE_OPTIMAL
@ HUFFMAN_TABLE_OPTIMAL
Compute and use optimal Huffman tables.
Definition: mjpegenc.h:100
ff_mjpeg_encode_stuffing
int ff_mjpeg_encode_stuffing(MpegEncContext *s)
Writes the complete JPEG frame when optimal huffman tables are enabled, otherwise writes the stuffing...
Definition: mjpegenc.c:220
MJpegContext::val_ac_chrominance
uint8_t val_ac_chrominance[256]
AC chrominance Huffman values.
Definition: mjpegenc.h:89
PutBitContext
Definition: put_bits.h:50
NB_HUFFMAN_TABLE_OPTION
@ NB_HUFFMAN_TABLE_OPTION
Definition: mjpegenc.h:101
MJpegContext::huff_ncode
size_t huff_ncode
Number of current entries in the buffer.
Definition: mjpegenc.h:91
HUFFMAN_TABLE_DEFAULT
@ HUFFMAN_TABLE_DEFAULT
Use the default Huffman tables.
Definition: mjpegenc.h:99
MJpegContext::huff_code_ac_luminance
uint16_t huff_code_ac_luminance[256]
AC luminance Huffman table codes.
Definition: mjpegenc.h:70
MJpegContext::huff_code_ac_chrominance
uint16_t huff_code_ac_chrominance[256]
AC chrominance Huffman table codes.
Definition: mjpegenc.h:72
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
ff_mjpeg_encode_mb
void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64])
Definition: mjpegenc.c:523
MJpegContext::bits_dc_chrominance
uint8_t bits_dc_chrominance[17]
DC chrominance Huffman bits.
Definition: mjpegenc.h:82
MJpegContext::huff_size_dc_luminance
uint8_t huff_size_dc_luminance[12]
DC luminance Huffman table size.
Definition: mjpegenc.h:64
MJpegContext::huff_buffer
MJpegHuffmanCode * huff_buffer
Buffer for Huffman code values.
Definition: mjpegenc.h:92
MJpegContext
Holds JPEG frame data and Huffman table data.
Definition: mjpegenc.h:59
put_marker
static void put_marker(PutBitContext *p, enum JpegMarker code)
Definition: mjpegenc.h:104
MJpegContext::huff_size_ac_chrominance
uint8_t huff_size_ac_chrominance[256]
AC chrominance Huffman table size.
Definition: mjpegenc.h:71
HuffmanTableOption
HuffmanTableOption
Enum for the Huffman encoding strategy.
Definition: mjpegenc.h:98
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
MJpegContext::bits_ac_luminance
uint8_t bits_ac_luminance[17]
AC luminance Huffman bits.
Definition: mjpegenc.h:86
MJpegContext::val_ac_luminance
uint8_t val_ac_luminance[256]
AC luminance Huffman values.
Definition: mjpegenc.h:87
MJpegContext::huff_size_ac_luminance
uint8_t huff_size_ac_luminance[256]
AC luminance Huffman table size.
Definition: mjpegenc.h:69
put_bits.h
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:67
MJpegHuffmanCode::code
uint8_t code
The exponent.
Definition: mjpegenc.h:52
MJpegContext::huff_code_dc_luminance
uint16_t huff_code_dc_luminance[12]
DC luminance Huffman table codes.
Definition: mjpegenc.h:65