2 * MJPEG encoder and decoder
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
4 * Copyright (c) 2003 Alex Beregszaszi
5 * Copyright (c) 2003-2004 Michael Niedermayer
7 * This file is part of FFmpeg.
9 * FFmpeg is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * FFmpeg is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with FFmpeg; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 * Support for external huffman table, various fixes (AVID workaround),
24 * aspecting, new decode_frame mechanism and apple mjpeg-b support
30 * MJPEG encoder and decoder.
37 #include "bitstream.h"
39 #include "mpegvideo.h"
42 /* JPEG marker codes */
45 SOF0
= 0xc0, /* baseline */
46 SOF1
= 0xc1, /* extended sequential, huffman */
47 SOF2
= 0xc2, /* progressive, huffman */
48 SOF3
= 0xc3, /* lossless, huffman */
50 SOF5
= 0xc5, /* differential sequential, huffman */
51 SOF6
= 0xc6, /* differential progressive, huffman */
52 SOF7
= 0xc7, /* differential lossless, huffman */
53 JPG
= 0xc8, /* reserved for JPEG extension */
54 SOF9
= 0xc9, /* extended sequential, arithmetic */
55 SOF10
= 0xca, /* progressive, arithmetic */
56 SOF11
= 0xcb, /* lossless, arithmetic */
58 SOF13
= 0xcd, /* differential sequential, arithmetic */
59 SOF14
= 0xce, /* differential progressive, arithmetic */
60 SOF15
= 0xcf, /* differential lossless, arithmetic */
62 DHT
= 0xc4, /* define huffman tables */
64 DAC
= 0xcc, /* define arithmetic-coding conditioning */
66 /* restart with modulo 8 count "m" */
76 SOI
= 0xd8, /* start of image */
77 EOI
= 0xd9, /* end of image */
78 SOS
= 0xda, /* start of scan */
79 DQT
= 0xdb, /* define quantization tables */
80 DNL
= 0xdc, /* define number of lines */
81 DRI
= 0xdd, /* define restart interval */
82 DHP
= 0xde, /* define hierarchical progression */
83 EXP
= 0xdf, /* expand reference components */
109 SOF48
= 0xf7, ///< JPEG-LS
110 LSE
= 0xf8, ///< JPEG-LS extension parameters
117 COM
= 0xfe, /* comment */
119 TEM
= 0x01, /* temporary private use for arithmetic coding */
121 /* 0x02 -> 0xbf reserved */
124 static inline void put_marker(PutBitContext
*p
, int code
)
126 put_bits(p
, 8, 0xff);
127 put_bits(p
, 8, code
);
130 #define MAX_COMPONENTS 4
132 typedef struct MJpegDecodeContext
{
133 AVCodecContext
*avctx
;
136 int start_code
; /* current start code */
140 int16_t quant_matrixes
[4][64];
142 int qscale
[4]; ///< quantizer scale calculated from quant_matrixes
144 int org_height
; /* size given at codec init */
145 int first_picture
; /* true if decoding first picture */
146 int interlaced
; /* true if interlaced */
147 int bottom_field
; /* true if bottom field */
152 int rct
; /* standard rct */
153 int pegasus_rct
; /* pegasus reversible colorspace transform */
154 int bits
; /* bits per component */
157 int near
; ///< near lossless bound (si 0 for lossless)
159 int reset
; ///< context halfing intervall ?rename
162 int mb_width
, mb_height
;
164 int component_id
[MAX_COMPONENTS
];
165 int h_count
[MAX_COMPONENTS
]; /* horizontal and vertical count for each component */
166 int v_count
[MAX_COMPONENTS
];
167 int comp_index
[MAX_COMPONENTS
];
168 int dc_index
[MAX_COMPONENTS
];
169 int ac_index
[MAX_COMPONENTS
];
170 int nb_blocks
[MAX_COMPONENTS
];
171 int h_scount
[MAX_COMPONENTS
];
172 int v_scount
[MAX_COMPONENTS
];
173 int h_max
, v_max
; /* maximum h and v counts */
174 int quant_index
[4]; /* quant table index for each component */
175 int last_dc
[MAX_COMPONENTS
]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */
176 AVFrame picture
; /* picture structure */
177 int linesize
[MAX_COMPONENTS
]; ///< linesize << interlaced
178 int8_t *qscale_table
;
179 DECLARE_ALIGNED_8(DCTELEM
, block
[64]);
183 int restart_interval
;
188 int interlace_polarity
;
192 int cur_scan
; /* current scan, used by JPEG-LS */
193 } MJpegDecodeContext
;