From e15455891bc673f9767c1ececa3fa92f05267ce3 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 18 Mar 2015 23:05:22 +0100 Subject: [PATCH] avcodec/mjpegdec: Change upscale_* to an array instead of a bitmask This allows storing integer factors instead of just 0 and 1 Signed-off-by: Michael Niedermayer --- libavcodec/mjpegdec.c | 43 +++++++++++++++++++++++-------------------- libavcodec/mjpegdec.h | 4 ++-- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index a0548c18a0..b7dc418ba2 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -250,7 +250,8 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) int v_count[MAX_COMPONENTS] = { 0 }; s->cur_scan = 0; - s->upscale_h = s->upscale_v = 0; + memset(s->upscale_h, 0, sizeof(s->upscale_h)); + memset(s->upscale_v, 0, sizeof(s->upscale_v)); /* XXX: verify len field validity */ len = get_bits(&s->gb, 16); @@ -404,8 +405,8 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) js = (pix_fmt_id >> (16 + 4*(i&1))) & 0xF; if (is == 1 && js == 2) { - if (i & 1) s->upscale_h |= 1 << (j/2); - else s->upscale_v |= 1 << (j/2); + if (i & 1) s->upscale_h[j/2] = 1; + else s->upscale_v[j/2] = 1; } } @@ -441,12 +442,12 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) case 0x22111111: if (s->adobe_transform == 0 && s->bits <= 8) { s->avctx->pix_fmt = AV_PIX_FMT_GBRAP; - s->upscale_v |= 6; - s->upscale_h |= 6; + s->upscale_v[1] = s->upscale_v[2] = 1; + s->upscale_h[1] = s->upscale_h[2] = 1; } else if (s->adobe_transform == 2 && s->bits <= 8) { s->avctx->pix_fmt = AV_PIX_FMT_YUVA444P; - s->upscale_v |= 6; - s->upscale_h |= 6; + s->upscale_v[1] = s->upscale_v[2] = 1; + s->upscale_h[1] = s->upscale_h[2] = 1; s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; } else { if (s->bits <= 8) s->avctx->pix_fmt = AV_PIX_FMT_YUVA420P; @@ -495,10 +496,10 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) if (s->bits <= 8) s->avctx->pix_fmt = AV_PIX_FMT_GBRP; else goto unk_pixfmt; - s->upscale_v |= 3; + s->upscale_v[0] = s->upscale_v[1] = 1; } else { if (pix_fmt_id == 0x14111100) - s->upscale_v |= 6; + s->upscale_v[1] = s->upscale_v[2] = 1; if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV440P : AV_PIX_FMT_YUVJ440P; else goto unk_pixfmt; @@ -510,7 +511,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) if (s->bits <= 8) s->avctx->pix_fmt = AV_PIX_FMT_GBRP; else goto unk_pixfmt; - s->upscale_h |= 3; + s->upscale_h[0] = s->upscale_h[1] = 1; } else { if (s->bits <= 8) s->avctx->pix_fmt = s->cs_itu601 ? AV_PIX_FMT_YUV422P : AV_PIX_FMT_YUVJ422P; else s->avctx->pix_fmt = AV_PIX_FMT_YUV422P16; @@ -533,11 +534,11 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) if (pix_fmt_id == 0x42111100) { if (s->bits > 8) goto unk_pixfmt; - s->upscale_h = 6; + s->upscale_h[1] = s->upscale_h[2] = 1; } else if (pix_fmt_id == 0x24111100) { if (s->bits > 8) goto unk_pixfmt; - s->upscale_v = 6; + s->upscale_v[1] = s->upscale_v[2] = 1; } break; case 0x41111100: @@ -549,15 +550,17 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s) default: unk_pixfmt: av_log(s->avctx, AV_LOG_ERROR, "Unhandled pixel format 0x%x bits:%d\n", pix_fmt_id, s->bits); - s->upscale_h = s->upscale_v = 0; + memset(s->upscale_h, 0, sizeof(s->upscale_h)); + memset(s->upscale_v, 0, sizeof(s->upscale_v)); return AVERROR_PATCHWELCOME; } - if ((s->upscale_h || s->upscale_v) && s->avctx->lowres) { + if ((AV_RB32(s->upscale_h) || AV_RB32(s->upscale_v)) && s->avctx->lowres) { av_log(s->avctx, AV_LOG_ERROR, "lowres not supported for weird subsampling\n"); return AVERROR_PATCHWELCOME; } if (s->ls) { - s->upscale_h = s->upscale_v = 0; + memset(s->upscale_h, 0, sizeof(s->upscale_h)); + memset(s->upscale_v, 0, sizeof(s->upscale_v)); if (s->nb_components == 3) { s->avctx->pix_fmt = AV_PIX_FMT_RGB24; } else if (s->nb_components != 1) { @@ -2129,7 +2132,7 @@ the_end: is16bit = av_pix_fmt_desc_get(s->avctx->pix_fmt)->comp[0].step_minus1; - if (s->upscale_h) { + if (AV_RB32(s->upscale_h)) { int p; av_assert0(avctx->pix_fmt == AV_PIX_FMT_YUVJ444P || avctx->pix_fmt == AV_PIX_FMT_YUV444P || @@ -2149,13 +2152,13 @@ the_end: uint8_t *line = s->picture_ptr->data[p]; int w = s->width; int h = s->height; - if (!(s->upscale_h & (1<upscale_h[p]) continue; if (p==1 || p==2) { w = FF_CEIL_RSHIFT(w, hshift); h = FF_CEIL_RSHIFT(h, vshift); } - if (s->upscale_v & (1<upscale_v[p]) h = (h+1)>>1; av_assert0(w > 0); for (i = 0; i < h; i++) { @@ -2171,7 +2174,7 @@ the_end: } } } - if (s->upscale_v) { + if (AV_RB32(s->upscale_v)) { int p; av_assert0(avctx->pix_fmt == AV_PIX_FMT_YUVJ444P || avctx->pix_fmt == AV_PIX_FMT_YUV444P || @@ -2192,7 +2195,7 @@ the_end: uint8_t *dst; int w = s->width; int h = s->height; - if (!(s->upscale_v & (1<upscale_v[p]) continue; if (p==1 || p==2) { w = FF_CEIL_RSHIFT(w, hshift); diff --git a/libavcodec/mjpegdec.h b/libavcodec/mjpegdec.h index deacabe752..28d3e4aa7d 100644 --- a/libavcodec/mjpegdec.h +++ b/libavcodec/mjpegdec.h @@ -62,8 +62,8 @@ typedef struct MJpegDecodeContext { int ls; int progressive; int rgb; - int upscale_h; - int upscale_v; + uint8_t upscale_h[4]; + uint8_t upscale_v[4]; int rct; /* standard rct */ int pegasus_rct; /* pegasus reversible colorspace transform */ int bits; /* bits per component */