35 const uint8_t *buf = avpkt->
data;
36 int buf_size = avpkt->
size;
37 unsigned int fsize, hsize;
42 int i, j, n, linesize, ret;
43 uint32_t
rgb[3] = {0};
47 const uint8_t *buf0 = buf;
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) {
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);
109 if (bytestream_get_le16(&buf) != 1) {
114 depth = bytestream_get_le16(&buf);
117 comp = bytestream_get_le32(&buf);
129 rgb[0] = bytestream_get_le32(&buf);
130 rgb[1] = bytestream_get_le32(&buf);
131 rgb[2] = bytestream_get_le32(&buf);
133 alpha = bytestream_get_le32(&buf);
147 if (
rgb[0] == 0xFF000000 &&
rgb[1] == 0x00FF0000 &&
rgb[2] == 0x0000FF00)
149 else if (
rgb[0] == 0x00FF0000 &&
rgb[1] == 0x0000FF00 &&
rgb[2] == 0x000000FF)
151 else if (
rgb[0] == 0x0000FF00 &&
rgb[1] == 0x00FF0000 &&
rgb[2] == 0xFF000000)
153 else if (
rgb[0] == 0x000000FF &&
rgb[1] == 0x0000FF00 &&
rgb[2] == 0x00FF0000)
157 "%0"PRIX32
" %0"PRIX32
" %0"PRIX32
"\n",
rgb[0],
rgb[1],
rgb[2]);
171 if (
rgb[0] == 0xF800 &&
rgb[1] == 0x07E0 &&
rgb[2] == 0x001F)
173 else if (
rgb[0] == 0x7C00 &&
rgb[1] == 0x03E0 &&
rgb[2] == 0x001F)
175 else if (
rgb[0] == 0x0F00 &&
rgb[1] == 0x00F0 &&
rgb[2] == 0x000F)
179 "Unknown bitfields %0"PRIX32
" %0"PRIX32
" %0"PRIX32
"\n",
186 if (hsize - ihsize - 14 > 0)
193 if (hsize - ihsize - 14 > 0) {
212 dsize = buf_size - hsize;
215 n = ((avctx->
width * depth + 31) / 8) & ~3;
218 n = (avctx->
width * depth + 7) / 8;
219 if (n * avctx->
height > dsize) {
221 dsize, n * avctx->
height);
224 av_log(avctx,
AV_LOG_ERROR,
"data size too small, assuming missing line alignment\n");
231 memset(p->data[0], 0, avctx->
height * p->linesize[0]);
234 ptr = p->data[0] + (avctx->
height - 1) * p->linesize[0];
235 linesize = -p->linesize[0];
238 linesize = p->linesize[0];
242 int colors = 1 << depth;
244 memset(p->data[1], 0, 1024);
249 t = bytestream_get_le32(&buf);
250 if (t < 0 || t > (1 << depth)) {
252 "Incorrect number of colors - %X for bitdepth %u\n",
258 colors =
FFMIN(256, (hsize-ihsize-14) / 3);
260 buf = buf0 + 14 + ihsize;
262 if ((hsize-ihsize-14) < (colors << 2)) {
263 if ((hsize-ihsize-14) < colors * 3) {
267 for (
i = 0;
i < colors;
i++)
268 ((uint32_t*)p->data[1])[
i] = (0xFFU<<24) | bytestream_get_le24(&buf);
270 for (
i = 0;
i < colors;
i++)
271 ((uint32_t*)p->data[1])[
i] = 0xFFU << 24 | bytestream_get_le32(&buf);
277 p->data[0] += p->linesize[0] * (avctx->
height - 1);
278 p->linesize[0] = -p->linesize[0];
283 p->data[0] += p->linesize[0] * (avctx->
height - 1);
284 p->linesize[0] = -p->linesize[0];
291 for (j = 0; j < avctx->
width >> 3; j++) {
292 ptr[j*8+0] = buf[j] >> 7;
293 ptr[j*8+1] = (buf[j] >> 6) & 1;
294 ptr[j*8+2] = (buf[j] >> 5) & 1;
295 ptr[j*8+3] = (buf[j] >> 4) & 1;
296 ptr[j*8+4] = (buf[j] >> 3) & 1;
297 ptr[j*8+5] = (buf[j] >> 2) & 1;
298 ptr[j*8+6] = (buf[j] >> 1) & 1;
299 ptr[j*8+7] = buf[j] & 1;
301 for (j = 0; j < (avctx->
width & 7); j++) {
302 ptr[avctx->
width - (avctx->
width & 7) + j] = buf[avctx->
width >> 3] >> (7 - j) & 1;
320 for (j = 0; j < n; j++) {
321 ptr[j*2+0] = (buf[j] >> 4) & 0xF;
322 ptr[j*2+1] = buf[j] & 0xF;
330 const uint8_t *
src = buf;
331 uint16_t *
dst = (uint16_t *) ptr;
333 for (j = 0; j < avctx->
width; j++) {
350 uint8_t *ptr = p->data[0] + p->linesize[0]*
i + 3;
351 for (j = 0; j < avctx->
width; j++) {
355 if (j < avctx->
width)
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
const FFCodec ff_bmp_decoder
static int64_t fsize(FILE *f)
Libavcodec external API header.
static int bmp_decode_frame(AVCodecContext *avctx, AVFrame *p, int *got_frame, AVPacket *avpkt)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define i(width, name, range_min, range_max)
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_set_dimensions(AVCodecContext *s, int width, int height)
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const int16_t alpha[]
void avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
int ff_msrle_decode(AVCodecContext *avctx, AVFrame *pic, int depth, GetByteContext *gb)
Decode stream in MS RLE format into frame.
@ AV_PIX_FMT_BGR0
packed BGR 8:8:8, 32bpp, BGRXBGRX... X=unused/undefined
@ AV_PIX_FMT_ARGB
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
@ AV_PIX_FMT_BGRA
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
@ AV_PIX_FMT_ABGR
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
@ AV_PIX_FMT_0BGR
packed BGR 8:8:8, 32bpp, XBGRXBGR... X=unused/undefined
@ AV_PIX_FMT_RGBA
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
@ AV_PIX_FMT_RGB0
packed RGB 8:8:8, 32bpp, RGBXRGBX... X=unused/undefined
@ AV_PIX_FMT_PAL8
8 bits with AV_PIX_FMT_RGB32 palette
@ AV_PIX_FMT_BGR24
packed RGB 8:8:8, 24bpp, BGRBGR...
@ AV_PIX_FMT_0RGB
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
#define AV_PIX_FMT_RGB565
#define AV_PIX_FMT_RGB444
#define AV_PIX_FMT_RGB555
main external API structure.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int width
picture width / height.
This structure describes decoded (raw) audio or video data.
This structure stores compressed data.