annotate iff.c @ 11146:e8461dae9672 libavcodec

Fix reading beyond buffer end on RA144Context.lpc_tables. Patch by Francesco Lavra (francescolavra -at- interfree -dot- it)
author vitor
date Sat, 13 Feb 2010 17:42:58 +0000
parents 85a1b00a2413
children 30856cadb01b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11074
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
1 /*
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
2 * IFF PBM/ILBM bitmap decoder
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
3 * Copyright (c) 2010 Peter Ross <pross@xvid.org>
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
4 *
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
5 * This file is part of FFmpeg.
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
6 *
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
11 *
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
15 * Lesser General Public License for more details.
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
16 *
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
20 */
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
21
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
22 /**
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
23 * @file libavcodec/iff.c
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
24 * IFF PBM/ILBM bitmap decoder
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
25 */
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
26
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
27 #include "bytestream.h"
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
28 #include "avcodec.h"
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
29
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
30 /**
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
31 * Convert CMAP buffer (stored in extradata) to lavc palette format
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
32 */
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
33 int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal)
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
34 {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
35 int count, i;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
36
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
37 if (avctx->bits_per_coded_sample > 8) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
38 av_log(avctx, AV_LOG_ERROR, "bit_per_coded_sample > 8 not supported\n");
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
39 return AVERROR_INVALIDDATA;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
40 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
41
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
42 count = 1 << avctx->bits_per_coded_sample;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
43 if (avctx->extradata_size < count * 3) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
44 av_log(avctx, AV_LOG_ERROR, "palette data underflow\n");
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
45 return AVERROR_INVALIDDATA;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
46 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
47 for (i=0; i < count; i++) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
48 pal[i] = AV_RB24( avctx->extradata + i*3 );
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
49 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
50 return 0;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
51 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
52
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
53 static av_cold int decode_init(AVCodecContext *avctx)
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
54 {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
55 AVFrame *frame = avctx->priv_data;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
56
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
57 avctx->pix_fmt = PIX_FMT_PAL8;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
58 frame->reference = 1;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
59
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
60 if (avctx->get_buffer(avctx, frame) < 0) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
61 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
62 return AVERROR_UNKNOWN;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
63 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
64 return ff_cmap_read_palette(avctx, (uint32_t*)frame->data[1]);
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
65 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
66
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
67 /**
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
68 * Interleaved memcpy
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
69 */
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
70 static void imemcpy(uint8_t *dst, const uint8_t const *buf, int x, int bps, int plane, int length)
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
71 {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
72 int i, b;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
73 for(i = 0; i < length; i++) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
74 int value = buf[i];
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
75 for (b = 0; b < bps; b++) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
76 if (value & (1<<b))
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
77 dst[ (x+i)*bps + 7 - b] |= 1<<plane;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
78 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
79 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
80 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
81
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
82 /**
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
83 * Interleaved memset
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
84 */
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
85 static void imemset(uint8_t *dst, int value, int x, int bps, int plane, int length)
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
86 {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
87 int i, b;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
88 for(i = 0; i < length; i++) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
89 for (b = 0; b < bps; b++) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
90 if (value & (1<<b))
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
91 dst[ (x+i)*bps + 7 - b] |= 1<<plane;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
92 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
93 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
94 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
95
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
96 static int decode_frame_ilbm(AVCodecContext *avctx,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
97 void *data, int *data_size,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
98 AVPacket *avpkt)
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
99 {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
100 AVFrame *frame = avctx->priv_data;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
101 const uint8_t *buf = avpkt->data;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
102 int buf_size = avpkt->size;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
103 int planewidth = avctx->width / avctx->bits_per_coded_sample;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
104 int y, plane;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
105
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
106 if (avctx->reget_buffer(avctx, frame) < 0){
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
107 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
108 return -1;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
109 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
110
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
111 if (buf_size < avctx->width * avctx->height) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
112 av_log(avctx, AV_LOG_ERROR, "buffer underflow\n");
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
113 return -1;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
114 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
115
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
116 for(y = 0; y < avctx->height; y++ ) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
117 uint8_t *row = &frame->data[0][ y*frame->linesize[0] ];
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
118 memset(row, 0, avctx->width);
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
119 for (plane = 0; plane < avctx->bits_per_coded_sample; plane++) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
120 imemcpy(row, buf, 0, avctx->bits_per_coded_sample, plane, planewidth);
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
121 buf += planewidth;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
122 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
123 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
124
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
125 *data_size = sizeof(AVFrame);
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
126 *(AVFrame*)data = *frame;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
127 return buf_size;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
128 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
129
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
130 static int decode_frame_byterun1(AVCodecContext *avctx,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
131 void *data, int *data_size,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
132 AVPacket *avpkt)
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
133 {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
134 AVFrame *frame = avctx->priv_data;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
135 const uint8_t *buf = avpkt->data;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
136 int buf_size = avpkt->size;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
137 const uint8_t *buf_end = buf+buf_size;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
138 int planewidth = avctx->width / avctx->bits_per_coded_sample;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
139 int y, plane, x;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
140
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
141 if (avctx->reget_buffer(avctx, frame) < 0){
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
142 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
143 return -1;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
144 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
145
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
146 for(y = 0; y < avctx->height ; y++ ) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
147 uint8_t *row = &frame->data[0][ y*frame->linesize[0] ];
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
148 if (avctx->codec_tag == MKTAG('I','L','B','M')) { //interleaved
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
149 memset(row, 0, avctx->width);
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
150 for (plane = 0; plane < avctx->bits_per_coded_sample; plane++) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
151 for(x = 0; x < planewidth && buf < buf_end; ) {
11124
85a1b00a2413 Use int8_t instead of char, the signedness of char can differ between systems.
reimar
parents: 11074
diff changeset
152 int8_t value = *buf++;
11074
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
153 int length;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
154 if (value >= 0) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
155 length = value + 1;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
156 imemcpy(row, buf, x, avctx->bits_per_coded_sample, plane, FFMIN3(length, buf_end - buf, planewidth - x));
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
157 buf += length;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
158 } else if (value > -128) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
159 length = -value + 1;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
160 imemset(row, *buf++, x, avctx->bits_per_coded_sample, plane, FFMIN(length, planewidth - x));
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
161 } else { //noop
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
162 continue;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
163 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
164 x += length;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
165 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
166 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
167 } else {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
168 for(x = 0; x < avctx->width && buf < buf_end; ) {
11124
85a1b00a2413 Use int8_t instead of char, the signedness of char can differ between systems.
reimar
parents: 11074
diff changeset
169 int8_t value = *buf++;
11074
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
170 int length;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
171 if (value >= 0) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
172 length = value + 1;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
173 memcpy(row + x, buf, FFMIN3(length, buf_end - buf, avctx->width - x));
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
174 buf += length;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
175 } else if (value > -128) {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
176 length = -value + 1;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
177 memset(row + x, *buf++, FFMIN(length, avctx->width - x));
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
178 } else { //noop
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
179 continue;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
180 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
181 x += length;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
182 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
183 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
184 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
185
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
186 *data_size = sizeof(AVFrame);
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
187 *(AVFrame*)data = *frame;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
188 return buf_size;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
189 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
190
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
191 static av_cold int decode_end(AVCodecContext *avctx)
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
192 {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
193 AVFrame *frame = avctx->priv_data;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
194 if (frame->data[0])
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
195 avctx->release_buffer(avctx, frame);
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
196 return 0;
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
197 }
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
198
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
199 AVCodec iff_ilbm_decoder = {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
200 "iff_ilbm",
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
201 CODEC_TYPE_VIDEO,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
202 CODEC_ID_IFF_ILBM,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
203 sizeof(AVFrame),
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
204 decode_init,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
205 NULL,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
206 decode_end,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
207 decode_frame_ilbm,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
208 CODEC_CAP_DR1,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
209 .long_name = NULL_IF_CONFIG_SMALL("IFF ILBM"),
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
210 };
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
211
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
212 AVCodec iff_byterun1_decoder = {
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
213 "iff_byterun1",
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
214 CODEC_TYPE_VIDEO,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
215 CODEC_ID_IFF_BYTERUN1,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
216 sizeof(AVFrame),
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
217 decode_init,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
218 NULL,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
219 decode_end,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
220 decode_frame_byterun1,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
221 CODEC_CAP_DR1,
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
222 .long_name = NULL_IF_CONFIG_SMALL("IFF ByteRun1"),
9fe3b0dcd33d IFF PBM/ILBM bitmap decoder
pross
parents:
diff changeset
223 };