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/log.h"
34#include "libavutil/pixdesc.h"
35#include "libavutil/stereo3d.h"
36
37#include "avcodec.h"
38#include "blockdsp.h"
39#include "bytestream.h"
40#include "exif.h"
41#include "get_bits.h"
42#include "hpeldsp.h"
43#include "idctdsp.h"
44
45#undef near /* This file uses struct member 'near' which in windows.h is defined as empty. */
46
47#define MAX_COMPONENTS 4
48
49typedef struct ICCEntry {
50 uint8_t *data;
51 int length;
52} ICCEntry;
53
54struct JLSState;
55
56typedef struct MJpegDecodeContext {
57 AVClass *class;
62
64 uint8_t *buffer;
65
66 uint16_t quant_matrixes[4][64];
67 VLC vlcs[3][4];
68 int qscale[4]; ///< quantizer scale calculated from quant_matrixes
69
70 int orig_height; /* size given at codec init */
71 int first_picture; /* true if decoding first picture */
72 int interlaced; /* true if interlaced */
73 int bottom_field; /* true if bottom field */
75 int ls;
77 int bayer; /* true if it's a bayer-encoded JPEG embedded in a DNG */
78 int rgb;
79 uint8_t upscale_h[4];
80 uint8_t upscale_v[4];
81 int rct; /* standard rct */
82 int pegasus_rct; /* pegasus reversible colorspace transform */
83 int bits; /* bits per component */
84 int colr;
85 int xfrm;
87
88 /* SOS fields */
90 int Ss;
91 int Se;
92 int Ah;
93 int Al;
94
95 int maxval;
96 int near; ///< near lossless bound (si 0 for lossless)
97 int t1,t2,t3;
98 int reset; ///< context halfing interval ?rename
99
105 int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */
114 int h_max, v_max; /* maximum h and v counts */
115 int quant_index[4]; /* quant table index for each component */
116 int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */
117 AVFrame *picture; /* picture structure */
118 AVFrame *picture_ptr; /* pointer to picture structure */
119 int got_picture; ///< we found a SOF and picture is valid, too.
120 int nb_seq_component_scans; ///< component scans decoded since the SOF (sequential images: <= nb_components)
121 int linesize[MAX_COMPONENTS]; ///< linesize << interlaced
122 DECLARE_ALIGNED(32, int16_t, block)[64];
123 int16_t (*blocks[MAX_COMPONENTS])[64]; ///< intermediate sums (progressive mode)
125 uint64_t coefs_finished[MAX_COMPONENTS]; ///< bitmask of which coefs have been completely decoded (progressive mode)
131 op_pixels_func copy_block; ///< only set and used by mxpeg
132
135
139
141
142 int cur_scan; /* current scan, used by JPEG-LS */
143 int64_t total_ls_decoded_height; /* cumulative JPEG-LS rows decoded in the current packet */
144 int flipped; /* true if picture is flipped */
145
146 uint16_t (*ljpeg_buffer)[4];
147 unsigned int ljpeg_buffer_size;
148
149#if FF_API_MJPEG_EXTERN_HUFF
150 int extern_huff;
151#endif
153
154 AVStereo3D *stereo3d; ///!< stereoscopic information (cached, since it is read before frame allocation)
155
157
161
165
166 // Raw stream data for hwaccel use.
167 const uint8_t *raw_image_buffer;
169
170 uint8_t raw_huffman_lengths[2][4][16];
171 uint8_t raw_huffman_values[2][4][256];
172
177
178 const uint8_t *mb_bitmask;
182
183int ff_mjpeg_build_vlc(VLC *vlc, const uint8_t *bits_table,
184 const uint8_t *val_table, int is_ac, void *logctx);
188 AVFrame *frame, int *got_frame,
189 AVPacket *avpkt);
191 AVFrame *frame, int *got_frame,
192 const AVPacket *avpkt, const uint8_t *buf, int buf_size);
197int ff_mjpeg_find_marker(const uint8_t **buf_ptr, const uint8_t *buf_end);
199
201{
202 int restart = 0;
203 if (s->restart_interval) {
204 if (s->restart_count <= 0) {
205 s->restart_count = s->restart_interval;
206 restart = 1;
207 }
208 s->restart_count--;
209 } else {
210 if (s->restart_count < 0) {
211 s->restart_count = 0;
212 restart = 1;
213 }
214 }
215 return restart;
216}
217
218static inline int ff_mjpeg_handle_restart(MJpegDecodeContext *s, int *restart)
219{
220 *restart = ff_mjpeg_should_restart(s);
221 if (*restart) {
222 int ret = ff_mjpeg_unescape_sos(s);
223 if (ret < 0)
224 return ret;
225 }
226 return 0;
227}
228
229#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.
bitstream reader API header.
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:218
int ff_mjpeg_decode_init(AVCodecContext *avctx)
Definition mjpegdec.c:124
int ff_mjpeg_decode_sos(MJpegDecodeContext *s)
Definition mjpegdec.c:1680
int ff_mjpeg_decode_end(AVCodecContext *avctx)
Definition mjpegdec.c:2900
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:47
int ff_mjpeg_decode_dqt(MJpegDecodeContext *s)
Definition mjpegdec.c:208
static int ff_mjpeg_should_restart(MJpegDecodeContext *s)
Definition mjpegdec.h:200
int ff_mjpeg_unescape_sos(MJpegDecodeContext *s)
Definition mjpegdec.c:2251
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:2394
int ff_mjpeg_find_marker(const uint8_t **buf_ptr, const uint8_t *buf_end)
Definition mjpegdec.c:2195
int ff_mjpeg_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *avpkt)
Definition mjpegdec.c:2890
int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
Definition mjpegdec.c:310
int ff_mjpeg_decode_dht(MJpegDecodeContext *s)
Definition mjpegdec.c:251
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:472
This structure stores compressed data.
Definition packet.h:580
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:50
int length
Definition mjpegdec.h:51
uint8_t upscale_v[4]
Definition mjpegdec.h:80
AVStereo3D * stereo3d
Definition mjpegdec.h:154
int block_stride[MAX_COMPONENTS]
Definition mjpegdec.h:103
int nb_seq_component_scans
component scans decoded since the SOF (sequential images: <= nb_components)
Definition mjpegdec.h:120
AVExifMetadata exif_metadata
Definition mjpegdec.h:152
int reset
context halfing interval ?rename
Definition mjpegdec.h:98
enum AVPixelFormat hwaccel_pix_fmt
Definition mjpegdec.h:174
int nb_blocks[MAX_COMPONENTS]
Definition mjpegdec.h:110
int ac_index[MAX_COMPONENTS]
Definition mjpegdec.h:109
ICCEntry * iccentries
Definition mjpegdec.h:158
int h_count[MAX_COMPONENTS]
Definition mjpegdec.h:105
uint8_t raw_huffman_lengths[2][4][16]
Definition mjpegdec.h:170
int64_t total_ls_decoded_height
Definition mjpegdec.h:143
int16_t block[64]
Definition mjpegdec.h:122
const AVFrame * reference
Definition mjpegdec.h:180
int linesize[MAX_COMPONENTS]
linesize << interlaced
Definition mjpegdec.h:121
IDCTDSPContext idsp
Definition mjpegdec.h:130
void * hwaccel_picture_private
Definition mjpegdec.h:175
int component_id[MAX_COMPONENTS]
Definition mjpegdec.h:104
uint8_t * buffer
Definition mjpegdec.h:64
int qscale[4]
quantizer scale calculated from quant_matrixes
Definition mjpegdec.h:68
uint8_t * last_nnz[MAX_COMPONENTS]
Definition mjpegdec.h:124
AVFrame * picture_ptr
Definition mjpegdec.h:118
op_pixels_func copy_block
only set and used by mxpeg
Definition mjpegdec.h:131
GetBitContext gb
Definition mjpegdec.h:59
uint8_t raw_huffman_values[2][4][256]
Definition mjpegdec.h:171
int comp_index[MAX_COMPONENTS]
Definition mjpegdec.h:107
int quant_sindex[MAX_COMPONENTS]
Definition mjpegdec.h:113
uint64_t coefs_finished[MAX_COMPONENTS]
bitmask of which coefs have been completely decoded (progressive mode)
Definition mjpegdec.h:125
uint16_t quant_matrixes[4][64]
Definition mjpegdec.h:66
enum AVPixelFormat hwaccel_sw_pix_fmt
Definition mjpegdec.h:173
const AVPixFmtDescriptor * pix_desc
!< stereoscopic information (cached, since it is read before frame allocation)
Definition mjpegdec.h:156
AVFrame * smv_frame
Definition mjpegdec.h:162
int v_scount[MAX_COMPONENTS]
Definition mjpegdec.h:112
int16_t(*[MAX_COMPONENTS] blocks)[64]
intermediate sums (progressive mode)
Definition mjpegdec.h:123
uint8_t upscale_h[4]
Definition mjpegdec.h:79
const uint8_t * mb_bitmask
Definition mjpegdec.h:178
struct JLSState * jls_state
Definition mjpegdec.h:176
GetByteContext gB
Definition mjpegdec.h:60
int got_picture
we found a SOF and picture is valid, too.
Definition mjpegdec.h:119
size_t mb_bitmask_size
Definition mjpegdec.h:179
size_t raw_image_buffer_size
Definition mjpegdec.h:168
uint16_t(* ljpeg_buffer)[4]
Definition mjpegdec.h:146
int dc_index[MAX_COMPONENTS]
Definition mjpegdec.h:108
int h_scount[MAX_COMPONENTS]
Definition mjpegdec.h:111
VLC vlcs[3][4]
Definition mjpegdec.h:67
int v_count[MAX_COMPONENTS]
Definition mjpegdec.h:106
int near
near lossless bound (si 0 for lossless)
Definition mjpegdec.h:96
BlockDSPContext bdsp
Definition mjpegdec.h:129
const uint8_t * raw_image_buffer
Definition mjpegdec.h:167
AVCodecContext * avctx
Definition mjpegdec.h:58
unsigned int ljpeg_buffer_size
Definition mjpegdec.h:147
uint8_t permutated_scantable[64]
Definition mjpegdec.h:128
AVFrame * picture
Definition mjpegdec.h:117
int last_dc[MAX_COMPONENTS]
Definition mjpegdec.h:116
Definition vlc.h:50