mirror of https://git.ffmpeg.org/ffmpeg.git
avcodec/rawdec: for 16-bit pix fmts, shift pixels when bits_per_coded_sample < 16
Signed-off-by: Peter Ross <pross@xvid.org> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
a3a4d07d6a
commit
7e23cfba76
|
@ -41,6 +41,7 @@ typedef struct RawVideoContext {
|
||||||
int flip;
|
int flip;
|
||||||
int is_2_4_bpp; // 2 or 4 bpp raw in avi/mov
|
int is_2_4_bpp; // 2 or 4 bpp raw in avi/mov
|
||||||
int is_yuv2;
|
int is_yuv2;
|
||||||
|
int is_lt_16bpp; // 16bpp pixfmt and bits_per_coded_sample < 16
|
||||||
int tff;
|
int tff;
|
||||||
} RawVideoContext;
|
} RawVideoContext;
|
||||||
|
|
||||||
|
@ -142,6 +143,7 @@ static av_cold int raw_init_decoder(AVCodecContext *avctx)
|
||||||
FFALIGN(avctx->width, 16),
|
FFALIGN(avctx->width, 16),
|
||||||
avctx->height);
|
avctx->height);
|
||||||
} else {
|
} else {
|
||||||
|
context->is_lt_16bpp = av_get_bits_per_pixel(desc) == 16 && avctx->bits_per_coded_sample && avctx->bits_per_coded_sample < 16;
|
||||||
context->frame_size = avpicture_get_size(avctx->pix_fmt, avctx->width,
|
context->frame_size = avpicture_get_size(avctx->pix_fmt, avctx->width,
|
||||||
avctx->height);
|
avctx->height);
|
||||||
}
|
}
|
||||||
|
@ -175,7 +177,7 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
|
||||||
int buf_size = avpkt->size;
|
int buf_size = avpkt->size;
|
||||||
int linesize_align = 4;
|
int linesize_align = 4;
|
||||||
int res, len;
|
int res, len;
|
||||||
int need_copy = !avpkt->buf || context->is_2_4_bpp || context->is_yuv2;
|
int need_copy = !avpkt->buf || context->is_2_4_bpp || context->is_yuv2 || context->is_lt_16bpp;
|
||||||
|
|
||||||
AVFrame *frame = data;
|
AVFrame *frame = data;
|
||||||
AVPicture *picture = data;
|
AVPicture *picture = data;
|
||||||
|
@ -240,6 +242,19 @@ static int raw_decode(AVCodecContext *avctx, void *data, int *got_frame,
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (context->is_lt_16bpp) {
|
||||||
|
int i;
|
||||||
|
uint8_t *dst = frame->buf[0]->data;
|
||||||
|
if (desc->flags & AV_PIX_FMT_FLAG_BE) {
|
||||||
|
for (i = 0; i + 1 < buf_size; i += 2)
|
||||||
|
AV_WB16(dst + i, AV_RB16(buf + i) << (16 - avctx->bits_per_coded_sample));
|
||||||
|
} else {
|
||||||
|
for (i = 0; i + 1 < buf_size; i += 2)
|
||||||
|
AV_WL16(dst + i, AV_RL16(buf + i) << (16 - avctx->bits_per_coded_sample));
|
||||||
|
}
|
||||||
|
buf = dst;
|
||||||
|
}
|
||||||
|
|
||||||
if ((res = avpicture_fill(picture, buf, avctx->pix_fmt,
|
if ((res = avpicture_fill(picture, buf, avctx->pix_fmt,
|
||||||
avctx->width, avctx->height)) < 0) {
|
avctx->width, avctx->height)) < 0) {
|
||||||
av_buffer_unref(&frame->buf[0]);
|
av_buffer_unref(&frame->buf[0]);
|
||||||
|
|
Loading…
Reference in New Issue