1 /*
2 * PC Paintbrush PCX (.pcx) image decoder
3 * Copyright (c) 2007, 2008 Ivo van Poorten
4 *
5 * This decoder does not support CGA palettes. I am unable to find samples
6 * and Netpbm cannot generate them.
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
30
31 #define PCX_HEADER_SIZE 128
32
35 unsigned int bytes_per_scanline,
36 int compressed)
37 {
38 unsigned int i = 0;
40
41 if (compressed) {
43 run = 1;
44 value = bytestream2_get_byte(gb);
46 run = value & 0x3f;
47 value = bytestream2_get_byte(gb);
48 }
49 while (i < bytes_per_scanline && run--)
51 }
52 } else {
54 }
55 }
56
58 {
59 int i;
60
62 for (i = 0; i < pallen; i++)
63 *dst++ = 0xFF000000 | bytestream2_get_be24u(gb);
64 if (pallen < 256)
65 memset(dst, 0, (256 - pallen) * sizeof(*dst));
66 }
67
70 {
73 int compressed, xmin, ymin, xmax, ymax;
74 int ret;
75 unsigned int w,
h, bits_per_pixel, bytes_per_line, nplanes,
stride, y, x,
76 bytes_per_scanline;
78
82 }
83
85
86 if (bytestream2_get_byteu(&gb) != 0x0a || bytestream2_get_byteu(&gb) > 5) {
89 }
90
91 compressed = bytestream2_get_byteu(&gb);
92 bits_per_pixel = bytestream2_get_byteu(&gb);
93 xmin = bytestream2_get_le16u(&gb);
94 ymin = bytestream2_get_le16u(&gb);
95 xmax = bytestream2_get_le16u(&gb);
96 ymax = bytestream2_get_le16u(&gb);
99
100 if (xmax < xmin || ymax < ymin) {
103 }
104
105 w = xmax - xmin + 1;
106 h = ymax - ymin + 1;
107
109 nplanes = bytestream2_get_byteu(&gb);
110 bytes_per_line = bytestream2_get_le16u(&gb);
111 bytes_per_scanline = nplanes * bytes_per_line;
112
113 if (bytes_per_scanline < (w * bits_per_pixel * nplanes + 7) / 8 ||
117 }
118
119 switch ((nplanes << 8) + bits_per_pixel) {
120 case 0x0308:
122 break;
123 case 0x0108:
124 case 0x0104:
125 case 0x0102:
126 case 0x0101:
127 case 0x0401:
128 case 0x0301:
129 case 0x0201:
131 break;
132 default:
135 }
136
138
140 return ret;
141
143 return ret;
144
146
149
151 if (!scanline)
153
154 if (nplanes == 3 && bits_per_pixel == 8) {
155 for (y = 0; y <
h; y++) {
157
158 for (x = 0; x <
w; x++) {
159 ptr[3 * x] = scanline[x];
160 ptr[3 * x + 1] = scanline[x + bytes_per_line];
161 ptr[3 * x + 2] = scanline[x + (bytes_per_line << 1)];
162 }
163
165 }
166 } else if (nplanes == 1 && bits_per_pixel == 8) {
167 int palstart = avpkt->
size - 769;
168
169 if (avpkt->
size < 769) {
174 }
175
176 for (y = 0; y <
h; y++, ptr +=
stride) {
178 memcpy(ptr, scanline, w);
179 }
180
184 }
185 if (bytestream2_get_byte(&gb) != 12) {
190 }
191 } else if (nplanes == 1) { /* all packed formats, max. 16 colors */
193
194 for (y = 0; y <
h; y++) {
196
198
199 for (x = 0; x <
w; x++)
200 ptr[x] =
get_bits(&s, bits_per_pixel);
202 }
203 } else { /* planar, 4, 8 or 16 colors */
204 int i;
205
206 for (y = 0; y <
h; y++) {
208
209 for (x = 0; x <
w; x++) {
210 int m = 0x80 >> (x & 7), v = 0;
211 for (i = nplanes - 1; i >= 0; i--) {
212 v <<= 1;
213 v += !!(scanline[i * bytes_per_line + (x >> 3)] & m);
214 }
215 ptr[x] = v;
216 }
218 }
219 }
220
222 if (nplanes == 1 && bits_per_pixel == 8) {
224 ret += 256 * 3;
225 } else if (bits_per_pixel * nplanes == 1) {
228 } else if (bits_per_pixel < 8) {
231 }
232
233 *got_frame = 1;
234
237 return ret;
238 }
239
247 };
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
packed RGB 8:8:8, 24bpp, RGBRGB...
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
8 bits with AV_PIX_FMT_RGB32 palette
static av_cold int end(AVCodecContext *avctx)
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
bitstream reader API header.
static int pcx_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#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. ...
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
const char * name
Name of the codec implementation.
enum AVPictureType pict_type
Picture type of the frame.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
static void pcx_palette(GetByteContext *gb, uint32_t *dst, int pallen)
GLsizei GLboolean const GLfloat * value
#define AV_EF_EXPLODE
abort decoding on minor error detection
static av_always_inline int bytestream2_tell(GetByteContext *g)
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
main external API structure.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
static void pcx_rle_decode(GetByteContext *gb, uint8_t *dst, unsigned int bytes_per_scanline, int compressed)
common internal api header.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, int whence)
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.