1 /*
2 * XWD image format
3 *
4 * Copyright (c) 2012 Paul B Mahol
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <inttypes.h>
24
30
33 {
35 const uint8_t *buf = avpkt->
data;
37 uint32_t
version, header_size, vclass, ncolors;
38 uint32_t xoffset,
be, bpp, lsize, rsize;
39 uint32_t pixformat, pixdepth, bunit, bitorder, bpad;
41 uint8_t *ptr;
44
47
49 header_size = bytestream2_get_be32u(&gb);
50
51 version = bytestream2_get_be32u(&gb);
55 }
56
60 }
61
62 pixformat = bytestream2_get_be32u(&gb);
63 pixdepth = bytestream2_get_be32u(&gb);
64 width = bytestream2_get_be32u(&gb);
65 height = bytestream2_get_be32u(&gb);
66 xoffset = bytestream2_get_be32u(&gb);
67 be = bytestream2_get_be32u(&gb);
68 bunit = bytestream2_get_be32u(&gb);
69 bitorder = bytestream2_get_be32u(&gb);
70 bpad = bytestream2_get_be32u(&gb);
71 bpp = bytestream2_get_be32u(&gb);
72 lsize = bytestream2_get_be32u(&gb);
73 vclass = bytestream2_get_be32u(&gb);
74 rgb[0] = bytestream2_get_be32u(&gb);
75 rgb[1] = bytestream2_get_be32u(&gb);
76 rgb[2] = bytestream2_get_be32u(&gb);
78 ncolors = bytestream2_get_be32u(&gb);
80
83
85 "pixformat %"PRIu32", pixdepth %"PRIu32", bunit %"PRIu32", bitorder %"PRIu32", bpad %"PRIu32"\n",
86 pixformat, pixdepth, bunit, bitorder, bpad);
88 "vclass %"PRIu32", ncolors %"PRIu32", bpp %"PRIu32", be %"PRIu32", lsize %"PRIu32", xoffset %"PRIu32"\n",
89 vclass, ncolors, bpp,
be, lsize, xoffset);
91 "red %0"PRIx32", green %0"PRIx32", blue %0"PRIx32"\n",
93
97 }
98
99 if (pixdepth == 0 || pixdepth > 32) {
102 }
103
104 if (xoffset) {
107 }
108
112 }
113
114 if (bitorder > 1) {
117 }
118
119 if (bunit != 8 && bunit != 16 && bunit != 32) {
122 }
123
124 if (bpad != 8 && bpad != 16 && bpad != 32) {
127 }
128
129 if (bpp == 0 || bpp > 32) {
132 }
133
134 if (ncolors > 256) {
137 }
138
141
143 if (lsize < rsize) {
146 }
147
151 }
152
156 }
157
159 switch (vclass) {
162 if (bpp != 1 && bpp != 8)
164 if (bpp == 1 && pixdepth == 1) {
166 } else if (bpp == 8 && pixdepth == 8) {
168 }
169 break;
172 if (bpp == 8)
174 break;
177 if (bpp != 16 && bpp != 24 && bpp != 32)
179 if (bpp == 16 && pixdepth == 15) {
180 if (
rgb[0] == 0x7C00 &&
rgb[1] == 0x3E0 &&
rgb[2] == 0x1F)
182 else if (
rgb[0] == 0x1F &&
rgb[1] == 0x3E0 &&
rgb[2] == 0x7C00)
184 } else if (bpp == 16 && pixdepth == 16) {
185 if (
rgb[0] == 0xF800 &&
rgb[1] == 0x7E0 &&
rgb[2] == 0x1F)
187 else if (
rgb[0] == 0x1F &&
rgb[1] == 0x7E0 &&
rgb[2] == 0xF800)
189 } else if (bpp == 24) {
190 if (
rgb[0] == 0xFF0000 &&
rgb[1] == 0xFF00 &&
rgb[2] == 0xFF)
192 else if (
rgb[0] == 0xFF &&
rgb[1] == 0xFF00 &&
rgb[2] == 0xFF0000)
194 } else if (bpp == 32) {
195 if (
rgb[0] == 0xFF0000 &&
rgb[1] == 0xFF00 &&
rgb[2] == 0xFF)
197 else if (
rgb[0] == 0xFF &&
rgb[1] == 0xFF00 &&
rgb[2] == 0xFF0000)
199 }
201 break;
202 default:
205 }
206
209 "Unknown file: bpp %"PRIu32", pixdepth %"PRIu32", vclass %"PRIu32"",
210 bpp, pixdepth, vclass);
212 }
213
216
219
221 uint32_t *dst = (uint32_t *)p->
data[1];
222 uint8_t red, green, blue;
223
224 for (
i = 0;
i < ncolors;
i++) {
225
227 red = bytestream2_get_byteu(&gb);
229 green = bytestream2_get_byteu(&gb);
231 blue = bytestream2_get_byteu(&gb);
233
234 dst[
i] = 0xFF
U << 24 | red << 16 | green << 8 | blue;
235 }
236 }
237
243 }
244
245 *got_frame = 1;
246
247 return buf_size;
248 }
249
257 };