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
28
31 {
34 int i,
ret, buf_size = avpkt->
size;
35 uint32_t
version, header_size, vclass, ncolors;
36 uint32_t xoffset, be, bpp, lsize, rsize;
37 uint32_t pixformat, pixdepth, bunit, bitorder, bpad;
38 uint32_t rgb[3];
41
44
46 header_size = bytestream2_get_be32u(&gb);
47
48 version = bytestream2_get_be32u(&gb);
52 }
53
57 }
58
59 pixformat = bytestream2_get_be32u(&gb);
60 pixdepth = bytestream2_get_be32u(&gb);
61 avctx->
width = bytestream2_get_be32u(&gb);
62 avctx->
height = bytestream2_get_be32u(&gb);
63 xoffset = bytestream2_get_be32u(&gb);
64 be = bytestream2_get_be32u(&gb);
65 bunit = bytestream2_get_be32u(&gb);
66 bitorder = bytestream2_get_be32u(&gb);
67 bpad = bytestream2_get_be32u(&gb);
68 bpp = bytestream2_get_be32u(&gb);
69 lsize = bytestream2_get_be32u(&gb);
70 vclass = bytestream2_get_be32u(&gb);
71 rgb[0] = bytestream2_get_be32u(&gb);
72 rgb[1] = bytestream2_get_be32u(&gb);
73 rgb[2] = bytestream2_get_be32u(&gb);
75 ncolors = bytestream2_get_be32u(&gb);
77
78 av_log(avctx,
AV_LOG_DEBUG,
"pixformat %d, pixdepth %d, bunit %d, bitorder %d, bpad %d\n",
79 pixformat, pixdepth, bunit, bitorder, bpad);
80 av_log(avctx,
AV_LOG_DEBUG,
"vclass %d, ncolors %d, bpp %d, be %d, lsize %d, xoffset %d\n",
81 vclass, ncolors, bpp, be, lsize, xoffset);
83
87 }
88
89 if (pixdepth == 0 || pixdepth > 32) {
92 }
93
94 if (xoffset) {
97 }
98
99 if (be > 1) {
102 }
103
104 if (bitorder > 1) {
107 }
108
109 if (bunit != 8 && bunit != 16 && bunit != 32) {
112 }
113
114 if (bpad != 8 && bpad != 16 && bpad != 32) {
117 }
118
119 if (bpp == 0 || bpp > 32) {
122 }
123
124 if (ncolors > 256) {
127 }
128
131
133 if (lsize < rsize) {
136 }
137
141 }
142
146 }
147
149 switch (vclass) {
152 if (bpp != 1 && bpp != 8)
154 if (pixdepth == 1) {
156 } else if (pixdepth == 8) {
158 }
159 break;
162 if (bpp == 8)
164 break;
167 if (bpp != 16 && bpp != 24 && bpp != 32)
169 if (bpp == 16 && pixdepth == 15) {
170 if (rgb[0] == 0x7C00 && rgb[1] == 0x3E0 && rgb[2] == 0x1F)
172 else if (rgb[0] == 0x1F && rgb[1] == 0x3E0 && rgb[2] == 0x7C00)
174 } else if (bpp == 16 && pixdepth == 16) {
175 if (rgb[0] == 0xF800 && rgb[1] == 0x7E0 && rgb[2] == 0x1F)
177 else if (rgb[0] == 0x1F && rgb[1] == 0x7E0 && rgb[2] == 0xF800)
179 } else if (bpp == 24) {
180 if (rgb[0] == 0xFF0000 && rgb[1] == 0xFF00 && rgb[2] == 0xFF)
182 else if (rgb[0] == 0xFF && rgb[1] == 0xFF00 && rgb[2] == 0xFF0000)
184 } else if (bpp == 32) {
185 if (rgb[0] == 0xFF0000 && rgb[1] == 0xFF00 && rgb[2] == 0xFF)
187 else if (rgb[0] == 0xFF && rgb[1] == 0xFF00 && rgb[2] == 0xFF0000)
189 }
191 break;
192 default:
195 }
196
199 "Unknown file: bpp %d, pixdepth %d, vclass %d",
200 bpp, pixdepth, vclass);
202 }
203
206
209
211 uint32_t *dst = (uint32_t *)p->
data[1];
213
214 for (i = 0; i < ncolors; i++) {
215
217 red = bytestream2_get_byteu(&gb);
219 green = bytestream2_get_byteu(&gb);
221 blue = bytestream2_get_byteu(&gb);
223
224 dst[i] = red << 16 | green << 8 | blue;
225 }
226 }
227
229 for (i = 0; i < avctx->
height; i++) {
233 }
234
235 *got_frame = 1;
236
237 return buf_size;
238 }
239
247 };