diff options
Diffstat (limited to 'src/libffmpeg/libavcodec/raw.c')
-rw-r--r-- | src/libffmpeg/libavcodec/raw.c | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/libffmpeg/libavcodec/raw.c b/src/libffmpeg/libavcodec/raw.c index 8c554c41c..957a809d8 100644 --- a/src/libffmpeg/libavcodec/raw.c +++ b/src/libffmpeg/libavcodec/raw.c @@ -47,7 +47,7 @@ const PixelFormatTag pixelFormatTags[] = { { PIX_FMT_YUV422, MKTAG('Y', '4', '2', '2') }, /* Packed formats */ - { PIX_FMT_YUV422, MKTAG('U', 'Y', 'V', 'Y') }, + { PIX_FMT_UYVY422, MKTAG('U', 'Y', 'V', 'Y') }, { PIX_FMT_GRAY8, MKTAG('G', 'R', 'E', 'Y') }, { -1, 0 }, @@ -64,7 +64,7 @@ static int findPixelFormat(unsigned int fourcc) return PIX_FMT_YUV420P; } -static unsigned int findFourCC(int fmt) +unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat fmt) { const PixelFormatTag * tags = pixelFormatTags; while (tags->pix_fmt >= 0) { @@ -83,6 +83,14 @@ static int raw_init_decoder(AVCodecContext *avctx) if (avctx->codec_tag) avctx->pix_fmt = findPixelFormat(avctx->codec_tag); + else if (avctx->bits_per_sample){ + switch(avctx->bits_per_sample){ + case 15: avctx->pix_fmt= PIX_FMT_RGB555; break; + case 16: avctx->pix_fmt= PIX_FMT_RGB565; break; + case 24: avctx->pix_fmt= PIX_FMT_BGR24 ; break; + case 32: avctx->pix_fmt= PIX_FMT_RGBA32; break; + } + } context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); context->buffer = av_malloc(context->length); @@ -98,6 +106,13 @@ static int raw_init_decoder(AVCodecContext *avctx) return 0; } +static void flip(AVCodecContext *avctx, AVPicture * picture){ + if(!avctx->codec_tag && avctx->bits_per_sample && picture->linesize[1]==0){ + picture->data[0] += picture->linesize[0] * (avctx->height-1); + picture->linesize[0] *= -1; + } +} + static int raw_decode(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) @@ -110,6 +125,7 @@ static int raw_decode(AVCodecContext *avctx, /* Early out without copy if packet size == frame size */ if (buf_size == context->length && context->p == context->buffer) { avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height); + flip(avctx, picture); *data_size = sizeof(AVPicture); return buf_size; } @@ -124,6 +140,7 @@ static int raw_decode(AVCodecContext *avctx, memcpy(context->p, buf, bytesNeeded); context->p = context->buffer; avpicture_fill(picture, context->buffer, avctx->pix_fmt, avctx->width, avctx->height); + flip(avctx, picture); *data_size = sizeof(AVPicture); return bytesNeeded; } @@ -143,7 +160,8 @@ static int raw_init_encoder(AVCodecContext *avctx) avctx->coded_frame = (AVFrame *)avctx->priv_data; avctx->coded_frame->pict_type = FF_I_TYPE; avctx->coded_frame->key_frame = 1; - avctx->codec_tag = findFourCC(avctx->pix_fmt); + if(!avctx->codec_tag) + avctx->codec_tag = avcodec_pix_fmt_to_codec_tag(avctx->pix_fmt); return 0; } |