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 AOM_AV1_ENCODER_TOKENIZE_H_
13 #define AOM_AV1_ENCODER_TOKENIZE_H_
14 
15 #include "av1/common/entropy.h"
16 #include "av1/encoder/block.h"
17 #include "aom_dsp/bitwriter.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 typedef struct {
24   aom_cdf_prob *color_map_cdf;
25   uint8_t token;
26 } TOKENEXTRA;
27 
28 struct AV1_COMP;
29 struct ThreadData;
30 struct FRAME_COUNTS;
31 
32 enum {
33   OUTPUT_ENABLED = 0,
34   DRY_RUN_NORMAL,
35   DRY_RUN_COSTCOEFFS,
36 } UENUM1BYTE(RUN_TYPE);
37 
38 struct tokenize_b_args {
39   const struct AV1_COMP *cpi;
40   struct ThreadData *td;
41   int this_rate;
42   uint8_t allow_update_cdf;
43   RUN_TYPE dry_run;
44 };
45 
46 // Note in all the tokenize functions rate if non NULL is incremented
47 // with the coefficient token cost only if dry_run = DRY_RUN_COSTCOEFS,
48 // otherwise rate is not incremented.
49 void av1_tokenize_sb_vartx(const struct AV1_COMP *cpi, struct ThreadData *td,
50                            RUN_TYPE dry_run, BLOCK_SIZE bsize, int *rate,
51                            uint8_t allow_update_cdf);
52 
53 int av1_cost_color_map(const MACROBLOCK *const x, int plane, BLOCK_SIZE bsize,
54                        TX_SIZE tx_size, COLOR_MAP_TYPE type);
55 
56 void av1_tokenize_color_map(const MACROBLOCK *const x, int plane,
57                             TOKENEXTRA **t, BLOCK_SIZE bsize, TX_SIZE tx_size,
58                             COLOR_MAP_TYPE type, int allow_update_cdf,
59                             struct FRAME_COUNTS *counts);
60 
av1_get_tx_eob(const struct segmentation * seg,int segment_id,TX_SIZE tx_size)61 static INLINE int av1_get_tx_eob(const struct segmentation *seg, int segment_id,
62                                  TX_SIZE tx_size) {
63   const int eob_max = av1_get_max_eob(tx_size);
64   return segfeature_active(seg, segment_id, SEG_LVL_SKIP) ? 0 : eob_max;
65 }
66 
67 #ifdef __cplusplus
68 }  // extern "C"
69 #endif
70 
71 #endif  // AOM_AV1_ENCODER_TOKENIZE_H_
72