tokenize.h 3.66 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10 11
 */

12 13
#ifndef AV1_ENCODER_TOKENIZE_H_
#define AV1_ENCODER_TOKENIZE_H_
Jingning Han's avatar
Jingning Han committed
14

Yaowu Xu's avatar
Yaowu Xu committed
15
#include "av1/common/entropy.h"
Jingning Han's avatar
Jingning Han committed
16

Yaowu Xu's avatar
Yaowu Xu committed
17 18
#include "av1/encoder/block.h"
#include "av1/encoder/treewriter.h"
Jingning Han's avatar
Jingning Han committed
19 20 21 22 23

#ifdef __cplusplus
extern "C" {
#endif

clang-format's avatar
clang-format committed
24
#define EOSB_TOKEN 127  // Not signalled, encoder only
Jingning Han's avatar
Jingning Han committed
25

26
#if CONFIG_AOM_HIGHBITDEPTH
clang-format's avatar
clang-format committed
27
typedef int32_t EXTRABIT;
Jingning Han's avatar
Jingning Han committed
28
#else
clang-format's avatar
clang-format committed
29
typedef int16_t EXTRABIT;
Jingning Han's avatar
Jingning Han committed
30 31 32 33 34 35 36 37
#endif

typedef struct {
  int16_t token;
  EXTRABIT extra;
} TOKENVALUE;

typedef struct {
Adrian Grange's avatar
Adrian Grange committed
38
  const aom_prob *context_tree;
39 40
#if CONFIG_RANS || CONFIG_DAALA_EC
  const aom_cdf_prob (*token_cdf)[ENTROPY_TOKENS];
41
#endif
Jingning Han's avatar
Jingning Han committed
42 43 44 45 46
  EXTRABIT extra;
  uint8_t token;
  uint8_t skip_eob_node;
} TOKENEXTRA;

47 48 49
extern const aom_tree_index av1_coef_tree[];
extern const aom_tree_index av1_coef_con_tree[];
extern const struct av1_token av1_coef_encodings[];
Jingning Han's avatar
Jingning Han committed
50

51 52
int av1_is_skippable_in_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane);
int av1_has_high_freq_in_plane(MACROBLOCK *x, BLOCK_SIZE bsize, int plane);
Jingning Han's avatar
Jingning Han committed
53

54
struct AV1_COMP;
Jingning Han's avatar
Jingning Han committed
55 56
struct ThreadData;

57
#if CONFIG_PALETTE
58 59
void av1_tokenize_palette_sb(const struct ThreadData *const td,
                             BLOCK_SIZE bsize, int plane, TOKENEXTRA **t);
60 61
#endif  // CONFIG_PALETTE

62
void av1_tokenize_sb(const struct AV1_COMP *cpi, struct ThreadData *td,
clang-format's avatar
clang-format committed
63
                     TOKENEXTRA **t, int dry_run, BLOCK_SIZE bsize);
Jingning Han's avatar
Jingning Han committed
64

65
extern const int16_t *av1_dct_value_cost_ptr;
Jingning Han's avatar
Jingning Han committed
66 67 68 69
/* TODO: The Token field should be broken out into a separate char array to
 *  improve cache locality, since it's needed for costing when the rest of the
 *  fields are not.
 */
70 71 72 73 74 75 76
extern const TOKENVALUE *av1_dct_value_tokens_ptr;
extern const TOKENVALUE *av1_dct_cat_lt_10_value_tokens;
extern const int16_t av1_cat6_low_cost[256];
extern const int av1_cat6_high_cost[64];
extern const int av1_cat6_high10_high_cost[256];
extern const int av1_cat6_high12_high_cost[1024];
static INLINE int av1_get_cost(int16_t token, EXTRABIT extrabits,
clang-format's avatar
clang-format committed
77
                               const int *cat6_high_table) {
78
  if (token != CATEGORY6_TOKEN)
79 80
    return av1_extra_bits[token].cost[extrabits >> 1];
  return av1_cat6_low_cost[(extrabits >> 1) & 0xff] +
81
         cat6_high_table[extrabits >> 9];
Jingning Han's avatar
Jingning Han committed
82 83
}

84 85 86 87 88
#if CONFIG_AOM_HIGHBITDEPTH
static INLINE const int *av1_get_high_cost_table(int bit_depth) {
  return bit_depth == 8 ? av1_cat6_high_cost
                        : (bit_depth == 10 ? av1_cat6_high10_high_cost
                                           : av1_cat6_high12_high_cost);
Jingning Han's avatar
Jingning Han committed
89 90
}
#else
91
static INLINE const int *av1_get_high_cost_table(int bit_depth) {
clang-format's avatar
clang-format committed
92
  (void)bit_depth;
93
  return av1_cat6_high_cost;
Jingning Han's avatar
Jingning Han committed
94
}
95
#endif  // CONFIG_AOM_HIGHBITDEPTH
Jingning Han's avatar
Jingning Han committed
96

clang-format's avatar
clang-format committed
97
static INLINE void av1_get_token_extra(int v, int16_t *token, EXTRABIT *extra) {
Jingning Han's avatar
Jingning Han committed
98 99 100 101 102 103 104 105
  if (v >= CAT6_MIN_VAL || v <= -CAT6_MIN_VAL) {
    *token = CATEGORY6_TOKEN;
    if (v >= CAT6_MIN_VAL)
      *extra = 2 * v - 2 * CAT6_MIN_VAL;
    else
      *extra = -2 * v - 2 * CAT6_MIN_VAL + 1;
    return;
  }
106 107
  *token = av1_dct_cat_lt_10_value_tokens[v].token;
  *extra = av1_dct_cat_lt_10_value_tokens[v].extra;
Jingning Han's avatar
Jingning Han committed
108
}
109
static INLINE int16_t av1_get_token(int v) {
clang-format's avatar
clang-format committed
110
  if (v >= CAT6_MIN_VAL || v <= -CAT6_MIN_VAL) return 10;
111
  return av1_dct_cat_lt_10_value_tokens[v].token;
Jingning Han's avatar
Jingning Han committed
112 113 114 115 116 117
}

#ifdef __cplusplus
}  // extern "C"
#endif

118
#endif  // AV1_ENCODER_TOKENIZE_H_