1 /*
2 * PC Paintbrush PCX (.pcx) image decoder
3 * Copyright (c) 2007, 2008 Ivo van Poorten
4 *
5 * This decoder does not support CGA palettes. I am unable to find samples
6 * and Netpbm cannot generate them.
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
31
32 #define PCX_HEADER_SIZE 128
33
36 unsigned int bytes_per_scanline,
37 int compressed)
38 {
41
44
45 if (compressed) {
48 value = bytestream2_get_byte(gb);
51 value = bytestream2_get_byte(gb);
52 }
53 while (
i < bytes_per_scanline &&
run--)
55 }
56 } else {
58 }
59 return 0;
60 }
61
63 {
65
67 for (
i = 0;
i < pallen;
i++)
68 *
dst++ = 0xFF000000 | bytestream2_get_be24u(gb);
69 if (pallen < 256)
70 memset(
dst, 0, (256 - pallen) *
sizeof(*
dst));
71 }
72
75 {
77 int compressed, xmin, ymin, xmax, ymax;
79 unsigned int w,
h, bits_per_pixel, bytes_per_line, nplanes, y, x,
80 bytes_per_scanline;
81 uint8_t *ptr, *scanline;
83
87 }
88
90
91 if (bytestream2_get_byteu(&gb) != 0x0a || bytestream2_get_byteu(&gb) > 5) {
94 }
95
96 compressed = bytestream2_get_byteu(&gb);
97 bits_per_pixel = bytestream2_get_byteu(&gb);
98 xmin = bytestream2_get_le16u(&gb);
99 ymin = bytestream2_get_le16u(&gb);
100 xmax = bytestream2_get_le16u(&gb);
101 ymax = bytestream2_get_le16u(&gb);
104
105 if (xmax < xmin || ymax < ymin) {
108 }
109
112
114 nplanes = bytestream2_get_byteu(&gb);
115 bytes_per_line = bytestream2_get_le16u(&gb);
116 bytes_per_scanline = nplanes * bytes_per_line;
117
118 if (bytes_per_scanline < (
w * bits_per_pixel * nplanes + 7) / 8 ||
122 }
123
124 switch ((nplanes << 8) + bits_per_pixel) {
125 case 0x0308:
127 break;
128 case 0x0108:
129 case 0x0104:
130 case 0x0102:
131 case 0x0101:
132 case 0x0401:
133 case 0x0301:
134 case 0x0201:
136 break;
137 default:
140 }
141
143
146
149
151
154
156 if (!scanline)
158
159 if (nplanes == 3 && bits_per_pixel == 8) {
160 for (y = 0; y <
h; y++) {
163 goto end;
164
165 for (x = 0; x <
w; x++) {
166 ptr[3 * x] = scanline[x];
167 ptr[3 * x + 1] = scanline[x + bytes_per_line];
168 ptr[3 * x + 2] = scanline[x + (bytes_per_line << 1)];
169 }
170
172 }
173 } else if (nplanes == 1 && bits_per_pixel == 8) {
174 int palstart = avpkt->
size - 769;
175
176 if (avpkt->
size < 769) {
180 goto end;
181 }
182
183 for (y = 0; y <
h; y++, ptr +=
stride) {
186 goto end;
187 memcpy(ptr, scanline,
w);
188 }
189
193 }
194 if (bytestream2_get_byte(&gb) != 12) {
198 goto end;
199 }
200 } else if (nplanes == 1) { /* all packed formats, max. 16 colors */
202
203 for (y = 0; y <
h; y++) {
205
208 goto end;
209
210 for (x = 0; x <
w; x++)
213 }
214 } else { /* planar, 4, 8 or 16 colors */
216
217 for (y = 0; y <
h; y++) {
220 goto end;
221
222 for (x = 0; x <
w; x++) {
223 int m = 0x80 >> (x & 7), v = 0;
224 for (
i = nplanes - 1;
i >= 0;
i--) {
225 v <<= 1;
226 v += !!(scanline[
i * bytes_per_line + (x >> 3)] & m);
227 }
228 ptr[x] = v;
229 }
231 }
232 }
233
235 if (nplanes == 1 && bits_per_pixel == 8) {
238 } else if (bits_per_pixel * nplanes == 1) {
241 } else if (bits_per_pixel < 8) {
244 }
245
246 *got_frame = 1;
247
248 end:
251 }
252
260 };