annotate pcx.c @ 11449:e62f45fd47d4 libavcodec

aacsbr: Cleanup read_sbr_grid and copy_sbr_grid after the recent overhaul of those functions.
author alexc
date Tue, 09 Mar 2010 21:46:46 +0000
parents 2422415a296c
children 8a4984c5cacc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
1 /*
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
2 * PC Paintbrush PCX (.pcx) image decoder
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
3 * Copyright (c) 2007, 2008 Ivo van Poorten
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
4 *
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
5 * This decoder does not support CGA palettes. I am unable to find samples
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
6 * and Netpbm cannot generate them.
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
7 *
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
8 * This file is part of FFmpeg.
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
9 *
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
10 * FFmpeg is free software; you can redistribute it and/or
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
11 * modify it under the terms of the GNU Lesser General Public
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
12 * License as published by the Free Software Foundation; either
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
13 * version 2.1 of the License, or (at your option) any later version.
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
14 *
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
15 * FFmpeg is distributed in the hope that it will be useful,
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
18 * Lesser General Public License for more details.
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
19 *
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
20 * You should have received a copy of the GNU Lesser General Public
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
21 * License along with FFmpeg; if not, write to the Free Software
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
23 */
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
24
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
25 #include "avcodec.h"
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
26 #include "bytestream.h"
9428
0dce4fe6e6f3 Rename bitstream.h to get_bits.h.
stefano
parents: 9355
diff changeset
27 #include "get_bits.h"
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
28
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
29 typedef struct PCXContext {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
30 AVFrame picture;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
31 } PCXContext;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
32
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6244
diff changeset
33 static av_cold int pcx_init(AVCodecContext *avctx) {
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
34 PCXContext *s = avctx->priv_data;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
35
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
36 avcodec_get_frame_defaults(&s->picture);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
37 avctx->coded_frame= &s->picture;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
38
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
39 return 0;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
40 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
41
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
42 /**
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
43 * @return advanced src pointer
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
44 */
6793
3a715cb7f4b2 Correct type for pcx_rle_decode().
cehoyos
parents: 6722
diff changeset
45 static const uint8_t *pcx_rle_decode(const uint8_t *src, uint8_t *dst,
10351
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
46 unsigned int bytes_per_scanline, int compressed) {
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
47 unsigned int i = 0;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
48 unsigned char run, value;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
49
10351
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
50 if (compressed) {
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
51 while (i<bytes_per_scanline) {
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
52 run = 1;
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
53 value = *src++;
10351
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
54 if (value >= 0xc0) {
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
55 run = value & 0x3f;
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
56 value = *src++;
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
57 }
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
58 while (i<bytes_per_scanline && run--)
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
59 dst[i++] = value;
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
60 }
10351
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
61 } else {
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
62 memcpy(dst, src, bytes_per_scanline);
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
63 src += bytes_per_scanline;
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
64 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
65
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
66 return src;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
67 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
68
6244
michael
parents: 6075
diff changeset
69 static void pcx_palette(const uint8_t **src, uint32_t *dst, unsigned int pallen) {
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
70 unsigned int i;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
71
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
72 for (i=0; i<pallen; i++)
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
73 *dst++ = bytestream_get_be24(src);
10455
0609da72112c Only memset for palettes of 16 elements.
benoit
parents: 10351
diff changeset
74 if (pallen < 256)
10456
2422415a296c Fix indentation.
benoit
parents: 10455
diff changeset
75 memset(dst, 0, (256 - pallen) * sizeof(*dst));
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
76 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
77
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
78 static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 7040
diff changeset
79 AVPacket *avpkt) {
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 7040
diff changeset
80 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 7040
diff changeset
81 int buf_size = avpkt->size;
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
82 PCXContext * const s = avctx->priv_data;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
83 AVFrame *picture = data;
6075
4d43f2e3aaa5 remove useless cast
ivo
parents: 6073
diff changeset
84 AVFrame * const p = &s->picture;
10351
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
85 int compressed, xmin, ymin, xmax, ymax;
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
86 unsigned int w, h, bits_per_pixel, bytes_per_line, nplanes, stride, y, x,
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
87 bytes_per_scanline;
6244
michael
parents: 6075
diff changeset
88 uint8_t *ptr;
michael
parents: 6075
diff changeset
89 uint8_t const *bufstart = buf;
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
90
10351
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
91 if (buf[0] != 0x0a || buf[1] > 5) {
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
92 av_log(avctx, AV_LOG_ERROR, "this is not PCX encoded data\n");
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
93 return -1;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
94 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
95
10351
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
96 compressed = buf[2];
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
97 xmin = AV_RL16(buf+ 4);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
98 ymin = AV_RL16(buf+ 6);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
99 xmax = AV_RL16(buf+ 8);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
100 ymax = AV_RL16(buf+10);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
101
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
102 if (xmax < xmin || ymax < ymin) {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
103 av_log(avctx, AV_LOG_ERROR, "invalid image dimensions\n");
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
104 return -1;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
105 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
106
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
107 w = xmax - xmin + 1;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
108 h = ymax - ymin + 1;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
109
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
110 bits_per_pixel = buf[3];
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
111 bytes_per_line = AV_RL16(buf+66);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
112 nplanes = buf[65];
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
113 bytes_per_scanline = nplanes * bytes_per_line;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
114
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
115 if (bytes_per_scanline < w * bits_per_pixel * nplanes / 8) {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
116 av_log(avctx, AV_LOG_ERROR, "PCX data is corrupted\n");
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
117 return -1;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
118 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
119
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
120 switch ((nplanes<<8) + bits_per_pixel) {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
121 case 0x0308:
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
122 avctx->pix_fmt = PIX_FMT_RGB24;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
123 break;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
124 case 0x0108:
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
125 case 0x0104:
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
126 case 0x0102:
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
127 case 0x0101:
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
128 case 0x0401:
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
129 case 0x0301:
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
130 case 0x0201:
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
131 avctx->pix_fmt = PIX_FMT_PAL8;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
132 break;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
133 default:
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
134 av_log(avctx, AV_LOG_ERROR, "invalid PCX file\n");
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
135 return -1;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
136 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
137
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
138 buf += 128;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
139
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
140 if (p->data[0])
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
141 avctx->release_buffer(avctx, p);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
142
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
143 if (avcodec_check_dimensions(avctx, w, h))
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
144 return -1;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
145 if (w != avctx->width || h != avctx->height)
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
146 avcodec_set_dimensions(avctx, w, h);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
147 if (avctx->get_buffer(avctx, p) < 0) {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
148 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
149 return -1;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
150 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
151
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
152 p->pict_type = FF_I_TYPE;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
153
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
154 ptr = p->data[0];
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
155 stride = p->linesize[0];
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
156
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
157 if (nplanes == 3 && bits_per_pixel == 8) {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
158 uint8_t scanline[bytes_per_scanline];
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
159
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
160 for (y=0; y<h; y++) {
10351
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
161 buf = pcx_rle_decode(buf, scanline, bytes_per_scanline, compressed);
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
162
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
163 for (x=0; x<w; x++) {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
164 ptr[3*x ] = scanline[x ];
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
165 ptr[3*x+1] = scanline[x+ bytes_per_line ];
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
166 ptr[3*x+2] = scanline[x+(bytes_per_line<<1)];
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
167 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
168
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
169 ptr += stride;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
170 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
171
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
172 } else if (nplanes == 1 && bits_per_pixel == 8) {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
173 uint8_t scanline[bytes_per_scanline];
6244
michael
parents: 6075
diff changeset
174 const uint8_t *palstart = bufstart + buf_size - 769;
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
175
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
176 for (y=0; y<h; y++, ptr+=stride) {
10351
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
177 buf = pcx_rle_decode(buf, scanline, bytes_per_scanline, compressed);
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
178 memcpy(ptr, scanline, w);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
179 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
180
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
181 if (buf != palstart) {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
182 av_log(avctx, AV_LOG_WARNING, "image data possibly corrupted\n");
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
183 buf = palstart;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
184 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
185 if (*buf++ != 12) {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
186 av_log(avctx, AV_LOG_ERROR, "expected palette after image data\n");
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
187 return -1;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
188 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
189
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
190 } else if (nplanes == 1) { /* all packed formats, max. 16 colors */
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
191 uint8_t scanline[bytes_per_scanline];
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
192 GetBitContext s;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
193
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
194 for (y=0; y<h; y++) {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
195 init_get_bits(&s, scanline, bytes_per_scanline<<3);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
196
10351
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
197 buf = pcx_rle_decode(buf, scanline, bytes_per_scanline, compressed);
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
198
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
199 for (x=0; x<w; x++)
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
200 ptr[x] = get_bits(&s, bits_per_pixel);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
201 ptr += stride;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
202 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
203
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
204 } else { /* planar, 4, 8 or 16 colors */
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
205 uint8_t scanline[bytes_per_scanline];
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
206 int i;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
207
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
208 for (y=0; y<h; y++) {
10351
997bdf43a4ed Support decoding of uncompressed PCX scanlines
pross
parents: 9802
diff changeset
209 buf = pcx_rle_decode(buf, scanline, bytes_per_scanline, compressed);
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
210
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
211 for (x=0; x<w; x++) {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
212 int m = 0x80 >> (x&7), v = 0;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
213 for (i=nplanes - 1; i>=0; i--) {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
214 v <<= 1;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
215 v += !!(scanline[i*bytes_per_line + (x>>3)] & m);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
216 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
217 ptr[x] = v;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
218 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
219 ptr += stride;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
220 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
221 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
222
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
223 if (nplanes == 1 && bits_per_pixel == 8) {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
224 pcx_palette(&buf, (uint32_t *) p->data[1], 256);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
225 } else if (bits_per_pixel < 8) {
6244
michael
parents: 6075
diff changeset
226 const uint8_t *palette = bufstart+16;
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
227 pcx_palette(&palette, (uint32_t *) p->data[1], 16);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
228 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
229
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
230 *picture = s->picture;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
231 *data_size = sizeof(AVFrame);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
232
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
233 return buf - bufstart;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
234 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
235
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6244
diff changeset
236 static av_cold int pcx_end(AVCodecContext *avctx) {
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
237 PCXContext *s = avctx->priv_data;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
238
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
239 if(s->picture.data[0])
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
240 avctx->release_buffer(avctx, &s->picture);
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
241
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
242 return 0;
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
243 }
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
244
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
245 AVCodec pcx_decoder = {
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
246 "pcx",
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
247 CODEC_TYPE_VIDEO,
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
248 CODEC_ID_PCX,
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
249 sizeof(PCXContext),
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
250 pcx_init,
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
251 NULL,
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
252 pcx_end,
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
253 pcx_decode_frame,
9802
aebbb6c631b6 pcx decoder use get_buffer, set CODEC_CAP_DR1
bcoudurier
parents: 9428
diff changeset
254 CODEC_CAP_DR1,
6722
6eeb19edcee3 Add long names to some AVCodec declarations.
diego
parents: 6517
diff changeset
255 NULL,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6793
diff changeset
256 .long_name = NULL_IF_CONFIG_SMALL("PC Paintbrush PCX image"),
6073
60d30d88cf71 PC Paintbrush PCX image decoder
ivo
parents:
diff changeset
257 };