avcodec/vmnc: Simplify "24bit" support

This also makes the code more robust, removing potential out of
array writes.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2015-05-20 18:50:38 +02:00
parent a4c7aeaf82
commit b6ca7bfc7c
1 changed files with 6 additions and 15 deletions

View File

@ -432,18 +432,10 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
c->pic->pict_type = AV_PICTURE_TYPE_I; c->pic->pict_type = AV_PICTURE_TYPE_I;
depth = bytestream2_get_byte(gb); depth = bytestream2_get_byte(gb);
if (depth != c->bpp) { if (depth != c->bpp) {
av_log(avctx, AV_LOG_WARNING, "Depth mismatch. " av_log(avctx, AV_LOG_INFO,
"Container %i bpp / Codec %i bpp\n", c->bpp, depth); "Depth mismatch. Container %i bpp, "
"Frame data: %i bpp\n",
if (depth != 8 && depth != 16 && depth != 32) { c->bpp, depth);
av_log(avctx, AV_LOG_ERROR,
"Unsupported codec bitdepth %i\n", depth);
return AVERROR_INVALIDDATA;
}
/* reset values */
c->bpp = depth;
c->bpp2 = c->bpp / 8;
} }
bytestream2_skip(gb, 1); bytestream2_skip(gb, 1);
c->bigendian = bytestream2_get_byte(gb); c->bigendian = bytestream2_get_byte(gb);
@ -536,7 +528,6 @@ static av_cold int decode_init(AVCodecContext *avctx)
c->width = avctx->width; c->width = avctx->width;
c->height = avctx->height; c->height = avctx->height;
c->bpp = avctx->bits_per_coded_sample; c->bpp = avctx->bits_per_coded_sample;
c->bpp2 = c->bpp / 8;
switch (c->bpp) { switch (c->bpp) {
case 8: case 8:
@ -546,8 +537,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
avctx->pix_fmt = AV_PIX_FMT_RGB555; avctx->pix_fmt = AV_PIX_FMT_RGB555;
break; break;
case 24: case 24:
/* 24 bits is not technically supported, but some clients might c->bpp = 32;
* mistakenly set it -- delay the actual check until decode_frame() */
case 32: case 32:
avctx->pix_fmt = AV_PIX_FMT_0RGB32; avctx->pix_fmt = AV_PIX_FMT_0RGB32;
break; break;
@ -555,6 +545,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
av_log(avctx, AV_LOG_ERROR, "Unsupported bitdepth %i\n", c->bpp); av_log(avctx, AV_LOG_ERROR, "Unsupported bitdepth %i\n", c->bpp);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
c->bpp2 = c->bpp / 8;
c->pic = av_frame_alloc(); c->pic = av_frame_alloc();
if (!c->pic) if (!c->pic)