/src/ffmpeg/libavcodec/mjpegdec.h
Line | Count | Source |
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 "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 | 4.32M | #define MAX_COMPONENTS 4 |
48 | | |
49 | | typedef struct ICCEntry { |
50 | | uint8_t *data; |
51 | | int length; |
52 | | } ICCEntry; |
53 | | |
54 | | struct JLSState; |
55 | | |
56 | | typedef struct MJpegDecodeContext { |
57 | | AVClass *class; |
58 | | AVCodecContext *avctx; |
59 | | GetBitContext gb; |
60 | | GetByteContext gB; |
61 | | int buf_size; |
62 | | |
63 | | int buffer_size; |
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 */ |
74 | | int lossless; |
75 | | int ls; |
76 | | int progressive; |
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; |
86 | | int adobe_transform; |
87 | | |
88 | | /* SOS fields */ |
89 | | int nb_components_sos; |
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 | | |
100 | | int width, height; |
101 | | int mb_width, mb_height; |
102 | | int nb_components; |
103 | | int block_stride[MAX_COMPONENTS]; |
104 | | int component_id[MAX_COMPONENTS]; |
105 | | int h_count[MAX_COMPONENTS]; /* horizontal and vertical count for each component */ |
106 | | int v_count[MAX_COMPONENTS]; |
107 | | int comp_index[MAX_COMPONENTS]; |
108 | | int dc_index[MAX_COMPONENTS]; |
109 | | int ac_index[MAX_COMPONENTS]; |
110 | | int nb_blocks[MAX_COMPONENTS]; |
111 | | int h_scount[MAX_COMPONENTS]; |
112 | | int v_scount[MAX_COMPONENTS]; |
113 | | int quant_sindex[MAX_COMPONENTS]; |
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) |
124 | | uint8_t *last_nnz[MAX_COMPONENTS]; |
125 | | uint64_t coefs_finished[MAX_COMPONENTS]; ///< bitmask of which coefs have been completely decoded (progressive mode) |
126 | | int palette_index; |
127 | | int force_pal8; |
128 | | uint8_t permutated_scantable[64]; |
129 | | BlockDSPContext bdsp; |
130 | | IDCTDSPContext idsp; |
131 | | op_pixels_func copy_block; ///< only set and used by mxpeg |
132 | | |
133 | | int restart_interval; |
134 | | int restart_count; |
135 | | |
136 | | int cs_itu601; |
137 | | int interlace_polarity; |
138 | | int multiscope; |
139 | | |
140 | | int mjpb_skiptosod; |
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 |
152 | | AVExifMetadata exif_metadata; |
153 | | |
154 | | AVStereo3D *stereo3d; ///!< stereoscopic information (cached, since it is read before frame allocation) |
155 | | |
156 | | const AVPixFmtDescriptor *pix_desc; |
157 | | |
158 | | ICCEntry *iccentries; |
159 | | int iccnum; |
160 | | int iccread; |
161 | | |
162 | | AVFrame *smv_frame; |
163 | | int smv_frames_per_jpeg; |
164 | | int smv_next_frame; |
165 | | |
166 | | // Raw stream data for hwaccel use. |
167 | | const uint8_t *raw_image_buffer; |
168 | | size_t raw_image_buffer_size; |
169 | | |
170 | | uint8_t raw_huffman_lengths[2][4][16]; |
171 | | uint8_t raw_huffman_values[2][4][256]; |
172 | | |
173 | | enum AVPixelFormat hwaccel_sw_pix_fmt; |
174 | | enum AVPixelFormat hwaccel_pix_fmt; |
175 | | void *hwaccel_picture_private; |
176 | | struct JLSState *jls_state; |
177 | | |
178 | | const uint8_t *mb_bitmask; |
179 | | size_t mb_bitmask_size; |
180 | | const AVFrame *reference; |
181 | | } MJpegDecodeContext; |
182 | | |
183 | | int ff_mjpeg_build_vlc(VLC *vlc, const uint8_t *bits_table, |
184 | | const uint8_t *val_table, int is_ac, void *logctx); |
185 | | int ff_mjpeg_decode_init(AVCodecContext *avctx); |
186 | | int ff_mjpeg_decode_end(AVCodecContext *avctx); |
187 | | int ff_mjpeg_decode_frame(AVCodecContext *avctx, |
188 | | AVFrame *frame, int *got_frame, |
189 | | AVPacket *avpkt); |
190 | | int ff_mjpeg_decode_frame_from_buf(AVCodecContext *avctx, |
191 | | AVFrame *frame, int *got_frame, |
192 | | const AVPacket *avpkt, const uint8_t *buf, int buf_size); |
193 | | int ff_mjpeg_decode_dqt(MJpegDecodeContext *s); |
194 | | int ff_mjpeg_decode_dht(MJpegDecodeContext *s); |
195 | | int ff_mjpeg_decode_sof(MJpegDecodeContext *s); |
196 | | int ff_mjpeg_decode_sos(MJpegDecodeContext *s); |
197 | | int ff_mjpeg_find_marker(const uint8_t **buf_ptr, const uint8_t *buf_end); |
198 | | int ff_mjpeg_unescape_sos(MJpegDecodeContext *s); |
199 | | |
200 | | static inline int ff_mjpeg_should_restart(MJpegDecodeContext *s) |
201 | 155M | { |
202 | 155M | int restart = 0; |
203 | 155M | if (s->restart_interval) { |
204 | 98.7M | if (s->restart_count <= 0) { |
205 | 86.7M | s->restart_count = s->restart_interval; |
206 | 86.7M | restart = 1; |
207 | 86.7M | } |
208 | 98.7M | s->restart_count--; |
209 | 98.7M | } else { |
210 | 57.0M | if (s->restart_count < 0) { |
211 | 1.04M | s->restart_count = 0; |
212 | 1.04M | restart = 1; |
213 | 1.04M | } |
214 | 57.0M | } |
215 | 155M | return restart; |
216 | 155M | } mjpegdec.c:ff_mjpeg_should_restart Line | Count | Source | 201 | 153M | { | 202 | 153M | int restart = 0; | 203 | 153M | if (s->restart_interval) { | 204 | 97.3M | if (s->restart_count <= 0) { | 205 | 86.0M | s->restart_count = s->restart_interval; | 206 | 86.0M | restart = 1; | 207 | 86.0M | } | 208 | 97.3M | s->restart_count--; | 209 | 97.3M | } else { | 210 | 56.2M | if (s->restart_count < 0) { | 211 | 887k | s->restart_count = 0; | 212 | 887k | restart = 1; | 213 | 887k | } | 214 | 56.2M | } | 215 | 153M | return restart; | 216 | 153M | } |
Unexecuted instantiation: mjpegdec_common.c:ff_mjpeg_should_restart jpeglsdec.c:ff_mjpeg_should_restart Line | Count | Source | 201 | 2.23M | { | 202 | 2.23M | int restart = 0; | 203 | 2.23M | if (s->restart_interval) { | 204 | 1.35M | if (s->restart_count <= 0) { | 205 | 708k | s->restart_count = s->restart_interval; | 206 | 708k | restart = 1; | 207 | 708k | } | 208 | 1.35M | s->restart_count--; | 209 | 1.35M | } else { | 210 | 886k | if (s->restart_count < 0) { | 211 | 152k | s->restart_count = 0; | 212 | 152k | restart = 1; | 213 | 152k | } | 214 | 886k | } | 215 | 2.23M | return restart; | 216 | 2.23M | } |
Unexecuted instantiation: mxpegdec.c:ff_mjpeg_should_restart Unexecuted instantiation: tiff.c:ff_mjpeg_should_restart Unexecuted instantiation: mjpegbdec.c:ff_mjpeg_should_restart Unexecuted instantiation: g2meet.c:ff_mjpeg_should_restart Unexecuted instantiation: sp5xdec.c:ff_mjpeg_should_restart |
217 | | |
218 | | static inline int ff_mjpeg_handle_restart(MJpegDecodeContext *s, int *restart) |
219 | 152M | { |
220 | 152M | *restart = ff_mjpeg_should_restart(s); |
221 | 152M | if (*restart) { |
222 | 87.7M | int ret = ff_mjpeg_unescape_sos(s); |
223 | 87.7M | if (ret < 0) |
224 | 0 | return ret; |
225 | 87.7M | } |
226 | 152M | return 0; |
227 | 152M | } mjpegdec.c:ff_mjpeg_handle_restart Line | Count | Source | 219 | 150M | { | 220 | 150M | *restart = ff_mjpeg_should_restart(s); | 221 | 150M | if (*restart) { | 222 | 86.8M | int ret = ff_mjpeg_unescape_sos(s); | 223 | 86.8M | if (ret < 0) | 224 | 0 | return ret; | 225 | 86.8M | } | 226 | 150M | return 0; | 227 | 150M | } |
Unexecuted instantiation: mjpegdec_common.c:ff_mjpeg_handle_restart jpeglsdec.c:ff_mjpeg_handle_restart Line | Count | Source | 219 | 2.23M | { | 220 | 2.23M | *restart = ff_mjpeg_should_restart(s); | 221 | 2.23M | if (*restart) { | 222 | 861k | int ret = ff_mjpeg_unescape_sos(s); | 223 | 861k | if (ret < 0) | 224 | 0 | return ret; | 225 | 861k | } | 226 | 2.23M | return 0; | 227 | 2.23M | } |
Unexecuted instantiation: mxpegdec.c:ff_mjpeg_handle_restart Unexecuted instantiation: tiff.c:ff_mjpeg_handle_restart Unexecuted instantiation: mjpegbdec.c:ff_mjpeg_handle_restart Unexecuted instantiation: g2meet.c:ff_mjpeg_handle_restart Unexecuted instantiation: sp5xdec.c:ff_mjpeg_handle_restart |
228 | | |
229 | | #endif /* AVCODEC_MJPEGDEC_H */ |