mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
bmpdec: proper check for alpha
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
f068ce570f
commit
bd36ec55be
@ -49,6 +49,7 @@ static int bmp_decode_frame(AVCodecContext *avctx,
|
|||||||
unsigned int ihsize;
|
unsigned int ihsize;
|
||||||
int i, j, n, linesize;
|
int i, j, n, linesize;
|
||||||
uint32_t rgb[3];
|
uint32_t rgb[3];
|
||||||
|
uint32_t alpha = 0;
|
||||||
uint8_t *ptr;
|
uint8_t *ptr;
|
||||||
int dsize;
|
int dsize;
|
||||||
const uint8_t *buf0 = buf;
|
const uint8_t *buf0 = buf;
|
||||||
@ -131,6 +132,8 @@ static int bmp_decode_frame(AVCodecContext *avctx,
|
|||||||
rgb[0] = bytestream_get_le32(&buf);
|
rgb[0] = bytestream_get_le32(&buf);
|
||||||
rgb[1] = bytestream_get_le32(&buf);
|
rgb[1] = bytestream_get_le32(&buf);
|
||||||
rgb[2] = bytestream_get_le32(&buf);
|
rgb[2] = bytestream_get_le32(&buf);
|
||||||
|
if (ihsize >= 108)
|
||||||
|
alpha = bytestream_get_le32(&buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
avctx->width = width;
|
avctx->width = width;
|
||||||
@ -142,13 +145,13 @@ static int bmp_decode_frame(AVCodecContext *avctx,
|
|||||||
case 32:
|
case 32:
|
||||||
if(comp == BMP_BITFIELDS){
|
if(comp == BMP_BITFIELDS){
|
||||||
if (rgb[0] == 0xFF000000 && rgb[1] == 0x00FF0000 && rgb[2] == 0x0000FF00)
|
if (rgb[0] == 0xFF000000 && rgb[1] == 0x00FF0000 && rgb[2] == 0x0000FF00)
|
||||||
avctx->pix_fmt = PIX_FMT_ABGR;
|
avctx->pix_fmt = alpha ? PIX_FMT_ABGR : PIX_FMT_0BGR;
|
||||||
else if (rgb[0] == 0x00FF0000 && rgb[1] == 0x0000FF00 && rgb[2] == 0x000000FF)
|
else if (rgb[0] == 0x00FF0000 && rgb[1] == 0x0000FF00 && rgb[2] == 0x000000FF)
|
||||||
avctx->pix_fmt = PIX_FMT_BGRA;
|
avctx->pix_fmt = alpha ? PIX_FMT_BGRA : PIX_FMT_BGR0;
|
||||||
else if (rgb[0] == 0x0000FF00 && rgb[1] == 0x00FF0000 && rgb[2] == 0xFF000000)
|
else if (rgb[0] == 0x0000FF00 && rgb[1] == 0x00FF0000 && rgb[2] == 0xFF000000)
|
||||||
avctx->pix_fmt = PIX_FMT_ARGB;
|
avctx->pix_fmt = alpha ? PIX_FMT_ARGB : PIX_FMT_0RGB;
|
||||||
else if (rgb[0] == 0x000000FF && rgb[1] == 0x0000FF00 && rgb[2] == 0x00FF0000)
|
else if (rgb[0] == 0x000000FF && rgb[1] == 0x0000FF00 && rgb[2] == 0x00FF0000)
|
||||||
avctx->pix_fmt = PIX_FMT_RGBA;
|
avctx->pix_fmt = alpha ? PIX_FMT_RGBA : PIX_FMT_RGB0;
|
||||||
else {
|
else {
|
||||||
av_log(avctx, AV_LOG_ERROR, "Unknown bitfields %0X %0X %0X\n", rgb[0], rgb[1], rgb[2]);
|
av_log(avctx, AV_LOG_ERROR, "Unknown bitfields %0X %0X %0X\n", rgb[0], rgb[1], rgb[2]);
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
|
Loading…
Reference in New Issue
Block a user