Line data Source code
1 : /*
2 : * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 : *
4 : * This source code is subject to the terms of the BSD 2 Clause License and
5 : * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 : * was not distributed with this source code in the LICENSE file, you can
7 : * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 : * Media Patent License 1.0 was not distributed with this source code in the
9 : * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 : */
11 :
12 : #ifndef AV1_ENCODER_TOKENIZE_H_
13 : #define AV1_ENCODER_TOKENIZE_H_
14 :
15 : #include "av1/common/entropy.h"
16 :
17 : #include "av1/encoder/block.h"
18 : #include "av1/encoder/treewriter.h"
19 :
20 : #ifdef __cplusplus
21 : extern "C" {
22 : #endif
23 :
24 : #define EOSB_TOKEN 127 // Not signalled, encoder only
25 :
26 : #if CONFIG_HIGHBITDEPTH
27 : typedef int32_t EXTRABIT;
28 : #else
29 : typedef int16_t EXTRABIT;
30 : #endif
31 :
32 : typedef struct {
33 : int16_t token;
34 : EXTRABIT extra;
35 : } TOKENVALUE;
36 :
37 : typedef struct {
38 : aom_cdf_prob (*tail_cdf)[CDF_SIZE(ENTROPY_TOKENS)];
39 : aom_cdf_prob (*head_cdf)[CDF_SIZE(ENTROPY_TOKENS)];
40 : int eob_val;
41 : int first_val;
42 : const aom_prob *context_tree;
43 : EXTRABIT extra;
44 : uint8_t token;
45 : uint8_t skip_eob_node;
46 : } TOKENEXTRA;
47 :
48 : extern const aom_tree_index av1_coef_tree[];
49 : extern const aom_tree_index av1_coef_con_tree[];
50 :
51 : int av1_is_skippable_in_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane);
52 :
53 : struct AV1_COMP;
54 : struct ThreadData;
55 :
56 : struct tokenize_b_args {
57 : const struct AV1_COMP *cpi;
58 : struct ThreadData *td;
59 : TOKENEXTRA **tp;
60 : int this_rate;
61 : };
62 :
63 : typedef enum {
64 : OUTPUT_ENABLED = 0,
65 : DRY_RUN_NORMAL,
66 : DRY_RUN_COSTCOEFFS,
67 : } RUN_TYPE;
68 :
69 : // Note in all the tokenize functions rate if non NULL is incremented
70 : // with the coefficient token cost only if dry_run = DRY_RUN_COSTCOEFS,
71 : // otherwise rate is not incremented.
72 : #if CONFIG_VAR_TX
73 : void av1_tokenize_sb_vartx(const struct AV1_COMP *cpi, struct ThreadData *td,
74 : TOKENEXTRA **t, RUN_TYPE dry_run, int mi_row,
75 : int mi_col, BLOCK_SIZE bsize, int *rate);
76 : #endif
77 : #if CONFIG_PALETTE
78 : void av1_tokenize_palette_sb(const struct AV1_COMP *cpi,
79 : const struct ThreadData *const td, int plane,
80 : TOKENEXTRA **t, RUN_TYPE dry_run, BLOCK_SIZE bsize,
81 : int *rate);
82 : #endif // CONFIG_PALETTE
83 : void av1_tokenize_sb(const struct AV1_COMP *cpi, struct ThreadData *td,
84 : TOKENEXTRA **t, RUN_TYPE dry_run, BLOCK_SIZE bsize,
85 : int *rate, const int mi_row, const int mi_col);
86 : #if CONFIG_SUPERTX
87 : void av1_tokenize_sb_supertx(const struct AV1_COMP *cpi, struct ThreadData *td,
88 : TOKENEXTRA **t, RUN_TYPE dry_run, int mi_row,
89 : int mi_col, BLOCK_SIZE bsize, int *rate);
90 : #endif
91 :
92 : extern const int16_t *av1_dct_value_cost_ptr;
93 : /* TODO: The Token field should be broken out into a separate char array to
94 : * improve cache locality, since it's needed for costing when the rest of the
95 : * fields are not.
96 : */
97 : extern const TOKENVALUE *av1_dct_value_tokens_ptr;
98 : extern const TOKENVALUE *av1_dct_cat_lt_10_value_tokens;
99 : extern const int *av1_dct_cat_lt_10_value_cost;
100 : extern const int16_t av1_cat6_low_cost[256];
101 : #if CONFIG_HIGHBITDEPTH
102 : #define CAT6_HIGH_COST_ENTRIES 1024
103 : #else
104 : #define CAT6_HIGH_COST_ENTRIES 64
105 : #endif
106 : extern const int av1_cat6_high_cost[CAT6_HIGH_COST_ENTRIES];
107 : extern const uint8_t av1_cat6_skipped_bits_discount[8];
108 :
109 0 : static INLINE void av1_get_token_extra(int v, int16_t *token, EXTRABIT *extra) {
110 0 : if (v >= CAT6_MIN_VAL || v <= -CAT6_MIN_VAL) {
111 0 : *token = CATEGORY6_TOKEN;
112 0 : if (v >= CAT6_MIN_VAL)
113 0 : *extra = 2 * v - 2 * CAT6_MIN_VAL;
114 : else
115 0 : *extra = -2 * v - 2 * CAT6_MIN_VAL + 1;
116 0 : return;
117 : }
118 0 : *token = av1_dct_cat_lt_10_value_tokens[v].token;
119 0 : *extra = av1_dct_cat_lt_10_value_tokens[v].extra;
120 : }
121 : static INLINE int16_t av1_get_token(int v) {
122 : if (v >= CAT6_MIN_VAL || v <= -CAT6_MIN_VAL) return 10;
123 : return av1_dct_cat_lt_10_value_tokens[v].token;
124 : }
125 :
126 0 : static INLINE int av1_get_token_cost(int v, int16_t *token, int cat6_bits) {
127 0 : if (v >= CAT6_MIN_VAL || v <= -CAT6_MIN_VAL) {
128 : EXTRABIT extrabits;
129 0 : *token = CATEGORY6_TOKEN;
130 0 : extrabits = abs(v) - CAT6_MIN_VAL;
131 0 : return av1_cat6_low_cost[extrabits & 0xff] +
132 0 : av1_cat6_high_cost[extrabits >> 8] -
133 0 : av1_cat6_skipped_bits_discount[18 - cat6_bits];
134 : }
135 0 : *token = av1_dct_cat_lt_10_value_tokens[v].token;
136 0 : return av1_dct_cat_lt_10_value_cost[v];
137 : }
138 :
139 : #if !CONFIG_PVQ || CONFIG_VAR_TX
140 0 : static INLINE int get_tx_eob(const struct segmentation *seg, int segment_id,
141 : TX_SIZE tx_size) {
142 0 : const int eob_max = tx_size_2d[tx_size];
143 0 : return segfeature_active(seg, segment_id, SEG_LVL_SKIP) ? 0 : eob_max;
144 : }
145 : #endif
146 :
147 : #ifdef __cplusplus
148 : } // extern "C"
149 : #endif
150 :
151 : #endif // AV1_ENCODER_TOKENIZE_H_
|