media/libvpx/vp9/common/vp9_blockd.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libvpx/vp9/common/vp9_blockd.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,501 @@
     1.4 +/*
     1.5 + *  Copyright (c) 2010 The WebM project authors. All Rights Reserved.
     1.6 + *
     1.7 + *  Use of this source code is governed by a BSD-style license
     1.8 + *  that can be found in the LICENSE file in the root of the source
     1.9 + *  tree. An additional intellectual property rights grant can be found
    1.10 + *  in the file PATENTS.  All contributing project authors may
    1.11 + *  be found in the AUTHORS file in the root of the source tree.
    1.12 + */
    1.13 +
    1.14 +
    1.15 +#ifndef VP9_COMMON_VP9_BLOCKD_H_
    1.16 +#define VP9_COMMON_VP9_BLOCKD_H_
    1.17 +
    1.18 +#include "./vpx_config.h"
    1.19 +
    1.20 +#include "vpx_ports/mem.h"
    1.21 +#include "vpx_scale/yv12config.h"
    1.22 +
    1.23 +#include "vp9/common/vp9_common.h"
    1.24 +#include "vp9/common/vp9_common_data.h"
    1.25 +#include "vp9/common/vp9_enums.h"
    1.26 +#include "vp9/common/vp9_filter.h"
    1.27 +#include "vp9/common/vp9_mv.h"
    1.28 +#include "vp9/common/vp9_scale.h"
    1.29 +#include "vp9/common/vp9_seg_common.h"
    1.30 +#include "vp9/common/vp9_treecoder.h"
    1.31 +
    1.32 +#define BLOCK_SIZE_GROUPS   4
    1.33 +#define MBSKIP_CONTEXTS 3
    1.34 +
    1.35 +/* Segment Feature Masks */
    1.36 +#define MAX_MV_REF_CANDIDATES 2
    1.37 +
    1.38 +#define INTRA_INTER_CONTEXTS 4
    1.39 +#define COMP_INTER_CONTEXTS 5
    1.40 +#define REF_CONTEXTS 5
    1.41 +
    1.42 +typedef enum {
    1.43 +  PLANE_TYPE_Y_WITH_DC,
    1.44 +  PLANE_TYPE_UV,
    1.45 +} PLANE_TYPE;
    1.46 +
    1.47 +typedef char ENTROPY_CONTEXT;
    1.48 +
    1.49 +typedef char PARTITION_CONTEXT;
    1.50 +
    1.51 +static INLINE int combine_entropy_contexts(ENTROPY_CONTEXT a,
    1.52 +                                           ENTROPY_CONTEXT b) {
    1.53 +  return (a != 0) + (b != 0);
    1.54 +}
    1.55 +
    1.56 +typedef enum {
    1.57 +  KEY_FRAME = 0,
    1.58 +  INTER_FRAME = 1,
    1.59 +  FRAME_TYPES,
    1.60 +} FRAME_TYPE;
    1.61 +
    1.62 +typedef enum {
    1.63 +  DC_PRED,         // Average of above and left pixels
    1.64 +  V_PRED,          // Vertical
    1.65 +  H_PRED,          // Horizontal
    1.66 +  D45_PRED,        // Directional 45  deg = round(arctan(1/1) * 180/pi)
    1.67 +  D135_PRED,       // Directional 135 deg = 180 - 45
    1.68 +  D117_PRED,       // Directional 117 deg = 180 - 63
    1.69 +  D153_PRED,       // Directional 153 deg = 180 - 27
    1.70 +  D207_PRED,       // Directional 207 deg = 180 + 27
    1.71 +  D63_PRED,        // Directional 63  deg = round(arctan(2/1) * 180/pi)
    1.72 +  TM_PRED,         // True-motion
    1.73 +  NEARESTMV,
    1.74 +  NEARMV,
    1.75 +  ZEROMV,
    1.76 +  NEWMV,
    1.77 +  MB_MODE_COUNT
    1.78 +} MB_PREDICTION_MODE;
    1.79 +
    1.80 +static INLINE int is_inter_mode(MB_PREDICTION_MODE mode) {
    1.81 +  return mode >= NEARESTMV && mode <= NEWMV;
    1.82 +}
    1.83 +
    1.84 +#define INTRA_MODES (TM_PRED + 1)
    1.85 +
    1.86 +#define INTER_MODES (1 + NEWMV - NEARESTMV)
    1.87 +
    1.88 +#define INTER_OFFSET(mode) ((mode) - NEARESTMV)
    1.89 +
    1.90 +
    1.91 +/* For keyframes, intra block modes are predicted by the (already decoded)
    1.92 +   modes for the Y blocks to the left and above us; for interframes, there
    1.93 +   is a single probability table. */
    1.94 +
    1.95 +typedef struct {
    1.96 +  MB_PREDICTION_MODE as_mode;
    1.97 +  int_mv as_mv[2];  // first, second inter predictor motion vectors
    1.98 +} b_mode_info;
    1.99 +
   1.100 +typedef enum {
   1.101 +  NONE = -1,
   1.102 +  INTRA_FRAME = 0,
   1.103 +  LAST_FRAME = 1,
   1.104 +  GOLDEN_FRAME = 2,
   1.105 +  ALTREF_FRAME = 3,
   1.106 +  MAX_REF_FRAMES = 4
   1.107 +} MV_REFERENCE_FRAME;
   1.108 +
   1.109 +static INLINE int b_width_log2(BLOCK_SIZE sb_type) {
   1.110 +  return b_width_log2_lookup[sb_type];
   1.111 +}
   1.112 +static INLINE int b_height_log2(BLOCK_SIZE sb_type) {
   1.113 +  return b_height_log2_lookup[sb_type];
   1.114 +}
   1.115 +
   1.116 +static INLINE int mi_width_log2(BLOCK_SIZE sb_type) {
   1.117 +  return mi_width_log2_lookup[sb_type];
   1.118 +}
   1.119 +
   1.120 +static INLINE int mi_height_log2(BLOCK_SIZE sb_type) {
   1.121 +  return mi_height_log2_lookup[sb_type];
   1.122 +}
   1.123 +
   1.124 +// This structure now relates to 8x8 block regions.
   1.125 +typedef struct {
   1.126 +  MB_PREDICTION_MODE mode, uv_mode;
   1.127 +  MV_REFERENCE_FRAME ref_frame[2];
   1.128 +  TX_SIZE tx_size;
   1.129 +  int_mv mv[2];                // for each reference frame used
   1.130 +  int_mv ref_mvs[MAX_REF_FRAMES][MAX_MV_REF_CANDIDATES];
   1.131 +  int_mv best_mv[2];
   1.132 +
   1.133 +  uint8_t mode_context[MAX_REF_FRAMES];
   1.134 +
   1.135 +  unsigned char skip_coeff;    // 0=need to decode coeffs, 1=no coefficients
   1.136 +  unsigned char segment_id;    // Segment id for this block.
   1.137 +
   1.138 +  // Flags used for prediction status of various bit-stream signals
   1.139 +  unsigned char seg_id_predicted;
   1.140 +
   1.141 +  INTERPOLATION_TYPE interp_filter;
   1.142 +
   1.143 +  BLOCK_SIZE sb_type;
   1.144 +} MB_MODE_INFO;
   1.145 +
   1.146 +typedef struct {
   1.147 +  MB_MODE_INFO mbmi;
   1.148 +  b_mode_info bmi[4];
   1.149 +} MODE_INFO;
   1.150 +
   1.151 +static INLINE int is_inter_block(const MB_MODE_INFO *mbmi) {
   1.152 +  return mbmi->ref_frame[0] > INTRA_FRAME;
   1.153 +}
   1.154 +
   1.155 +static INLINE int has_second_ref(const MB_MODE_INFO *mbmi) {
   1.156 +  return mbmi->ref_frame[1] > INTRA_FRAME;
   1.157 +}
   1.158 +
   1.159 +enum mv_precision {
   1.160 +  MV_PRECISION_Q3,
   1.161 +  MV_PRECISION_Q4
   1.162 +};
   1.163 +
   1.164 +#if CONFIG_ALPHA
   1.165 +enum { MAX_MB_PLANE = 4 };
   1.166 +#else
   1.167 +enum { MAX_MB_PLANE = 3 };
   1.168 +#endif
   1.169 +
   1.170 +struct buf_2d {
   1.171 +  uint8_t *buf;
   1.172 +  int stride;
   1.173 +};
   1.174 +
   1.175 +struct macroblockd_plane {
   1.176 +  int16_t *qcoeff;
   1.177 +  int16_t *dqcoeff;
   1.178 +  uint16_t *eobs;
   1.179 +  PLANE_TYPE plane_type;
   1.180 +  int subsampling_x;
   1.181 +  int subsampling_y;
   1.182 +  struct buf_2d dst;
   1.183 +  struct buf_2d pre[2];
   1.184 +  int16_t *dequant;
   1.185 +  ENTROPY_CONTEXT *above_context;
   1.186 +  ENTROPY_CONTEXT *left_context;
   1.187 +};
   1.188 +
   1.189 +#define BLOCK_OFFSET(x, i) ((x) + (i) * 16)
   1.190 +
   1.191 +typedef struct macroblockd {
   1.192 +  struct macroblockd_plane plane[MAX_MB_PLANE];
   1.193 +
   1.194 +  struct scale_factors scale_factor[2];
   1.195 +
   1.196 +  MODE_INFO *last_mi;
   1.197 +  int mode_info_stride;
   1.198 +
   1.199 +  // A NULL indicates that the 8x8 is not part of the image
   1.200 +  MODE_INFO **mi_8x8;
   1.201 +  MODE_INFO **prev_mi_8x8;
   1.202 +  MODE_INFO *mi_stream;
   1.203 +
   1.204 +  int up_available;
   1.205 +  int left_available;
   1.206 +
   1.207 +  /* Distance of MB away from frame edges */
   1.208 +  int mb_to_left_edge;
   1.209 +  int mb_to_right_edge;
   1.210 +  int mb_to_top_edge;
   1.211 +  int mb_to_bottom_edge;
   1.212 +
   1.213 +  int lossless;
   1.214 +  /* Inverse transform function pointers. */
   1.215 +  void (*itxm_add)(const int16_t *input, uint8_t *dest, int stride, int eob);
   1.216 +
   1.217 +  struct subpix_fn_table  subpix;
   1.218 +
   1.219 +  int corrupted;
   1.220 +
   1.221 +  /* Y,U,V,(A) */
   1.222 +  ENTROPY_CONTEXT *above_context[MAX_MB_PLANE];
   1.223 +  ENTROPY_CONTEXT left_context[MAX_MB_PLANE][16];
   1.224 +
   1.225 +  PARTITION_CONTEXT *above_seg_context;
   1.226 +  PARTITION_CONTEXT left_seg_context[8];
   1.227 +} MACROBLOCKD;
   1.228 +
   1.229 +
   1.230 +
   1.231 +static BLOCK_SIZE get_subsize(BLOCK_SIZE bsize, PARTITION_TYPE partition) {
   1.232 +  const BLOCK_SIZE subsize = subsize_lookup[partition][bsize];
   1.233 +  assert(subsize < BLOCK_SIZES);
   1.234 +  return subsize;
   1.235 +}
   1.236 +
   1.237 +extern const TX_TYPE mode2txfm_map[MB_MODE_COUNT];
   1.238 +
   1.239 +static INLINE TX_TYPE get_tx_type_4x4(PLANE_TYPE plane_type,
   1.240 +                                      const MACROBLOCKD *xd, int ib) {
   1.241 +  const MODE_INFO *const mi = xd->mi_8x8[0];
   1.242 +  const MB_MODE_INFO *const mbmi = &mi->mbmi;
   1.243 +
   1.244 +  if (plane_type != PLANE_TYPE_Y_WITH_DC ||
   1.245 +      xd->lossless ||
   1.246 +      is_inter_block(mbmi))
   1.247 +    return DCT_DCT;
   1.248 +
   1.249 +  return mode2txfm_map[mbmi->sb_type < BLOCK_8X8 ?
   1.250 +                       mi->bmi[ib].as_mode : mbmi->mode];
   1.251 +}
   1.252 +
   1.253 +static INLINE TX_TYPE get_tx_type_8x8(PLANE_TYPE plane_type,
   1.254 +                                      const MACROBLOCKD *xd) {
   1.255 +  return plane_type == PLANE_TYPE_Y_WITH_DC ?
   1.256 +             mode2txfm_map[xd->mi_8x8[0]->mbmi.mode] : DCT_DCT;
   1.257 +}
   1.258 +
   1.259 +static INLINE TX_TYPE get_tx_type_16x16(PLANE_TYPE plane_type,
   1.260 +                                        const MACROBLOCKD *xd) {
   1.261 +  return plane_type == PLANE_TYPE_Y_WITH_DC ?
   1.262 +             mode2txfm_map[xd->mi_8x8[0]->mbmi.mode] : DCT_DCT;
   1.263 +}
   1.264 +
   1.265 +static void setup_block_dptrs(MACROBLOCKD *xd, int ss_x, int ss_y) {
   1.266 +  int i;
   1.267 +
   1.268 +  for (i = 0; i < MAX_MB_PLANE; i++) {
   1.269 +    xd->plane[i].plane_type = i ? PLANE_TYPE_UV : PLANE_TYPE_Y_WITH_DC;
   1.270 +    xd->plane[i].subsampling_x = i ? ss_x : 0;
   1.271 +    xd->plane[i].subsampling_y = i ? ss_y : 0;
   1.272 +  }
   1.273 +#if CONFIG_ALPHA
   1.274 +  // TODO(jkoleszar): Using the Y w/h for now
   1.275 +  xd->plane[3].subsampling_x = 0;
   1.276 +  xd->plane[3].subsampling_y = 0;
   1.277 +#endif
   1.278 +}
   1.279 +
   1.280 +
   1.281 +static INLINE TX_SIZE get_uv_tx_size(const MB_MODE_INFO *mbmi) {
   1.282 +  return MIN(mbmi->tx_size, max_uv_txsize_lookup[mbmi->sb_type]);
   1.283 +}
   1.284 +
   1.285 +static BLOCK_SIZE get_plane_block_size(BLOCK_SIZE bsize,
   1.286 +                                       const struct macroblockd_plane *pd) {
   1.287 +  BLOCK_SIZE bs = ss_size_lookup[bsize][pd->subsampling_x][pd->subsampling_y];
   1.288 +  assert(bs < BLOCK_SIZES);
   1.289 +  return bs;
   1.290 +}
   1.291 +
   1.292 +static INLINE int plane_block_width(BLOCK_SIZE bsize,
   1.293 +                                    const struct macroblockd_plane* plane) {
   1.294 +  return 4 << (b_width_log2(bsize) - plane->subsampling_x);
   1.295 +}
   1.296 +
   1.297 +static INLINE int plane_block_height(BLOCK_SIZE bsize,
   1.298 +                                     const struct macroblockd_plane* plane) {
   1.299 +  return 4 << (b_height_log2(bsize) - plane->subsampling_y);
   1.300 +}
   1.301 +
   1.302 +typedef void (*foreach_transformed_block_visitor)(int plane, int block,
   1.303 +                                                  BLOCK_SIZE plane_bsize,
   1.304 +                                                  TX_SIZE tx_size,
   1.305 +                                                  void *arg);
   1.306 +
   1.307 +static INLINE void foreach_transformed_block_in_plane(
   1.308 +    const MACROBLOCKD *const xd, BLOCK_SIZE bsize, int plane,
   1.309 +    foreach_transformed_block_visitor visit, void *arg) {
   1.310 +  const struct macroblockd_plane *const pd = &xd->plane[plane];
   1.311 +  const MB_MODE_INFO* mbmi = &xd->mi_8x8[0]->mbmi;
   1.312 +  // block and transform sizes, in number of 4x4 blocks log 2 ("*_b")
   1.313 +  // 4x4=0, 8x8=2, 16x16=4, 32x32=6, 64x64=8
   1.314 +  // transform size varies per plane, look it up in a common way.
   1.315 +  const TX_SIZE tx_size = plane ? get_uv_tx_size(mbmi)
   1.316 +                                : mbmi->tx_size;
   1.317 +  const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd);
   1.318 +  const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize];
   1.319 +  const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize];
   1.320 +  const int step = 1 << (tx_size << 1);
   1.321 +  int i;
   1.322 +
   1.323 +  // If mb_to_right_edge is < 0 we are in a situation in which
   1.324 +  // the current block size extends into the UMV and we won't
   1.325 +  // visit the sub blocks that are wholly within the UMV.
   1.326 +  if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0) {
   1.327 +    int r, c;
   1.328 +
   1.329 +    int max_blocks_wide = num_4x4_w;
   1.330 +    int max_blocks_high = num_4x4_h;
   1.331 +
   1.332 +    // xd->mb_to_right_edge is in units of pixels * 8.  This converts
   1.333 +    // it to 4x4 block sizes.
   1.334 +    if (xd->mb_to_right_edge < 0)
   1.335 +      max_blocks_wide += (xd->mb_to_right_edge >> (5 + pd->subsampling_x));
   1.336 +
   1.337 +    if (xd->mb_to_bottom_edge < 0)
   1.338 +      max_blocks_high += (xd->mb_to_bottom_edge >> (5 + pd->subsampling_y));
   1.339 +
   1.340 +    i = 0;
   1.341 +    // Unlike the normal case - in here we have to keep track of the
   1.342 +    // row and column of the blocks we use so that we know if we are in
   1.343 +    // the unrestricted motion border.
   1.344 +    for (r = 0; r < num_4x4_h; r += (1 << tx_size)) {
   1.345 +      for (c = 0; c < num_4x4_w; c += (1 << tx_size)) {
   1.346 +        if (r < max_blocks_high && c < max_blocks_wide)
   1.347 +          visit(plane, i, plane_bsize, tx_size, arg);
   1.348 +        i += step;
   1.349 +      }
   1.350 +    }
   1.351 +  } else {
   1.352 +    for (i = 0; i < num_4x4_w * num_4x4_h; i += step)
   1.353 +      visit(plane, i, plane_bsize, tx_size, arg);
   1.354 +  }
   1.355 +}
   1.356 +
   1.357 +static INLINE void foreach_transformed_block(
   1.358 +    const MACROBLOCKD* const xd, BLOCK_SIZE bsize,
   1.359 +    foreach_transformed_block_visitor visit, void *arg) {
   1.360 +  int plane;
   1.361 +
   1.362 +  for (plane = 0; plane < MAX_MB_PLANE; plane++)
   1.363 +    foreach_transformed_block_in_plane(xd, bsize, plane, visit, arg);
   1.364 +}
   1.365 +
   1.366 +static INLINE void foreach_transformed_block_uv(
   1.367 +    const MACROBLOCKD* const xd, BLOCK_SIZE bsize,
   1.368 +    foreach_transformed_block_visitor visit, void *arg) {
   1.369 +  int plane;
   1.370 +
   1.371 +  for (plane = 1; plane < MAX_MB_PLANE; plane++)
   1.372 +    foreach_transformed_block_in_plane(xd, bsize, plane, visit, arg);
   1.373 +}
   1.374 +
   1.375 +static int raster_block_offset(BLOCK_SIZE plane_bsize,
   1.376 +                               int raster_block, int stride) {
   1.377 +  const int bw = b_width_log2(plane_bsize);
   1.378 +  const int y = 4 * (raster_block >> bw);
   1.379 +  const int x = 4 * (raster_block & ((1 << bw) - 1));
   1.380 +  return y * stride + x;
   1.381 +}
   1.382 +static int16_t* raster_block_offset_int16(BLOCK_SIZE plane_bsize,
   1.383 +                                          int raster_block, int16_t *base) {
   1.384 +  const int stride = 4 << b_width_log2(plane_bsize);
   1.385 +  return base + raster_block_offset(plane_bsize, raster_block, stride);
   1.386 +}
   1.387 +static uint8_t* raster_block_offset_uint8(BLOCK_SIZE plane_bsize,
   1.388 +                                          int raster_block, uint8_t *base,
   1.389 +                                          int stride) {
   1.390 +  return base + raster_block_offset(plane_bsize, raster_block, stride);
   1.391 +}
   1.392 +
   1.393 +static int txfrm_block_to_raster_block(BLOCK_SIZE plane_bsize,
   1.394 +                                       TX_SIZE tx_size, int block) {
   1.395 +  const int bwl = b_width_log2(plane_bsize);
   1.396 +  const int tx_cols_log2 = bwl - tx_size;
   1.397 +  const int tx_cols = 1 << tx_cols_log2;
   1.398 +  const int raster_mb = block >> (tx_size << 1);
   1.399 +  const int x = (raster_mb & (tx_cols - 1)) << tx_size;
   1.400 +  const int y = (raster_mb >> tx_cols_log2) << tx_size;
   1.401 +  return x + (y << bwl);
   1.402 +}
   1.403 +
   1.404 +static void txfrm_block_to_raster_xy(BLOCK_SIZE plane_bsize,
   1.405 +                                     TX_SIZE tx_size, int block,
   1.406 +                                     int *x, int *y) {
   1.407 +  const int bwl = b_width_log2(plane_bsize);
   1.408 +  const int tx_cols_log2 = bwl - tx_size;
   1.409 +  const int tx_cols = 1 << tx_cols_log2;
   1.410 +  const int raster_mb = block >> (tx_size << 1);
   1.411 +  *x = (raster_mb & (tx_cols - 1)) << tx_size;
   1.412 +  *y = (raster_mb >> tx_cols_log2) << tx_size;
   1.413 +}
   1.414 +
   1.415 +static void extend_for_intra(MACROBLOCKD *xd, BLOCK_SIZE plane_bsize,
   1.416 +                             int plane, int block, TX_SIZE tx_size) {
   1.417 +  struct macroblockd_plane *const pd = &xd->plane[plane];
   1.418 +  uint8_t *const buf = pd->dst.buf;
   1.419 +  const int stride = pd->dst.stride;
   1.420 +
   1.421 +  int x, y;
   1.422 +  txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y);
   1.423 +  x = x * 4 - 1;
   1.424 +  y = y * 4 - 1;
   1.425 +  // Copy a pixel into the umv if we are in a situation where the block size
   1.426 +  // extends into the UMV.
   1.427 +  // TODO(JBB): Should be able to do the full extend in place so we don't have
   1.428 +  // to do this multiple times.
   1.429 +  if (xd->mb_to_right_edge < 0) {
   1.430 +    const int bw = 4 << b_width_log2(plane_bsize);
   1.431 +    const int umv_border_start = bw + (xd->mb_to_right_edge >>
   1.432 +                                       (3 + pd->subsampling_x));
   1.433 +
   1.434 +    if (x + bw > umv_border_start)
   1.435 +      vpx_memset(&buf[y * stride + umv_border_start],
   1.436 +                 buf[y * stride + umv_border_start - 1], bw);
   1.437 +  }
   1.438 +
   1.439 +  if (xd->mb_to_bottom_edge < 0) {
   1.440 +    if (xd->left_available || x >= 0) {
   1.441 +      const int bh = 4 << b_height_log2(plane_bsize);
   1.442 +      const int umv_border_start =
   1.443 +          bh + (xd->mb_to_bottom_edge >> (3 + pd->subsampling_y));
   1.444 +
   1.445 +      if (y + bh > umv_border_start) {
   1.446 +        const uint8_t c = buf[(umv_border_start - 1) * stride + x];
   1.447 +        uint8_t *d = &buf[umv_border_start * stride + x];
   1.448 +        int i;
   1.449 +        for (i = 0; i < bh; ++i, d += stride)
   1.450 +          *d = c;
   1.451 +      }
   1.452 +    }
   1.453 +  }
   1.454 +}
   1.455 +
   1.456 +static void set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
   1.457 +                         BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
   1.458 +                         int has_eob, int aoff, int loff) {
   1.459 +  ENTROPY_CONTEXT *const a = pd->above_context + aoff;
   1.460 +  ENTROPY_CONTEXT *const l = pd->left_context + loff;
   1.461 +  const int tx_size_in_blocks = 1 << tx_size;
   1.462 +
   1.463 +  // above
   1.464 +  if (has_eob && xd->mb_to_right_edge < 0) {
   1.465 +    int i;
   1.466 +    const int blocks_wide = num_4x4_blocks_wide_lookup[plane_bsize] +
   1.467 +                            (xd->mb_to_right_edge >> (5 + pd->subsampling_x));
   1.468 +    int above_contexts = tx_size_in_blocks;
   1.469 +    if (above_contexts + aoff > blocks_wide)
   1.470 +      above_contexts = blocks_wide - aoff;
   1.471 +
   1.472 +    for (i = 0; i < above_contexts; ++i)
   1.473 +      a[i] = has_eob;
   1.474 +    for (i = above_contexts; i < tx_size_in_blocks; ++i)
   1.475 +      a[i] = 0;
   1.476 +  } else {
   1.477 +    vpx_memset(a, has_eob, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks);
   1.478 +  }
   1.479 +
   1.480 +  // left
   1.481 +  if (has_eob && xd->mb_to_bottom_edge < 0) {
   1.482 +    int i;
   1.483 +    const int blocks_high = num_4x4_blocks_high_lookup[plane_bsize] +
   1.484 +                            (xd->mb_to_bottom_edge >> (5 + pd->subsampling_y));
   1.485 +    int left_contexts = tx_size_in_blocks;
   1.486 +    if (left_contexts + loff > blocks_high)
   1.487 +      left_contexts = blocks_high - loff;
   1.488 +
   1.489 +    for (i = 0; i < left_contexts; ++i)
   1.490 +      l[i] = has_eob;
   1.491 +    for (i = left_contexts; i < tx_size_in_blocks; ++i)
   1.492 +      l[i] = 0;
   1.493 +  } else {
   1.494 +    vpx_memset(l, has_eob, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks);
   1.495 +  }
   1.496 +}
   1.497 +
   1.498 +static int get_tx_eob(const struct segmentation *seg, int segment_id,
   1.499 +                      TX_SIZE tx_size) {
   1.500 +  const int eob_max = 16 << (tx_size << 1);
   1.501 +  return vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP) ? 0 : eob_max;
   1.502 +}
   1.503 +
   1.504 +#endif  // VP9_COMMON_VP9_BLOCKD_H_

mercurial