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