Coverage Report

Created: 2024-09-06 07:53

/src/libvpx/vp9/encoder/vp9_aq_360.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 *  Copyright (c) 2013 The WebM project authors. All Rights Reserved.
3
 *
4
 *  Use of this source code is governed by a BSD-style license
5
 *  that can be found in the LICENSE file in the root of the source
6
 *  tree. An additional intellectual property rights grant can be found
7
 *  in the file PATENTS.  All contributing project authors may
8
 *  be found in the AUTHORS file in the root of the source tree.
9
 */
10
11
#include <math.h>
12
13
#include "vpx_ports/mem.h"
14
#include "vpx_ports/system_state.h"
15
16
#include "vp9/encoder/vp9_aq_360.h"
17
#include "vp9/encoder/vp9_aq_variance.h"
18
19
#include "vp9/common/vp9_seg_common.h"
20
21
#include "vp9/encoder/vp9_ratectrl.h"
22
#include "vp9/encoder/vp9_rd.h"
23
#include "vp9/encoder/vp9_segmentation.h"
24
25
static const double rate_ratio[MAX_SEGMENTS] = { 1.0, 0.75, 0.6, 0.5,
26
                                                 0.4, 0.3,  0.25 };
27
28
// Sets segment id 0 for the equatorial region, 1 for temperate region
29
// and 2 for the polar regions
30
0
unsigned int vp9_360aq_segment_id(int mi_row, int mi_rows) {
31
0
  if (mi_row < mi_rows / 8 || mi_row > mi_rows - mi_rows / 8)
32
0
    return 2;
33
0
  else if (mi_row < mi_rows / 4 || mi_row > mi_rows - mi_rows / 4)
34
0
    return 1;
35
0
  else
36
0
    return 0;
37
0
}
38
39
0
void vp9_360aq_frame_setup(VP9_COMP *cpi) {
40
0
  VP9_COMMON *cm = &cpi->common;
41
0
  struct segmentation *seg = &cm->seg;
42
0
  int i;
43
44
0
  if (frame_is_intra_only(cm) || cpi->force_update_segmentation ||
45
0
      cm->error_resilient_mode) {
46
0
    vp9_enable_segmentation(seg);
47
0
    vp9_clearall_segfeatures(seg);
48
49
0
    seg->abs_delta = SEGMENT_DELTADATA;
50
51
0
    vpx_clear_system_state();
52
53
0
    for (i = 0; i < MAX_SEGMENTS; ++i) {
54
0
      int qindex_delta =
55
0
          vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type, cm->base_qindex,
56
0
                                     rate_ratio[i], cm->bit_depth);
57
58
      // We don't allow qindex 0 in a segment if the base value is not 0.
59
      // Q index 0 (lossless) implies 4x4 encoding only and in AQ mode a segment
60
      // Q delta is sometimes applied without going back around the rd loop.
61
      // This could lead to an illegal combination of partition size and q.
62
0
      if ((cm->base_qindex != 0) && ((cm->base_qindex + qindex_delta) == 0)) {
63
0
        qindex_delta = -cm->base_qindex + 1;
64
0
      }
65
66
      // No need to enable SEG_LVL_ALT_Q for this segment.
67
0
      if (rate_ratio[i] == 1.0) {
68
0
        continue;
69
0
      }
70
71
0
      vp9_set_segdata(seg, i, SEG_LVL_ALT_Q, qindex_delta);
72
0
      vp9_enable_segfeature(seg, i, SEG_LVL_ALT_Q);
73
0
    }
74
0
  }
75
0
}