History

XWD encoder and decoder

Paul B Mahol committed 14 years ago

Commit 27ed0271 parent 7662a5310 files · +564 −2Browse files

Unified · Split

10 files
  1. Changelog +1 −0
  2. doc/general.texi +2 −0
  3. libavcodec/Makefile +2 −0
  4. libavcodec/allcodecs.c +1 −0
  5. libavcodec/avcodec.h +1 −0
  6. libavcodec/version.h +1 −1
  7. libavcodec/xwd.h +41 −0
  8. libavcodec/xwddec.c +267 −0
  9. libavcodec/xwdenc.c +246 −0
  10. libavformat/img2.c +2 −1
Changelog+1−0
@@ -6,6 +6,7 @@ version 0.8: · 5 unmodified lines
6 6
7- GSM audio parser7- GSM audio parser
8- SMJPEG muxer8- SMJPEG muxer
9- XWD encoder and decoder
9 10
10 11
11version 0.8_beta2:12version 0.8_beta2:
doc/general.texi+2−0
@@ -379,6 +379,8 @@ following image formats are supported: · 378 unmodified lines
379 @tab YUV, JPEG and some extension is not supported yet.379 @tab YUV, JPEG and some extension is not supported yet.
380@item Truevision Targa @tab X @tab X380@item Truevision Targa @tab X @tab X
381 @tab Targa (.TGA) image format381 @tab Targa (.TGA) image format
382@item XWD @tab X @tab X
383 @tab X Window Dump image format
382@end multitable384@end multitable
383 385
384@code{X} means that encoding (resp. decoding) is supported.386@code{X} means that encoding (resp. decoding) is supported.
libavcodec/Makefile+2−0
@@ -435,6 +435,8 @@ OBJS-$(CONFIG_XAN_WC4_DECODER) += xxan.o · 434 unmodified lines
435OBJS-$(CONFIG_XL_DECODER) += xl.o435OBJS-$(CONFIG_XL_DECODER) += xl.o
436OBJS-$(CONFIG_XSUB_DECODER) += xsubdec.o436OBJS-$(CONFIG_XSUB_DECODER) += xsubdec.o
437OBJS-$(CONFIG_XSUB_ENCODER) += xsubenc.o437OBJS-$(CONFIG_XSUB_ENCODER) += xsubenc.o
438OBJS-$(CONFIG_XWD_DECODER) += xwddec.o
439OBJS-$(CONFIG_XWD_ENCODER) += xwdenc.o
438OBJS-$(CONFIG_YOP_DECODER) += yop.o440OBJS-$(CONFIG_YOP_DECODER) += yop.o
439OBJS-$(CONFIG_ZLIB_DECODER) += lcldec.o441OBJS-$(CONFIG_ZLIB_DECODER) += lcldec.o
440OBJS-$(CONFIG_ZLIB_ENCODER) += lclenc.o442OBJS-$(CONFIG_ZLIB_ENCODER) += lclenc.o
libavcodec/allcodecs.c+1−0
@@ -230,6 +230,7 @@ void avcodec_register_all(void) · 229 unmodified lines
230 REGISTER_DECODER (XAN_WC3, xan_wc3);230 REGISTER_DECODER (XAN_WC3, xan_wc3);
231 REGISTER_DECODER (XAN_WC4, xan_wc4);231 REGISTER_DECODER (XAN_WC4, xan_wc4);
232 REGISTER_DECODER (XL, xl);232 REGISTER_DECODER (XL, xl);
233 REGISTER_ENCDEC (XWD, xwd);
233 REGISTER_DECODER (YOP, yop);234 REGISTER_DECODER (YOP, yop);
234 REGISTER_ENCDEC (ZLIB, zlib);235 REGISTER_ENCDEC (ZLIB, zlib);
235 REGISTER_ENCDEC (ZMBV, zmbv);236 REGISTER_ENCDEC (ZMBV, zmbv);
libavcodec/avcodec.h+1−0
@@ -254,6 +254,7 @@ enum CodecID { · 253 unmodified lines
254 CODEC_ID_VBLE,254 CODEC_ID_VBLE,
255 CODEC_ID_DXTORY,255 CODEC_ID_DXTORY,
256 CODEC_ID_V410,256 CODEC_ID_V410,
257 CODEC_ID_XWD,
257 258
258 /* various PCM "codecs" */259 /* various PCM "codecs" */
259 CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs260 CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs
libavcodec/version.h+1−1
@@ -21,7 +21,7 @@ · 20 unmodified lines
21#define AVCODEC_VERSION_H21#define AVCODEC_VERSION_H
22 22
23#define LIBAVCODEC_VERSION_MAJOR 5323#define LIBAVCODEC_VERSION_MAJOR 53
24#define LIBAVCODEC_VERSION_MINOR 3424#define LIBAVCODEC_VERSION_MINOR 35
25#define LIBAVCODEC_VERSION_MICRO 025#define LIBAVCODEC_VERSION_MICRO 0
26 26
27#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \27#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
libavcodec/xwd.h+41−0
@@ -0,0 +1,41 @@
1/*
2 * XWD image format
3 *
4 * Copyright (c) 2012 Paul B Mahol
5 *
6 * This file is part of Libav.
7 *
8 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#ifndef AVCODEC_XWD_H
24#define AVCODEC_XWD_H
25
26#define XWD_VERSION 7
27#define XWD_HEADER_SIZE 100
28#define XWD_CMAP_SIZE 12
29
30#define XWD_XY_BITMAP 0
31#define XWD_XY_PIXMAP 1
32#define XWD_Z_PIXMAP 2
33
34#define XWD_STATIC_GRAY 0
35#define XWD_GRAY_SCALE 1
36#define XWD_STATIC_COLOR 2
37#define XWD_PSEUDO_COLOR 3
38#define XWD_TRUE_COLOR 4
39#define XWD_DIRECT_COLOR 5
40
41#endif /* AVCODEC_XWD_H */
libavcodec/xwddec.c+267−0
@@ -0,0 +1,267 @@
1/*
2 * XWD image format
3 *
4 * Copyright (c) 2012 Paul B Mahol
5 *
6 * This file is part of Libav.
7 *
8 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include "libavutil/imgutils.h"
24#include "avcodec.h"
25#include "bytestream.h"
26#include "xwd.h"
27
28static av_cold int xwd_decode_init(AVCodecContext *avctx)
29{
30 avctx->coded_frame = avcodec_alloc_frame();
31 if (!avctx->coded_frame)
32 return AVERROR(ENOMEM);
33
34 return 0;
35}
36
37static int xwd_decode_frame(AVCodecContext *avctx, void *data,
38 int *data_size, AVPacket *avpkt)
39{
40 AVFrame *p = avctx->coded_frame;
41 const uint8_t *buf = avpkt->data;
42 int i, ret, buf_size = avpkt->size;
43 uint32_t version, header_size, vclass, ncolors;
44 uint32_t xoffset, be, bpp, lsize, rsize;
45 uint32_t pixformat, pixdepth, bunit, bitorder, bpad;
46 uint32_t rgb[3];
47 uint8_t *ptr;
48
49 if (buf_size < XWD_HEADER_SIZE)
50 return AVERROR_INVALIDDATA;
51
52 header_size = bytestream_get_be32(&buf);
53 if (buf_size < header_size)
54 return AVERROR_INVALIDDATA;
55
56 version = bytestream_get_be32(&buf);
57 if (version != XWD_VERSION) {
58 av_log(avctx, AV_LOG_ERROR, "unsupported version\n");
59 return AVERROR_INVALIDDATA;
60 }
61
62 if (header_size < XWD_HEADER_SIZE) {
63 av_log(avctx, AV_LOG_ERROR, "invalid header size\n");
64 return AVERROR_INVALIDDATA;
65 }
66
67 pixformat = bytestream_get_be32(&buf);
68 pixdepth = bytestream_get_be32(&buf);
69 avctx->width = bytestream_get_be32(&buf);
70 avctx->height = bytestream_get_be32(&buf);
71 xoffset = bytestream_get_be32(&buf);
72 be = bytestream_get_be32(&buf);
73 bunit = bytestream_get_be32(&buf);
74 bitorder = bytestream_get_be32(&buf);
75 bpad = bytestream_get_be32(&buf);
76 bpp = bytestream_get_be32(&buf);
77 lsize = bytestream_get_be32(&buf);
78 vclass = bytestream_get_be32(&buf);
79 rgb[0] = bytestream_get_be32(&buf);
80 rgb[1] = bytestream_get_be32(&buf);
81 rgb[2] = bytestream_get_be32(&buf);
82 buf += 8;
83 ncolors = bytestream_get_be32(&buf);
84 buf += header_size - (XWD_HEADER_SIZE - 20);
85
86 av_log(avctx, AV_LOG_DEBUG, "pixformat %d, pixdepth %d, bunit %d, bitorder %d, bpad %d\n",
87 pixformat, pixdepth, bunit, bitorder, bpad);
88 av_log(avctx, AV_LOG_DEBUG, "vclass %d, ncolors %d, bpp %d, be %d, lsize %d, xoffset %d\n",
89 vclass, ncolors, bpp, be, lsize, xoffset);
90 av_log(avctx, AV_LOG_DEBUG, "red %0x, green %0x, blue %0x\n", rgb[0], rgb[1], rgb[2]);
91
92 if (pixformat > XWD_Z_PIXMAP) {
93 av_log(avctx, AV_LOG_ERROR, "invalid pixmap format\n");
94 return AVERROR_INVALIDDATA;
95 }
96
97 if (pixdepth == 0 || pixdepth > 32) {
98 av_log(avctx, AV_LOG_ERROR, "invalid pixmap depth\n");
99 return AVERROR_INVALIDDATA;
100 }
101
102 if (xoffset) {
103 av_log_ask_for_sample(avctx, "unsupported xoffset %d\n", xoffset);
104 return AVERROR_PATCHWELCOME;
105 }
106
107 if (be > 1) {
108 av_log(avctx, AV_LOG_ERROR, "invalid byte order\n");
109 return AVERROR_INVALIDDATA;
110 }
111
112 if (bitorder > 1) {
113 av_log(avctx, AV_LOG_ERROR, "invalid bitmap bit order\n");
114 return AVERROR_INVALIDDATA;
115 }
116
117 if (bunit != 8 && bunit != 16 && bunit != 32) {
118 av_log(avctx, AV_LOG_ERROR, "invalid bitmap unit\n");
119 return AVERROR_INVALIDDATA;
120 }
121
122 if (bpad != 8 && bpad != 16 && bpad != 32) {
123 av_log(avctx, AV_LOG_ERROR, "invalid bitmap scan-line pad\n");
124 return AVERROR_INVALIDDATA;
125 }
126
127 if (bpp == 0 || bpp > 32) {
128 av_log(avctx, AV_LOG_ERROR, "invalid bits per pixel\n");
129 return AVERROR_INVALIDDATA;
130 }
131
132 if (ncolors > 256) {
133 av_log(avctx, AV_LOG_ERROR, "invalid number of entries in colormap\n");
134 return AVERROR_INVALIDDATA;
135 }
136
137 if ((ret = av_image_check_size(avctx->width, avctx->height, 0, NULL)) < 0)
138 return ret;
139
140 rsize = FFALIGN(avctx->width * bpp, bpad) / 8;
141 if (lsize < rsize) {
142 av_log(avctx, AV_LOG_ERROR, "invalid bytes per scan-line\n");
143 return AVERROR_INVALIDDATA;
144 }
145
146 if (buf_size < header_size + ncolors * XWD_CMAP_SIZE + avctx->height * lsize) {
147 av_log(avctx, AV_LOG_ERROR, "input buffer too small\n");
148 return AVERROR_INVALIDDATA;
149 }
150
151 if (pixformat != XWD_Z_PIXMAP) {
152 av_log(avctx, AV_LOG_ERROR, "pixmap format %d unsupported\n", pixformat);
153 return AVERROR_PATCHWELCOME;
154 }
155
156 avctx->pix_fmt = PIX_FMT_NONE;
157 switch (vclass) {
158 case XWD_STATIC_GRAY:
159 case XWD_GRAY_SCALE:
160 if (bpp != 1)
161 return AVERROR_INVALIDDATA;
162 if (pixdepth == 1)
163 avctx->pix_fmt = PIX_FMT_MONOWHITE;
164 break;
165 case XWD_STATIC_COLOR:
166 case XWD_PSEUDO_COLOR:
167 if (bpp == 8)
168 avctx->pix_fmt = PIX_FMT_PAL8;
169 break;
170 case XWD_TRUE_COLOR:
171 case XWD_DIRECT_COLOR:
172 if (bpp != 16 && bpp != 24 && bpp != 32)
173 return AVERROR_INVALIDDATA;
174 if (bpp == 16 && pixdepth == 15) {
175 if (rgb[0] == 0x7C00 && rgb[1] == 0x3E0 && rgb[2] == 0x1F)
176 avctx->pix_fmt = be ? PIX_FMT_RGB555BE : PIX_FMT_RGB555LE;
177 else if (rgb[0] == 0x1F && rgb[1] == 0x3E0 && rgb[2] == 0x7C00)
178 avctx->pix_fmt = be ? PIX_FMT_BGR555BE : PIX_FMT_BGR555LE;
179 } else if (bpp == 16 && pixdepth == 16) {
180 if (rgb[0] == 0xF800 && rgb[1] == 0x7E0 && rgb[2] == 0x1F)
181 avctx->pix_fmt = be ? PIX_FMT_RGB565BE : PIX_FMT_RGB565LE;
182 else if (rgb[0] == 0x1F && rgb[1] == 0x7E0 && rgb[2] == 0xF800)
183 avctx->pix_fmt = be ? PIX_FMT_BGR565BE : PIX_FMT_BGR565LE;
184 } else if (bpp == 24) {
185 if (rgb[0] == 0xFF0000 && rgb[1] == 0xFF00 && rgb[2] == 0xFF)
186 avctx->pix_fmt = be ? PIX_FMT_RGB24 : PIX_FMT_BGR24;
187 else if (rgb[0] == 0xFF && rgb[1] == 0xFF00 && rgb[2] == 0xFF0000)
188 avctx->pix_fmt = be ? PIX_FMT_BGR24 : PIX_FMT_RGB24;
189 } else if (bpp == 32) {
190 if (rgb[0] == 0xFF0000 && rgb[1] == 0xFF00 && rgb[2] == 0xFF)
191 avctx->pix_fmt = be ? PIX_FMT_ARGB : PIX_FMT_BGRA;
192 else if (rgb[0] == 0xFF && rgb[1] == 0xFF00 && rgb[2] == 0xFF0000)
193 avctx->pix_fmt = be ? PIX_FMT_ABGR : PIX_FMT_RGBA;
194 }
195 buf += ncolors * XWD_CMAP_SIZE;
196 break;
197 default:
198 av_log(avctx, AV_LOG_ERROR, "invalid visual class\n");
199 return AVERROR_INVALIDDATA;
200 }
201
202 if (avctx->pix_fmt == PIX_FMT_NONE) {
203 av_log_ask_for_sample(avctx, "unknown file: bpp %d, pixdepth %d, vclass %d\n", bpp, pixdepth, vclass);
204 return AVERROR_PATCHWELCOME;
205 }
206
207 if (p->data[0])
208 avctx->release_buffer(avctx, p);
209
210 p->reference = 0;
211 if ((ret = avctx->get_buffer(avctx, p)) < 0) {
212 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
213 return ret;
214 }
215
216 p->key_frame = 1;
217 p->pict_type = AV_PICTURE_TYPE_I;
218
219 if (avctx->pix_fmt == PIX_FMT_PAL8) {
220 uint32_t *dst = (uint32_t *)p->data[1];
221 uint8_t red, green, blue;
222
223 for (i = 0; i < ncolors; i++) {
224
225 buf += 4; // skip colormap entry number
226 red = *buf; buf += 2;
227 green = *buf; buf += 2;
228 blue = *buf; buf += 2;
229 buf += 2; // skip bitmask flag and padding
230
231 dst[i] = red << 16 | green << 8 | blue;
232 }
233 }
234
235 ptr = p->data[0];
236 for (i = 0; i < avctx->height; i++) {
237 bytestream_get_buffer(&buf, ptr, rsize);
238 buf += lsize - rsize;
239 ptr += p->linesize[0];
240 }
241
242 *data_size = sizeof(AVFrame);
243 *(AVFrame *)data = *p;
244
245 return buf_size;
246}
247
248static av_cold int xwd_decode_close(AVCodecContext *avctx)
249{
250 if (avctx->coded_frame->data[0])
251 avctx->release_buffer(avctx, avctx->coded_frame);
252
253 av_freep(&avctx->coded_frame);
254
255 return 0;
256}
257
258AVCodec ff_xwd_decoder = {
259 .name = "xwd",
260 .type = AVMEDIA_TYPE_VIDEO,
261 .id = CODEC_ID_XWD,
262 .init = xwd_decode_init,
263 .close = xwd_decode_close,
264 .decode = xwd_decode_frame,
265 .capabilities = CODEC_CAP_DR1,
266 .long_name = NULL_IF_CONFIG_SMALL("XWD (X Window Dump) image"),
267};
libavcodec/xwdenc.c+246−0
@@ -0,0 +1,246 @@
1/*
2 * XWD image format
3 *
4 * Copyright (c) 2012 Paul B Mahol
5 *
6 * This file is part of Libav.
7 *
8 * Libav 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 * Libav 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 Libav; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include "libavutil/intreadwrite.h"
24#include "libavutil/pixdesc.h"
25#include "avcodec.h"
26#include "bytestream.h"
27#include "xwd.h"
28
29#define WINDOW_NAME "lavcxwdenc"
30#define WINDOW_NAME_SIZE 11
31
32static av_cold int xwd_encode_init(AVCodecContext *avctx)
33{
34 avctx->coded_frame = avcodec_alloc_frame();
35 if (!avctx->coded_frame)
36 return AVERROR(ENOMEM);
37
38 return 0;
39}
40
41static int xwd_encode_frame(AVCodecContext *avctx, uint8_t *buf,
42 int buf_size, void *data)
43{
44 AVFrame *p = data;
45 enum PixelFormat pix_fmt = avctx->pix_fmt;
46 uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0;
47 uint32_t rgb[3] = { 0 };
48 uint32_t header_size;
49 int i, out_size;
50 uint8_t *ptr;
51
52 pixdepth = av_get_bits_per_pixel(&av_pix_fmt_descriptors[pix_fmt]);
53 if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_BE)
54 be = 1;
55 switch (pix_fmt) {
56 case PIX_FMT_ARGB:
57 case PIX_FMT_BGRA:
58 case PIX_FMT_RGBA:
59 case PIX_FMT_ABGR:
60 if (pix_fmt == PIX_FMT_ARGB ||
61 pix_fmt == PIX_FMT_ABGR)
62 be = 1;
63 if (pix_fmt == PIX_FMT_ABGR ||
64 pix_fmt == PIX_FMT_RGBA) {
65 rgb[0] = 0xFF;
66 rgb[1] = 0xFF00;
67 rgb[2] = 0xFF0000;
68 } else {
69 rgb[0] = 0xFF0000;
70 rgb[1] = 0xFF00;
71 rgb[2] = 0xFF;
72 }
73 bpp = 32;
74 pixdepth = 24;
75 vclass = XWD_TRUE_COLOR;
76 bpad = 32;
77 break;
78 case PIX_FMT_BGR24:
79 case PIX_FMT_RGB24:
80 if (pix_fmt == PIX_FMT_RGB24)
81 be = 1;
82 bpp = 24;
83 vclass = XWD_TRUE_COLOR;
84 bpad = 32;
85 rgb[0] = 0xFF0000;
86 rgb[1] = 0xFF00;
87 rgb[2] = 0xFF;
88 break;
89 case PIX_FMT_RGB565LE:
90 case PIX_FMT_RGB565BE:
91 case PIX_FMT_BGR565LE:
92 case PIX_FMT_BGR565BE:
93 if (pix_fmt == PIX_FMT_BGR565LE ||
94 pix_fmt == PIX_FMT_BGR565BE) {
95 rgb[0] = 0x1F;
96 rgb[1] = 0x7E0;
97 rgb[2] = 0xF800;
98 } else {
99 rgb[0] = 0xF800;
100 rgb[1] = 0x7E0;
101 rgb[2] = 0x1F;
102 }
103 bpp = 16;
104 vclass = XWD_TRUE_COLOR;
105 bpad = 16;
106 break;
107 case PIX_FMT_RGB555LE:
108 case PIX_FMT_RGB555BE:
109 case PIX_FMT_BGR555LE:
110 case PIX_FMT_BGR555BE:
111 if (pix_fmt == PIX_FMT_BGR555LE ||
112 pix_fmt == PIX_FMT_BGR555BE) {
113 rgb[0] = 0x1F;
114 rgb[1] = 0x3E0;
115 rgb[2] = 0x7C00;
116 } else {
117 rgb[0] = 0x7C00;
118 rgb[1] = 0x3E0;
119 rgb[2] = 0x1F;
120 }
121 bpp = 16;
122 vclass = XWD_TRUE_COLOR;
123 bpad = 16;
124 break;
125 case PIX_FMT_RGB8:
126 case PIX_FMT_BGR8:
127 case PIX_FMT_RGB4_BYTE:
128 case PIX_FMT_BGR4_BYTE:
129 case PIX_FMT_PAL8:
130 bpp = 8;
131 vclass = XWD_PSEUDO_COLOR;
132 bpad = 8;
133 ncolors = 256;
134 break;
135 case PIX_FMT_MONOWHITE:
136 bpp = 1;
137 bpad = 8;
138 vclass = XWD_STATIC_GRAY;
139 break;
140 default:
141 av_log(avctx, AV_LOG_INFO, "unsupported pixel format\n");
142 return AVERROR(EINVAL);
143 }
144
145 lsize = FFALIGN(bpp * avctx->width, bpad) / 8;
146 header_size = XWD_HEADER_SIZE + WINDOW_NAME_SIZE;
147 out_size = header_size + ncolors * XWD_CMAP_SIZE + avctx->height * lsize;
148
149 if (buf_size < out_size) {
150 av_log(avctx, AV_LOG_ERROR, "output buffer too small\n");
151 return AVERROR(ENOMEM);
152 }
153
154 avctx->coded_frame->key_frame = 1;
155 avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I;
156
157 bytestream_put_be32(&buf, header_size);
158 bytestream_put_be32(&buf, XWD_VERSION); // file version
159 bytestream_put_be32(&buf, XWD_Z_PIXMAP); // pixmap format
160 bytestream_put_be32(&buf, pixdepth); // pixmap depth in pixels
161 bytestream_put_be32(&buf, avctx->width); // pixmap width in pixels
162 bytestream_put_be32(&buf, avctx->height); // pixmap height in pixels
163 bytestream_put_be32(&buf, 0); // bitmap x offset
164 bytestream_put_be32(&buf, be); // byte order
165 bytestream_put_be32(&buf, 32); // bitmap unit
166 bytestream_put_be32(&buf, be); // bit-order of image data
167 bytestream_put_be32(&buf, bpad); // bitmap scan-line pad in bits
168 bytestream_put_be32(&buf, bpp); // bits per pixel
169 bytestream_put_be32(&buf, lsize); // bytes per scan-line
170 bytestream_put_be32(&buf, vclass); // visual class
171 bytestream_put_be32(&buf, rgb[0]); // red mask
172 bytestream_put_be32(&buf, rgb[1]); // green mask
173 bytestream_put_be32(&buf, rgb[2]); // blue mask
174 bytestream_put_be32(&buf, 8); // size of each bitmask in bits
175 bytestream_put_be32(&buf, ncolors); // number of colors
176 bytestream_put_be32(&buf, ncolors); // number of entries in color map
177 bytestream_put_be32(&buf, avctx->width); // window width
178 bytestream_put_be32(&buf, avctx->height); // window height
179 bytestream_put_be32(&buf, 0); // window upper left X coordinate
180 bytestream_put_be32(&buf, 0); // window upper left Y coordinate
181 bytestream_put_be32(&buf, 0); // window border width
182 bytestream_put_buffer(&buf, WINDOW_NAME, WINDOW_NAME_SIZE);
183
184 for (i = 0; i < ncolors; i++) {
185 uint32_t val;
186 uint8_t red, green, blue;
187
188 val = AV_RN32A(p->data[1] + i * 4);
189 red = (val >> 16) & 0xFF;
190 green = (val >> 8) & 0xFF;
191 blue = val & 0xFF;
192
193 bytestream_put_be32(&buf, i); // colormap entry number
194 bytestream_put_be16(&buf, red << 8);
195 bytestream_put_be16(&buf, green << 8);
196 bytestream_put_be16(&buf, blue << 8);
197 bytestream_put_byte(&buf, 0x7); // bitmask flag
198 bytestream_put_byte(&buf, 0); // padding
199 }
200
201 ptr = p->data[0];
202 for (i = 0; i < avctx->height; i++) {
203 bytestream_put_buffer(&buf, ptr, lsize);
204 ptr += p->linesize[0];
205 }
206
207 return out_size;
208}
209
210static av_cold int xwd_encode_close(AVCodecContext *avctx)
211{
212 av_freep(&avctx->coded_frame);
213
214 return 0;
215}
216
217AVCodec ff_xwd_encoder = {
218 .name = "xwd",
219 .type = AVMEDIA_TYPE_VIDEO,
220 .id = CODEC_ID_XWD,
221 .init = xwd_encode_init,
222 .encode = xwd_encode_frame,
223 .close = xwd_encode_close,
224 .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_BGRA,
225 PIX_FMT_RGBA,
226 PIX_FMT_ARGB,
227 PIX_FMT_ABGR,
228 PIX_FMT_RGB24,
229 PIX_FMT_BGR24,
230 PIX_FMT_RGB565BE,
231 PIX_FMT_RGB565LE,
232 PIX_FMT_BGR565BE,
233 PIX_FMT_BGR565LE,
234 PIX_FMT_RGB555BE,
235 PIX_FMT_RGB555LE,
236 PIX_FMT_BGR555BE,
237 PIX_FMT_BGR555LE,
238 PIX_FMT_RGB8,
239 PIX_FMT_BGR8,
240 PIX_FMT_RGB4_BYTE,
241 PIX_FMT_BGR4_BYTE,
242 PIX_FMT_PAL8,
243 PIX_FMT_MONOWHITE,
244 PIX_FMT_NONE },
245 .long_name = NULL_IF_CONFIG_SMALL("XWD (X Window Dump) image"),
246};
libavformat/img2.c+2−1
@@ -85,6 +85,7 @@ static const IdStrMap img_tags[] = { · 84 unmodified lines
85 { CODEC_ID_JPEG2000 , "jpc"},85 { CODEC_ID_JPEG2000 , "jpc"},
86 { CODEC_ID_DPX , "dpx"},86 { CODEC_ID_DPX , "dpx"},
87 { CODEC_ID_PICTOR , "pic"},87 { CODEC_ID_PICTOR , "pic"},
88 { CODEC_ID_XWD , "xwd"},
88 { CODEC_ID_NONE , NULL}89 { CODEC_ID_NONE , NULL}
89};90};
90 91
@@ -501,7 +502,7 @@ AVOutputFormat ff_image2_muxer = { · 410 unmodified lines
501 .name = "image2",502 .name = "image2",
502 .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"),503 .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"),
503 .extensions = "bmp,dpx,jpeg,jpg,ljpg,pam,pbm,pcx,pgm,pgmyuv,png,"504 .extensions = "bmp,dpx,jpeg,jpg,ljpg,pam,pbm,pcx,pgm,pgmyuv,png,"
504 "ppm,sgi,tga,tif,tiff,jp2",505 "ppm,sgi,tga,tif,tiff,jp2,xwd",
505 .priv_data_size = sizeof(VideoData),506 .priv_data_size = sizeof(VideoData),
506 .video_codec = CODEC_ID_MJPEG,507 .video_codec = CODEC_ID_MJPEG,
507 .write_header = write_header,508 .write_header = write_header,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t