media/libvpx/vp8/common/blockd.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libvpx/vp8/common/blockd.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,300 @@
     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 __INC_BLOCKD_H
    1.16 +#define __INC_BLOCKD_H
    1.17 +
    1.18 +void vpx_log(const char *format, ...);
    1.19 +
    1.20 +#include "vpx_config.h"
    1.21 +#include "vpx_scale/yv12config.h"
    1.22 +#include "mv.h"
    1.23 +#include "treecoder.h"
    1.24 +#include "vpx_ports/mem.h"
    1.25 +
    1.26 +/*#define DCPRED 1*/
    1.27 +#define DCPREDSIMTHRESH 0
    1.28 +#define DCPREDCNTTHRESH 3
    1.29 +
    1.30 +#define MB_FEATURE_TREE_PROBS   3
    1.31 +#define MAX_MB_SEGMENTS         4
    1.32 +
    1.33 +#define MAX_REF_LF_DELTAS       4
    1.34 +#define MAX_MODE_LF_DELTAS      4
    1.35 +
    1.36 +/* Segment Feature Masks */
    1.37 +#define SEGMENT_DELTADATA   0
    1.38 +#define SEGMENT_ABSDATA     1
    1.39 +
    1.40 +typedef struct
    1.41 +{
    1.42 +    int r, c;
    1.43 +} POS;
    1.44 +
    1.45 +#define PLANE_TYPE_Y_NO_DC    0
    1.46 +#define PLANE_TYPE_Y2         1
    1.47 +#define PLANE_TYPE_UV         2
    1.48 +#define PLANE_TYPE_Y_WITH_DC  3
    1.49 +
    1.50 +
    1.51 +typedef char ENTROPY_CONTEXT;
    1.52 +typedef struct
    1.53 +{
    1.54 +    ENTROPY_CONTEXT y1[4];
    1.55 +    ENTROPY_CONTEXT u[2];
    1.56 +    ENTROPY_CONTEXT v[2];
    1.57 +    ENTROPY_CONTEXT y2;
    1.58 +} ENTROPY_CONTEXT_PLANES;
    1.59 +
    1.60 +extern const unsigned char vp8_block2left[25];
    1.61 +extern const unsigned char vp8_block2above[25];
    1.62 +
    1.63 +#define VP8_COMBINEENTROPYCONTEXTS( Dest, A, B) \
    1.64 +    Dest = (A)+(B);
    1.65 +
    1.66 +
    1.67 +typedef enum
    1.68 +{
    1.69 +    KEY_FRAME = 0,
    1.70 +    INTER_FRAME = 1
    1.71 +} FRAME_TYPE;
    1.72 +
    1.73 +typedef enum
    1.74 +{
    1.75 +    DC_PRED,            /* average of above and left pixels */
    1.76 +    V_PRED,             /* vertical prediction */
    1.77 +    H_PRED,             /* horizontal prediction */
    1.78 +    TM_PRED,            /* Truemotion prediction */
    1.79 +    B_PRED,             /* block based prediction, each block has its own prediction mode */
    1.80 +
    1.81 +    NEARESTMV,
    1.82 +    NEARMV,
    1.83 +    ZEROMV,
    1.84 +    NEWMV,
    1.85 +    SPLITMV,
    1.86 +
    1.87 +    MB_MODE_COUNT
    1.88 +} MB_PREDICTION_MODE;
    1.89 +
    1.90 +/* Macroblock level features */
    1.91 +typedef enum
    1.92 +{
    1.93 +    MB_LVL_ALT_Q = 0,               /* Use alternate Quantizer .... */
    1.94 +    MB_LVL_ALT_LF = 1,              /* Use alternate loop filter value... */
    1.95 +    MB_LVL_MAX = 2                  /* Number of MB level features supported */
    1.96 +
    1.97 +} MB_LVL_FEATURES;
    1.98 +
    1.99 +/* Segment Feature Masks */
   1.100 +#define SEGMENT_ALTQ    0x01
   1.101 +#define SEGMENT_ALT_LF  0x02
   1.102 +
   1.103 +#define VP8_YMODES  (B_PRED + 1)
   1.104 +#define VP8_UV_MODES (TM_PRED + 1)
   1.105 +
   1.106 +#define VP8_MVREFS (1 + SPLITMV - NEARESTMV)
   1.107 +
   1.108 +typedef enum
   1.109 +{
   1.110 +    B_DC_PRED,          /* average of above and left pixels */
   1.111 +    B_TM_PRED,
   1.112 +
   1.113 +    B_VE_PRED,           /* vertical prediction */
   1.114 +    B_HE_PRED,           /* horizontal prediction */
   1.115 +
   1.116 +    B_LD_PRED,
   1.117 +    B_RD_PRED,
   1.118 +
   1.119 +    B_VR_PRED,
   1.120 +    B_VL_PRED,
   1.121 +    B_HD_PRED,
   1.122 +    B_HU_PRED,
   1.123 +
   1.124 +    LEFT4X4,
   1.125 +    ABOVE4X4,
   1.126 +    ZERO4X4,
   1.127 +    NEW4X4,
   1.128 +
   1.129 +    B_MODE_COUNT
   1.130 +} B_PREDICTION_MODE;
   1.131 +
   1.132 +#define VP8_BINTRAMODES (B_HU_PRED + 1)  /* 10 */
   1.133 +#define VP8_SUBMVREFS (1 + NEW4X4 - LEFT4X4)
   1.134 +
   1.135 +/* For keyframes, intra block modes are predicted by the (already decoded)
   1.136 +   modes for the Y blocks to the left and above us; for interframes, there
   1.137 +   is a single probability table. */
   1.138 +
   1.139 +union b_mode_info
   1.140 +{
   1.141 +    B_PREDICTION_MODE as_mode;
   1.142 +    int_mv mv;
   1.143 +};
   1.144 +
   1.145 +typedef enum
   1.146 +{
   1.147 +    INTRA_FRAME = 0,
   1.148 +    LAST_FRAME = 1,
   1.149 +    GOLDEN_FRAME = 2,
   1.150 +    ALTREF_FRAME = 3,
   1.151 +    MAX_REF_FRAMES = 4
   1.152 +} MV_REFERENCE_FRAME;
   1.153 +
   1.154 +typedef struct
   1.155 +{
   1.156 +    uint8_t mode, uv_mode;
   1.157 +    uint8_t ref_frame;
   1.158 +    uint8_t is_4x4;
   1.159 +    int_mv mv;
   1.160 +
   1.161 +    uint8_t partitioning;
   1.162 +    uint8_t mb_skip_coeff;                                /* does this mb has coefficients at all, 1=no coefficients, 0=need decode tokens */
   1.163 +    uint8_t need_to_clamp_mvs;
   1.164 +    uint8_t segment_id;                  /* Which set of segmentation parameters should be used for this MB */
   1.165 +} MB_MODE_INFO;
   1.166 +
   1.167 +typedef struct modeinfo
   1.168 +{
   1.169 +    MB_MODE_INFO mbmi;
   1.170 +    union b_mode_info bmi[16];
   1.171 +} MODE_INFO;
   1.172 +
   1.173 +#if CONFIG_MULTI_RES_ENCODING
   1.174 +/* The mb-level information needed to be stored for higher-resolution encoder */
   1.175 +typedef struct
   1.176 +{
   1.177 +    MB_PREDICTION_MODE mode;
   1.178 +    MV_REFERENCE_FRAME ref_frame;
   1.179 +    int_mv mv;
   1.180 +    int dissim;    /* dissimilarity level of the macroblock */
   1.181 +} LOWER_RES_MB_INFO;
   1.182 +
   1.183 +/* The frame-level information needed to be stored for higher-resolution
   1.184 + *  encoder */
   1.185 +typedef struct
   1.186 +{
   1.187 +    FRAME_TYPE frame_type;
   1.188 +    int is_frame_dropped;
   1.189 +    /* The frame number of each reference frames */
   1.190 +    unsigned int low_res_ref_frames[MAX_REF_FRAMES];
   1.191 +    LOWER_RES_MB_INFO *mb_info;
   1.192 +} LOWER_RES_FRAME_INFO;
   1.193 +#endif
   1.194 +
   1.195 +typedef struct blockd
   1.196 +{
   1.197 +    short *qcoeff;
   1.198 +    short *dqcoeff;
   1.199 +    unsigned char  *predictor;
   1.200 +    short *dequant;
   1.201 +
   1.202 +    int offset;
   1.203 +    char *eob;
   1.204 +
   1.205 +    union b_mode_info bmi;
   1.206 +} BLOCKD;
   1.207 +
   1.208 +typedef void (*vp8_subpix_fn_t)(unsigned char *src, int src_pitch, int xofst, int yofst, unsigned char *dst, int dst_pitch);
   1.209 +
   1.210 +typedef struct macroblockd
   1.211 +{
   1.212 +    DECLARE_ALIGNED(16, unsigned char,  predictor[384]);
   1.213 +    DECLARE_ALIGNED(16, short, qcoeff[400]);
   1.214 +    DECLARE_ALIGNED(16, short, dqcoeff[400]);
   1.215 +    DECLARE_ALIGNED(16, char,  eobs[25]);
   1.216 +
   1.217 +    DECLARE_ALIGNED(16, short,  dequant_y1[16]);
   1.218 +    DECLARE_ALIGNED(16, short,  dequant_y1_dc[16]);
   1.219 +    DECLARE_ALIGNED(16, short,  dequant_y2[16]);
   1.220 +    DECLARE_ALIGNED(16, short,  dequant_uv[16]);
   1.221 +
   1.222 +    /* 16 Y blocks, 4 U, 4 V, 1 DC 2nd order block, each with 16 entries. */
   1.223 +    BLOCKD block[25];
   1.224 +    int fullpixel_mask;
   1.225 +
   1.226 +    YV12_BUFFER_CONFIG pre; /* Filtered copy of previous frame reconstruction */
   1.227 +    YV12_BUFFER_CONFIG dst;
   1.228 +
   1.229 +    MODE_INFO *mode_info_context;
   1.230 +    int mode_info_stride;
   1.231 +
   1.232 +    FRAME_TYPE frame_type;
   1.233 +
   1.234 +    int up_available;
   1.235 +    int left_available;
   1.236 +
   1.237 +    unsigned char *recon_above[3];
   1.238 +    unsigned char *recon_left[3];
   1.239 +    int recon_left_stride[2];
   1.240 +
   1.241 +    /* Y,U,V,Y2 */
   1.242 +    ENTROPY_CONTEXT_PLANES *above_context;
   1.243 +    ENTROPY_CONTEXT_PLANES *left_context;
   1.244 +
   1.245 +    /* 0 indicates segmentation at MB level is not enabled. Otherwise the individual bits indicate which features are active. */
   1.246 +    unsigned char segmentation_enabled;
   1.247 +
   1.248 +    /* 0 (do not update) 1 (update) the macroblock segmentation map. */
   1.249 +    unsigned char update_mb_segmentation_map;
   1.250 +
   1.251 +    /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */
   1.252 +    unsigned char update_mb_segmentation_data;
   1.253 +
   1.254 +    /* 0 (do not update) 1 (update) the macroblock segmentation feature data. */
   1.255 +    unsigned char mb_segement_abs_delta;
   1.256 +
   1.257 +    /* Per frame flags that define which MB level features (such as quantizer or loop filter level) */
   1.258 +    /* are enabled and when enabled the proabilities used to decode the per MB flags in MB_MODE_INFO */
   1.259 +    vp8_prob mb_segment_tree_probs[MB_FEATURE_TREE_PROBS];         /* Probability Tree used to code Segment number */
   1.260 +
   1.261 +    signed char segment_feature_data[MB_LVL_MAX][MAX_MB_SEGMENTS];            /* Segment parameters */
   1.262 +
   1.263 +    /* mode_based Loop filter adjustment */
   1.264 +    unsigned char mode_ref_lf_delta_enabled;
   1.265 +    unsigned char mode_ref_lf_delta_update;
   1.266 +
   1.267 +    /* Delta values have the range +/- MAX_LOOP_FILTER */
   1.268 +    signed char last_ref_lf_deltas[MAX_REF_LF_DELTAS];                /* 0 = Intra, Last, GF, ARF */
   1.269 +    signed char ref_lf_deltas[MAX_REF_LF_DELTAS];                     /* 0 = Intra, Last, GF, ARF */
   1.270 +    signed char last_mode_lf_deltas[MAX_MODE_LF_DELTAS];                      /* 0 = BPRED, ZERO_MV, MV, SPLIT */
   1.271 +    signed char mode_lf_deltas[MAX_MODE_LF_DELTAS];                           /* 0 = BPRED, ZERO_MV, MV, SPLIT */
   1.272 +
   1.273 +    /* Distance of MB away from frame edges */
   1.274 +    int mb_to_left_edge;
   1.275 +    int mb_to_right_edge;
   1.276 +    int mb_to_top_edge;
   1.277 +    int mb_to_bottom_edge;
   1.278 +
   1.279 +
   1.280 +
   1.281 +    vp8_subpix_fn_t  subpixel_predict;
   1.282 +    vp8_subpix_fn_t  subpixel_predict8x4;
   1.283 +    vp8_subpix_fn_t  subpixel_predict8x8;
   1.284 +    vp8_subpix_fn_t  subpixel_predict16x16;
   1.285 +
   1.286 +    void *current_bc;
   1.287 +
   1.288 +    int corrupted;
   1.289 +
   1.290 +#if ARCH_X86 || ARCH_X86_64
   1.291 +    /* This is an intermediate buffer currently used in sub-pixel motion search
   1.292 +     * to keep a copy of the reference area. This buffer can be used for other
   1.293 +     * purpose.
   1.294 +     */
   1.295 +    DECLARE_ALIGNED(32, unsigned char, y_buf[22*32]);
   1.296 +#endif
   1.297 +} MACROBLOCKD;
   1.298 +
   1.299 +
   1.300 +extern void vp8_build_block_doffsets(MACROBLOCKD *x);
   1.301 +extern void vp8_setup_block_dptrs(MACROBLOCKD *x);
   1.302 +
   1.303 +#endif  /* __INC_BLOCKD_H */

mercurial