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
45 {
46 const uint8_t *buf = avpkt->
data;
47 int buf_size = avpkt->
size;
49 const uint8_t *buf_end, *buf_ptr;
51 uint32_t dqt_offs, dht_offs, sof_offs, sos_offs, second_field_offs;
52 uint32_t field_size, sod_offs;
54
55 buf_ptr = buf;
56 buf_end = buf + buf_size;
58 s->adobe_transform = -1;
59 s->buf_size = buf_size;
60
62 /* reset on every SOI */
63 s->restart_interval = 0;
65 s->mjpb_skiptosod = 0;
66
69
71
75 }
76
79 skip_bits(&hgb, 32);
/* padded field size */
80 second_field_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"second_field_offs is %d and size is %d\n");
82 second_field_offs);
83
84 dqt_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"dqt is %d and size is %d\n");
86 if (dqt_offs) {
87 init_get_bits(&
s->gb, buf_ptr+dqt_offs, (buf_end - (buf_ptr+dqt_offs))*8);
92 }
93
94 dht_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"dht is %d and size is %d\n");
96 if (dht_offs) {
97 init_get_bits(&
s->gb, buf_ptr+dht_offs, (buf_end - (buf_ptr+dht_offs))*8);
100 }
101
102 sof_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sof is %d and size is %d\n");
104 if (sof_offs) {
105 init_get_bits(&
s->gb, buf_ptr+sof_offs, (buf_end - (buf_ptr+sof_offs))*8);
106 s->start_code =
SOF0;
109 }
110
111 sos_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sos is %d and size is %d\n");
113 sod_offs =
read_offs(avctx, &hgb, buf_end - buf_ptr,
"sof is %d and size is %d\n");
115 if (sos_offs) {
117 8 *
FFMIN(field_size, buf_end - buf_ptr - sos_offs));
118 s->mjpb_skiptosod = (sod_offs - sos_offs -
show_bits(&
s->gb, 16));
122 } else {
126 }
127 }
128
130 s->bottom_field ^= 1;
131 /* if not bottom field, do not output image yet */
132 if (
s->bottom_field !=
s->interlace_polarity && second_field_offs) {
133 buf_ptr = buf + second_field_offs;
135 }
136 }
137
138 //XXX FIXME factorize, this looks very similar to the EOI code
139
140 if(!
s->got_picture) {
142 return buf_size;
143 }
147 return buf_size;
148 *got_frame = 1;
149
152 FFMAX3(
s->qscale[0],
s->qscale[1],
s->qscale[2]));
153 }
154
155 return buf_size;
156 }
157
168 .p.max_lowres = 3,
170 };
171
173 .
p.
name =
"media100",
182 .p.max_lowres = 3,
184 .bsfs = "media100_to_mjpegb",
185 };