--- libavcodec/intrax8.c | 65 ++++++++++++++++++++++++++-------------------------- libavcodec/intrax8.h | 7 ++++++ libavcodec/vc1dec.c | 4 +++- libavcodec/wmv2dec.c | 3 ++- 4 files changed, 44 insertions(+), 35 deletions(-)
diff --git a/libavcodec/intrax8.c b/libavcodec/intrax8.c index 18803b4..8ac3417 100644 --- a/libavcodec/intrax8.c +++ b/libavcodec/intrax8.c @@ -381,9 +381,7 @@ static int x8_setup_spatial_predictor(IntraX8Context *const w, const int chroma) static void x8_update_predictions(IntraX8Context *const w, const int orient, const int est_run) { - MpegEncContext *const s = w->s; - - w->prediction_table[s->mb_x * 2 + (s->mb_y & 1)] = (est_run << 2) + 1 * (orient == 4) + 2 * (orient == 8); + w->prediction_table[w->mb_x * 2 + (w->mb_y & 1)] = (est_run << 2) + 1 * (orient == 4) + 2 * (orient == 8); /* * y = 2n + 0 -> // 0 2 4 * y = 2n + 1 -> // 1 3 5 @@ -392,11 +390,9 @@ static void x8_update_predictions(IntraX8Context *const w, const int orient, static void x8_get_prediction_chroma(IntraX8Context *const w) { - MpegEncContext *const s = w->s; - - w->edges = 1 * (!(s->mb_x >> 1)); - w->edges |= 2 * (!(s->mb_y >> 1)); - w->edges |= 4 * (s->mb_x >= (2 * s->mb_width - 1)); // mb_x for chroma would always be odd + w->edges = 1 * (!(w->mb_x >> 1)); + w->edges |= 2 * (!(w->mb_y >> 1)); + w->edges |= 4 * (w->mb_x >= (2 * w->mb_width - 1)); // mb_x for chroma would always be odd w->raw_orient = 0; if (w->edges & 3) { @@ -405,29 +401,28 @@ static void x8_get_prediction_chroma(IntraX8Context *const w) return; } // block[x - 1][y | 1 - 1)] - w->chroma_orient = (w->prediction_table[2 * s->mb_x - 2] & 0x03) << 2; + w->chroma_orient = (w->prediction_table[2 * w->mb_x - 2] & 0x03) << 2; } static void x8_get_prediction(IntraX8Context *const w) { - MpegEncContext *const s = w->s; int a, b, c, i; - w->edges = 1 * (!s->mb_x); - w->edges |= 2 * (!s->mb_y); - w->edges |= 4 * (s->mb_x >= (2 * s->mb_width - 1)); + w->edges = 1 * (!w->mb_x); + w->edges |= 2 * (!w->mb_y); + w->edges |= 4 * (w->mb_x >= (2 * w->mb_width - 1)); switch (w->edges & 3) { case 0: break; case 1: // take the one from the above block[0][y - 1] - w->est_run = w->prediction_table[!(s->mb_y & 1)] >> 2; + w->est_run = w->prediction_table[!(w->mb_y & 1)] >> 2; w->orient = 1; return; case 2: // take the one from the previous block[x - 1][0] - w->est_run = w->prediction_table[2 * s->mb_x - 2] >> 2; + w->est_run = w->prediction_table[2 * w->mb_x - 2] >> 2; w->orient = 2; return; case 3: @@ -436,15 +431,15 @@ static void x8_get_prediction(IntraX8Context *const w) return; } // no edge cases - b = w->prediction_table[2 * s->mb_x + !(s->mb_y & 1)]; // block[x ][y- 1] - a = w->prediction_table[2 * s->mb_x - 2 + (s->mb_y & 1)]; // block[x - 1][y ] - c = w->prediction_table[2 * s->mb_x - 2 + !(s->mb_y & 1)]; // block[x - 1][y -1] + b = w->prediction_table[2 * w->mb_x + !(w->mb_y & 1)]; // block[x ][y- 1] + a = w->prediction_table[2 * w->mb_x - 2 + (w->mb_y & 1)]; // block[x - 1][y ] + c = w->prediction_table[2 * w->mb_x - 2 + !(w->mb_y & 1)]; // block[x - 1][y -1] w->est_run = FFMIN(b, a); /* This condition has nothing to do with w->edges, even if it looks * similar it would trigger if e.g. x = 3; y = 2; * I guess somebody wrote something wrong and it became standard. */ - if ((s->mb_x & s->mb_y) != 0) + if ((w->mb_x & w->mb_y) != 0) w->est_run = FFMIN(c, w->est_run); w->est_run >>= 2; @@ -713,7 +708,7 @@ block_placed: } // FIXME maybe merge with ff_* -static void x8_init_block_index(IntraX8Context *w, AVFrame *frame, int mb_y) +static void x8_init_block_index(IntraX8Context *w, AVFrame *frame) { // not parent codec linesize as this would be wrong for field pics // not that IntraX8 has interlacing support ;) @@ -724,14 +719,15 @@ static void x8_init_block_index(IntraX8Context *w, AVFrame *frame, int mb_y) w->dest[1] = frame->data[1]; w->dest[2] = frame->data[2]; - w->dest[0] += mb_y * linesize << 3; + w->dest[0] += w->mb_y * linesize << 3; // chroma blocks are on add rows - w->dest[1] += (mb_y & (~1)) * uvlinesize << 2; - w->dest[2] += (mb_y & (~1)) * uvlinesize << 2; + w->dest[1] += (w->mb_y & (~1)) * uvlinesize << 2; + w->dest[2] += (w->mb_y & (~1)) * uvlinesize << 2; } av_cold int ff_intrax8_common_init(AVCodecContext *avctx, IntraX8Context *w, IDCTDSPContext *idsp, + int mb_width, int mb_height, MpegEncContext *const s) { int ret = x8_vlc_init(); @@ -740,10 +736,14 @@ av_cold int ff_intrax8_common_init(AVCodecContext *avctx, w->avctx = avctx; w->idsp = *idsp; + w->mb_x = 0; + w->mb_y = 0; + w->mb_width = mb_width; + w->mb_height = mb_height; w->s = s; // two rows, 2 blocks per cannon mb - w->prediction_table = av_mallocz(s->mb_width * 2 * 2); + w->prediction_table = av_mallocz(w->mb_width * 2 * 2); if (!w->prediction_table) return AVERROR(ENOMEM); @@ -800,18 +800,17 @@ int ff_intrax8_decode_picture(IntraX8Context *const w, Picture *pict, s->resync_mb_x = 0; s->resync_mb_y = 0; - for (s->mb_y = 0; s->mb_y < s->mb_height * 2; s->mb_y++) { - x8_init_block_index(w, w->frame, s->mb_y); - mb_xy = (s->mb_y >> 1) * s->mb_stride; - - for (s->mb_x = 0; s->mb_x < s->mb_width * 2; s->mb_x++) { + for (w->mb_y = 0; w->mb_y < w->mb_height * 2; w->mb_y++) { + x8_init_block_index(w, w->frame); + mb_xy = (w->mb_y >> 1) * (w->mb_width + 1); + for (w->mb_x = 0; w->mb_x < w->mb_width * 2; w->mb_x++) { x8_get_prediction(w); if (x8_setup_spatial_predictor(w, 0)) goto error; if (x8_decode_intra_mb(w, 0)) goto error; - if (s->mb_x & s->mb_y & 1) { + if (w->mb_x & w->mb_y & 1) { x8_get_prediction_chroma(w); /* when setting up chroma, no vlc is read, @@ -835,13 +834,13 @@ int ff_intrax8_decode_picture(IntraX8Context *const w, Picture *pict, } w->dest[0] += 8; } - if (s->mb_y & 1) - ff_mpeg_draw_horiz_band(s, (s->mb_y - 1) * 8, 16); + if (w->mb_y & 1) + ff_mpeg_draw_horiz_band(s, (w->mb_y - 1) * 8, 16); } error: ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, - (s->mb_x >> 1) - 1, (s->mb_y >> 1) - 1, + (w->mb_x >> 1) - 1, (w->mb_y >> 1) - 1, ER_MB_END); return 0; } diff --git a/libavcodec/intrax8.h b/libavcodec/intrax8.h index 4b69b34..29fac89 100644 --- a/libavcodec/intrax8.h +++ b/libavcodec/intrax8.h @@ -66,6 +66,10 @@ typedef struct IntraX8Context { int chroma_orient; int orient; int est_run; + + // block props + int mb_x, mb_y; + int mb_width, mb_height; } IntraX8Context; /** @@ -74,11 +78,14 @@ typedef struct IntraX8Context { * @param avctx pointer to AVCodecContext * @param w pointer to IntraX8Context * @param idsp pointer to IDCTDSPContext + * @param mb_width macroblock width + * @param mb_height macroblock height * @param s pointer to MpegEncContext of the parent codec * @return 0 on success, < 0 on error */ int ff_intrax8_common_init(AVCodecContext *avctx, IntraX8Context *w, IDCTDSPContext *idsp, + int mb_width, int mb_height, MpegEncContext *const s); /** diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index b929401..b31089d 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -360,7 +360,9 @@ av_cold int ff_vc1_decode_init_alloc_tables(VC1Context *v) // return -1; } - ret = ff_intrax8_common_init(s->avctx, &v->x8, &s->idsp, s); + ret = ff_intrax8_common_init(s->avctx, &v->x8, &s->idsp, + s->mb_width, s->mb_height, + s); if (s->avctx->codec_id == AV_CODEC_ID_WMV3IMAGE || s->avctx->codec_id == AV_CODEC_ID_VC1IMAGE) { for (i = 0; i < 4; i++) diff --git a/libavcodec/wmv2dec.c b/libavcodec/wmv2dec.c index 381a3da..1eccc1f 100644 --- a/libavcodec/wmv2dec.c +++ b/libavcodec/wmv2dec.c @@ -469,7 +469,8 @@ static av_cold int wmv2_decode_init(AVCodecContext *avctx) ff_wmv2_common_init(w); - return ff_intrax8_common_init(avctx, &w->x8, &w->s.idsp, &w->s); + return ff_intrax8_common_init(avctx, &w->x8, &w->s.idsp, + w->s.mb_width, w->s.mb_height, &w->s); } static av_cold int wmv2_decode_end(AVCodecContext *avctx) -- 2.7.0 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel