1 /*
2 * Apple MJPEG-B decoder
3 * Copyright (c) 2002 Alex Beregszaszi
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * Apple MJPEG-B decoder.
25 */
26
27 #include <inttypes.h>
28
33
38 return 0;
39 }
40 return offs;
41 }
42
44 void *
data,
int *got_frame,
46 {
47 const uint8_t *buf = avpkt->
data;
48 int buf_size = avpkt->
size;
50 const uint8_t *buf_end, *buf_ptr;
52 uint32_t dqt_offs, dht_offs, sof_offs, sos_offs, second_field_offs;
53 uint32_t field_size, sod_offs;
55
56 buf_ptr = buf;
57 buf_end = buf + buf_size;
59 s->adobe_transform = -1;
60 s->buf_size = buf_size;
61
63 /* reset on every SOI */
64 s->restart_interval = 0;
66 s->mjpb_skiptosod = 0;
67
68 if (buf_end - buf_ptr >= 1 << 28)
70
71 init_get_bits(&hgb, buf_ptr,
/*buf_size*/(buf_end - buf_ptr)*8);
72
74
78 }
79
82 skip_bits(&hgb, 32);
/* padded field size */
83 second_field_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"second_field_offs is %d and size is %d\n");
85 second_field_offs);
86
87 dqt_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"dqt is %d and size is %d\n");
89 if (dqt_offs) {
90 init_get_bits(&
s->gb, buf_ptr+dqt_offs, (buf_end - (buf_ptr+dqt_offs))*8);
95 }
96
97 dht_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"dht is %d and size is %d\n");
99 if (dht_offs) {
100 init_get_bits(&
s->gb, buf_ptr+dht_offs, (buf_end - (buf_ptr+dht_offs))*8);
103 }
104
105 sof_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sof is %d and size is %d\n");
107 if (sof_offs) {
108 init_get_bits(&
s->gb, buf_ptr+sof_offs, (buf_end - (buf_ptr+sof_offs))*8);
109 s->start_code =
SOF0;
112 }
113
114 sos_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sos is %d and size is %d\n");
116 sod_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sof is %d and size is %d\n");
118 if (sos_offs) {
120 8 *
FFMIN(field_size, buf_end - buf_ptr - sos_offs));
121 s->mjpb_skiptosod = (sod_offs - sos_offs -
show_bits(&
s->gb, 16));
125 } else {
129 }
130 }
131
133 s->bottom_field ^= 1;
134 /* if not bottom field, do not output image yet */
135 if (
s->bottom_field !=
s->interlace_polarity && second_field_offs) {
136 buf_ptr = buf + second_field_offs;
138 }
139 }
140
141 //XXX FIXME factorize, this looks very similar to the EOI code
142
143 if(!
s->got_picture) {
145 return buf_size;
146 }
147
150 *got_frame = 1;
151
154 FFMAX3(
s->qscale[0],
s->qscale[1],
s->qscale[2]));
155 }
156
157 return buf_size;
158 }
159
170 .max_lowres = 3,
172 };