1635 lines · 59.3 KB · C
RawDownload
/* *  Copyright (c) 2010 The WebM project authors. All Rights Reserved. * *  Use of this source code is governed by a BSD-style license *  that can be found in the LICENSE file in the root of the source *  tree. An additional intellectual property rights grant can be found *  in the file PATENTS.  All contributing project authors may *  be found in the AUTHORS file in the root of the source tree. */ #include "./vpx_config.h"#include "./vpx_dsp_rtcd.h"#include "vp9/common/vp9_loopfilter.h"#include "vp9/common/vp9_onyxc_int.h"#include "vp9/common/vp9_reconinter.h"#include "vpx_dsp/vpx_dsp_common.h"#include "vpx_mem/vpx_mem.h"#include "vpx_ports/mem.h" #include "vp9/common/vp9_seg_common.h" // 64 bit masks for left transform size. Each 1 represents a position where// we should apply a loop filter across the left border of an 8x8 block// boundary.//// In the case of TX_16X16->  ( in low order byte first we end up with// a mask that looks like this////    10101010//    10101010//    10101010//    10101010//    10101010//    10101010//    10101010//    10101010//// A loopfilter should be applied to every other 8x8 horizontally.static const uint64_t left_64x64_txform_mask[TX_SIZES] = {  0xffffffffffffffffULL,  // TX_4X4  0xffffffffffffffffULL,  // TX_8x8  0x5555555555555555ULL,  // TX_16x16  0x1111111111111111ULL,  // TX_32x32}; // 64 bit masks for above transform size. Each 1 represents a position where// we should apply a loop filter across the top border of an 8x8 block// boundary.//// In the case of TX_32x32 ->  ( in low order byte first we end up with// a mask that looks like this////    11111111//    00000000//    00000000//    00000000//    11111111//    00000000//    00000000//    00000000//// A loopfilter should be applied to every other 4 the row vertically.static const uint64_t above_64x64_txform_mask[TX_SIZES] = {  0xffffffffffffffffULL,  // TX_4X4  0xffffffffffffffffULL,  // TX_8x8  0x00ff00ff00ff00ffULL,  // TX_16x16  0x000000ff000000ffULL,  // TX_32x32}; // 64 bit masks for prediction sizes (left). Each 1 represents a position// where left border of an 8x8 block. These are aligned to the right most// appropriate bit, and then shifted into place.//// In the case of TX_16x32 ->  ( low order byte first ) we end up with// a mask that looks like this :////  10000000//  10000000//  10000000//  10000000//  00000000//  00000000//  00000000//  00000000static const uint64_t left_prediction_mask[BLOCK_SIZES] = {  0x0000000000000001ULL,  // BLOCK_4X4,  0x0000000000000001ULL,  // BLOCK_4X8,  0x0000000000000001ULL,  // BLOCK_8X4,  0x0000000000000001ULL,  // BLOCK_8X8,  0x0000000000000101ULL,  // BLOCK_8X16,  0x0000000000000001ULL,  // BLOCK_16X8,  0x0000000000000101ULL,  // BLOCK_16X16,  0x0000000001010101ULL,  // BLOCK_16X32,  0x0000000000000101ULL,  // BLOCK_32X16,  0x0000000001010101ULL,  // BLOCK_32X32,  0x0101010101010101ULL,  // BLOCK_32X64,  0x0000000001010101ULL,  // BLOCK_64X32,  0x0101010101010101ULL,  // BLOCK_64X64}; // 64 bit mask to shift and set for each prediction size.static const uint64_t above_prediction_mask[BLOCK_SIZES] = {  0x0000000000000001ULL,  // BLOCK_4X4  0x0000000000000001ULL,  // BLOCK_4X8  0x0000000000000001ULL,  // BLOCK_8X4  0x0000000000000001ULL,  // BLOCK_8X8  0x0000000000000001ULL,  // BLOCK_8X16,  0x0000000000000003ULL,  // BLOCK_16X8  0x0000000000000003ULL,  // BLOCK_16X16  0x0000000000000003ULL,  // BLOCK_16X32,  0x000000000000000fULL,  // BLOCK_32X16,  0x000000000000000fULL,  // BLOCK_32X32,  0x000000000000000fULL,  // BLOCK_32X64,  0x00000000000000ffULL,  // BLOCK_64X32,  0x00000000000000ffULL,  // BLOCK_64X64};// 64 bit mask to shift and set for each prediction size. A bit is set for// each 8x8 block that would be in the left most block of the given block// size in the 64x64 block.static const uint64_t size_mask[BLOCK_SIZES] = {  0x0000000000000001ULL,  // BLOCK_4X4  0x0000000000000001ULL,  // BLOCK_4X8  0x0000000000000001ULL,  // BLOCK_8X4  0x0000000000000001ULL,  // BLOCK_8X8  0x0000000000000101ULL,  // BLOCK_8X16,  0x0000000000000003ULL,  // BLOCK_16X8  0x0000000000000303ULL,  // BLOCK_16X16  0x0000000003030303ULL,  // BLOCK_16X32,  0x0000000000000f0fULL,  // BLOCK_32X16,  0x000000000f0f0f0fULL,  // BLOCK_32X32,  0x0f0f0f0f0f0f0f0fULL,  // BLOCK_32X64,  0x00000000ffffffffULL,  // BLOCK_64X32,  0xffffffffffffffffULL,  // BLOCK_64X64}; // These are used for masking the left and above borders.static const uint64_t left_border = 0x1111111111111111ULL;static const uint64_t above_border = 0x000000ff000000ffULL; // 16 bit masks for uv transform sizes.static const uint16_t left_64x64_txform_mask_uv[TX_SIZES] = {  0xffff,  // TX_4X4  0xffff,  // TX_8x8  0x5555,  // TX_16x16  0x1111,  // TX_32x32}; static const uint16_t above_64x64_txform_mask_uv[TX_SIZES] = {  0xffff,  // TX_4X4  0xffff,  // TX_8x8  0x0f0f,  // TX_16x16  0x000f,  // TX_32x32}; // 16 bit left mask to shift and set for each uv prediction size.static const uint16_t left_prediction_mask_uv[BLOCK_SIZES] = {  0x0001,  // BLOCK_4X4,  0x0001,  // BLOCK_4X8,  0x0001,  // BLOCK_8X4,  0x0001,  // BLOCK_8X8,  0x0001,  // BLOCK_8X16,  0x0001,  // BLOCK_16X8,  0x0001,  // BLOCK_16X16,  0x0011,  // BLOCK_16X32,  0x0001,  // BLOCK_32X16,  0x0011,  // BLOCK_32X32,  0x1111,  // BLOCK_32X64  0x0011,  // BLOCK_64X32,  0x1111,  // BLOCK_64X64};// 16 bit above mask to shift and set for uv each prediction size.static const uint16_t above_prediction_mask_uv[BLOCK_SIZES] = {  0x0001,  // BLOCK_4X4  0x0001,  // BLOCK_4X8  0x0001,  // BLOCK_8X4  0x0001,  // BLOCK_8X8  0x0001,  // BLOCK_8X16,  0x0001,  // BLOCK_16X8  0x0001,  // BLOCK_16X16  0x0001,  // BLOCK_16X32,  0x0003,  // BLOCK_32X16,  0x0003,  // BLOCK_32X32,  0x0003,  // BLOCK_32X64,  0x000f,  // BLOCK_64X32,  0x000f,  // BLOCK_64X64}; // 64 bit mask to shift and set for each uv prediction sizestatic const uint16_t size_mask_uv[BLOCK_SIZES] = {  0x0001,  // BLOCK_4X4  0x0001,  // BLOCK_4X8  0x0001,  // BLOCK_8X4  0x0001,  // BLOCK_8X8  0x0001,  // BLOCK_8X16,  0x0001,  // BLOCK_16X8  0x0001,  // BLOCK_16X16  0x0011,  // BLOCK_16X32,  0x0003,  // BLOCK_32X16,  0x0033,  // BLOCK_32X32,  0x3333,  // BLOCK_32X64,  0x00ff,  // BLOCK_64X32,  0xffff,  // BLOCK_64X64};static const uint16_t left_border_uv = 0x1111;static const uint16_t above_border_uv = 0x000f; static const int mode_lf_lut[MB_MODE_COUNT] = {  0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  // INTRA_MODES  1, 1, 0, 1                     // INTER_MODES (ZEROMV == 0)}; static void update_sharpness(loop_filter_info_n *lfi, int sharpness_lvl) {  int lvl;   // For each possible value for the loop filter fill out limits  for (lvl = 0; lvl <= MAX_LOOP_FILTER; lvl++) {    // Set loop filter parameters that control sharpness.    int block_inside_limit = lvl >> ((sharpness_lvl > 0) + (sharpness_lvl > 4));     if (sharpness_lvl > 0) {      if (block_inside_limit > (9 - sharpness_lvl))        block_inside_limit = (9 - sharpness_lvl);    }     if (block_inside_limit < 1) block_inside_limit = 1;     memset(lfi->lfthr[lvl].lim, block_inside_limit, SIMD_WIDTH);    memset(lfi->lfthr[lvl].mblim, (2 * (lvl + 2) + block_inside_limit),           SIMD_WIDTH);  }} static uint8_t get_filter_level(const loop_filter_info_n *lfi_n,                                const MODE_INFO *mi) {  return lfi_n->lvl[mi->segment_id][mi->ref_frame[0]][mode_lf_lut[mi->mode]];} void vp9_loop_filter_init(VP9_COMMON *cm) {  loop_filter_info_n *lfi = &cm->lf_info;  struct loopfilter *lf = &cm->lf;  int lvl;   // init limits for given sharpness  update_sharpness(lfi, lf->sharpness_level);  lf->last_sharpness_level = lf->sharpness_level;   // init hev threshold const vectors  for (lvl = 0; lvl <= MAX_LOOP_FILTER; lvl++)    memset(lfi->lfthr[lvl].hev_thr, (lvl >> 4), SIMD_WIDTH);} void vp9_loop_filter_frame_init(VP9_COMMON *cm, int default_filt_lvl) {  int seg_id;  // n_shift is the multiplier for lf_deltas  // the multiplier is 1 for when filter_lvl is between 0 and 31;  // 2 when filter_lvl is between 32 and 63  const int scale = 1 << (default_filt_lvl >> 5);  loop_filter_info_n *const lfi = &cm->lf_info;  struct loopfilter *const lf = &cm->lf;  const struct segmentation *const seg = &cm->seg;   // update limits if sharpness has changed  if (lf->last_sharpness_level != lf->sharpness_level) {    update_sharpness(lfi, lf->sharpness_level);    lf->last_sharpness_level = lf->sharpness_level;  }   for (seg_id = 0; seg_id < MAX_SEGMENTS; seg_id++) {    int lvl_seg = default_filt_lvl;    if (segfeature_active(seg, seg_id, SEG_LVL_ALT_LF)) {      const int data = get_segdata(seg, seg_id, SEG_LVL_ALT_LF);      lvl_seg = clamp(          seg->abs_delta == SEGMENT_ABSDATA ? data : default_filt_lvl + data, 0,          MAX_LOOP_FILTER);    }     if (!lf->mode_ref_delta_enabled) {      // we could get rid of this if we assume that deltas are set to      // zero when not in use; encoder always uses deltas      memset(lfi->lvl[seg_id], lvl_seg, sizeof(lfi->lvl[seg_id]));    } else {      int ref, mode;      const int intra_lvl = lvl_seg + lf->ref_deltas[INTRA_FRAME] * scale;      lfi->lvl[seg_id][INTRA_FRAME][0] = clamp(intra_lvl, 0, MAX_LOOP_FILTER);       for (ref = LAST_FRAME; ref < MAX_REF_FRAMES; ++ref) {        for (mode = 0; mode < MAX_MODE_LF_DELTAS; ++mode) {          const int inter_lvl = lvl_seg + lf->ref_deltas[ref] * scale +                                lf->mode_deltas[mode] * scale;          lfi->lvl[seg_id][ref][mode] = clamp(inter_lvl, 0, MAX_LOOP_FILTER);        }      }    }  }} static void filter_selectively_vert_row2(    int subsampling_factor, uint8_t *s, int pitch, unsigned int mask_16x16,    unsigned int mask_8x8, unsigned int mask_4x4, unsigned int mask_4x4_int,    const loop_filter_thresh *lfthr, const uint8_t *lfl) {  const int dual_mask_cutoff = subsampling_factor ? 0xff : 0xffff;  const int lfl_forward = subsampling_factor ? 4 : 8;  const unsigned int dual_one = 1 | (1 << lfl_forward);  unsigned int mask;  uint8_t *ss[2];  ss[0] = s;   for (mask =           (mask_16x16 | mask_8x8 | mask_4x4 | mask_4x4_int) & dual_mask_cutoff;       mask; mask = (mask & ~dual_one) >> 1) {    if (mask & dual_one) {      const loop_filter_thresh *lfis[2];      lfis[0] = lfthr + *lfl;      lfis[1] = lfthr + *(lfl + lfl_forward);      ss[1] = ss[0] + 8 * pitch;       if (mask_16x16 & dual_one) {        if ((mask_16x16 & dual_one) == dual_one) {          vpx_lpf_vertical_16_dual(ss[0], pitch, lfis[0]->mblim, lfis[0]->lim,                                   lfis[0]->hev_thr);        } else {          const loop_filter_thresh *lfi = lfis[!(mask_16x16 & 1)];          vpx_lpf_vertical_16(ss[!(mask_16x16 & 1)], pitch, lfi->mblim,                              lfi->lim, lfi->hev_thr);        }      }       if (mask_8x8 & dual_one) {        if ((mask_8x8 & dual_one) == dual_one) {          vpx_lpf_vertical_8_dual(ss[0], pitch, lfis[0]->mblim, lfis[0]->lim,                                  lfis[0]->hev_thr, lfis[1]->mblim,                                  lfis[1]->lim, lfis[1]->hev_thr);        } else {          const loop_filter_thresh *lfi = lfis[!(mask_8x8 & 1)];          vpx_lpf_vertical_8(ss[!(mask_8x8 & 1)], pitch, lfi->mblim, lfi->lim,                             lfi->hev_thr);        }      }       if (mask_4x4 & dual_one) {        if ((mask_4x4 & dual_one) == dual_one) {          vpx_lpf_vertical_4_dual(ss[0], pitch, lfis[0]->mblim, lfis[0]->lim,                                  lfis[0]->hev_thr, lfis[1]->mblim,                                  lfis[1]->lim, lfis[1]->hev_thr);        } else {          const loop_filter_thresh *lfi = lfis[!(mask_4x4 & 1)];          vpx_lpf_vertical_4(ss[!(mask_4x4 & 1)], pitch, lfi->mblim, lfi->lim,                             lfi->hev_thr);        }      }       if (mask_4x4_int & dual_one) {        if ((mask_4x4_int & dual_one) == dual_one) {          vpx_lpf_vertical_4_dual(              ss[0] + 4, pitch, lfis[0]->mblim, lfis[0]->lim, lfis[0]->hev_thr,              lfis[1]->mblim, lfis[1]->lim, lfis[1]->hev_thr);        } else {          const loop_filter_thresh *lfi = lfis[!(mask_4x4_int & 1)];          vpx_lpf_vertical_4(ss[!(mask_4x4_int & 1)] + 4, pitch, lfi->mblim,                             lfi->lim, lfi->hev_thr);        }      }    }     ss[0] += 8;    lfl += 1;    mask_16x16 >>= 1;    mask_8x8 >>= 1;    mask_4x4 >>= 1;    mask_4x4_int >>= 1;  }} #if CONFIG_VP9_HIGHBITDEPTHstatic void highbd_filter_selectively_vert_row2(    int subsampling_factor, uint16_t *s, int pitch, unsigned int mask_16x16,    unsigned int mask_8x8, unsigned int mask_4x4, unsigned int mask_4x4_int,    const loop_filter_thresh *lfthr, const uint8_t *lfl, int bd) {  const int dual_mask_cutoff = subsampling_factor ? 0xff : 0xffff;  const int lfl_forward = subsampling_factor ? 4 : 8;  const unsigned int dual_one = 1 | (1 << lfl_forward);  unsigned int mask;  uint16_t *ss[2];  ss[0] = s;   for (mask =           (mask_16x16 | mask_8x8 | mask_4x4 | mask_4x4_int) & dual_mask_cutoff;       mask; mask = (mask & ~dual_one) >> 1) {    if (mask & dual_one) {      const loop_filter_thresh *lfis[2];      lfis[0] = lfthr + *lfl;      lfis[1] = lfthr + *(lfl + lfl_forward);      ss[1] = ss[0] + 8 * pitch;       if (mask_16x16 & dual_one) {        if ((mask_16x16 & dual_one) == dual_one) {          vpx_highbd_lpf_vertical_16_dual(ss[0], pitch, lfis[0]->mblim,                                          lfis[0]->lim, lfis[0]->hev_thr, bd);        } else {          const loop_filter_thresh *lfi = lfis[!(mask_16x16 & 1)];          vpx_highbd_lpf_vertical_16(ss[!(mask_16x16 & 1)], pitch, lfi->mblim,                                     lfi->lim, lfi->hev_thr, bd);        }      }       if (mask_8x8 & dual_one) {        if ((mask_8x8 & dual_one) == dual_one) {          vpx_highbd_lpf_vertical_8_dual(              ss[0], pitch, lfis[0]->mblim, lfis[0]->lim, lfis[0]->hev_thr,              lfis[1]->mblim, lfis[1]->lim, lfis[1]->hev_thr, bd);        } else {          const loop_filter_thresh *lfi = lfis[!(mask_8x8 & 1)];          vpx_highbd_lpf_vertical_8(ss[!(mask_8x8 & 1)], pitch, lfi->mblim,                                    lfi->lim, lfi->hev_thr, bd);        }      }       if (mask_4x4 & dual_one) {        if ((mask_4x4 & dual_one) == dual_one) {          vpx_highbd_lpf_vertical_4_dual(              ss[0], pitch, lfis[0]->mblim, lfis[0]->lim, lfis[0]->hev_thr,              lfis[1]->mblim, lfis[1]->lim, lfis[1]->hev_thr, bd);        } else {          const loop_filter_thresh *lfi = lfis[!(mask_4x4 & 1)];          vpx_highbd_lpf_vertical_4(ss[!(mask_4x4 & 1)], pitch, lfi->mblim,                                    lfi->lim, lfi->hev_thr, bd);        }      }       if (mask_4x4_int & dual_one) {        if ((mask_4x4_int & dual_one) == dual_one) {          vpx_highbd_lpf_vertical_4_dual(              ss[0] + 4, pitch, lfis[0]->mblim, lfis[0]->lim, lfis[0]->hev_thr,              lfis[1]->mblim, lfis[1]->lim, lfis[1]->hev_thr, bd);        } else {          const loop_filter_thresh *lfi = lfis[!(mask_4x4_int & 1)];          vpx_highbd_lpf_vertical_4(ss[!(mask_4x4_int & 1)] + 4, pitch,                                    lfi->mblim, lfi->lim, lfi->hev_thr, bd);        }      }    }     ss[0] += 8;    lfl += 1;    mask_16x16 >>= 1;    mask_8x8 >>= 1;    mask_4x4 >>= 1;    mask_4x4_int >>= 1;  }}#endif  // CONFIG_VP9_HIGHBITDEPTH static void filter_selectively_horiz(    uint8_t *s, int pitch, unsigned int mask_16x16, unsigned int mask_8x8,    unsigned int mask_4x4, unsigned int mask_4x4_int,    const loop_filter_thresh *lfthr, const uint8_t *lfl) {  unsigned int mask;  int count;   for (mask = mask_16x16 | mask_8x8 | mask_4x4 | mask_4x4_int; mask;       mask >>= count) {    count = 1;    if (mask & 1) {      const loop_filter_thresh *lfi = lfthr + *lfl;       if (mask_16x16 & 1) {        if ((mask_16x16 & 3) == 3) {          vpx_lpf_horizontal_16_dual(s, pitch, lfi->mblim, lfi->lim,                                     lfi->hev_thr);          count = 2;        } else {          vpx_lpf_horizontal_16(s, pitch, lfi->mblim, lfi->lim, lfi->hev_thr);        }      } else if (mask_8x8 & 1) {        if ((mask_8x8 & 3) == 3) {          // Next block's thresholds.          const loop_filter_thresh *lfin = lfthr + *(lfl + 1);           vpx_lpf_horizontal_8_dual(s, pitch, lfi->mblim, lfi->lim,                                    lfi->hev_thr, lfin->mblim, lfin->lim,                                    lfin->hev_thr);           if ((mask_4x4_int & 3) == 3) {            vpx_lpf_horizontal_4_dual(s + 4 * pitch, pitch, lfi->mblim,                                      lfi->lim, lfi->hev_thr, lfin->mblim,                                      lfin->lim, lfin->hev_thr);          } else {            if (mask_4x4_int & 1)              vpx_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim, lfi->lim,                                   lfi->hev_thr);            else if (mask_4x4_int & 2)              vpx_lpf_horizontal_4(s + 8 + 4 * pitch, pitch, lfin->mblim,                                   lfin->lim, lfin->hev_thr);          }          count = 2;        } else {          vpx_lpf_horizontal_8(s, pitch, lfi->mblim, lfi->lim, lfi->hev_thr);           if (mask_4x4_int & 1)            vpx_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim, lfi->lim,

Lines 1–500 of 1635.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t