1 /*
2 * QuickDraw (qdrw) codec
3 * Copyright (c) 2004 Konstantin Shishkov
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 QuickDraw codec.
25 */
26
31
33 void *
data,
int *got_frame,
35 {
38 int buf_size = avpkt->
size;
41 int colors;
43 uint32_t *pal;
45
50
52
53 if (buf_end - buf < 0x68 + 4)
55 buf += 0x68; /* jump to palette */
57 buf += 4;
58
59 if (colors < 0 || colors > 256) {
62 }
63 if (buf_end - buf < (colors + 1) * 8)
65
66 pal = (uint32_t*)p->
data[1];
67 for (i = 0; i <= colors; i++) {
68 unsigned int idx;
69 idx =
AV_RB16(buf);
/* color index */
70 buf += 2;
71
72 if (idx > 255) {
74 buf += 6;
75 continue;
76 }
77 r = *buf++;
78 buf++;
79 g = *buf++;
80 buf++;
81 b = *buf++;
82 buf++;
83 pal[idx] = 0xFF
U << 24 | r << 16 | g << 8 |
b;
84 }
86
87 if (buf_end - buf < 18)
89 buf += 18; /* skip unneeded data */
90 for (i = 0; i < avctx->
height; i++) {
91 int size, left, code, pix;
94 int tsize = 0;
95
96 /* decode line */
97 out = outdata;
98 size =
AV_RB16(buf);
/* size of packed line */
99 buf += 2;
100 if (buf_end - buf < size)
102
105 while (left > 0) {
106 code = *buf++;
107 if (code & 0x80 ) { /* run */
108 pix = *buf++;
109 if ((out + (257 - code)) > (outdata + p->
linesize[0]))
110 break;
111 memset(out, pix, 257 - code);
112 out += 257 - code;
113 tsize += 257 - code;
114 left -= 2;
115 } else { /* copy */
116 if ((out + code) > (outdata + p->
linesize[0]))
117 break;
118 if (buf_end - buf < code + 1)
120 memcpy(out, buf, code + 1);
121 out += code + 1;
122 buf += code + 1;
123 left -= 2 + code;
124 tsize += code + 1;
125 }
126 }
127 buf = next;
129 }
130
131 *got_frame = 1;
132
133 return buf_size;
134 }
135
137 {
139
140 return 0;
141 }
142
151 };