Lines Matching refs:w
93 static void x8_reset_vlc_tables(IntraX8Context *w) in x8_reset_vlc_tables() argument
95 memset(w->j_dc_vlc, 0, sizeof(w->j_dc_vlc)); in x8_reset_vlc_tables()
96 memset(w->j_ac_vlc, 0, sizeof(w->j_ac_vlc)); in x8_reset_vlc_tables()
97 w->j_orient_vlc = NULL; in x8_reset_vlc_tables()
100 static inline void x8_select_ac_table(IntraX8Context *const w, int mode) in x8_select_ac_table() argument
106 if (w->j_ac_vlc[mode]) in x8_select_ac_table()
109 table_index = get_bits(w->gb, 3); in x8_select_ac_table()
111 w->j_ac_vlc[mode] = &j_ac_vlc[w->quant < 13][mode >> 1][table_index]; in x8_select_ac_table()
112 av_assert2(w->j_ac_vlc[mode]); in x8_select_ac_table()
115 static inline int x8_get_orient_vlc(IntraX8Context *w) in x8_get_orient_vlc() argument
117 if (!w->j_orient_vlc) { in x8_get_orient_vlc()
118 int table_index = get_bits(w->gb, 1 + (w->quant < 13)); in x8_get_orient_vlc()
119 w->j_orient_vlc = &j_orient_vlc[w->quant < 13][table_index]; in x8_get_orient_vlc()
122 return get_vlc2(w->gb, w->j_orient_vlc->table, OR_VLC_BITS, OR_VLC_MTD); in x8_get_orient_vlc()
172 static void x8_get_ac_rlf(IntraX8Context *const w, const int mode, in x8_get_ac_rlf() argument
178 i = get_vlc2(w->gb, w->j_ac_vlc[mode]->table, AC_VLC_BITS, AC_VLC_MTD); in x8_get_ac_rlf()
217 e = get_bits(w->gb, sm & 0xF); in x8_get_ac_rlf()
234 e = get_bits(w->gb, 5); // get the extra bits in x8_get_ac_rlf()
238 *level = get_bits(w->gb, 7 - 3 * (i & 1)); in x8_get_ac_rlf()
239 *run = get_bits(w->gb, 6); in x8_get_ac_rlf()
240 *final = get_bits1(w->gb); in x8_get_ac_rlf()
252 static int x8_get_dc_rlf(IntraX8Context *const w, const int mode, in x8_get_dc_rlf() argument
258 if (!w->j_dc_vlc[mode]) { in x8_get_dc_rlf()
259 int table_index = get_bits(w->gb, 3); in x8_get_dc_rlf()
261 w->j_dc_vlc[mode] = &j_dc_vlc[w->quant < 13][table_index]; in x8_get_dc_rlf()
264 i = get_vlc2(w->gb, w->j_dc_vlc[mode]->table, DC_VLC_BITS, DC_VLC_MTD); in x8_get_dc_rlf()
278 e = get_bits(w->gb, c); // get the extra bits in x8_get_dc_rlf()
288 static int x8_setup_spatial_predictor(IntraX8Context *const w, const int chroma) in x8_setup_spatial_predictor() argument
294 w->dsp.setup_spatial_compensation(w->dest[chroma], w->scratchpad, in x8_setup_spatial_predictor()
295 w->frame->linesize[chroma > 0], in x8_setup_spatial_predictor()
296 &range, &sum, w->edges); in x8_setup_spatial_predictor()
298 w->orient = w->chroma_orient; in x8_setup_spatial_predictor()
299 quant = w->quant_dc_chroma; in x8_setup_spatial_predictor()
301 quant = w->quant; in x8_setup_spatial_predictor()
304 w->flat_dc = 0; in x8_setup_spatial_predictor()
306 w->orient = 0; in x8_setup_spatial_predictor()
310 w->flat_dc = 1; in x8_setup_spatial_predictor()
313 w->predicted_dc = sum * 6899 >> 17; in x8_setup_spatial_predictor()
319 av_assert2(w->orient < 3); in x8_setup_spatial_predictor()
320 if (range < 2 * w->quant) { in x8_setup_spatial_predictor()
321 if ((w->edges & 3) == 0) { in x8_setup_spatial_predictor()
322 if (w->orient == 1) in x8_setup_spatial_predictor()
323 w->orient = 11; in x8_setup_spatial_predictor()
324 if (w->orient == 2) in x8_setup_spatial_predictor()
325 w->orient = 10; in x8_setup_spatial_predictor()
327 w->orient = 0; in x8_setup_spatial_predictor()
329 w->raw_orient = 0; in x8_setup_spatial_predictor()
336 w->raw_orient = x8_get_orient_vlc(w); in x8_setup_spatial_predictor()
337 if (w->raw_orient < 0) in x8_setup_spatial_predictor()
339 av_assert2(w->raw_orient < 12); in x8_setup_spatial_predictor()
340 av_assert2(w->orient < 3); in x8_setup_spatial_predictor()
341 w->orient=prediction_table[w->orient][w->raw_orient]; in x8_setup_spatial_predictor()
346 static void x8_update_predictions(IntraX8Context *const w, const int orient, in x8_update_predictions() argument
349 …w->prediction_table[w->mb_x * 2 + (w->mb_y & 1)] = (est_run << 2) + 1 * (orient == 4) + 2 * (orien… in x8_update_predictions()
356 static void x8_get_prediction_chroma(IntraX8Context *const w) in x8_get_prediction_chroma() argument
358 w->edges = 1 * !(w->mb_x >> 1); in x8_get_prediction_chroma()
359 w->edges |= 2 * !(w->mb_y >> 1); in x8_get_prediction_chroma()
360 w->edges |= 4 * (w->mb_x >= (2 * w->mb_width - 1)); // mb_x for chroma would always be odd in x8_get_prediction_chroma()
362 w->raw_orient = 0; in x8_get_prediction_chroma()
364 if (w->edges & 3) { in x8_get_prediction_chroma()
365 w->chroma_orient = 4 << ((0xCC >> w->edges) & 1); in x8_get_prediction_chroma()
369 w->chroma_orient = (w->prediction_table[2 * w->mb_x - 2] & 0x03) << 2; in x8_get_prediction_chroma()
372 static void x8_get_prediction(IntraX8Context *const w) in x8_get_prediction() argument
376 w->edges = 1 * !w->mb_x; in x8_get_prediction()
377 w->edges |= 2 * !w->mb_y; in x8_get_prediction()
378 w->edges |= 4 * (w->mb_x >= (2 * w->mb_width - 1)); in x8_get_prediction()
380 switch (w->edges & 3) { in x8_get_prediction()
385 w->est_run = w->prediction_table[!(w->mb_y & 1)] >> 2; in x8_get_prediction()
386 w->orient = 1; in x8_get_prediction()
390 w->est_run = w->prediction_table[2 * w->mb_x - 2] >> 2; in x8_get_prediction()
391 w->orient = 2; in x8_get_prediction()
394 w->est_run = 16; in x8_get_prediction()
395 w->orient = 0; in x8_get_prediction()
399 b = w->prediction_table[2 * w->mb_x + !(w->mb_y & 1)]; // block[x ][y - 1] in x8_get_prediction()
400 a = w->prediction_table[2 * w->mb_x - 2 + (w->mb_y & 1)]; // block[x - 1][y ] in x8_get_prediction()
401 c = w->prediction_table[2 * w->mb_x - 2 + !(w->mb_y & 1)]; // block[x - 1][y - 1] in x8_get_prediction()
403 w->est_run = FFMIN(b, a); in x8_get_prediction()
407 if ((w->mb_x & w->mb_y) != 0) in x8_get_prediction()
408 w->est_run = FFMIN(c, w->est_run); in x8_get_prediction()
409 w->est_run >>= 2; in x8_get_prediction()
417 w->orient = i; in x8_get_prediction()
419 w->orient = (0xFFEAD8 >> (2 * c + 8 * (w->quant > 12))) & 3; in x8_get_prediction()
441 static void x8_ac_compensation(IntraX8Context *const w, const int direction, in x8_ac_compensation() argument
445 #define B(x,y) w->block[0][w->idct_permutation[(x) + (y) * 8]] in x8_ac_compensation()
489 w->block_last_index[0] = FFMAX(w->block_last_index[0], 7 * 8); in x8_ac_compensation()
497 w->block_last_index[0] = FFMAX(w->block_last_index[0], 7 * 8); in x8_ac_compensation()
505 w->block_last_index[0] = FFMAX(w->block_last_index[0], 7); in x8_ac_compensation()
533 static int x8_decode_intra_mb(IntraX8Context *const w, const int chroma) in x8_decode_intra_mb() argument
543 av_assert2(w->orient < 12); in x8_decode_intra_mb()
544 w->bdsp.clear_block(w->block[0]); in x8_decode_intra_mb()
549 dc_mode = !!w->est_run; // 0, 1 in x8_decode_intra_mb()
551 if (x8_get_dc_rlf(w, dc_mode, &dc_level, &final)) in x8_decode_intra_mb()
556 use_quant_matrix = w->use_quant_matrix; in x8_decode_intra_mb()
561 if (w->raw_orient < 3) in x8_decode_intra_mb()
564 if (w->raw_orient > 4) { in x8_decode_intra_mb()
568 if (w->est_run > 1) { in x8_decode_intra_mb()
570 est_run = w->est_run; in x8_decode_intra_mb()
577 x8_select_ac_table(w, ac_mode); in x8_decode_intra_mb()
580 scantable = w->scantable[(0x928548 >> (2 * w->orient)) & 3].permutated; in x8_decode_intra_mb()
586 x8_select_ac_table(w, 3); in x8_decode_intra_mb()
589 x8_get_ac_rlf(w, ac_mode, &run, &level, &final); in x8_decode_intra_mb()
596 level = (level + 1) * w->dquant; in x8_decode_intra_mb()
597 level += w->qsum; in x8_decode_intra_mb()
599 sign = -get_bits1(w->gb); in x8_decode_intra_mb()
605 w->block[0][scantable[pos]] = level; in x8_decode_intra_mb()
608 w->block_last_index[0] = pos; in x8_decode_intra_mb()
610 w->block_last_index[0] = 0; in x8_decode_intra_mb()
611 if (w->flat_dc && ((unsigned) (dc_level + 1)) < 3) { // [-1; 1] in x8_decode_intra_mb()
612 int32_t divide_quant = !chroma ? w->divide_quant_dc_luma in x8_decode_intra_mb()
613 : w->divide_quant_dc_chroma; in x8_decode_intra_mb()
614 int32_t dc_quant = !chroma ? w->quant in x8_decode_intra_mb()
615 : w->quant_dc_chroma; in x8_decode_intra_mb()
619 dc_level += (w->predicted_dc * divide_quant + (1 << 12)) >> 13; in x8_decode_intra_mb()
622 w->dest[chroma], in x8_decode_intra_mb()
623 w->frame->linesize[!!chroma]); in x8_decode_intra_mb()
630 w->block[0][0] = dc_level * w->quant; in x8_decode_intra_mb()
632 w->block[0][0] = dc_level * w->quant_dc_chroma; in x8_decode_intra_mb()
635 if ((unsigned int) (dc_level + 1) >= 3 && (w->edges & 3) != 3) { in x8_decode_intra_mb()
639 direction = (0x6A017C >> (w->orient * 2)) & 3; in x8_decode_intra_mb()
642 x8_ac_compensation(w, direction, w->block[0][0]); in x8_decode_intra_mb()
646 if (w->flat_dc) { in x8_decode_intra_mb()
647 dsp_x8_put_solidcolor(w->predicted_dc, w->dest[chroma], in x8_decode_intra_mb()
648 w->frame->linesize[!!chroma]); in x8_decode_intra_mb()
650 w->dsp.spatial_compensation[w->orient](w->scratchpad, in x8_decode_intra_mb()
651 w->dest[chroma], in x8_decode_intra_mb()
652 w->frame->linesize[!!chroma]); in x8_decode_intra_mb()
655 w->wdsp.idct_add(w->dest[chroma], in x8_decode_intra_mb()
656 w->frame->linesize[!!chroma], in x8_decode_intra_mb()
657 w->block[0]); in x8_decode_intra_mb()
661 x8_update_predictions(w, w->orient, n); in x8_decode_intra_mb()
663 if (w->loopfilter) { in x8_decode_intra_mb()
664 uint8_t *ptr = w->dest[chroma]; in x8_decode_intra_mb()
665 ptrdiff_t linesize = w->frame->linesize[!!chroma]; in x8_decode_intra_mb()
667 if (!((w->edges & 2) || (zeros_only && (w->orient | 4) == 4))) in x8_decode_intra_mb()
668 w->dsp.h_loop_filter(ptr, linesize, w->quant); in x8_decode_intra_mb()
670 if (!((w->edges & 1) || (zeros_only && (w->orient | 8) == 8))) in x8_decode_intra_mb()
671 w->dsp.v_loop_filter(ptr, linesize, w->quant); in x8_decode_intra_mb()
677 static void x8_init_block_index(IntraX8Context *w, AVFrame *frame) in x8_init_block_index() argument
684 w->dest[0] = frame->data[0]; in x8_init_block_index()
685 w->dest[1] = frame->data[1]; in x8_init_block_index()
686 w->dest[2] = frame->data[2]; in x8_init_block_index()
688 w->dest[0] += w->mb_y * linesize << 3; in x8_init_block_index()
690 w->dest[1] += (w->mb_y & ~1) * uvlinesize << 2; in x8_init_block_index()
691 w->dest[2] += (w->mb_y & ~1) * uvlinesize << 2; in x8_init_block_index()
695 IntraX8Context *w, IDCTDSPContext *idsp, in ff_intrax8_common_init() argument
702 w->avctx = avctx; in ff_intrax8_common_init()
703 w->idsp = *idsp; in ff_intrax8_common_init()
704 w->mb_width = mb_width; in ff_intrax8_common_init()
705 w->mb_height = mb_height; in ff_intrax8_common_init()
706 w->block = block; in ff_intrax8_common_init()
707 w->block_last_index = block_last_index; in ff_intrax8_common_init()
710 w->prediction_table = av_mallocz(w->mb_width * 2 * 2); in ff_intrax8_common_init()
711 if (!w->prediction_table) in ff_intrax8_common_init()
714 ff_wmv2dsp_init(&w->wdsp); in ff_intrax8_common_init()
716 ff_init_scantable_permutation(w->idct_permutation, in ff_intrax8_common_init()
717 w->wdsp.idct_perm); in ff_intrax8_common_init()
719 ff_init_scantable(w->idct_permutation, &w->scantable[0], in ff_intrax8_common_init()
721 ff_init_scantable(w->idct_permutation, &w->scantable[1], in ff_intrax8_common_init()
723 ff_init_scantable(w->idct_permutation, &w->scantable[2], in ff_intrax8_common_init()
726 ff_intrax8dsp_init(&w->dsp); in ff_intrax8_common_init()
727 ff_blockdsp_init(&w->bdsp, avctx); in ff_intrax8_common_init()
734 av_cold void ff_intrax8_common_end(IntraX8Context *w) in ff_intrax8_common_end() argument
736 av_freep(&w->prediction_table); in ff_intrax8_common_end()
739 int ff_intrax8_decode_picture(IntraX8Context *w, Picture *pict, in ff_intrax8_decode_picture() argument
746 w->gb = gb; in ff_intrax8_decode_picture()
747 w->dquant = dquant; in ff_intrax8_decode_picture()
748 w->quant = dquant >> 1; in ff_intrax8_decode_picture()
749 w->qsum = quant_offset; in ff_intrax8_decode_picture()
750 w->frame = pict->f; in ff_intrax8_decode_picture()
751 w->loopfilter = loopfilter; in ff_intrax8_decode_picture()
752 w->use_quant_matrix = get_bits1(w->gb); in ff_intrax8_decode_picture()
754 w->mb_x = *mb_x; in ff_intrax8_decode_picture()
755 w->mb_y = *mb_y; in ff_intrax8_decode_picture()
757 w->divide_quant_dc_luma = ((1 << 16) + (w->quant >> 1)) / w->quant; in ff_intrax8_decode_picture()
758 if (w->quant < 5) { in ff_intrax8_decode_picture()
759 w->quant_dc_chroma = w->quant; in ff_intrax8_decode_picture()
760 w->divide_quant_dc_chroma = w->divide_quant_dc_luma; in ff_intrax8_decode_picture()
762 w->quant_dc_chroma = w->quant + ((w->quant + 3) >> 3); in ff_intrax8_decode_picture()
763 w->divide_quant_dc_chroma = ((1 << 16) + (w->quant_dc_chroma >> 1)) / w->quant_dc_chroma; in ff_intrax8_decode_picture()
765 x8_reset_vlc_tables(w); in ff_intrax8_decode_picture()
767 for (w->mb_y = 0; w->mb_y < w->mb_height * 2; w->mb_y++) { in ff_intrax8_decode_picture()
768 x8_init_block_index(w, w->frame); in ff_intrax8_decode_picture()
769 mb_xy = (w->mb_y >> 1) * (w->mb_width + 1); in ff_intrax8_decode_picture()
772 for (w->mb_x = 0; w->mb_x < w->mb_width * 2; w->mb_x++) { in ff_intrax8_decode_picture()
773 x8_get_prediction(w); in ff_intrax8_decode_picture()
774 if (x8_setup_spatial_predictor(w, 0)) in ff_intrax8_decode_picture()
776 if (x8_decode_intra_mb(w, 0)) in ff_intrax8_decode_picture()
779 if (w->mb_x & w->mb_y & 1) { in ff_intrax8_decode_picture()
780 x8_get_prediction_chroma(w); in ff_intrax8_decode_picture()
784 x8_setup_spatial_predictor(w, 1); in ff_intrax8_decode_picture()
785 if (x8_decode_intra_mb(w, 1)) in ff_intrax8_decode_picture()
788 x8_setup_spatial_predictor(w, 2); in ff_intrax8_decode_picture()
789 if (x8_decode_intra_mb(w, 2)) in ff_intrax8_decode_picture()
792 w->dest[1] += 8; in ff_intrax8_decode_picture()
793 w->dest[2] += 8; in ff_intrax8_decode_picture()
795 pict->qscale_table[mb_xy] = w->quant; in ff_intrax8_decode_picture()
798 w->dest[0] += 8; in ff_intrax8_decode_picture()
800 if (w->mb_y & 1) in ff_intrax8_decode_picture()
801 ff_draw_horiz_band(w->avctx, w->frame, w->frame, in ff_intrax8_decode_picture()
802 (w->mb_y - 1) * 8, 16, in ff_intrax8_decode_picture()
807 *mb_x = w->mb_x; in ff_intrax8_decode_picture()
808 *mb_y = w->mb_y; in ff_intrax8_decode_picture()