[FFmpeg-devel] [PATCH]Decode yuv421 and yuv442 in jpg
Michael Niedermayer
michaelni at gmx.at
Mon Dec 26 05:44:46 CET 2011
On Sun, Dec 25, 2011 at 04:30:30AM +0100, Carl-Eugen Hoyos wrote:
> Hi!
>
> Attached allows to decode the samples from ticket #787.
>
> Please review, Carl Eugen
> mjpegdec.c | 25 +++++++++++++++++++++++++
> mjpegdec.h | 2 ++
> 2 files changed, 27 insertions(+)
> fd5896cc1dff2da3a3b211cf116a94b9625fb773 patchyuv4xx.diff
> diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c
> index e082147..1b46ce6 100644
> --- a/libavcodec/mjpegdec.c
> +++ b/libavcodec/mjpegdec.c
> @@ -337,12 +337,19 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
> }
> assert(s->nb_components==3);
> break;
> + case 0x12121100:
> + s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV444P : PIX_FMT_YUVJ444P;
> + s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
> + s->yuv442 = 1;
> + break;
> case 0x11000000:
> s->avctx->pix_fmt = PIX_FMT_GRAY8;
> break;
> case 0x12111100:
> + case 0x22211100:
> s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV440P : PIX_FMT_YUVJ440P;
> s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG;
> + s->yuv421 = pix_fmt_id == 0x22211100;
> break;
> case 0x21111100:
> s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV422P : PIX_FMT_YUVJ422P;
> @@ -1091,6 +1098,24 @@ int ff_mjpeg_decode_sos(MJpegDecodeContext *s,
> return -1;
> }
> }
> + if (s->yuv421)
> + for (i = 0; i < s->height / 2; i++) {
> + uint8_t *line = &((uint8_t *)s->picture_ptr->data[2])[i * s->linesize[2]];
> + for (index = s->linesize[2] - 1; index; index--)
> + line[index] = (line[index / 2] + line[(index + 1) / 2]) >> 1;
> + }
> + if (s->yuv442)
> + for (i = s->height - 1; i; i--) {
> + uint8_t *dst = &((uint8_t *)s->picture_ptr->data[2])[i * s->linesize[2]];
> + uint8_t *src1 = &((uint8_t *)s->picture_ptr->data[2])[i / 2 * s->linesize[2]];
> + uint8_t *src2 = &((uint8_t *)s->picture_ptr->data[2])[(i + 1) / 2 * s->linesize[2]];
> + if (src1 == src2) {
> + memcpy(dst, src1, s->linesize[2]);
> + } else {
> + for (index = 0; index < s->linesize[2]; index++)
a few of the linesize should be width as linesize can be negative
or larger than width
otherwise LGTM
it could be of course optimized but its pointless as this is just a
relly odd rare format
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Many that live deserve death. And some that die deserve life. Can you give
it to them? Then do not be too eager to deal out death in judgement. For
even the very wise cannot see all ends. -- Gandalf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20111226/a83015b5/attachment.asc>
More information about the ffmpeg-devel
mailing list