]> git.sesse.net Git - ffmpeg/blob - libavcodec/mjpegdec.h
avcodec/adpcm_argo: reset state on flush
[ffmpeg] / libavcodec / mjpegdec.h
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"
33 #include "libavutil/mem_internal.h"
34 #include "libavutil/pixdesc.h"
35 #include "libavutil/stereo3d.h"
36
37 #include "avcodec.h"
38 #include "blockdsp.h"
39 #include "get_bits.h"
40 #include "hpeldsp.h"
41 #include "idctdsp.h"
42
43 #undef near /* This file uses struct member 'near' which in windows.h is defined as empty. */
44
45 #define MAX_COMPONENTS 4
46
47 typedef struct MJpegDecodeContext {
48     AVClass *class;
49     AVCodecContext *avctx;
50     GetBitContext gb;
51     int buf_size;
52
53     AVPacket *pkt;
54
55     int start_code; /* current start code */
56     int buffer_size;
57     uint8_t *buffer;
58
59     uint16_t quant_matrixes[4][64];
60     VLC vlcs[3][4];
61     int qscale[4];      ///< quantizer scale calculated from quant_matrixes
62
63     int orig_height;  /* size given at codec init */
64     int first_picture;    /* true if decoding first picture */
65     int interlaced;     /* true if interlaced */
66     int bottom_field;   /* true if bottom field */
67     int lossless;
68     int ls;
69     int progressive;
70     int bayer;          /* true if it's a bayer-encoded JPEG embedded in a DNG */
71     int rgb;
72     uint8_t upscale_h[4];
73     uint8_t upscale_v[4];
74     int rct;            /* standard rct */
75     int pegasus_rct;    /* pegasus reversible colorspace transform */
76     int bits;           /* bits per component */
77     int colr;
78     int xfrm;
79     int adobe_transform;
80
81     int maxval;
82     int near;         ///< near lossless bound (si 0 for lossless)
83     int t1,t2,t3;
84     int reset;        ///< context halfing interval ?rename
85
86     int width, height;
87     int mb_width, mb_height;
88     int nb_components;
89     int block_stride[MAX_COMPONENTS];
90     int component_id[MAX_COMPONENTS];
91     int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */
92     int v_count[MAX_COMPONENTS];
93     int comp_index[MAX_COMPONENTS];
94     int dc_index[MAX_COMPONENTS];
95     int ac_index[MAX_COMPONENTS];
96     int nb_blocks[MAX_COMPONENTS];
97     int h_scount[MAX_COMPONENTS];
98     int v_scount[MAX_COMPONENTS];
99     int quant_sindex[MAX_COMPONENTS];
100     int h_max, v_max; /* maximum h and v counts */
101     int quant_index[4];   /* quant table index for each component */
102     int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */
103     AVFrame *picture; /* picture structure */
104     AVFrame *picture_ptr; /* pointer to picture structure */
105     int got_picture;                                ///< we found a SOF and picture is valid, too.
106     int linesize[MAX_COMPONENTS];                   ///< linesize << interlaced
107     int8_t *qscale_table;
108     DECLARE_ALIGNED(32, int16_t, block)[64];
109     int16_t (*blocks[MAX_COMPONENTS])[64]; ///< intermediate sums (progressive mode)
110     uint8_t *last_nnz[MAX_COMPONENTS];
111     uint64_t coefs_finished[MAX_COMPONENTS]; ///< bitmask of which coefs have been completely decoded (progressive mode)
112     int palette_index;
113     ScanTable scantable;
114     BlockDSPContext bdsp;
115     HpelDSPContext hdsp;
116     IDCTDSPContext idsp;
117
118     int restart_interval;
119     int restart_count;
120
121     int buggy_avid;
122     int cs_itu601;
123     int interlace_polarity;
124     int multiscope;
125
126     int mjpb_skiptosod;
127
128     int cur_scan; /* current scan, used by JPEG-LS */
129     int flipped; /* true if picture is flipped */
130
131     uint16_t (*ljpeg_buffer)[4];
132     unsigned int ljpeg_buffer_size;
133
134     int extern_huff;
135     AVDictionary *exif_metadata;
136
137     AVStereo3D *stereo3d; ///!< stereoscopic information (cached, since it is read before frame allocation)
138
139     const AVPixFmtDescriptor *pix_desc;
140
141     uint8_t **iccdata;
142     int *iccdatalens;
143     int iccnum;
144     int iccread;
145
146     AVFrame *smv_frame;
147     int smv_frames_per_jpeg;
148     int smv_next_frame;
149
150     // Raw stream data for hwaccel use.
151     const uint8_t *raw_image_buffer;
152     size_t         raw_image_buffer_size;
153     const uint8_t *raw_scan_buffer;
154     size_t         raw_scan_buffer_size;
155
156     uint8_t raw_huffman_lengths[2][4][16];
157     uint8_t raw_huffman_values[2][4][256];
158
159     enum AVPixelFormat hwaccel_sw_pix_fmt;
160     enum AVPixelFormat hwaccel_pix_fmt;
161     void *hwaccel_picture_private;
162 } MJpegDecodeContext;
163
164 int ff_mjpeg_build_vlc(VLC *vlc, const uint8_t *bits_table,
165                        const uint8_t *val_table, int is_ac, void *logctx);
166 int ff_mjpeg_decode_init(AVCodecContext *avctx);
167 int ff_mjpeg_decode_end(AVCodecContext *avctx);
168 int ff_mjpeg_receive_frame(AVCodecContext *avctx, AVFrame *frame);
169 int ff_mjpeg_decode_dqt(MJpegDecodeContext *s);
170 int ff_mjpeg_decode_dht(MJpegDecodeContext *s);
171 int ff_mjpeg_decode_sof(MJpegDecodeContext *s);
172 int ff_mjpeg_decode_sos(MJpegDecodeContext *s,
173                         const uint8_t *mb_bitmask,int mb_bitmask_size,
174                         const AVFrame *reference);
175 int ff_mjpeg_find_marker(MJpegDecodeContext *s,
176                          const uint8_t **buf_ptr, const uint8_t *buf_end,
177                          const uint8_t **unescaped_buf_ptr, int *unescaped_buf_size);
178
179 int ff_sp5x_process_packet(AVCodecContext *avctx, AVPacket *avpkt);
180
181 #endif /* AVCODEC_MJPEGDEC_H */