FFmpeg
Loading...
Searching...
No Matches
mjpegdec.h
Go to the documentation of this file.
1/*
2 * MJPEG decoder
3 * Copyright (c) 2000, 2001 Fabrice Bellard
4 * Copyright (c) 2003 Alex Beregszaszi
5 * Copyright (c) 2003-2004 Michael Niedermayer
6 *
7 * This file is part of FFmpeg.
8 *
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.
13 *
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.
18 *
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
22 */
23
24/**
25 * @file
26 * MJPEG decoder.
27 */
28
29#ifndef AVCODEC_MJPEGDEC_H
30#define AVCODEC_MJPEGDEC_H
31
32#include "libavutil/gain_map.h"
33#include "libavutil/log.h"
35#include "libavutil/pixdesc.h"
36#include "libavutil/stereo3d.h"
37
38#include "avcodec.h"
39#include "blockdsp.h"
40#include "bytestream.h"
41#include "exif.h"
42#include "get_bits.h"
43#include "hpeldsp.h"
44#include "idctdsp.h"
45
46#undef near /* This file uses struct member 'near' which in windows.h is defined as empty. */
47
48#define MAX_COMPONENTS 4
49
50typedef struct ICCEntry {
51 uint8_t *data;
52 int length;
53} ICCEntry;
54
55struct JLSState;
56
57typedef struct MJpegDecodeContext {
58 AVClass *class;
63
65 uint8_t *buffer;
66
67 uint16_t quant_matrixes[4][64];
68 VLC vlcs[3][4];
69 int qscale[4]; ///< quantizer scale calculated from quant_matrixes
70
71 int orig_height; /* size given at codec init */
72 int first_picture; /* true if decoding first picture */
73 int interlaced; /* true if interlaced */
74 int bottom_field; /* true if bottom field */
76 int ls;
78 int bayer; /* true if it's a bayer-encoded JPEG embedded in a DNG */
79 int rgb;
80 uint8_t upscale_h[4];
81 uint8_t upscale_v[4];
82 int rct; /* standard rct */
83 int pegasus_rct; /* pegasus reversible colorspace transform */
84 int bits; /* bits per component */
85 int colr;
86 int xfrm;
88
89 /* SOS fields */
91 int Ss;
92 int Se;
93 int Ah;
94 int Al;
95
96 int maxval;
97 int near; ///< near lossless bound (si 0 for lossless)
98 int t1,t2,t3;
99 int reset; ///< context halfing interval ?rename
100
106 int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */
115 int h_max, v_max; /* maximum h and v counts */
116 int quant_index[4]; /* quant table index for each component */
117 int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */
118 AVFrame *picture; /* picture structure */
119 AVFrame *picture_ptr; /* pointer to picture structure */
120 int got_picture; ///< we found a SOF and picture is valid, too.
121 int nb_seq_component_scans; ///< component scans decoded since the SOF (sequential images: <= nb_components)
122 int linesize[MAX_COMPONENTS]; ///< linesize << interlaced
123 DECLARE_ALIGNED(32, int16_t, block)[64];
124 int16_t (*blocks[MAX_COMPONENTS])[64]; ///< intermediate sums (progressive mode)
126 uint64_t coefs_finished[MAX_COMPONENTS]; ///< bitmask of which coefs have been completely decoded (progressive mode)
132 op_pixels_func copy_block; ///< only set and used by mxpeg
133
136
140
142
143 int cur_scan; /* current scan, used by JPEG-LS */
144 int64_t total_ls_decoded_height; /* cumulative JPEG-LS rows decoded in the current packet */
145 int flipped; /* true if picture is flipped */
146
147 uint16_t (*ljpeg_buffer)[4];
148 unsigned int ljpeg_buffer_size;
149
150#if FF_API_MJPEG_EXTERN_HUFF
151 int extern_huff;
152#endif
154
155 AVStereo3D *stereo3d; ///!< stereoscopic information (cached, since it is read before frame allocation)
156
159
161
165
169
170 // Raw stream data for hwaccel use.
171 const uint8_t *raw_image_buffer;
173
174 uint8_t raw_huffman_lengths[2][4][16];
175 uint8_t raw_huffman_values[2][4][256];
176
181
182 const uint8_t *mb_bitmask;
186
187int ff_mjpeg_build_vlc(VLC *vlc, const uint8_t *bits_table,
188 const uint8_t *val_table, int is_ac, void *logctx);
192 AVFrame *frame, int *got_frame,
193 AVPacket *avpkt);
195 AVFrame *frame, int *got_frame,
196 const AVPacket *avpkt, const uint8_t *buf, int buf_size);
201int ff_mjpeg_find_marker(const uint8_t **buf_ptr, const uint8_t *buf_end);
203
205{
206 int restart = 0;
207 if (s->restart_interval) {
208 if (s->restart_count <= 0) {
209 s->restart_count = s->restart_interval;
210 restart = 1;
211 }
212 s->restart_count--;
213 } else {
214 if (s->restart_count < 0) {
215 s->restart_count = 0;
216 restart = 1;
217 }
218 }
219 return restart;
220}
221
222static inline int ff_mjpeg_handle_restart(MJpegDecodeContext *s, int *restart)
223{
224 int first = s->restart_count < 0;
225 *restart = ff_mjpeg_should_restart(s);
226 if (*restart) {
227 if (s->avctx->codec_id == AV_CODEC_ID_THP && !first) {
228 align_get_bits(&s->gb);
229 return 0;
230 }
232 if (ret < 0)
233 return ret;
234 }
235 return 0;
236}
237
238#endif /* AVCODEC_MJPEGDEC_H */
Libavcodec external API header.
#define s(width, name)
Definition cbs_vp9.c:198
long long int64_t
Definition coverity.c:34
static AVFrame * frame
EXIF metadata parser.
int ret
Definition ffplay.c:391
bitstream reader API header.
static const uint8_t * align_get_bits(GetBitContext *s)
Definition get_bits.h:560
@ AV_CODEC_ID_THP
Definition codec_id.h:150
Half-pel DSP functions.
void(* op_pixels_func)(uint8_t *block, const uint8_t *pixels, ptrdiff_t line_size, int h)
Average and put pixel Widths can be 16, 8, 4 or 2.
Definition hpeldsp.h:39
Stereoscopic video.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
static int ff_mjpeg_handle_restart(MJpegDecodeContext *s, int *restart)
Definition mjpegdec.h:222
int ff_mjpeg_decode_init(AVCodecContext *avctx)
Definition mjpegdec.c:125
int ff_mjpeg_decode_sos(MJpegDecodeContext *s)
Definition mjpegdec.c:1681
int ff_mjpeg_decode_end(AVCodecContext *avctx)
Definition mjpegdec.c:2948
int ff_mjpeg_build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table, int is_ac, void *logctx)
#define MAX_COMPONENTS
Definition mjpegdec.h:48
int ff_mjpeg_decode_dqt(MJpegDecodeContext *s)
Definition mjpegdec.c:209
static int ff_mjpeg_should_restart(MJpegDecodeContext *s)
Definition mjpegdec.h:204
int ff_mjpeg_unescape_sos(MJpegDecodeContext *s)
Definition mjpegdec.c:2284
int ff_mjpeg_decode_frame_from_buf(AVCodecContext *avctx, AVFrame *frame, int *got_frame, const AVPacket *avpkt, const uint8_t *buf, int buf_size)
Definition mjpegdec.c:2427
int ff_mjpeg_find_marker(const uint8_t **buf_ptr, const uint8_t *buf_end)
Definition mjpegdec.c:2228
int ff_mjpeg_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition mjpegdec.c:2938
int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
Definition mjpegdec.c:311
int ff_mjpeg_decode_dht(MJpegDecodeContext *s)
Definition mjpegdec.c:252
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
Describe the class of an AVClass context structure.
Definition log.h:76
main external API structure.
Definition avcodec.h:443
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
Parameters describing how to combine a gain map rendition with its base rendition to recover the alte...
Definition gain_map.h:39
This structure stores compressed data.
Definition packet.h:587
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
Stereo 3D type: this structure describes how two videos are packed within a single video surface,...
Definition stereo3d.h:203
uint8_t * data
Definition mjpegdec.h:51
int length
Definition mjpegdec.h:52
uint8_t upscale_v[4]
Definition mjpegdec.h:81
AVStereo3D * stereo3d
Definition mjpegdec.h:155
int block_stride[MAX_COMPONENTS]
Definition mjpegdec.h:104
int nb_seq_component_scans
component scans decoded since the SOF (sequential images: <= nb_components)
Definition mjpegdec.h:121
AVExifMetadata exif_metadata
Definition mjpegdec.h:153
int reset
context halfing interval ?rename
Definition mjpegdec.h:99
enum AVPixelFormat hwaccel_pix_fmt
Definition mjpegdec.h:178
int nb_blocks[MAX_COMPONENTS]
Definition mjpegdec.h:111
int ac_index[MAX_COMPONENTS]
Definition mjpegdec.h:110
ICCEntry * iccentries
Definition mjpegdec.h:162
int h_count[MAX_COMPONENTS]
Definition mjpegdec.h:106
uint8_t raw_huffman_lengths[2][4][16]
Definition mjpegdec.h:174
int64_t total_ls_decoded_height
Definition mjpegdec.h:144
AVGainMapParams * gain_map
!< stereoscopic information (cached, since it is read before frame allocation)
Definition mjpegdec.h:157
int16_t block[64]
Definition mjpegdec.h:123
const AVFrame * reference
Definition mjpegdec.h:184
int linesize[MAX_COMPONENTS]
linesize << interlaced
Definition mjpegdec.h:122
IDCTDSPContext idsp
Definition mjpegdec.h:131
void * hwaccel_picture_private
Definition mjpegdec.h:179
int component_id[MAX_COMPONENTS]
Definition mjpegdec.h:105
uint8_t * buffer
Definition mjpegdec.h:65
int qscale[4]
quantizer scale calculated from quant_matrixes
Definition mjpegdec.h:69
uint8_t * last_nnz[MAX_COMPONENTS]
Definition mjpegdec.h:125
AVFrame * picture_ptr
Definition mjpegdec.h:119
op_pixels_func copy_block
only set and used by mxpeg
Definition mjpegdec.h:132
GetBitContext gb
Definition mjpegdec.h:60
uint8_t raw_huffman_values[2][4][256]
Definition mjpegdec.h:175
int comp_index[MAX_COMPONENTS]
Definition mjpegdec.h:108
int quant_sindex[MAX_COMPONENTS]
Definition mjpegdec.h:114
uint64_t coefs_finished[MAX_COMPONENTS]
bitmask of which coefs have been completely decoded (progressive mode)
Definition mjpegdec.h:126
uint16_t quant_matrixes[4][64]
Definition mjpegdec.h:67
enum AVPixelFormat hwaccel_sw_pix_fmt
Definition mjpegdec.h:177
const AVPixFmtDescriptor * pix_desc
Definition mjpegdec.h:160
AVFrame * smv_frame
Definition mjpegdec.h:166
int v_scount[MAX_COMPONENTS]
Definition mjpegdec.h:113
int16_t(*[MAX_COMPONENTS] blocks)[64]
intermediate sums (progressive mode)
Definition mjpegdec.h:124
uint8_t upscale_h[4]
Definition mjpegdec.h:80
const uint8_t * mb_bitmask
Definition mjpegdec.h:182
struct JLSState * jls_state
Definition mjpegdec.h:180
GetByteContext gB
Definition mjpegdec.h:61
int got_picture
we found a SOF and picture is valid, too.
Definition mjpegdec.h:120
size_t mb_bitmask_size
Definition mjpegdec.h:183
size_t raw_image_buffer_size
Definition mjpegdec.h:172
uint16_t(* ljpeg_buffer)[4]
Definition mjpegdec.h:147
int dc_index[MAX_COMPONENTS]
Definition mjpegdec.h:109
int h_scount[MAX_COMPONENTS]
Definition mjpegdec.h:112
VLC vlcs[3][4]
Definition mjpegdec.h:68
int v_count[MAX_COMPONENTS]
Definition mjpegdec.h:107
int near
near lossless bound (si 0 for lossless)
Definition mjpegdec.h:97
BlockDSPContext bdsp
Definition mjpegdec.h:130
const uint8_t * raw_image_buffer
Definition mjpegdec.h:171
AVCodecContext * avctx
Definition mjpegdec.h:59
unsigned int ljpeg_buffer_size
Definition mjpegdec.h:148
uint8_t permutated_scantable[64]
Definition mjpegdec.h:129
AVFrame * picture
Definition mjpegdec.h:118
int last_dc[MAX_COMPONENTS]
Definition mjpegdec.h:117
Definition vlc.h:50