annotate mjpegdec.c @ 11497:6962a149f0a4 libavcodec

mpegts muxer now needs mpeg4audio code like adts muxer
author bcoudurier
date Mon, 15 Mar 2010 23:11:02 +0000
parents 5ab861519e79
children 8a4984c5cacc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1 /*
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
2 * MJPEG decoder
8629
04423b2f6e0b cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 8612
diff changeset
3 * Copyright (c) 2000, 2001 Fabrice Bellard
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
4 * Copyright (c) 2003 Alex Beregszaszi
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
5 * Copyright (c) 2003-2004 Michael Niedermayer
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
6 *
5214
470601203f44 Group all copyright and author notices together.
diego
parents: 5153
diff changeset
7 * Support for external huffman table, various fixes (AVID workaround),
470601203f44 Group all copyright and author notices together.
diego
parents: 5153
diff changeset
8 * aspecting, new decode_frame mechanism and apple mjpeg-b support
470601203f44 Group all copyright and author notices together.
diego
parents: 5153
diff changeset
9 * by Alex Beregszaszi
470601203f44 Group all copyright and author notices together.
diego
parents: 5153
diff changeset
10 *
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
11 * This file is part of FFmpeg.
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
12 *
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
13 * FFmpeg is free software; you can redistribute it and/or
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
14 * modify it under the terms of the GNU Lesser General Public
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
15 * License as published by the Free Software Foundation; either
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
16 * version 2.1 of the License, or (at your option) any later version.
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
17 *
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
18 * FFmpeg is distributed in the hope that it will be useful,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
21 * Lesser General Public License for more details.
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
22 *
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
23 * You should have received a copy of the GNU Lesser General Public
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
24 * License along with FFmpeg; if not, write to the Free Software
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
26 */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
27
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
28 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 8629
diff changeset
29 * @file libavcodec/mjpegdec.c
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
30 * MJPEG decoder.
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
31 */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
32
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
33 //#define DEBUG
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
34 #include <assert.h>
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
35
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
36 #include "avcodec.h"
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
37 #include "dsputil.h"
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
38 #include "mjpeg.h"
5041
01a165280429 allows to disable jpegls decoder
aurel
parents: 5039
diff changeset
39 #include "mjpegdec.h"
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
40 #include "jpeglsdec.h"
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
41
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
42
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
43 static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
44 int nb_codes, int use_static, int is_ac)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
45 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
46 uint8_t huff_size[256+16];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
47 uint16_t huff_code[256+16];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
48
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
49 assert(nb_codes <= 256);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
50
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
51 memset(huff_size, 0, sizeof(huff_size));
5021
d73237575709 add proper prefix to new mjpeg extern func/var
aurel
parents: 5020
diff changeset
52 ff_mjpeg_build_huffman_codes(huff_size, huff_code, bits_table, val_table);
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
53
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
54 if(is_ac){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
55 memmove(huff_size+16, huff_size, sizeof(uint8_t)*nb_codes);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
56 memmove(huff_code+16, huff_code, sizeof(uint16_t)*nb_codes);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
57 memset(huff_size, 0, sizeof(uint8_t)*16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
58 memset(huff_code, 0, sizeof(uint16_t)*16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
59 nb_codes += 16;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
60 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
61
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
62 return init_vlc(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2, use_static);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
63 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
64
5068
93e369c55c31 fix mjpeg decoding with broken huffman table headers
ods15
parents: 5044
diff changeset
65 static void build_basic_mjpeg_vlc(MJpegDecodeContext * s) {
93e369c55c31 fix mjpeg decoding with broken huffman table headers
ods15
parents: 5044
diff changeset
66 build_vlc(&s->vlcs[0][0], ff_mjpeg_bits_dc_luminance,
7136
7a73d76aaaa0 remove duplicate tables
stefang
parents: 7040
diff changeset
67 ff_mjpeg_val_dc, 12, 0, 0);
5068
93e369c55c31 fix mjpeg decoding with broken huffman table headers
ods15
parents: 5044
diff changeset
68 build_vlc(&s->vlcs[0][1], ff_mjpeg_bits_dc_chrominance,
7136
7a73d76aaaa0 remove duplicate tables
stefang
parents: 7040
diff changeset
69 ff_mjpeg_val_dc, 12, 0, 0);
5068
93e369c55c31 fix mjpeg decoding with broken huffman table headers
ods15
parents: 5044
diff changeset
70 build_vlc(&s->vlcs[1][0], ff_mjpeg_bits_ac_luminance,
93e369c55c31 fix mjpeg decoding with broken huffman table headers
ods15
parents: 5044
diff changeset
71 ff_mjpeg_val_ac_luminance, 251, 0, 1);
93e369c55c31 fix mjpeg decoding with broken huffman table headers
ods15
parents: 5044
diff changeset
72 build_vlc(&s->vlcs[1][1], ff_mjpeg_bits_ac_chrominance,
93e369c55c31 fix mjpeg decoding with broken huffman table headers
ods15
parents: 5044
diff changeset
73 ff_mjpeg_val_ac_chrominance, 251, 0, 1);
93e369c55c31 fix mjpeg decoding with broken huffman table headers
ods15
parents: 5044
diff changeset
74 }
93e369c55c31 fix mjpeg decoding with broken huffman table headers
ods15
parents: 5044
diff changeset
75
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6448
diff changeset
76 av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
77 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
78 MJpegDecodeContext *s = avctx->priv_data;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
79
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
80 s->avctx = avctx;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
81 dsputil_init(&s->dsp, avctx);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
82 ff_init_scantable(s->dsp.idct_permutation, &s->scantable, ff_zigzag_direct);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
83 s->buffer_size = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
84 s->buffer = NULL;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
85 s->start_code = -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
86 s->first_picture = 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
87 s->org_height = avctx->coded_height;
9626
bd3e11b60ccd Add a chroma_sample_location field to define positioning of chroma samples
conrad
parents: 9459
diff changeset
88 avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
89
5068
93e369c55c31 fix mjpeg decoding with broken huffman table headers
ods15
parents: 5044
diff changeset
90 build_basic_mjpeg_vlc(s);
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
91
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
92 if (avctx->flags & CODEC_FLAG_EXTERN_HUFF)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
93 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
94 av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
95 init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8);
5068
93e369c55c31 fix mjpeg decoding with broken huffman table headers
ods15
parents: 5044
diff changeset
96 if (ff_mjpeg_decode_dht(s)) {
93e369c55c31 fix mjpeg decoding with broken huffman table headers
ods15
parents: 5044
diff changeset
97 av_log(avctx, AV_LOG_ERROR, "mjpeg: error using external huffman table, switching back to internal\n");
93e369c55c31 fix mjpeg decoding with broken huffman table headers
ods15
parents: 5044
diff changeset
98 build_basic_mjpeg_vlc(s);
93e369c55c31 fix mjpeg decoding with broken huffman table headers
ods15
parents: 5044
diff changeset
99 }
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
100 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
101 if (avctx->extradata_size > 9 &&
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
102 AV_RL32(avctx->extradata + 4) == MKTAG('f','i','e','l')) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
103 if (avctx->extradata[9] == 6) { /* quicktime icefloe 019 */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
104 s->interlace_polarity = 1; /* bottom field first */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
105 av_log(avctx, AV_LOG_DEBUG, "mjpeg bottom field first\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
106 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
107 }
10438
710e226783f0 Flip (M)JPEG frames encoded by Intel JPEG library.
cehoyos
parents: 10412
diff changeset
108 if (avctx->codec->id == CODEC_ID_AMV)
710e226783f0 Flip (M)JPEG frames encoded by Intel JPEG library.
cehoyos
parents: 10412
diff changeset
109 s->flipped = 1;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
110
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
111 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
112 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
113
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
114
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
115 /* quantize tables */
5044
924fdd6175b1 move mjpeg-b decoder in its own file
aurel
parents: 5042
diff changeset
116 int ff_mjpeg_decode_dqt(MJpegDecodeContext *s)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
117 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
118 int len, index, i, j;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
119
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
120 len = get_bits(&s->gb, 16) - 2;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
121
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
122 while (len >= 65) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
123 /* only 8 bit precision handled */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
124 if (get_bits(&s->gb, 4) != 0)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
125 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
126 av_log(s->avctx, AV_LOG_ERROR, "dqt: 16bit precision\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
127 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
128 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
129 index = get_bits(&s->gb, 4);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
130 if (index >= 4)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
131 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
132 av_log(s->avctx, AV_LOG_DEBUG, "index=%d\n", index);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
133 /* read quant table */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
134 for(i=0;i<64;i++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
135 j = s->scantable.permutated[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
136 s->quant_matrixes[index][j] = get_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
137 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
138
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
139 //XXX FIXME finetune, and perhaps add dc too
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
140 s->qscale[index]= FFMAX(
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
141 s->quant_matrixes[index][s->scantable.permutated[1]],
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
142 s->quant_matrixes[index][s->scantable.permutated[8]]) >> 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
143 av_log(s->avctx, AV_LOG_DEBUG, "qscale[%d]: %d\n", index, s->qscale[index]);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
144 len -= 65;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
145 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
146
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
147 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
148 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
149
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
150 /* decode huffman tables and build VLC decoders */
5044
924fdd6175b1 move mjpeg-b decoder in its own file
aurel
parents: 5042
diff changeset
151 int ff_mjpeg_decode_dht(MJpegDecodeContext *s)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
152 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
153 int len, index, i, class, n, v, code_max;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
154 uint8_t bits_table[17];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
155 uint8_t val_table[256];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
156
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
157 len = get_bits(&s->gb, 16) - 2;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
158
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
159 while (len > 0) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
160 if (len < 17)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
161 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
162 class = get_bits(&s->gb, 4);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
163 if (class >= 2)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
164 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
165 index = get_bits(&s->gb, 4);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
166 if (index >= 4)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
167 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
168 n = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
169 for(i=1;i<=16;i++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
170 bits_table[i] = get_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
171 n += bits_table[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
172 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
173 len -= 17;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
174 if (len < n || n > 256)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
175 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
176
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
177 code_max = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
178 for(i=0;i<n;i++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
179 v = get_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
180 if (v > code_max)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
181 code_max = v;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
182 val_table[i] = v;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
183 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
184 len -= n;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
185
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
186 /* build VLC and flush previous vlc if present */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
187 free_vlc(&s->vlcs[class][index]);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
188 av_log(s->avctx, AV_LOG_DEBUG, "class=%d index=%d nb_codes=%d\n",
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
189 class, index, code_max + 1);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
190 if(build_vlc(&s->vlcs[class][index], bits_table, val_table, code_max + 1, 0, class > 0) < 0){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
191 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
192 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
193 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
194 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
195 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
196
5044
924fdd6175b1 move mjpeg-b decoder in its own file
aurel
parents: 5042
diff changeset
197 int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
198 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
199 int len, nb_components, i, width, height, pix_fmt_id;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
200
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
201 /* XXX: verify len field validity */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
202 len = get_bits(&s->gb, 16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
203 s->bits= get_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
204
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
205 if(s->pegasus_rct) s->bits=9;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
206 if(s->bits==9 && !s->pegasus_rct) s->rct=1; //FIXME ugly
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
207
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
208 if (s->bits != 8 && !s->lossless){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
209 av_log(s->avctx, AV_LOG_ERROR, "only 8 bits/component accepted\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
210 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
211 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
212
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
213 height = get_bits(&s->gb, 16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
214 width = get_bits(&s->gb, 16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
215
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
216 //HACK for odd_height.mov
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
217 if(s->interlaced && s->width == width && s->height == height + 1)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
218 height= s->height;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
219
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
220 av_log(s->avctx, AV_LOG_DEBUG, "sof0: picture: %dx%d\n", width, height);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
221 if(avcodec_check_dimensions(s->avctx, width, height))
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
222 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
223
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
224 nb_components = get_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
225 if (nb_components <= 0 ||
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
226 nb_components > MAX_COMPONENTS)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
227 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
228 if (s->ls && !(s->bits <= 8 || nb_components == 1)){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
229 av_log(s->avctx, AV_LOG_ERROR, "only <= 8 bits/component or 16-bit gray accepted for JPEG-LS\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
230 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
231 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
232 s->nb_components = nb_components;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
233 s->h_max = 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
234 s->v_max = 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
235 for(i=0;i<nb_components;i++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
236 /* component id */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
237 s->component_id[i] = get_bits(&s->gb, 8) - 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
238 s->h_count[i] = get_bits(&s->gb, 4);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
239 s->v_count[i] = get_bits(&s->gb, 4);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
240 /* compute hmax and vmax (only used in interleaved case) */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
241 if (s->h_count[i] > s->h_max)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
242 s->h_max = s->h_count[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
243 if (s->v_count[i] > s->v_max)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
244 s->v_max = s->v_count[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
245 s->quant_index[i] = get_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
246 if (s->quant_index[i] >= 4)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
247 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
248 av_log(s->avctx, AV_LOG_DEBUG, "component %d %d:%d id: %d quant:%d\n", i, s->h_count[i],
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
249 s->v_count[i], s->component_id[i], s->quant_index[i]);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
250 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
251
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
252 if(s->ls && (s->h_max > 1 || s->v_max > 1)) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
253 av_log(s->avctx, AV_LOG_ERROR, "Subsampling in JPEG-LS is not supported.\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
254 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
255 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
256
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
257 if(s->v_max==1 && s->h_max==1 && s->lossless==1) s->rgb=1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
258
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
259 /* if different size, realloc/alloc picture */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
260 /* XXX: also check h_count and v_count */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
261 if (width != s->width || height != s->height) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
262 av_freep(&s->qscale_table);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
263
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
264 s->width = width;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
265 s->height = height;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
266 s->interlaced = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
267
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
268 /* test interlaced mode */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
269 if (s->first_picture &&
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
270 s->org_height != 0 &&
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
271 s->height < ((s->org_height * 3) / 4)) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
272 s->interlaced = 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
273 s->bottom_field = s->interlace_polarity;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
274 s->picture.interlaced_frame = 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
275 s->picture.top_field_first = !s->interlace_polarity;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
276 height *= 2;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
277 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
278
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
279 avcodec_set_dimensions(s->avctx, width, height);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
280
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
281 s->qscale_table= av_mallocz((s->width+15)/16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
282
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
283 s->first_picture = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
284 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
285
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
286 if(s->interlaced && (s->bottom_field == !s->interlace_polarity))
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
287 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
288
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
289 /* XXX: not complete test ! */
7930
fae5e74eef1b Check the 4th plane too when selecting the pixfmt.
michael
parents: 7478
diff changeset
290 pix_fmt_id = (s->h_count[0] << 28) | (s->v_count[0] << 24) |
fae5e74eef1b Check the 4th plane too when selecting the pixfmt.
michael
parents: 7478
diff changeset
291 (s->h_count[1] << 20) | (s->v_count[1] << 16) |
fae5e74eef1b Check the 4th plane too when selecting the pixfmt.
michael
parents: 7478
diff changeset
292 (s->h_count[2] << 12) | (s->v_count[2] << 8) |
fae5e74eef1b Check the 4th plane too when selecting the pixfmt.
michael
parents: 7478
diff changeset
293 (s->h_count[3] << 4) | s->v_count[3];
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
294 av_log(s->avctx, AV_LOG_DEBUG, "pix fmt id %x\n", pix_fmt_id);
10549
981e7720fc03 Allocate pictures with enough padding for jpeg.
michael
parents: 10539
diff changeset
295 //NOTE we do not allocate pictures large enough for the possible padding of h/v_count being 4
981e7720fc03 Allocate pictures with enough padding for jpeg.
michael
parents: 10539
diff changeset
296 if(!(pix_fmt_id & 0xD0D0D0D0))
7931
fd6c05a225aa Simplify pix_fmt_id instead of listing a subset of non-simplified ones.
michael
parents: 7930
diff changeset
297 pix_fmt_id-= (pix_fmt_id & 0xF0F0F0F0)>>1;
10549
981e7720fc03 Allocate pictures with enough padding for jpeg.
michael
parents: 10539
diff changeset
298 if(!(pix_fmt_id & 0x0D0D0D0D))
7931
fd6c05a225aa Simplify pix_fmt_id instead of listing a subset of non-simplified ones.
michael
parents: 7930
diff changeset
299 pix_fmt_id-= (pix_fmt_id & 0x0F0F0F0F)>>1;
fd6c05a225aa Simplify pix_fmt_id instead of listing a subset of non-simplified ones.
michael
parents: 7930
diff changeset
300
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
301 switch(pix_fmt_id){
7930
fae5e74eef1b Check the 4th plane too when selecting the pixfmt.
michael
parents: 7478
diff changeset
302 case 0x11111100:
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
303 if(s->rgb){
10666
7127645ee791 Lossless jpeg expects and uses BGRA not RGB32 (this probably caused a problem on
michael
parents: 10549
diff changeset
304 s->avctx->pix_fmt = PIX_FMT_BGRA;
7932
7729da3e4866 Replace apparently always true condition by assert().
michael
parents: 7931
diff changeset
305 }else
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
306 s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV444P : PIX_FMT_YUVJ444P;
7932
7729da3e4866 Replace apparently always true condition by assert().
michael
parents: 7931
diff changeset
307 assert(s->nb_components==3);
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
308 break;
7930
fae5e74eef1b Check the 4th plane too when selecting the pixfmt.
michael
parents: 7478
diff changeset
309 case 0x11000000:
5478
41103dc22ad5 Add support for grayscale MJPEG streams sent by Axis cameras such as the
diego
parents: 5381
diff changeset
310 s->avctx->pix_fmt = PIX_FMT_GRAY8;
41103dc22ad5 Add support for grayscale MJPEG streams sent by Axis cameras such as the
diego
parents: 5381
diff changeset
311 break;
7930
fae5e74eef1b Check the 4th plane too when selecting the pixfmt.
michael
parents: 7478
diff changeset
312 case 0x12111100:
5363
1a25f2f6316e add YUV440P and YUVJ440P support
benoit
parents: 5214
diff changeset
313 s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV440P : PIX_FMT_YUVJ440P;
1a25f2f6316e add YUV440P and YUVJ440P support
benoit
parents: 5214
diff changeset
314 break;
7930
fae5e74eef1b Check the 4th plane too when selecting the pixfmt.
michael
parents: 7478
diff changeset
315 case 0x21111100:
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
316 s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV422P : PIX_FMT_YUVJ422P;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
317 break;
7930
fae5e74eef1b Check the 4th plane too when selecting the pixfmt.
michael
parents: 7478
diff changeset
318 case 0x22111100:
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
319 s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420P;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
320 break;
5381
4cac2cfe2745 bail out on unknown jpeg pixel format instead of silently decoding data incorrectly
gpoirier
parents: 5363
diff changeset
321 default:
4cac2cfe2745 bail out on unknown jpeg pixel format instead of silently decoding data incorrectly
gpoirier
parents: 5363
diff changeset
322 av_log(s->avctx, AV_LOG_ERROR, "Unhandled pixel format 0x%x\n", pix_fmt_id);
4cac2cfe2745 bail out on unknown jpeg pixel format instead of silently decoding data incorrectly
gpoirier
parents: 5363
diff changeset
323 return -1;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
324 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
325 if(s->ls){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
326 if(s->nb_components > 1)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
327 s->avctx->pix_fmt = PIX_FMT_RGB24;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
328 else if(s->bits <= 8)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
329 s->avctx->pix_fmt = PIX_FMT_GRAY8;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
330 else
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
331 s->avctx->pix_fmt = PIX_FMT_GRAY16;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
332 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
333
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
334 if(s->picture.data[0])
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
335 s->avctx->release_buffer(s->avctx, &s->picture);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
336
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
337 s->picture.reference= 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
338 if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
339 av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
340 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
341 }
6448
7fa807dd7958 remove #include "mpegvideo.h" where it is not needed
aurel
parents: 6222
diff changeset
342 s->picture.pict_type= FF_I_TYPE;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
343 s->picture.key_frame= 1;
9913
b73796e93571 Add a got_picture flag to MJpegDecodeContext which indicates if its picture
reimar
parents: 9912
diff changeset
344 s->got_picture = 1;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
345
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
346 for(i=0; i<3; i++){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
347 s->linesize[i]= s->picture.linesize[i] << s->interlaced;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
348 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
349
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
350 // printf("%d %d %d %d %d %d\n", s->width, s->height, s->linesize[0], s->linesize[1], s->interlaced, s->avctx->height);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
351
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
352 if (len != (8+(3*nb_components)))
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
353 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
354 av_log(s->avctx, AV_LOG_DEBUG, "decode_sof0: error, len(%d) mismatch\n", len);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
355 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
356
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
357 /* totally blank picture as progressive JPEG will only add details to it */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
358 if(s->progressive){
8287
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
359 int bw = (width + s->h_max*8-1) / (s->h_max*8);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
360 int bh = (height + s->v_max*8-1) / (s->v_max*8);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
361 for(i=0; i<s->nb_components; i++) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
362 int size = bw * bh * s->h_count[i] * s->v_count[i];
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
363 av_freep(&s->blocks[i]);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
364 av_freep(&s->last_nnz[i]);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
365 s->blocks[i] = av_malloc(size * sizeof(**s->blocks));
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
366 s->last_nnz[i] = av_mallocz(size * sizeof(**s->last_nnz));
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
367 s->block_stride[i] = bw * s->h_count[i];
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
368 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
369 memset(s->coefs_finished, 0, sizeof(s->coefs_finished));
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
370 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
371 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
372 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
373
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
374 static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
375 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
376 int code;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
377 code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
378 if (code < 0)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
379 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
380 av_log(s->avctx, AV_LOG_WARNING, "mjpeg_decode_dc: bad vlc: %d:%d (%p)\n", 0, dc_index,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
381 &s->vlcs[0][dc_index]);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
382 return 0xffff;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
383 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
384
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
385 if(code)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
386 return get_xbits(&s->gb, code);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
387 else
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
388 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
389 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
390
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
391 /* decode block and dequantize */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
392 static int decode_block(MJpegDecodeContext *s, DCTELEM *block,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
393 int component, int dc_index, int ac_index, int16_t *quant_matrix)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
394 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
395 int code, i, j, level, val;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
396
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
397 /* DC coef */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
398 val = mjpeg_decode_dc(s, dc_index);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
399 if (val == 0xffff) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
400 av_log(s->avctx, AV_LOG_ERROR, "error dc\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
401 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
402 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
403 val = val * quant_matrix[0] + s->last_dc[component];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
404 s->last_dc[component] = val;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
405 block[0] = val;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
406 /* AC coefs */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
407 i = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
408 {OPEN_READER(re, &s->gb)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
409 for(;;) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
410 UPDATE_CACHE(re, &s->gb);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
411 GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
412
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
413 /* EOB */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
414 if (code == 0x10)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
415 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
416 i += ((unsigned)code) >> 4;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
417 if(code != 0x100){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
418 code &= 0xf;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
419 if(code > MIN_CACHE_BITS - 16){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
420 UPDATE_CACHE(re, &s->gb)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
421 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
422 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
423 int cache=GET_CACHE(re,&s->gb);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
424 int sign=(~cache)>>31;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
425 level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
426 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
427
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
428 LAST_SKIP_BITS(re, &s->gb, code)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
429
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
430 if (i >= 63) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
431 if(i == 63){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
432 j = s->scantable.permutated[63];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
433 block[j] = level * quant_matrix[j];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
434 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
435 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
436 av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
437 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
438 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
439 j = s->scantable.permutated[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
440 block[j] = level * quant_matrix[j];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
441 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
442 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
443 CLOSE_READER(re, &s->gb)}
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
444
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
445 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
446 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
447
8287
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
448 static int decode_dc_progressive(MJpegDecodeContext *s, DCTELEM *block, int component,
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
449 int dc_index, int16_t *quant_matrix, int Al)
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
450 {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
451 int val;
8288
800444234375 clear_block mmx
lorenm
parents: 8287
diff changeset
452 s->dsp.clear_block(block);
8287
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
453 val = mjpeg_decode_dc(s, dc_index);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
454 if (val == 0xffff) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
455 av_log(s->avctx, AV_LOG_ERROR, "error dc\n");
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
456 return -1;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
457 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
458 val = (val * quant_matrix[0] << Al) + s->last_dc[component];
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
459 s->last_dc[component] = val;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
460 block[0] = val;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
461 return 0;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
462 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
463
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
464 /* decode block and dequantize - progressive JPEG version */
8287
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
465 static int decode_block_progressive(MJpegDecodeContext *s, DCTELEM *block, uint8_t *last_nnz,
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
466 int ac_index, int16_t *quant_matrix,
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
467 int ss, int se, int Al, int *EOBRUN)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
468 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
469 int code, i, j, level, val, run;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
470
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
471 if(*EOBRUN){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
472 (*EOBRUN)--;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
473 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
474 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
475 {OPEN_READER(re, &s->gb)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
476 for(i=ss;;i++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
477 UPDATE_CACHE(re, &s->gb);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
478 GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
479 /* Progressive JPEG use AC coeffs from zero and this decoder sets offset 16 by default */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
480 code -= 16;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
481 if(code & 0xF) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
482 i += ((unsigned) code) >> 4;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
483 code &= 0xf;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
484 if(code > MIN_CACHE_BITS - 16){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
485 UPDATE_CACHE(re, &s->gb)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
486 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
487 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
488 int cache=GET_CACHE(re,&s->gb);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
489 int sign=(~cache)>>31;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
490 level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
491 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
492
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
493 LAST_SKIP_BITS(re, &s->gb, code)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
494
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
495 if (i >= se) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
496 if(i == se){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
497 j = s->scantable.permutated[se];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
498 block[j] = level * quant_matrix[j] << Al;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
499 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
500 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
501 av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
502 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
503 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
504 j = s->scantable.permutated[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
505 block[j] = level * quant_matrix[j] << Al;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
506 }else{
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
507 run = ((unsigned) code) >> 4;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
508 if(run == 0xF){// ZRL - skip 15 coefficients
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
509 i += 15;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
510 }else{
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
511 val = run;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
512 run = (1 << run);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
513 UPDATE_CACHE(re, &s->gb);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
514 run += (GET_CACHE(re, &s->gb) >> (32 - val)) & (run - 1);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
515 if(val)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
516 LAST_SKIP_BITS(re, &s->gb, val);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
517 *EOBRUN = run - 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
518 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
519 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
520 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
521 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
522 CLOSE_READER(re, &s->gb)}
8287
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
523 if(i > *last_nnz)
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
524 *last_nnz = i;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
525 return 0;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
526 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
527
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
528 #define REFINE_BIT(j) {\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
529 UPDATE_CACHE(re, &s->gb);\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
530 sign = block[j]>>15;\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
531 block[j] += SHOW_UBITS(re, &s->gb, 1) * ((quant_matrix[j]^sign)-sign) << Al;\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
532 LAST_SKIP_BITS(re, &s->gb, 1);\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
533 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
534
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
535 #define ZERO_RUN \
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
536 for(;;i++) {\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
537 if(i > last) {\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
538 i += run;\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
539 if(i > se) {\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
540 av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i);\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
541 return -1;\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
542 }\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
543 break;\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
544 }\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
545 j = s->scantable.permutated[i];\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
546 if(block[j])\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
547 REFINE_BIT(j)\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
548 else if(run-- == 0)\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
549 break;\
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
550 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
551
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
552 /* decode block and dequantize - progressive JPEG refinement pass */
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
553 static int decode_block_refinement(MJpegDecodeContext *s, DCTELEM *block, uint8_t *last_nnz,
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
554 int ac_index, int16_t *quant_matrix,
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
555 int ss, int se, int Al, int *EOBRUN)
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
556 {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
557 int code, i=ss, j, sign, val, run;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
558 int last = FFMIN(se, *last_nnz);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
559
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
560 OPEN_READER(re, &s->gb);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
561 if(*EOBRUN)
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
562 (*EOBRUN)--;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
563 else {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
564 for(;;i++) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
565 UPDATE_CACHE(re, &s->gb);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
566 GET_VLC(code, re, &s->gb, s->vlcs[1][ac_index].table, 9, 2)
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
567 /* Progressive JPEG use AC coeffs from zero and this decoder sets offset 16 by default */
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
568 code -= 16;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
569 if(code & 0xF) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
570 run = ((unsigned) code) >> 4;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
571 UPDATE_CACHE(re, &s->gb);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
572 val = SHOW_UBITS(re, &s->gb, 1);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
573 LAST_SKIP_BITS(re, &s->gb, 1);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
574 ZERO_RUN;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
575 j = s->scantable.permutated[i];
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
576 val--;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
577 block[j] = ((quant_matrix[j]^val)-val) << Al;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
578 if(i == se) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
579 if(i > *last_nnz)
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
580 *last_nnz = i;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
581 CLOSE_READER(re, &s->gb)
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
582 return 0;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
583 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
584 }else{
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
585 run = ((unsigned) code) >> 4;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
586 if(run == 0xF){
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
587 ZERO_RUN;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
588 }else{
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
589 val = run;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
590 run = (1 << run);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
591 if(val) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
592 UPDATE_CACHE(re, &s->gb);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
593 run += SHOW_UBITS(re, &s->gb, val);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
594 LAST_SKIP_BITS(re, &s->gb, val);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
595 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
596 *EOBRUN = run - 1;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
597 break;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
598 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
599 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
600 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
601
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
602 if(i > *last_nnz)
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
603 *last_nnz = i;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
604 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
605
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
606 for(;i<=last;i++) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
607 j = s->scantable.permutated[i];
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
608 if(block[j])
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
609 REFINE_BIT(j)
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
610 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
611 CLOSE_READER(re, &s->gb);
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
612
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
613 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
614 }
8287
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
615 #undef REFINE_BIT
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
616 #undef ZERO_RUN
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
617
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
618 static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int predictor, int point_transform){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
619 int i, mb_x, mb_y;
10487
3e404d2520a7 Avoid huge array for rgb ljpeg on the stack.
michael
parents: 10438
diff changeset
620 uint16_t (*buffer)[4];
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
621 int left[3], top[3], topleft[3];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
622 const int linesize= s->linesize[0];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
623 const int mask= (1<<s->bits)-1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
624
10487
3e404d2520a7 Avoid huge array for rgb ljpeg on the stack.
michael
parents: 10438
diff changeset
625 av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size, (unsigned)s->mb_width * 4 * sizeof(s->ljpeg_buffer[0][0]));
3e404d2520a7 Avoid huge array for rgb ljpeg on the stack.
michael
parents: 10438
diff changeset
626 buffer= s->ljpeg_buffer;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
627
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
628 for(i=0; i<3; i++){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
629 buffer[0][i]= 1 << (s->bits + point_transform - 1);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
630 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
631 for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
632 const int modified_predictor= mb_y ? predictor : 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
633 uint8_t *ptr = s->picture.data[0] + (linesize * mb_y);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
634
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
635 if (s->interlaced && s->bottom_field)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
636 ptr += linesize >> 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
637
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
638 for(i=0; i<3; i++){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
639 top[i]= left[i]= topleft[i]= buffer[0][i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
640 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
641 for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
642 if (s->restart_interval && !s->restart_count)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
643 s->restart_count = s->restart_interval;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
644
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
645 for(i=0;i<3;i++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
646 int pred;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
647
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
648 topleft[i]= top[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
649 top[i]= buffer[mb_x][i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
650
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
651 PREDICT(pred, topleft[i], top[i], left[i], modified_predictor);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
652
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
653 left[i]=
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
654 buffer[mb_x][i]= mask & (pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform));
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
655 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
656
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
657 if (s->restart_interval && !--s->restart_count) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
658 align_get_bits(&s->gb);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
659 skip_bits(&s->gb, 16); /* skip RSTn */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
660 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
661 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
662
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
663 if(s->rct){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
664 for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
665 ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200)>>2);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
666 ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
667 ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
668 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
669 }else if(s->pegasus_rct){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
670 for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
671 ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2])>>2);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
672 ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
673 ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
674 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
675 }else{
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
676 for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
10667
26f4a5a07f7e Flip red and blue in rct-less lossless jpeg.
michael
parents: 10666
diff changeset
677 ptr[4*mb_x+0] = buffer[mb_x][2];
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
678 ptr[4*mb_x+1] = buffer[mb_x][1];
10667
26f4a5a07f7e Flip red and blue in rct-less lossless jpeg.
michael
parents: 10666
diff changeset
679 ptr[4*mb_x+2] = buffer[mb_x][0];
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
680 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
681 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
682 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
683 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
684 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
685
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
686 static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, int point_transform){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
687 int i, mb_x, mb_y;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
688 const int nb_components=3;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
689
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
690 for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
691 for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
692 if (s->restart_interval && !s->restart_count)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
693 s->restart_count = s->restart_interval;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
694
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
695 if(mb_x==0 || mb_y==0 || s->interlaced){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
696 for(i=0;i<nb_components;i++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
697 uint8_t *ptr;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
698 int n, h, v, x, y, c, j, linesize;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
699 n = s->nb_blocks[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
700 c = s->comp_index[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
701 h = s->h_scount[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
702 v = s->v_scount[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
703 x = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
704 y = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
705 linesize= s->linesize[c];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
706
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
707 for(j=0; j<n; j++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
708 int pred;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
709
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
710 ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
711 if(y==0 && mb_y==0){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
712 if(x==0 && mb_x==0){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
713 pred= 128 << point_transform;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
714 }else{
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
715 pred= ptr[-1];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
716 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
717 }else{
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
718 if(x==0 && mb_x==0){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
719 pred= ptr[-linesize];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
720 }else{
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
721 PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
722 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
723 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
724
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
725 if (s->interlaced && s->bottom_field)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
726 ptr += linesize >> 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
727 *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
728
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
729 if (++x == h) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
730 x = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
731 y++;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
732 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
733 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
734 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
735 }else{
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
736 for(i=0;i<nb_components;i++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
737 uint8_t *ptr;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
738 int n, h, v, x, y, c, j, linesize;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
739 n = s->nb_blocks[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
740 c = s->comp_index[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
741 h = s->h_scount[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
742 v = s->v_scount[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
743 x = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
744 y = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
745 linesize= s->linesize[c];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
746
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
747 for(j=0; j<n; j++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
748 int pred;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
749
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
750 ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
751 PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
752 *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
753 if (++x == h) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
754 x = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
755 y++;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
756 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
757 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
758 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
759 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
760 if (s->restart_interval && !--s->restart_count) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
761 align_get_bits(&s->gb);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
762 skip_bits(&s->gb, 16); /* skip RSTn */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
763 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
764 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
765 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
766 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
767 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
768
8287
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
769 static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, int Al){
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
770 int i, mb_x, mb_y;
5734
0590ad246eca Add variables to prepare to the AMV decoder patch.
vitor
parents: 5478
diff changeset
771 uint8_t* data[MAX_COMPONENTS];
0590ad246eca Add variables to prepare to the AMV decoder patch.
vitor
parents: 5478
diff changeset
772 int linesize[MAX_COMPONENTS];
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
773
10539
8d8fcc20dd30 Disable image flipping during JPEG decoding if CODEC_FLAG_EMU_EDGE is set
reimar
parents: 10487
diff changeset
774 if(s->flipped && s->avctx->flags & CODEC_FLAG_EMU_EDGE) {
8d8fcc20dd30 Disable image flipping during JPEG decoding if CODEC_FLAG_EMU_EDGE is set
reimar
parents: 10487
diff changeset
775 av_log(s->avctx, AV_LOG_ERROR, "Can not flip image with CODEC_FLAG_EMU_EDGE set!\n");
8d8fcc20dd30 Disable image flipping during JPEG decoding if CODEC_FLAG_EMU_EDGE is set
reimar
parents: 10487
diff changeset
776 s->flipped = 0;
8d8fcc20dd30 Disable image flipping during JPEG decoding if CODEC_FLAG_EMU_EDGE is set
reimar
parents: 10487
diff changeset
777 }
5734
0590ad246eca Add variables to prepare to the AMV decoder patch.
vitor
parents: 5478
diff changeset
778 for(i=0; i < nb_components; i++) {
0590ad246eca Add variables to prepare to the AMV decoder patch.
vitor
parents: 5478
diff changeset
779 int c = s->comp_index[i];
0590ad246eca Add variables to prepare to the AMV decoder patch.
vitor
parents: 5478
diff changeset
780 data[c] = s->picture.data[c];
0590ad246eca Add variables to prepare to the AMV decoder patch.
vitor
parents: 5478
diff changeset
781 linesize[c]=s->linesize[c];
8287
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
782 s->coefs_finished[c] |= 1;
10438
710e226783f0 Flip (M)JPEG frames encoded by Intel JPEG library.
cehoyos
parents: 10412
diff changeset
783 if(s->flipped) {
5736
810067f2c33d AMV video decoder.
vitor
parents: 5734
diff changeset
784 //picture should be flipped upside-down for this codec
5818
e0a872dd3ea1 Fix MJPEG decoder for AMV files.
voroshil
parents: 5736
diff changeset
785 data[c] += (linesize[c] * (s->v_scount[i] * (8 * s->mb_height -((s->height/s->v_max)&7)) - 1 ));
5736
810067f2c33d AMV video decoder.
vitor
parents: 5734
diff changeset
786 linesize[c] *= -1;
810067f2c33d AMV video decoder.
vitor
parents: 5734
diff changeset
787 }
5734
0590ad246eca Add variables to prepare to the AMV decoder patch.
vitor
parents: 5478
diff changeset
788 }
0590ad246eca Add variables to prepare to the AMV decoder patch.
vitor
parents: 5478
diff changeset
789
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
790 for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
791 for(mb_x = 0; mb_x < s->mb_width; mb_x++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
792 if (s->restart_interval && !s->restart_count)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
793 s->restart_count = s->restart_interval;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
794
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
795 for(i=0;i<nb_components;i++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
796 uint8_t *ptr;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
797 int n, h, v, x, y, c, j;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
798 n = s->nb_blocks[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
799 c = s->comp_index[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
800 h = s->h_scount[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
801 v = s->v_scount[i];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
802 x = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
803 y = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
804 for(j=0;j<n;j++) {
5734
0590ad246eca Add variables to prepare to the AMV decoder patch.
vitor
parents: 5478
diff changeset
805 ptr = data[c] +
0590ad246eca Add variables to prepare to the AMV decoder patch.
vitor
parents: 5478
diff changeset
806 (((linesize[c] * (v * mb_y + y) * 8) +
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
807 (h * mb_x + x) * 8) >> s->avctx->lowres);
8287
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
808 if(s->interlaced && s->bottom_field)
5734
0590ad246eca Add variables to prepare to the AMV decoder patch.
vitor
parents: 5478
diff changeset
809 ptr += linesize[c] >> 1;
8287
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
810 if(!s->progressive) {
8288
800444234375 clear_block mmx
lorenm
parents: 8287
diff changeset
811 s->dsp.clear_block(s->block);
8287
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
812 if(decode_block(s, s->block, i,
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
813 s->dc_index[i], s->ac_index[i],
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
814 s->quant_matrixes[ s->quant_index[c] ]) < 0) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
815 av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
816 return -1;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
817 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
818 s->dsp.idct_put(ptr, linesize[c], s->block);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
819 } else {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
820 int block_idx = s->block_stride[c] * (v * mb_y + y) + (h * mb_x + x);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
821 DCTELEM *block = s->blocks[c][block_idx];
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
822 if(Ah)
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
823 block[0] += get_bits1(&s->gb) * s->quant_matrixes[ s->quant_index[c] ][0] << Al;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
824 else if(decode_dc_progressive(s, block, i, s->dc_index[i], s->quant_matrixes[ s->quant_index[c] ], Al) < 0) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
825 av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
826 return -1;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
827 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
828 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
829 // av_log(s->avctx, AV_LOG_DEBUG, "mb: %d %d processed\n", mb_y, mb_x);
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
830 //av_log(NULL, AV_LOG_DEBUG, "%d %d %d %d %d %d %d %d \n", mb_x, mb_y, x, y, c, s->bottom_field, (v * mb_y + y) * 8, (h * mb_x + x) * 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
831 if (++x == h) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
832 x = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
833 y++;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
834 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
835 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
836 }
9706
473fbc242b43 honor restart interval in mjpeg, fix #861, SpectralFan.mov still decodes correctly
bcoudurier
parents: 9626
diff changeset
837
473fbc242b43 honor restart interval in mjpeg, fix #861, SpectralFan.mov still decodes correctly
bcoudurier
parents: 9626
diff changeset
838 if (s->restart_interval && !--s->restart_count) {
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
839 align_get_bits(&s->gb);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
840 skip_bits(&s->gb, 16); /* skip RSTn */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
841 for (i=0; i<nb_components; i++) /* reset dc */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
842 s->last_dc[i] = 1024;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
843 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
844 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
845 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
846 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
847 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
848
8287
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
849 static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss, int se, int Ah, int Al){
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
850 int mb_x, mb_y;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
851 int EOBRUN = 0;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
852 int c = s->comp_index[0];
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
853 uint8_t* data = s->picture.data[c];
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
854 int linesize = s->linesize[c];
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
855 int last_scan = 0;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
856 int16_t *quant_matrix = s->quant_matrixes[ s->quant_index[c] ];
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
857
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
858 if(!Al) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
859 s->coefs_finished[c] |= (1LL<<(se+1))-(1LL<<ss);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
860 last_scan = !~s->coefs_finished[c];
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
861 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
862
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
863 if(s->interlaced && s->bottom_field)
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
864 data += linesize >> 1;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
865
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
866 for(mb_y = 0; mb_y < s->mb_height; mb_y++) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
867 uint8_t *ptr = data + (mb_y*linesize*8 >> s->avctx->lowres);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
868 int block_idx = mb_y * s->block_stride[c];
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
869 DCTELEM (*block)[64] = &s->blocks[c][block_idx];
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
870 uint8_t *last_nnz = &s->last_nnz[c][block_idx];
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
871 for(mb_x = 0; mb_x < s->mb_width; mb_x++, block++, last_nnz++) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
872 int ret;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
873 if(Ah)
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
874 ret = decode_block_refinement(s, *block, last_nnz, s->ac_index[0],
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
875 quant_matrix, ss, se, Al, &EOBRUN);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
876 else
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
877 ret = decode_block_progressive(s, *block, last_nnz, s->ac_index[0],
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
878 quant_matrix, ss, se, Al, &EOBRUN);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
879 if(ret < 0) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
880 av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
881 return -1;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
882 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
883 if(last_scan) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
884 s->dsp.idct_put(ptr, linesize, *block);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
885 ptr += 8 >> s->avctx->lowres;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
886 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
887 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
888 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
889 return 0;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
890 }
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
891
5044
924fdd6175b1 move mjpeg-b decoder in its own file
aurel
parents: 5042
diff changeset
892 int ff_mjpeg_decode_sos(MJpegDecodeContext *s)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
893 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
894 int len, nb_components, i, h, v, predictor, point_transform;
9459
84932ac233a5 Remove unused variables from ff_mjpeg_decode_sos() found by CSA.
michael
parents: 9355
diff changeset
895 int index, id;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
896 const int block_size= s->lossless ? 1 : 8;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
897 int ilv, prev_shift;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
898
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
899 /* XXX: verify len field validity */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
900 len = get_bits(&s->gb, 16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
901 nb_components = get_bits(&s->gb, 8);
11006
d99420b73262 Fix heap overflow due to lack of nb_components check.
michael
parents: 10672
diff changeset
902 if (nb_components == 0 || nb_components > MAX_COMPONENTS){
d99420b73262 Fix heap overflow due to lack of nb_components check.
michael
parents: 10672
diff changeset
903 av_log(s->avctx, AV_LOG_ERROR, "decode_sos: nb_components (%d) unsupported\n", nb_components);
d99420b73262 Fix heap overflow due to lack of nb_components check.
michael
parents: 10672
diff changeset
904 return -1;
d99420b73262 Fix heap overflow due to lack of nb_components check.
michael
parents: 10672
diff changeset
905 }
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
906 if (len != 6+2*nb_components)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
907 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
908 av_log(s->avctx, AV_LOG_ERROR, "decode_sos: invalid len (%d)\n", len);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
909 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
910 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
911 for(i=0;i<nb_components;i++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
912 id = get_bits(&s->gb, 8) - 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
913 av_log(s->avctx, AV_LOG_DEBUG, "component: %d\n", id);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
914 /* find component index */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
915 for(index=0;index<s->nb_components;index++)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
916 if (id == s->component_id[index])
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
917 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
918 if (index == s->nb_components)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
919 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
920 av_log(s->avctx, AV_LOG_ERROR, "decode_sos: index(%d) out of components\n", index);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
921 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
922 }
11007
8d4ae55fdada Metasoft MJPEG codec has Cb and Cr swapped, fixes issue 1611.
cehoyos
parents: 11006
diff changeset
923 /* Metasoft MJPEG codec has Cb and Cr swapped */
8d4ae55fdada Metasoft MJPEG codec has Cb and Cr swapped, fixes issue 1611.
cehoyos
parents: 11006
diff changeset
924 if (s->avctx->codec_tag == MKTAG('M', 'T', 'S', 'J')
8d4ae55fdada Metasoft MJPEG codec has Cb and Cr swapped, fixes issue 1611.
cehoyos
parents: 11006
diff changeset
925 && nb_components == 3 && s->nb_components == 3 && i)
8d4ae55fdada Metasoft MJPEG codec has Cb and Cr swapped, fixes issue 1611.
cehoyos
parents: 11006
diff changeset
926 index = 3 - i;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
927
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
928 s->comp_index[i] = index;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
929
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
930 s->nb_blocks[i] = s->h_count[index] * s->v_count[index];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
931 s->h_scount[i] = s->h_count[index];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
932 s->v_scount[i] = s->v_count[index];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
933
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
934 s->dc_index[i] = get_bits(&s->gb, 4);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
935 s->ac_index[i] = get_bits(&s->gb, 4);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
936
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
937 if (s->dc_index[i] < 0 || s->ac_index[i] < 0 ||
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
938 s->dc_index[i] >= 4 || s->ac_index[i] >= 4)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
939 goto out_of_range;
9912
9502108caadf mjpegdec: check that the coded dc_index and ac_index have a valid associated VLC table.
reimar
parents: 9706
diff changeset
940 if (!s->vlcs[0][s->dc_index[i]].table || !s->vlcs[1][s->ac_index[i]].table)
9502108caadf mjpegdec: check that the coded dc_index and ac_index have a valid associated VLC table.
reimar
parents: 9706
diff changeset
941 goto out_of_range;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
942 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
943
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
944 predictor= get_bits(&s->gb, 8); /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
945 ilv= get_bits(&s->gb, 8); /* JPEG Se / JPEG-LS ILV */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
946 prev_shift = get_bits(&s->gb, 4); /* Ah */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
947 point_transform= get_bits(&s->gb, 4); /* Al */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
948
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
949 for(i=0;i<nb_components;i++)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
950 s->last_dc[i] = 1024;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
951
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
952 if (nb_components > 1) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
953 /* interleaved stream */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
954 s->mb_width = (s->width + s->h_max * block_size - 1) / (s->h_max * block_size);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
955 s->mb_height = (s->height + s->v_max * block_size - 1) / (s->v_max * block_size);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
956 } else if(!s->ls) { /* skip this for JPEG-LS */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
957 h = s->h_max / s->h_scount[0];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
958 v = s->v_max / s->v_scount[0];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
959 s->mb_width = (s->width + h * block_size - 1) / (h * block_size);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
960 s->mb_height = (s->height + v * block_size - 1) / (v * block_size);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
961 s->nb_blocks[0] = 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
962 s->h_scount[0] = 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
963 s->v_scount[0] = 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
964 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
965
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
966 if(s->avctx->debug & FF_DEBUG_PICT_INFO)
11024
5ab861519e79 Fix misc typos, patch by
stefano
parents: 11007
diff changeset
967 av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d ilv:%d bits:%d %s\n", s->lossless ? "lossless" : "sequential DCT", s->rgb ? "RGB" : "",
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
968 predictor, point_transform, ilv, s->bits,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
969 s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : ""));
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
970
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
971
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
972 /* mjpeg-b can have padding bytes between sos and image data, skip them */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
973 for (i = s->mjpb_skiptosod; i > 0; i--)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
974 skip_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
975
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
976 if(s->lossless){
8596
68e959302527 replace all occurrence of ENABLE_ by the corresponding CONFIG_, HAVE_ or ARCH_
aurel
parents: 8288
diff changeset
977 if(CONFIG_JPEGLS_DECODER && s->ls){
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
978 // for(){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
979 // reset_ls_coding_parameters(s, 0);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
980
7478
12d42593e467 Return an error when ff_jpegls_decode_picture fails.
benoit
parents: 7136
diff changeset
981 if(ff_jpegls_decode_picture(s, predictor, point_transform, ilv) < 0)
12d42593e467 Return an error when ff_jpegls_decode_picture fails.
benoit
parents: 7136
diff changeset
982 return -1;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
983 }else{
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
984 if(s->rgb){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
985 if(ljpeg_decode_rgb_scan(s, predictor, point_transform) < 0)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
986 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
987 }else{
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
988 if(ljpeg_decode_yuv_scan(s, predictor, point_transform) < 0)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
989 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
990 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
991 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
992 }else{
8287
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
993 if(s->progressive && predictor) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
994 if(mjpeg_decode_scan_progressive_ac(s, predictor, ilv, prev_shift, point_transform) < 0)
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
995 return -1;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
996 } else {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
997 if(mjpeg_decode_scan(s, nb_components, prev_shift, point_transform) < 0)
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
998 return -1;
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
999 }
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1000 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1001 emms_c();
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1002 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1003 out_of_range:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1004 av_log(s->avctx, AV_LOG_ERROR, "decode_sos: ac/dc index out of range\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1005 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1006 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1007
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1008 static int mjpeg_decode_dri(MJpegDecodeContext *s)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1009 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1010 if (get_bits(&s->gb, 16) != 4)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1011 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1012 s->restart_interval = get_bits(&s->gb, 16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1013 s->restart_count = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1014 av_log(s->avctx, AV_LOG_DEBUG, "restart interval: %d\n", s->restart_interval);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1015
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1016 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1017 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1018
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1019 static int mjpeg_decode_app(MJpegDecodeContext *s)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1020 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1021 int len, id, i;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1022
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1023 len = get_bits(&s->gb, 16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1024 if (len < 5)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1025 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1026 if(8*len + get_bits_count(&s->gb) > s->gb.size_in_bits)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1027 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1028
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1029 id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1030 id = be2me_32(id);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1031 len -= 6;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1032
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1033 if(s->avctx->debug & FF_DEBUG_STARTCODE){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1034 av_log(s->avctx, AV_LOG_DEBUG, "APPx %8X\n", id);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1035 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1036
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1037 /* buggy AVID, it puts EOI only at every 10th frame */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1038 /* also this fourcc is used by non-avid files too, it holds some
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1039 informations, but it's always present in AVID creates files */
8612
b20c590170cc remove ff_get_fourcc() and use AV_RL32() instead
aurel
parents: 8596
diff changeset
1040 if (id == AV_RL32("AVI1"))
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1041 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1042 /* structure:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1043 4bytes AVI1
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1044 1bytes polarity
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1045 1bytes always zero
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1046 4bytes field_size
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1047 4bytes field_size_less_padding
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1048 */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1049 s->buggy_avid = 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1050 // if (s->first_picture)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1051 // printf("mjpeg: workarounding buggy AVID\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1052 i = get_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1053 if (i==2) s->bottom_field= 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1054 else if(i==1) s->bottom_field= 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1055 #if 0
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1056 skip_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1057 skip_bits(&s->gb, 32);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1058 skip_bits(&s->gb, 32);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1059 len -= 10;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1060 #endif
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1061 // if (s->interlace_polarity)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1062 // printf("mjpeg: interlace polarity: %d\n", s->interlace_polarity);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1063 goto out;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1064 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1065
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1066 // len -= 2;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1067
8612
b20c590170cc remove ff_get_fourcc() and use AV_RL32() instead
aurel
parents: 8596
diff changeset
1068 if (id == AV_RL32("JFIF"))
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1069 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1070 int t_w, t_h, v1, v2;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1071 skip_bits(&s->gb, 8); /* the trailing zero-byte */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1072 v1= get_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1073 v2= get_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1074 skip_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1075
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1076 s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1077 s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1078
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1079 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1080 av_log(s->avctx, AV_LOG_INFO, "mjpeg: JFIF header found (version: %x.%x) SAR=%d/%d\n",
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1081 v1, v2,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1082 s->avctx->sample_aspect_ratio.num,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1083 s->avctx->sample_aspect_ratio.den
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1084 );
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1085
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1086 t_w = get_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1087 t_h = get_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1088 if (t_w && t_h)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1089 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1090 /* skip thumbnail */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1091 if (len-10-(t_w*t_h*3) > 0)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1092 len -= t_w*t_h*3;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1093 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1094 len -= 10;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1095 goto out;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1096 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1097
8612
b20c590170cc remove ff_get_fourcc() and use AV_RL32() instead
aurel
parents: 8596
diff changeset
1098 if (id == AV_RL32("Adob") && (get_bits(&s->gb, 8) == 'e'))
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1099 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1100 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1101 av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1102 skip_bits(&s->gb, 16); /* version */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1103 skip_bits(&s->gb, 16); /* flags0 */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1104 skip_bits(&s->gb, 16); /* flags1 */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1105 skip_bits(&s->gb, 8); /* transform */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1106 len -= 7;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1107 goto out;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1108 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1109
8612
b20c590170cc remove ff_get_fourcc() and use AV_RL32() instead
aurel
parents: 8596
diff changeset
1110 if (id == AV_RL32("LJIF")){
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1111 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1112 av_log(s->avctx, AV_LOG_INFO, "Pegasus lossless jpeg header found\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1113 skip_bits(&s->gb, 16); /* version ? */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1114 skip_bits(&s->gb, 16); /* unknwon always 0? */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1115 skip_bits(&s->gb, 16); /* unknwon always 0? */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1116 skip_bits(&s->gb, 16); /* unknwon always 0? */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1117 switch( get_bits(&s->gb, 8)){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1118 case 1:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1119 s->rgb= 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1120 s->pegasus_rct=0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1121 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1122 case 2:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1123 s->rgb= 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1124 s->pegasus_rct=1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1125 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1126 default:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1127 av_log(s->avctx, AV_LOG_ERROR, "unknown colorspace\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1128 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1129 len -= 9;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1130 goto out;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1131 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1132
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1133 /* Apple MJPEG-A */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1134 if ((s->start_code == APP1) && (len > (0x28 - 8)))
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1135 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1136 id = (get_bits(&s->gb, 16) << 16) | get_bits(&s->gb, 16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1137 id = be2me_32(id);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1138 len -= 4;
8612
b20c590170cc remove ff_get_fourcc() and use AV_RL32() instead
aurel
parents: 8596
diff changeset
1139 if (id == AV_RL32("mjpg")) /* Apple MJPEG-A */
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1140 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1141 #if 0
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1142 skip_bits(&s->gb, 32); /* field size */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1143 skip_bits(&s->gb, 32); /* pad field size */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1144 skip_bits(&s->gb, 32); /* next off */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1145 skip_bits(&s->gb, 32); /* quant off */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1146 skip_bits(&s->gb, 32); /* huff off */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1147 skip_bits(&s->gb, 32); /* image off */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1148 skip_bits(&s->gb, 32); /* scan off */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1149 skip_bits(&s->gb, 32); /* data off */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1150 #endif
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1151 if (s->avctx->debug & FF_DEBUG_PICT_INFO)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1152 av_log(s->avctx, AV_LOG_INFO, "mjpeg: Apple MJPEG-A header found\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1153 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1154 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1155
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1156 out:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1157 /* slow but needed for extreme adobe jpegs */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1158 if (len < 0)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1159 av_log(s->avctx, AV_LOG_ERROR, "mjpeg: error, decode_app parser read over the end\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1160 while(--len > 0)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1161 skip_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1162
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1163 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1164 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1165
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1166 static int mjpeg_decode_com(MJpegDecodeContext *s)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1167 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1168 int len = get_bits(&s->gb, 16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1169 if (len >= 2 && 8*len - 16 + get_bits_count(&s->gb) <= s->gb.size_in_bits) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1170 char *cbuf = av_malloc(len - 1);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1171 if (cbuf) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1172 int i;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1173 for (i = 0; i < len - 2; i++)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1174 cbuf[i] = get_bits(&s->gb, 8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1175 if (i > 0 && cbuf[i-1] == '\n')
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1176 cbuf[i-1] = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1177 else
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1178 cbuf[i] = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1179
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1180 if(s->avctx->debug & FF_DEBUG_PICT_INFO)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1181 av_log(s->avctx, AV_LOG_INFO, "mjpeg comment: '%s'\n", cbuf);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1182
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1183 /* buggy avid, it puts EOI only at every 10th frame */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1184 if (!strcmp(cbuf, "AVID"))
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1185 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1186 s->buggy_avid = 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1187 // if (s->first_picture)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1188 // printf("mjpeg: workarounding buggy AVID\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1189 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1190 else if(!strcmp(cbuf, "CS=ITU601")){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1191 s->cs_itu601= 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1192 }
10672
2aab93afc826 (Partly) support Metasoft MJPEG Codec, fixes half of issue 1611.
cehoyos
parents: 10667
diff changeset
1193 else if((len > 20 && !strncmp(cbuf, "Intel(R) JPEG Library", 21)) ||
2aab93afc826 (Partly) support Metasoft MJPEG Codec, fixes half of issue 1611.
cehoyos
parents: 10667
diff changeset
1194 (len > 19 && !strncmp(cbuf, "Metasoft MJPEG Codec", 20))){
10438
710e226783f0 Flip (M)JPEG frames encoded by Intel JPEG library.
cehoyos
parents: 10412
diff changeset
1195 s->flipped = 1;
710e226783f0 Flip (M)JPEG frames encoded by Intel JPEG library.
cehoyos
parents: 10412
diff changeset
1196 }
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1197
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1198 av_free(cbuf);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1199 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1200 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1201
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1202 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1203 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1204
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1205 #if 0
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1206 static int valid_marker_list[] =
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1207 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1208 /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1209 /* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1210 /* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1211 /* 2 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1212 /* 3 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1213 /* 4 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1214 /* 5 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1215 /* 6 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1216 /* 7 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1217 /* 8 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1218 /* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1219 /* a */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1220 /* b */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1221 /* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1222 /* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1223 /* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1224 /* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1225 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1226 #endif
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1227
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1228 /* return the 8 bit start code value and update the search
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1229 state. Return -1 if no start code found */
6222
michael
parents: 5818
diff changeset
1230 static int find_marker(const uint8_t **pbuf_ptr, const uint8_t *buf_end)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1231 {
6222
michael
parents: 5818
diff changeset
1232 const uint8_t *buf_ptr;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1233 unsigned int v, v2;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1234 int val;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1235 #ifdef DEBUG
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1236 int skipped=0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1237 #endif
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1238
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1239 buf_ptr = *pbuf_ptr;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1240 while (buf_ptr < buf_end) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1241 v = *buf_ptr++;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1242 v2 = *buf_ptr;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1243 if ((v == 0xff) && (v2 >= 0xc0) && (v2 <= 0xfe) && buf_ptr < buf_end) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1244 val = *buf_ptr++;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1245 goto found;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1246 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1247 #ifdef DEBUG
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1248 skipped++;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1249 #endif
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1250 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1251 val = -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1252 found:
9999
c78fd9154378 Change av_log() calls surrounded by '#ifdef DEBUG' into dprintf macros.
diego
parents: 9915
diff changeset
1253 dprintf(NULL, "find_marker skipped %d bytes\n", skipped);
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1254 *pbuf_ptr = buf_ptr;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1255 return val;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1256 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1257
5041
01a165280429 allows to disable jpegls decoder
aurel
parents: 5039
diff changeset
1258 int ff_mjpeg_decode_frame(AVCodecContext *avctx,
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1259 void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
1260 AVPacket *avpkt)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1261 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
1262 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
1263 int buf_size = avpkt->size;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1264 MJpegDecodeContext *s = avctx->priv_data;
6222
michael
parents: 5818
diff changeset
1265 const uint8_t *buf_end, *buf_ptr;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1266 int start_code;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1267 AVFrame *picture = data;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1268
9913
b73796e93571 Add a got_picture flag to MJpegDecodeContext which indicates if its picture
reimar
parents: 9912
diff changeset
1269 s->got_picture = 0; // picture from previous image can not be reused
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1270 buf_ptr = buf;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1271 buf_end = buf + buf_size;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1272 while (buf_ptr < buf_end) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1273 /* find start next marker */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1274 start_code = find_marker(&buf_ptr, buf_end);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1275 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1276 /* EOF */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1277 if (start_code < 0) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1278 goto the_end;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1279 } else {
5153
b985439e3e15 fix some printf format specifiers
mru
parents: 5068
diff changeset
1280 av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%td\n", start_code, buf_end - buf_ptr);
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1281
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1282 if ((buf_end - buf_ptr) > s->buffer_size)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1283 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1284 av_free(s->buffer);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1285 s->buffer_size = buf_end-buf_ptr;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1286 s->buffer = av_malloc(s->buffer_size + FF_INPUT_BUFFER_PADDING_SIZE);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1287 av_log(avctx, AV_LOG_DEBUG, "buffer too small, expanding to %d bytes\n",
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1288 s->buffer_size);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1289 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1290
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1291 /* unescape buffer of SOS, use special treatment for JPEG-LS */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1292 if (start_code == SOS && !s->ls)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1293 {
6222
michael
parents: 5818
diff changeset
1294 const uint8_t *src = buf_ptr;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1295 uint8_t *dst = s->buffer;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1296
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1297 while (src<buf_end)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1298 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1299 uint8_t x = *(src++);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1300
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1301 *(dst++) = x;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1302 if (avctx->codec_id != CODEC_ID_THP)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1303 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1304 if (x == 0xff) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1305 while (src < buf_end && x == 0xff)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1306 x = *(src++);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1307
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1308 if (x >= 0xd0 && x <= 0xd7)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1309 *(dst++) = x;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1310 else if (x)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1311 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1312 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1313 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1314 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1315 init_get_bits(&s->gb, s->buffer, (dst - s->buffer)*8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1316
5153
b985439e3e15 fix some printf format specifiers
mru
parents: 5068
diff changeset
1317 av_log(avctx, AV_LOG_DEBUG, "escaping removed %td bytes\n",
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1318 (buf_end - buf_ptr) - (dst - s->buffer));
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1319 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1320 else if(start_code == SOS && s->ls){
6222
michael
parents: 5818
diff changeset
1321 const uint8_t *src = buf_ptr;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1322 uint8_t *dst = s->buffer;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1323 int bit_count = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1324 int t = 0, b = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1325 PutBitContext pb;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1326
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1327 s->cur_scan++;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1328
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1329 /* find marker */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1330 while (src + t < buf_end){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1331 uint8_t x = src[t++];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1332 if (x == 0xff){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1333 while((src + t < buf_end) && x == 0xff)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1334 x = src[t++];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1335 if (x & 0x80) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1336 t -= 2;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1337 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1338 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1339 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1340 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1341 bit_count = t * 8;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1342
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1343 init_put_bits(&pb, dst, t);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1344
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1345 /* unescape bitstream */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1346 while(b < t){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1347 uint8_t x = src[b++];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1348 put_bits(&pb, 8, x);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1349 if(x == 0xFF){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1350 x = src[b++];
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1351 put_bits(&pb, 7, x);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1352 bit_count--;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1353 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1354 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1355 flush_put_bits(&pb);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1356
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1357 init_get_bits(&s->gb, dst, bit_count);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1358 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1359 else
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1360 init_get_bits(&s->gb, buf_ptr, (buf_end - buf_ptr)*8);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1361
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1362 s->start_code = start_code;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1363 if(s->avctx->debug & FF_DEBUG_STARTCODE){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1364 av_log(avctx, AV_LOG_DEBUG, "startcode: %X\n", start_code);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1365 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1366
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1367 /* process markers */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1368 if (start_code >= 0xd0 && start_code <= 0xd7) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1369 av_log(avctx, AV_LOG_DEBUG, "restart marker: %d\n", start_code&0x0f);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1370 /* APP fields */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1371 } else if (start_code >= APP0 && start_code <= APP15) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1372 mjpeg_decode_app(s);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1373 /* Comment */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1374 } else if (start_code == COM){
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1375 mjpeg_decode_com(s);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1376 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1377
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1378 switch(start_code) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1379 case SOI:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1380 s->restart_interval = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1381
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1382 s->restart_count = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1383 /* nothing to do on SOI */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1384 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1385 case DQT:
5044
924fdd6175b1 move mjpeg-b decoder in its own file
aurel
parents: 5042
diff changeset
1386 ff_mjpeg_decode_dqt(s);
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1387 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1388 case DHT:
5044
924fdd6175b1 move mjpeg-b decoder in its own file
aurel
parents: 5042
diff changeset
1389 if(ff_mjpeg_decode_dht(s) < 0){
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1390 av_log(avctx, AV_LOG_ERROR, "huffman table decode error\n");
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1391 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1392 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1393 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1394 case SOF0:
10336
a554d7e29e99 lavc MJPEG decoder is capable of decoding some extended sequential
kostya
parents: 9999
diff changeset
1395 case SOF1:
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1396 s->lossless=0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1397 s->ls=0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1398 s->progressive=0;
5044
924fdd6175b1 move mjpeg-b decoder in its own file
aurel
parents: 5042
diff changeset
1399 if (ff_mjpeg_decode_sof(s) < 0)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1400 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1401 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1402 case SOF2:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1403 s->lossless=0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1404 s->ls=0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1405 s->progressive=1;
5044
924fdd6175b1 move mjpeg-b decoder in its own file
aurel
parents: 5042
diff changeset
1406 if (ff_mjpeg_decode_sof(s) < 0)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1407 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1408 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1409 case SOF3:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1410 s->lossless=1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1411 s->ls=0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1412 s->progressive=0;
5044
924fdd6175b1 move mjpeg-b decoder in its own file
aurel
parents: 5042
diff changeset
1413 if (ff_mjpeg_decode_sof(s) < 0)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1414 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1415 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1416 case SOF48:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1417 s->lossless=1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1418 s->ls=1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1419 s->progressive=0;
5044
924fdd6175b1 move mjpeg-b decoder in its own file
aurel
parents: 5042
diff changeset
1420 if (ff_mjpeg_decode_sof(s) < 0)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1421 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1422 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1423 case LSE:
8596
68e959302527 replace all occurrence of ENABLE_ by the corresponding CONFIG_, HAVE_ or ARCH_
aurel
parents: 8288
diff changeset
1424 if (!CONFIG_JPEGLS_DECODER || ff_jpegls_decode_lse(s) < 0)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1425 return -1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1426 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1427 case EOI:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1428 s->cur_scan = 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1429 if ((s->buggy_avid && !s->interlaced) || s->restart_interval)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1430 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1431 eoi_parser:
9913
b73796e93571 Add a got_picture flag to MJpegDecodeContext which indicates if its picture
reimar
parents: 9912
diff changeset
1432 if (!s->got_picture) {
b73796e93571 Add a got_picture flag to MJpegDecodeContext which indicates if its picture
reimar
parents: 9912
diff changeset
1433 av_log(avctx, AV_LOG_WARNING, "Found EOI before any SOF, ignoring\n");
b73796e93571 Add a got_picture flag to MJpegDecodeContext which indicates if its picture
reimar
parents: 9912
diff changeset
1434 break;
b73796e93571 Add a got_picture flag to MJpegDecodeContext which indicates if its picture
reimar
parents: 9912
diff changeset
1435 }
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1436 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1437 if (s->interlaced) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1438 s->bottom_field ^= 1;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1439 /* if not bottom field, do not output image yet */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1440 if (s->bottom_field == !s->interlace_polarity)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1441 goto not_the_end;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1442 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1443 *picture = s->picture;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1444 *data_size = sizeof(AVFrame);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1445
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1446 if(!s->lossless){
6655
22cca5d3173a Implement FFMAX3(a,b,c) - maximum over three arguments.
voroshil
parents: 6517
diff changeset
1447 picture->quality= FFMAX3(s->qscale[0], s->qscale[1], s->qscale[2]);
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1448 picture->qstride= 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1449 picture->qscale_table= s->qscale_table;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1450 memset(picture->qscale_table, picture->quality, (s->width+15)/16);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1451 if(avctx->debug & FF_DEBUG_QP)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1452 av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", picture->quality);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1453 picture->quality*= FF_QP2LAMBDA;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1454 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1455
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1456 goto the_end;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1457 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1458 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1459 case SOS:
9913
b73796e93571 Add a got_picture flag to MJpegDecodeContext which indicates if its picture
reimar
parents: 9912
diff changeset
1460 if (!s->got_picture) {
b73796e93571 Add a got_picture flag to MJpegDecodeContext which indicates if its picture
reimar
parents: 9912
diff changeset
1461 av_log(avctx, AV_LOG_WARNING, "Can not process SOS before SOF, skipping\n");
b73796e93571 Add a got_picture flag to MJpegDecodeContext which indicates if its picture
reimar
parents: 9912
diff changeset
1462 break;
b73796e93571 Add a got_picture flag to MJpegDecodeContext which indicates if its picture
reimar
parents: 9912
diff changeset
1463 }
5044
924fdd6175b1 move mjpeg-b decoder in its own file
aurel
parents: 5042
diff changeset
1464 ff_mjpeg_decode_sos(s);
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1465 /* buggy avid puts EOI every 10-20th frame */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1466 /* if restart period is over process EOI */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1467 if ((s->buggy_avid && !s->interlaced) || s->restart_interval)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1468 goto eoi_parser;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1469 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1470 case DRI:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1471 mjpeg_decode_dri(s);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1472 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1473 case SOF5:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1474 case SOF6:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1475 case SOF7:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1476 case SOF9:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1477 case SOF10:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1478 case SOF11:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1479 case SOF13:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1480 case SOF14:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1481 case SOF15:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1482 case JPG:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1483 av_log(avctx, AV_LOG_ERROR, "mjpeg: unsupported coding type (%x)\n", start_code);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1484 break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1485 // default:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1486 // printf("mjpeg: unsupported marker (%x)\n", start_code);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1487 // break;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1488 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1489
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1490 not_the_end:
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1491 /* eof process start code */
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1492 buf_ptr += (get_bits_count(&s->gb)+7)/8;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1493 av_log(avctx, AV_LOG_DEBUG, "marker parser used %d bytes (%d bits)\n",
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1494 (get_bits_count(&s->gb)+7)/8, get_bits_count(&s->gb));
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1495 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1496 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1497 }
9915
f1707434e40b If the end of the input buffer is reached while decoding MJPEG and at least
reimar
parents: 9914
diff changeset
1498 if (s->got_picture) {
f1707434e40b If the end of the input buffer is reached while decoding MJPEG and at least
reimar
parents: 9914
diff changeset
1499 av_log(avctx, AV_LOG_WARNING, "EOI missing, emulating\n");
f1707434e40b If the end of the input buffer is reached while decoding MJPEG and at least
reimar
parents: 9914
diff changeset
1500 goto eoi_parser;
f1707434e40b If the end of the input buffer is reached while decoding MJPEG and at least
reimar
parents: 9914
diff changeset
1501 }
9914
e1aaf6216769 Make the MJPEG decoder return -1 when no image was decoded so that decode
reimar
parents: 9913
diff changeset
1502 av_log(avctx, AV_LOG_FATAL, "No JPEG data found in image\n");
e1aaf6216769 Make the MJPEG decoder return -1 when no image was decoded so that decode
reimar
parents: 9913
diff changeset
1503 return -1;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1504 the_end:
5153
b985439e3e15 fix some printf format specifiers
mru
parents: 5068
diff changeset
1505 av_log(avctx, AV_LOG_DEBUG, "mjpeg decode frame unused %td bytes\n", buf_end - buf_ptr);
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1506 // return buf_end - buf_ptr;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1507 return buf_ptr - buf;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1508 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1509
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6448
diff changeset
1510 av_cold int ff_mjpeg_decode_end(AVCodecContext *avctx)
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1511 {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1512 MJpegDecodeContext *s = avctx->priv_data;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1513 int i, j;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1514
10412
9d31db7bec63 Release unreleased buffers found by make test.
cehoyos
parents: 10336
diff changeset
1515 if (s->picture.data[0])
9d31db7bec63 Release unreleased buffers found by make test.
cehoyos
parents: 10336
diff changeset
1516 avctx->release_buffer(avctx, &s->picture);
9d31db7bec63 Release unreleased buffers found by make test.
cehoyos
parents: 10336
diff changeset
1517
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1518 av_free(s->buffer);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1519 av_free(s->qscale_table);
10487
3e404d2520a7 Avoid huge array for rgb ljpeg on the stack.
michael
parents: 10438
diff changeset
1520 av_freep(&s->ljpeg_buffer);
3e404d2520a7 Avoid huge array for rgb ljpeg on the stack.
michael
parents: 10438
diff changeset
1521 s->ljpeg_buffer_size=0;
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1522
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1523 for(i=0;i<2;i++) {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1524 for(j=0;j<4;j++)
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1525 free_vlc(&s->vlcs[i][j]);
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1526 }
8287
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
1527 for(i=0; i<MAX_COMPONENTS; i++) {
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
1528 av_freep(&s->blocks[i]);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
1529 av_freep(&s->last_nnz[i]);
7a1d037482c4 fix progressive jpeg:
lorenm
parents: 7932
diff changeset
1530 }
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1531 return 0;
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1532 }
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1533
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1534 AVCodec mjpeg_decoder = {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1535 "mjpeg",
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1536 CODEC_TYPE_VIDEO,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1537 CODEC_ID_MJPEG,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1538 sizeof(MJpegDecodeContext),
5041
01a165280429 allows to disable jpegls decoder
aurel
parents: 5039
diff changeset
1539 ff_mjpeg_decode_init,
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1540 NULL,
5041
01a165280429 allows to disable jpegls decoder
aurel
parents: 5039
diff changeset
1541 ff_mjpeg_decode_end,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5039
diff changeset
1542 ff_mjpeg_decode_frame,
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1543 CODEC_CAP_DR1,
6710
a4104482ceef Add long names to many AVCodec declarations.
diego
parents: 6655
diff changeset
1544 NULL,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6710
diff changeset
1545 .long_name = NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"),
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1546 };
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1547
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1548 AVCodec thp_decoder = {
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1549 "thp",
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1550 CODEC_TYPE_VIDEO,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1551 CODEC_ID_THP,
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1552 sizeof(MJpegDecodeContext),
5041
01a165280429 allows to disable jpegls decoder
aurel
parents: 5039
diff changeset
1553 ff_mjpeg_decode_init,
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1554 NULL,
5041
01a165280429 allows to disable jpegls decoder
aurel
parents: 5039
diff changeset
1555 ff_mjpeg_decode_end,
01a165280429 allows to disable jpegls decoder
aurel
parents: 5039
diff changeset
1556 ff_mjpeg_decode_frame,
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1557 CODEC_CAP_DR1,
6710
a4104482ceef Add long names to many AVCodec declarations.
diego
parents: 6655
diff changeset
1558 NULL,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6710
diff changeset
1559 .long_name = NULL_IF_CONFIG_SMALL("Nintendo Gamecube THP video"),
5020
eb0ad6423405 split mjpeg.c into an encoder and a decoder file
aurel
parents:
diff changeset
1560 };