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
31
34 {
35 uint32_t
version, header_size, vclass, ncolors;
36 uint32_t xoffset,
be, bpp, lsize, rsize;
37 uint32_t pixformat, pixdepth, bunit, bitorder, bpad;
39 uint8_t *ptr;
43
46
48 header_size = bytestream2_get_be32u(&gb);
49
50 version = bytestream2_get_be32u(&gb);
54 }
55
59 }
60
61 pixformat = bytestream2_get_be32u(&gb);
62 pixdepth = bytestream2_get_be32u(&gb);
63 width = bytestream2_get_be32u(&gb);
64 height = bytestream2_get_be32u(&gb);
65 xoffset = bytestream2_get_be32u(&gb);
66 be = bytestream2_get_be32u(&gb);
67 bunit = bytestream2_get_be32u(&gb);
68 bitorder = bytestream2_get_be32u(&gb);
69 bpad = bytestream2_get_be32u(&gb);
70 bpp = bytestream2_get_be32u(&gb);
71 lsize = bytestream2_get_be32u(&gb);
72 vclass = bytestream2_get_be32u(&gb);
73 rgb[0] = bytestream2_get_be32u(&gb);
74 rgb[1] = bytestream2_get_be32u(&gb);
75 rgb[2] = bytestream2_get_be32u(&gb);
77 ncolors = bytestream2_get_be32u(&gb);
79
82
84 "pixformat %"PRIu32", pixdepth %"PRIu32", bunit %"PRIu32", bitorder %"PRIu32", bpad %"PRIu32"\n",
85 pixformat, pixdepth, bunit, bitorder, bpad);
87 "vclass %"PRIu32", ncolors %"PRIu32", bpp %"PRIu32", be %"PRIu32", lsize %"PRIu32", xoffset %"PRIu32"\n",
88 vclass, ncolors, bpp,
be, lsize, xoffset);
90 "red %0"PRIx32", green %0"PRIx32", blue %0"PRIx32"\n",
92
96 }
97
98 if (pixdepth == 0 || pixdepth > 32) {
101 }
102
103 if (xoffset) {
106 }
107
111 }
112
113 if (bitorder > 1) {
116 }
117
118 if (bunit != 8 && bunit != 16 && bunit != 32) {
121 }
122
123 if (bpad != 8 && bpad != 16 && bpad != 32) {
126 }
127
128 if (bpp == 0 || bpp > 32) {
131 }
132
133 if (ncolors > 256) {
136 }
137
140
142 if (lsize < rsize) {
145 }
146
150 }
151
155 }
156
158 switch (vclass) {
161 if (bpp != 1 && bpp != 8)
163 if (bpp == 1 && pixdepth == 1) {
165 } else if (bpp == 8 && pixdepth == 8) {
167 }
168 break;
171 if (bpp == 8)
173 break;
176 if (bpp != 16 && bpp != 24 && bpp != 32)
178 if (bpp == 16 && pixdepth == 15) {
179 if (
rgb[0] == 0x7C00 &&
rgb[1] == 0x3E0 &&
rgb[2] == 0x1F)
181 else if (
rgb[0] == 0x1F &&
rgb[1] == 0x3E0 &&
rgb[2] == 0x7C00)
183 } else if (bpp == 16 && pixdepth == 16) {
184 if (
rgb[0] == 0xF800 &&
rgb[1] == 0x7E0 &&
rgb[2] == 0x1F)
186 else if (
rgb[0] == 0x1F &&
rgb[1] == 0x7E0 &&
rgb[2] == 0xF800)
188 } else if (bpp == 24) {
189 if (
rgb[0] == 0xFF0000 &&
rgb[1] == 0xFF00 &&
rgb[2] == 0xFF)
191 else if (
rgb[0] == 0xFF &&
rgb[1] == 0xFF00 &&
rgb[2] == 0xFF0000)
193 } else if (bpp == 32) {
194 if (
rgb[0] == 0xFF0000 &&
rgb[1] == 0xFF00 &&
rgb[2] == 0xFF)
196 else if (
rgb[0] == 0xFF &&
rgb[1] == 0xFF00 &&
rgb[2] == 0xFF0000)
198 }
200 break;
201 default:
204 }
205
208 "Unknown file: bpp %"PRIu32", pixdepth %"PRIu32", vclass %"PRIu32"",
209 bpp, pixdepth, vclass);
211 }
212
215
218
220 uint32_t *
dst = (uint32_t *)p->
data[1];
221 uint8_t red, green, blue;
222
223 for (
int i = 0;
i < ncolors;
i++) {
225 red = bytestream2_get_byteu(&gb);
227 green = bytestream2_get_byteu(&gb);
229 blue = bytestream2_get_byteu(&gb);
231
232 dst[
i] = 0xFF
U << 24 | red << 16 | green << 8 | blue;
233 }
234 }
235
237 for (
int i = 0;
i < avctx->
height;
i++) {
241 }
242
243 *got_frame = 1;
244
246 }
247
256 };