1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

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 <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2015-03-18 23:05:22 +01:00
parent ee648903f5
commit e15455891b
2 changed files with 25 additions and 22 deletions

View File

@ -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<<p)))
if (!s->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<<p))
if (s->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<<p)))
if (!s->upscale_v[p])
continue;
if (p==1 || p==2) {
w = FF_CEIL_RSHIFT(w, hshift);

View File

@ -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 */