31 void *
data,
int *got_frame,
35 int buf_size = avpkt->
size;
37 unsigned int fsize, hsize;
42 int i, j,
n, linesize,
ret;
43 uint32_t rgb[3] = {0};
55 if (bytestream_get_byte(&buf) !=
'B' ||
56 bytestream_get_byte(&buf) !=
'M') {
61 fsize = bytestream_get_le32(&buf);
62 if (buf_size < fsize) {
71 hsize = bytestream_get_le32(&buf);
72 ihsize = bytestream_get_le32(&buf);
73 if (ihsize + 14LL > hsize) {
79 if (fsize == 14 || fsize == ihsize + 14)
84 "Declared file size is less than header size (%u < %u)\n",
95 width = bytestream_get_le32(&buf);
96 height = bytestream_get_le32(&buf);
99 width = bytestream_get_le16(&buf);
100 height = bytestream_get_le16(&buf);
108 if (bytestream_get_le16(&buf) != 1) {
113 depth = bytestream_get_le16(&buf);
116 comp = bytestream_get_le32(&buf);
128 rgb[0] = bytestream_get_le32(&buf);
129 rgb[1] = bytestream_get_le32(&buf);
130 rgb[2] = bytestream_get_le32(&buf);
132 alpha = bytestream_get_le32(&buf);
143 if (rgb[0] == 0xFF000000 && rgb[1] == 0x00FF0000 && rgb[2] == 0x0000FF00)
145 else if (rgb[0] == 0x00FF0000 && rgb[1] == 0x0000FF00 && rgb[2] == 0x000000FF)
147 else if (rgb[0] == 0x0000FF00 && rgb[1] == 0x00FF0000 && rgb[2] == 0xFF000000)
149 else if (rgb[0] == 0x000000FF && rgb[1] == 0x0000FF00 && rgb[2] == 0x00FF0000)
152 av_log(avctx,
AV_LOG_ERROR,
"Unknown bitfields %0X %0X %0X\n", rgb[0], rgb[1], rgb[2]);
166 if (rgb[0] == 0xF800 && rgb[1] == 0x07E0 && rgb[2] == 0x001F)
168 else if (rgb[0] == 0x7C00 && rgb[1] == 0x03E0 && rgb[2] == 0x001F)
170 else if (rgb[0] == 0x0F00 && rgb[1] == 0x00F0 && rgb[2] == 0x000F)
174 "Unknown bitfields %0"PRIX32
" %0"PRIX32
" %0"PRIX32
"\n",
175 rgb[0], rgb[1], rgb[2]);
181 if (hsize - ihsize - 14 > 0)
188 if (hsize - ihsize - 14 > 0) {
212 dsize = buf_size - hsize;
215 n = ((avctx->
width * depth + 31) / 8) & ~3;
219 dsize, n * avctx->
height);
236 int colors = 1 <<
depth;
238 memset(p->
data[1], 0, 1024);
243 t = bytestream_get_le32(&buf);
244 if (t < 0 || t > (1 << depth)) {
246 "Incorrect number of colors - %X for bitdepth %u\n",
252 colors =
FFMIN(256, (hsize-ihsize-14) / 3);
254 buf = buf0 + 14 + ihsize;
256 if ((hsize-ihsize-14) < (colors << 2)) {
257 if ((hsize-ihsize-14) < colors * 3) {
261 for (i = 0; i < colors; i++)
262 ((uint32_t*)p->
data[1])[i] = (0xFF
U<<24) | bytestream_get_le24(&buf);
264 for (i = 0; i < colors; i++)
265 ((uint32_t*)p->
data[1])[i] = 0xFFU << 24 | bytestream_get_le32(&buf);
270 if (comp ==
BMP_RLE8 && height < 0) {
283 for (i = 0; i < avctx->
height; i++) {
285 for (j = 0; j <
n; j++) {
286 ptr[j*8+0] = buf[j] >> 7;
287 ptr[j*8+1] = (buf[j] >> 6) & 1;
288 ptr[j*8+2] = (buf[j] >> 5) & 1;
289 ptr[j*8+3] = (buf[j] >> 4) & 1;
290 ptr[j*8+4] = (buf[j] >> 3) & 1;
291 ptr[j*8+5] = (buf[j] >> 2) & 1;
292 ptr[j*8+6] = (buf[j] >> 1) & 1;
293 ptr[j*8+7] = buf[j] & 1;
302 for (i = 0; i < avctx->
height; i++) {
309 for (i = 0; i < avctx->
height; i++) {
311 for (j = 0; j <
n; j++) {
312 ptr[j*2+0] = (buf[j] >> 4) & 0xF;
313 ptr[j*2+1] = buf[j] & 0xF;
320 for (i = 0; i < avctx->
height; i++) {
321 const uint16_t *
src = (
const uint16_t *) buf;
322 uint16_t *dst = (uint16_t *) ptr;
324 for (j = 0; j < avctx->
width; j++)