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
29
30 #define WINDOW_NAME "lavcxwdenc"
31 #define WINDOW_NAME_SIZE 11
32
34 const AVFrame *pict,
int *got_packet)
35 {
38 uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0;
39 uint32_t rgb[3] = { 0 }, bitorder = 0;
40 uint32_t header_size;
44 uint32_t pal[256];
45
48 be = 1;
49 switch (pix_fmt) {
56 be = 1;
59 rgb[0] = 0xFF;
60 rgb[1] = 0xFF00;
61 rgb[2] = 0xFF0000;
62 } else {
63 rgb[0] = 0xFF0000;
64 rgb[1] = 0xFF00;
65 rgb[2] = 0xFF;
66 }
67 bpp = 32;
68 pixdepth = 24;
70 bpad = 32;
71 break;
75 be = 1;
76 bpp = 24;
78 bpad = 32;
79 rgb[0] = 0xFF0000;
80 rgb[1] = 0xFF00;
81 rgb[2] = 0xFF;
82 break;
89 rgb[0] = 0x1F;
90 rgb[1] = 0x7E0;
91 rgb[2] = 0xF800;
92 } else {
93 rgb[0] = 0xF800;
94 rgb[1] = 0x7E0;
95 rgb[2] = 0x1F;
96 }
97 bpp = 16;
99 bpad = 16;
100 break;
107 rgb[0] = 0x1F;
108 rgb[1] = 0x3E0;
109 rgb[2] = 0x7C00;
110 } else {
111 rgb[0] = 0x7C00;
112 rgb[1] = 0x3E0;
113 rgb[2] = 0x1F;
114 }
115 bpp = 16;
117 bpad = 16;
118 break;
124 bpp = 8;
126 bpad = 8;
127 ncolors = 256;
128 break;
130 bpp = 8;
131 bpad = 8;
133 break;
135 be = 1;
136 bitorder = 1;
137 bpp = 1;
138 bpad = 8;
140 break;
141 default:
144 }
145
149
151 return ret;
153
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, bitorder); // 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
183
185 memcpy(pal, p->
data[1],
sizeof(pal));
186 } else {
188 }
189
190 for (i = 0; i < ncolors; i++) {
193
194 val = pal[i];
195 red = (val >> 16) & 0xFF;
196 green = (val >> 8) & 0xFF;
197 blue = val & 0xFF;
198
199 bytestream_put_be32(&buf, i); // colormap entry number
200 bytestream_put_be16(&buf, red << 8);
201 bytestream_put_be16(&buf, green << 8);
202 bytestream_put_be16(&buf, blue << 8);
203 bytestream_put_byte(&buf, 0x7); // bitmask flag
204 bytestream_put_byte(&buf, 0); // padding
205 }
206
208 for (i = 0; i < avctx->
height; i++) {
211 }
212
214 *got_packet = 1;
215 return 0;
216 }
217
246 };
const char const char void * val
static enum AVPixelFormat pix_fmt
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
This structure describes decoded (raw) audio or video data.
packed RGB 8:8:8, 24bpp, RGBRGB...
int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel used by the pixel format described by pixdesc.
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), little-endian, X=unused/undefined ...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), little-endian
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
packed RGB 1:2:1, 8bpp, (msb)1B 2G 1R(lsb)
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
8 bits with AV_PIX_FMT_RGB32 palette
int avpriv_set_systematic_pal2(uint32_t pal[256], enum AVPixelFormat pix_fmt)
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
const char * name
Name of the codec implementation.
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
int flags
A combination of AV_PKT_FLAG values.
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
enum AVPictureType pict_type
Picture type of the frame.
packed RGB 1:2:1, 8bpp, (msb)1R 2G 1B(lsb)
int width
picture width / height.
packed RGB 8:8:8, 24bpp, BGRBGR...
packed BGR 5:6:5, 16bpp, (msb) 5B 6G 5R(lsb), big-endian
packed RGB 3:3:2, 8bpp, (msb)2B 3G 3R(lsb)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
main external API structure.
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), little-endian, X=unused/undefined ...
packed RGB 5:5:5, 16bpp, (msb)1X 5R 5G 5B(lsb), big-endian , X=unused/undefined
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
common internal api header.
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb...
packed RGB 3:3:2, 8bpp, (msb)2R 3G 3B(lsb)
#define AV_PIX_FMT_FLAG_BE
Pixel format is big-endian.
static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size)
static int xwd_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *pict, int *got_packet)
int key_frame
1 -> keyframe, 0-> not
packed BGR 5:5:5, 16bpp, (msb)1X 5B 5G 5R(lsb), big-endian , X=unused/undefined
AVPixelFormat
Pixel format.
This structure stores compressed data.