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_COMMON_SEG_COMMON_H_
13 #define AOM_AV1_COMMON_SEG_COMMON_H_
14
15 #include "aom_dsp/prob.h"
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 #define MAX_SEGMENTS 8
22 #define SEG_TREE_PROBS (MAX_SEGMENTS - 1)
23
24 #define SEG_TEMPORAL_PRED_CTXS 3
25 #define SPATIAL_PREDICTION_PROBS 3
26
27 enum {
28 SEG_LVL_ALT_Q, // Use alternate Quantizer ....
29 SEG_LVL_ALT_LF_Y_V, // Use alternate loop filter value on y plane vertical
30 SEG_LVL_ALT_LF_Y_H, // Use alternate loop filter value on y plane horizontal
31 SEG_LVL_ALT_LF_U, // Use alternate loop filter value on u plane
32 SEG_LVL_ALT_LF_V, // Use alternate loop filter value on v plane
33 SEG_LVL_REF_FRAME, // Optional Segment reference frame
34 SEG_LVL_SKIP, // Optional Segment (0,0) + skip mode
35 SEG_LVL_GLOBALMV,
36 SEG_LVL_MAX
37 } UENUM1BYTE(SEG_LVL_FEATURES);
38
39 struct segmentation {
40 uint8_t enabled;
41 uint8_t update_map;
42 uint8_t update_data;
43 uint8_t temporal_update;
44
45 int16_t feature_data[MAX_SEGMENTS][SEG_LVL_MAX];
46 unsigned int feature_mask[MAX_SEGMENTS];
47 int last_active_segid; // The highest numbered segment id that has some
48 // enabled feature.
49 uint8_t segid_preskip; // Whether the segment id will be read before the
50 // skip syntax element.
51 // 1: the segment id will be read first.
52 // 0: the skip syntax element will be read first.
53 };
54
55 struct segmentation_probs {
56 aom_cdf_prob tree_cdf[CDF_SIZE(MAX_SEGMENTS)];
57 aom_cdf_prob pred_cdf[SEG_TEMPORAL_PRED_CTXS][CDF_SIZE(2)];
58 aom_cdf_prob spatial_pred_seg_cdf[SPATIAL_PREDICTION_PROBS]
59 [CDF_SIZE(MAX_SEGMENTS)];
60 };
61
segfeature_active(const struct segmentation * seg,int segment_id,SEG_LVL_FEATURES feature_id)62 static INLINE int segfeature_active(const struct segmentation *seg,
63 int segment_id,
64 SEG_LVL_FEATURES feature_id) {
65 return seg->enabled && (seg->feature_mask[segment_id] & (1 << feature_id));
66 }
67
segfeatures_copy(struct segmentation * dst,const struct segmentation * src)68 static INLINE void segfeatures_copy(struct segmentation *dst,
69 const struct segmentation *src) {
70 int i, j;
71 for (i = 0; i < MAX_SEGMENTS; i++) {
72 dst->feature_mask[i] = src->feature_mask[i];
73 for (j = 0; j < SEG_LVL_MAX; j++) {
74 dst->feature_data[i][j] = src->feature_data[i][j];
75 }
76 }
77 dst->segid_preskip = src->segid_preskip;
78 dst->last_active_segid = src->last_active_segid;
79 }
80
81 void av1_clearall_segfeatures(struct segmentation *seg);
82
83 void av1_enable_segfeature(struct segmentation *seg, int segment_id,
84 SEG_LVL_FEATURES feature_id);
85
86 void av1_calculate_segdata(struct segmentation *seg);
87
88 int av1_seg_feature_data_max(SEG_LVL_FEATURES feature_id);
89
90 int av1_is_segfeature_signed(SEG_LVL_FEATURES feature_id);
91
92 void av1_set_segdata(struct segmentation *seg, int segment_id,
93 SEG_LVL_FEATURES feature_id, int seg_data);
94
get_segdata(const struct segmentation * seg,int segment_id,SEG_LVL_FEATURES feature_id)95 static INLINE int get_segdata(const struct segmentation *seg, int segment_id,
96 SEG_LVL_FEATURES feature_id) {
97 return seg->feature_data[segment_id][feature_id];
98 }
99
100 #ifdef __cplusplus
101 } // extern "C"
102 #endif
103
104 #endif // AOM_AV1_COMMON_SEG_COMMON_H_
105