Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/third_party/aom/av1/common/scale.c
Line
Count
Source (jump to first uncovered line)
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 "config/aom_dsp_rtcd.h"
13
#include "config/av1_rtcd.h"
14
15
#include "av1/common/filter.h"
16
#include "av1/common/scale.h"
17
#include "aom_dsp/aom_filter.h"
18
19
// Note: Expect val to be in q4 precision
20
0
static INLINE int scaled_x(int val, const struct scale_factors *sf) {
21
0
  const int off =
22
0
      (sf->x_scale_fp - (1 << REF_SCALE_SHIFT)) * (1 << (SUBPEL_BITS - 1));
23
0
  const int64_t tval = (int64_t)val * sf->x_scale_fp + off;
24
0
  return (int)ROUND_POWER_OF_TWO_SIGNED_64(tval,
25
0
                                           REF_SCALE_SHIFT - SCALE_EXTRA_BITS);
26
0
}
27
28
// Note: Expect val to be in q4 precision
29
0
static INLINE int scaled_y(int val, const struct scale_factors *sf) {
30
0
  const int off =
31
0
      (sf->y_scale_fp - (1 << REF_SCALE_SHIFT)) * (1 << (SUBPEL_BITS - 1));
32
0
  const int64_t tval = (int64_t)val * sf->y_scale_fp + off;
33
0
  return (int)ROUND_POWER_OF_TWO_SIGNED_64(tval,
34
0
                                           REF_SCALE_SHIFT - SCALE_EXTRA_BITS);
35
0
}
36
37
// Note: Expect val to be in q4 precision
38
0
static int unscaled_value(int val, const struct scale_factors *sf) {
39
0
  (void)sf;
40
0
  return val << SCALE_EXTRA_BITS;
41
0
}
42
43
0
static int get_fixed_point_scale_factor(int other_size, int this_size) {
44
0
  // Calculate scaling factor once for each reference frame
45
0
  // and use fixed point scaling factors in decoding and encoding routines.
46
0
  // Hardware implementations can calculate scale factor in device driver
47
0
  // and use multiplication and shifting on hardware instead of division.
48
0
  return ((other_size << REF_SCALE_SHIFT) + this_size / 2) / this_size;
49
0
}
50
51
// Given the fixed point scale, calculate coarse point scale.
52
0
static int fixed_point_scale_to_coarse_point_scale(int scale_fp) {
53
0
  return ROUND_POWER_OF_TWO(scale_fp, REF_SCALE_SHIFT - SCALE_SUBPEL_BITS);
54
0
}
55
56
// Note: x and y are integer precision, mvq4 is q4 precision.
57
MV32 av1_scale_mv(const MV *mvq4, int x, int y,
58
0
                  const struct scale_factors *sf) {
59
0
  const int x_off_q4 = scaled_x(x << SUBPEL_BITS, sf);
60
0
  const int y_off_q4 = scaled_y(y << SUBPEL_BITS, sf);
61
0
  const MV32 res = { scaled_y((y << SUBPEL_BITS) + mvq4->row, sf) - y_off_q4,
62
0
                     scaled_x((x << SUBPEL_BITS) + mvq4->col, sf) - x_off_q4 };
63
0
  return res;
64
0
}
65
66
void av1_setup_scale_factors_for_frame(struct scale_factors *sf, int other_w,
67
0
                                       int other_h, int this_w, int this_h) {
68
0
  if (!valid_ref_frame_size(other_w, other_h, this_w, this_h)) {
69
0
    sf->x_scale_fp = REF_INVALID_SCALE;
70
0
    sf->y_scale_fp = REF_INVALID_SCALE;
71
0
    return;
72
0
  }
73
0
74
0
  sf->x_scale_fp = get_fixed_point_scale_factor(other_w, this_w);
75
0
  sf->y_scale_fp = get_fixed_point_scale_factor(other_h, this_h);
76
0
77
0
  sf->x_step_q4 = fixed_point_scale_to_coarse_point_scale(sf->x_scale_fp);
78
0
  sf->y_step_q4 = fixed_point_scale_to_coarse_point_scale(sf->y_scale_fp);
79
0
80
0
  if (av1_is_scaled(sf)) {
81
0
    sf->scale_value_x = scaled_x;
82
0
    sf->scale_value_y = scaled_y;
83
0
  } else {
84
0
    sf->scale_value_x = unscaled_value;
85
0
    sf->scale_value_y = unscaled_value;
86
0
  }
87
0
88
0
  // AV1 convolve functions
89
0
  // Special case convolve functions should produce the same result as
90
0
  // av1_convolve_2d.
91
0
  // subpel_x_q4 == 0 && subpel_y_q4 == 0
92
0
  sf->convolve[0][0][0] = av1_convolve_2d_copy_sr;
93
0
  // subpel_x_q4 == 0
94
0
  sf->convolve[0][1][0] = av1_convolve_y_sr;
95
0
  // subpel_y_q4 == 0
96
0
  sf->convolve[1][0][0] = av1_convolve_x_sr;
97
0
  // subpel_x_q4 != 0 && subpel_y_q4 != 0
98
0
  sf->convolve[1][1][0] = av1_convolve_2d_sr;
99
0
  // subpel_x_q4 == 0 && subpel_y_q4 == 0
100
0
  sf->convolve[0][0][1] = av1_jnt_convolve_2d_copy;
101
0
  // subpel_x_q4 == 0
102
0
  sf->convolve[0][1][1] = av1_jnt_convolve_y;
103
0
  // subpel_y_q4 == 0
104
0
  sf->convolve[1][0][1] = av1_jnt_convolve_x;
105
0
  // subpel_x_q4 != 0 && subpel_y_q4 != 0
106
0
  sf->convolve[1][1][1] = av1_jnt_convolve_2d;
107
0
  // AV1 High BD convolve functions
108
0
  // Special case convolve functions should produce the same result as
109
0
  // av1_highbd_convolve_2d.
110
0
  // subpel_x_q4 == 0 && subpel_y_q4 == 0
111
0
  sf->highbd_convolve[0][0][0] = av1_highbd_convolve_2d_copy_sr;
112
0
  // subpel_x_q4 == 0
113
0
  sf->highbd_convolve[0][1][0] = av1_highbd_convolve_y_sr;
114
0
  // subpel_y_q4 == 0
115
0
  sf->highbd_convolve[1][0][0] = av1_highbd_convolve_x_sr;
116
0
  // subpel_x_q4 != 0 && subpel_y_q4 != 0
117
0
  sf->highbd_convolve[1][1][0] = av1_highbd_convolve_2d_sr;
118
0
  // subpel_x_q4 == 0 && subpel_y_q4 == 0
119
0
  sf->highbd_convolve[0][0][1] = av1_highbd_jnt_convolve_2d_copy;
120
0
  // subpel_x_q4 == 0
121
0
  sf->highbd_convolve[0][1][1] = av1_highbd_jnt_convolve_y;
122
0
  // subpel_y_q4 == 0
123
0
  sf->highbd_convolve[1][0][1] = av1_highbd_jnt_convolve_x;
124
0
  // subpel_x_q4 != 0 && subpel_y_q4 != 0
125
0
  sf->highbd_convolve[1][1][1] = av1_highbd_jnt_convolve_2d;
126
0
}