49 unsigned int bytes_per_scanline,
52 unsigned char run, value;
55 while (i < bytes_per_scanline && src < end) {
58 if (value >= 0xc0 && src < end) {
62 while (i<bytes_per_scanline && run--)
66 memcpy(dst, src, bytes_per_scanline);
67 src += bytes_per_scanline;
73 static void pcx_palette(
const uint8_t **src, uint32_t *dst,
unsigned int pallen) {
76 for (i=0; i<pallen; i++)
77 *dst++ = bytestream_get_be24(src);
79 memset(dst, 0, (256 - pallen) *
sizeof(*dst));
84 const uint8_t *buf = avpkt->
data;
85 int buf_size = avpkt->
size;
89 int compressed, xmin, ymin, xmax, ymax;
90 unsigned int w, h, bits_per_pixel, bytes_per_line, nplanes,
stride, y, x,
93 const uint8_t *buf_end = buf + buf_size;
94 uint8_t
const *bufstart = buf;
98 if (buf[0] != 0x0a || buf[1] > 5) {
109 if (xmax < xmin || ymax < ymin) {
117 bits_per_pixel = buf[3];
118 bytes_per_line =
AV_RL16(buf+66);
120 bytes_per_scanline = nplanes * bytes_per_line;
122 if (bytes_per_scanline < w * bits_per_pixel * nplanes / 8 ||
123 (!compressed && bytes_per_scanline > buf_size / h)) {
128 switch ((nplanes<<8) + bits_per_pixel) {
165 scanline =
av_malloc(bytes_per_scanline);
169 if (nplanes == 3 && bits_per_pixel == 8) {
170 for (y=0; y<h; y++) {
172 scanline, bytes_per_scanline, compressed);
174 for (x=0; x<w; x++) {
175 ptr[3*x ] = scanline[x ];
176 ptr[3*x+1] = scanline[x+ bytes_per_line ];
177 ptr[3*x+2] = scanline[x+(bytes_per_line<<1)];
183 }
else if (nplanes == 1 && bits_per_pixel == 8) {
184 const uint8_t *palstart = bufstart + buf_size - 769;
186 if (buf_size < 769) {
192 for (y = 0; y < h; y++, ptr +=
stride) {
194 scanline, bytes_per_scanline, compressed);
195 memcpy(ptr, scanline, w);
198 if (buf != palstart) {
208 }
else if (nplanes == 1) {
211 for (y=0; y<h; y++) {
215 scanline, bytes_per_scanline, compressed);
218 ptr[x] =
get_bits(&s, bits_per_pixel);
225 for (y=0; y<h; y++) {
227 scanline, bytes_per_scanline, compressed);
229 for (x=0; x<w; x++) {
230 int m = 0x80 >> (x&7),
v = 0;
231 for (i=nplanes - 1; i>=0; i--) {
233 v += !!(scanline[i*bytes_per_line + (x>>3)] & m);
241 if (nplanes == 1 && bits_per_pixel == 8) {
243 }
else if (bits_per_pixel < 8) {
244 const uint8_t *
palette = bufstart+16;
251 ret = buf - bufstart;