annotate pcxenc.c @ 9308:aad816bc3d54 libavcodec

Replacement reference DCT implementation. patch by Dylan Yudaken, dyudaken gmail com
author diego
date Tue, 31 Mar 2009 15:48:47 +0000
parents 04d827aafa7c
children 38cfe222e1a4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9204
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
1 /*
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
2 * PC Paintbrush PCX (.pcx) image encoder
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
3 * Copyright (c) 2009 Daniel Verkamp <daniel at drv.nu>
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
4 *
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
5 * This file is part of FFmpeg.
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
6 *
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
11 *
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
15 * Lesser General Public License for more details.
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
16 *
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
20 */
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
21
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
22 /**
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
23 * PCX image encoder
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
24 * @file libavcodec/pcxenc.c
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
25 * @author Daniel Verkamp
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
26 * @sa http://www.qzx.com/pc-gpe/pcx.txt
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
27 */
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
28
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
29 #include "avcodec.h"
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
30 #include "bytestream.h"
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
31
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
32 typedef struct PCXContext {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
33 AVFrame picture;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
34 } PCXContext;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
35
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
36 static const uint32_t monoblack_pal[] = { 0x000000, 0xFFFFFF };
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
37
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
38 static av_cold int pcx_encode_init(AVCodecContext *avctx)
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
39 {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
40 PCXContext *s = avctx->priv_data;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
41
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
42 avcodec_get_frame_defaults(&s->picture);
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
43 avctx->coded_frame = &s->picture;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
44
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
45 return 0;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
46 }
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
47
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
48 /**
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
49 * PCX run-length encoder
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
50 * @param dst output buffer
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
51 * @param dst_size size of output buffer
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
52 * @param src input buffer
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
53 * @param src_plane_size size of one plane of input buffer in bytes
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
54 * @param nplanes number of planes in input buffer
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
55 * @return number of bytes written to dst or -1 on error
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
56 * @bug will not work for nplanes != 1 && bpp != 8
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
57 */
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
58 static int pcx_rle_encode( uint8_t *dst, int dst_size,
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
59 const uint8_t *src, int src_plane_size, int nplanes)
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
60 {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
61 int p;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
62 const uint8_t *dst_start = dst;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
63
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
64 // check worst-case upper bound on dst_size
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
65 if (dst_size < 2LL * src_plane_size * nplanes || src_plane_size <= 0)
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
66 return -1;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
67
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
68 for (p = 0; p < nplanes; p++) {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
69 int count = 1;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
70 const uint8_t *src_plane = src + p;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
71 const uint8_t *src_plane_end = src_plane + src_plane_size * nplanes;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
72 uint8_t prev = *src_plane;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
73 src_plane += nplanes;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
74
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
75 for (; ; src_plane += nplanes) {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
76 if (src_plane < src_plane_end && *src_plane == prev && count < 0x3F) {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
77 // current byte is same as prev
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
78 ++count;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
79 } else {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
80 // output prev * count
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
81 if (count != 1 || prev >= 0xC0)
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
82 *dst++ = 0xC0 | count;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
83 *dst++ = prev;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
84
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
85 if (src_plane == src_plane_end)
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
86 break;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
87
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
88 // start new run
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
89 count = 1;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
90 prev = *src_plane;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
91 }
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
92 }
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
93 }
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
94
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
95 return dst - dst_start;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
96 }
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
97
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
98 static int pcx_encode_frame(AVCodecContext *avctx,
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
99 unsigned char *buf, int buf_size, void *data)
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
100 {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
101 PCXContext *s = avctx->priv_data;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
102 AVFrame *const pict = &s->picture;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
103 const uint8_t *buf_start = buf;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
104 const uint8_t *buf_end = buf + buf_size;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
105
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
106 int bpp, nplanes, i, y, line_bytes, written;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
107 const uint32_t *pal = NULL;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
108 const uint8_t *src;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
109
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
110 *pict = *(AVFrame *)data;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
111 pict->pict_type = FF_I_TYPE;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
112 pict->key_frame = 1;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
113
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
114 if (avctx->width > 65535 || avctx->height > 65535) {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
115 av_log(avctx, AV_LOG_ERROR, "image dimensions do not fit in 16 bits\n");
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
116 return -1;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
117 }
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
118
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
119 switch (avctx->pix_fmt) {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
120 case PIX_FMT_RGB24:
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
121 bpp = 8;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
122 nplanes = 3;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
123 break;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
124 case PIX_FMT_RGB8:
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
125 case PIX_FMT_BGR8:
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
126 case PIX_FMT_RGB4_BYTE:
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
127 case PIX_FMT_BGR4_BYTE:
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
128 case PIX_FMT_GRAY8:
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
129 case PIX_FMT_PAL8:
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
130 bpp = 8;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
131 nplanes = 1;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
132 pal = (uint32_t *)pict->data[1];
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
133 break;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
134 case PIX_FMT_MONOBLACK:
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
135 bpp = 1;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
136 nplanes = 1;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
137 pal = monoblack_pal;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
138 break;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
139 default:
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
140 av_log(avctx, AV_LOG_ERROR, "unsupported pixfmt\n");
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
141 return -1;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
142 }
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
143
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
144 line_bytes = (avctx->width * bpp + 7) >> 3;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
145 line_bytes = (line_bytes + 1) & ~1;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
146
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
147 bytestream_put_byte(&buf, 10); // manufacturer
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
148 bytestream_put_byte(&buf, 5); // version
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
149 bytestream_put_byte(&buf, 1); // encoding
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
150 bytestream_put_byte(&buf, bpp); // bits per pixel per plane
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
151 bytestream_put_le16(&buf, 0); // x min
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
152 bytestream_put_le16(&buf, 0); // y min
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
153 bytestream_put_le16(&buf, avctx->width - 1); // x max
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
154 bytestream_put_le16(&buf, avctx->height - 1); // y max
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
155 bytestream_put_le16(&buf, 0); // horizontal DPI
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
156 bytestream_put_le16(&buf, 0); // vertical DPI
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
157 for (i = 0; i < 16; i++)
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
158 bytestream_put_be24(&buf, pal ? pal[i] : 0);// palette (<= 16 color only)
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
159 bytestream_put_byte(&buf, 0); // reserved
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
160 bytestream_put_byte(&buf, nplanes); // number of planes
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
161 bytestream_put_le16(&buf, line_bytes); // scanline plane size in bytes
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
162
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
163 while (buf - buf_start < 128)
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
164 *buf++= 0;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
165
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
166 src = pict->data[0];
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
167
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
168 for (y = 0; y < avctx->height; y++) {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
169 if ((written = pcx_rle_encode(buf, buf_end - buf,
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
170 src, line_bytes, nplanes)) < 0) {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
171 av_log(avctx, AV_LOG_ERROR, "buffer too small\n");
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
172 return -1;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
173 }
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
174 buf += written;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
175 src += pict->linesize[0];
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
176 }
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
177
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
178 if (nplanes == 1 && bpp == 8) {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
179 if (buf_end - buf < 257) {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
180 av_log(avctx, AV_LOG_ERROR, "buffer too small\n");
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
181 return -1;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
182 }
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
183 bytestream_put_byte(&buf, 12);
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
184 for (i = 0; i < 256; i++) {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
185 bytestream_put_be24(&buf, pal[i]);
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
186 }
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
187 }
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
188
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
189 return buf - buf_start;
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
190 }
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
191
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
192 AVCodec pcx_encoder = {
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
193 "pcx",
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
194 CODEC_TYPE_VIDEO,
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
195 CODEC_ID_PCX,
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
196 sizeof(PCXContext),
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
197 pcx_encode_init,
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
198 pcx_encode_frame,
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
199 NULL,
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
200 .pix_fmts = (enum PixelFormat[]){
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
201 PIX_FMT_RGB24,
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
202 PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8,
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
203 PIX_FMT_MONOBLACK,
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
204 PIX_FMT_NONE},
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
205 .long_name = NULL_IF_CONFIG_SMALL("PC Paintbrush PCX image"),
04d827aafa7c PCX encoder that handles 1-, 8-, and 24-bpp pixfmts.
cehoyos
parents:
diff changeset
206 };