Coverage Report

Created: 2026-11-12 08:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/aom/av1/encoder/segmentation.c
Line
Count
Source
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
#include <limits.h>
13
14
#include "aom_mem/aom_mem.h"
15
16
#include "av1/common/pred_common.h"
17
#include "av1/common/tile_common.h"
18
19
#include "av1/encoder/cost.h"
20
#include "av1/encoder/segmentation.h"
21
22
0
void av1_enable_segmentation(struct segmentation *seg) {
23
0
  seg->enabled = 1;
24
0
  seg->update_map = 1;
25
0
  seg->update_data = 1;
26
0
  seg->temporal_update = 0;
27
0
}
28
29
0
void av1_disable_segmentation(struct segmentation *seg) {
30
0
  seg->enabled = 0;
31
0
  seg->update_map = 0;
32
0
  seg->update_data = 0;
33
0
  seg->temporal_update = 0;
34
0
}
35
36
0
void av1_reuse_ref_segment_features(AV1_COMMON *cm) {
37
0
  struct segmentation *const seg = &cm->seg;
38
0
  const RefCntBuffer *const ref = cm->prev_frame;
39
  // Frames without a primary reference frame always send the features.
40
0
  if (!seg->update_data || cm->features.primary_ref_frame == PRIMARY_REF_NONE ||
41
0
      ref == NULL || !ref->seg.enabled) {
42
0
    return;
43
0
  }
44
0
  for (int i = 0; i < MAX_SEGMENTS; i++) {
45
0
    if (seg->feature_mask[i] != ref->seg.feature_mask[i]) return;
46
0
    for (int j = 0; j < SEG_LVL_MAX; j++) {
47
0
      if (segfeature_active(seg, i, j) &&
48
0
          get_segdata(seg, i, j) != get_segdata(&ref->seg, i, j)) {
49
0
        return;
50
0
      }
51
0
    }
52
0
  }
53
0
  seg->update_data = 0;
54
0
}
55
56
void av1_disable_segfeature(struct segmentation *seg, int segment_id,
57
0
                            SEG_LVL_FEATURES feature_id) {
58
0
  seg->feature_mask[segment_id] &= ~(1u << feature_id);
59
0
}
60
61
void av1_clear_segdata(struct segmentation *seg, int segment_id,
62
0
                       SEG_LVL_FEATURES feature_id) {
63
0
  seg->feature_data[segment_id][feature_id] = 0;
64
0
}
65
66
0
void av1_reset_segment_features(AV1_COMMON *cm) {
67
0
  struct segmentation *seg = &cm->seg;
68
69
  // Set up default state for MB feature flags
70
0
  seg->enabled = 0;
71
0
  seg->update_map = 0;
72
0
  seg->update_data = 0;
73
0
  av1_clearall_segfeatures(seg);
74
0
}