1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
/*
* Copyright (c) 2013 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "./vpx_dsp_rtcd.h"
#include "vp9/common/vp9_filter.h"
#include "vp9/common/vp9_scale.h"
#include "vpx_dsp/vpx_filter.h"
static INLINE int scaled_x(int val, const struct scale_factors *sf) {
return (int)((int64_t)val * sf->x_scale_fp >> REF_SCALE_SHIFT);
}
static INLINE int scaled_y(int val, const struct scale_factors *sf) {
return (int)((int64_t)val * sf->y_scale_fp >> REF_SCALE_SHIFT);
}
static int unscaled_value(int val, const struct scale_factors *sf) {
(void) sf;
return val;
}
static int get_fixed_point_scale_factor(int other_size, int this_size) {
// Calculate scaling factor once for each reference frame
// and use fixed point scaling factors in decoding and encoding routines.
// Hardware implementations can calculate scale factor in device driver
// and use multiplication and shifting on hardware instead of division.
return (other_size << REF_SCALE_SHIFT) / this_size;
}
MV32 vp9_scale_mv(const MV *mv, int x, int y, const struct scale_factors *sf) {
const int x_off_q4 = scaled_x(x << SUBPEL_BITS, sf) & SUBPEL_MASK;
const int y_off_q4 = scaled_y(y << SUBPEL_BITS, sf) & SUBPEL_MASK;
const MV32 res = {
scaled_y(mv->row, sf) + y_off_q4,
scaled_x(mv->col, sf) + x_off_q4
};
return res;
}
#if CONFIG_VP9_HIGHBITDEPTH
void vp9_setup_scale_factors_for_frame(struct scale_factors *sf,
int other_w, int other_h,
int this_w, int this_h,
int use_highbd) {
#else
void vp9_setup_scale_factors_for_frame(struct scale_factors *sf,
int other_w, int other_h,
int this_w, int this_h) {
#endif
if (!valid_ref_frame_size(other_w, other_h, this_w, this_h)) {
sf->x_scale_fp = REF_INVALID_SCALE;
sf->y_scale_fp = REF_INVALID_SCALE;
return;
}
sf->x_scale_fp = get_fixed_point_scale_factor(other_w, this_w);
sf->y_scale_fp = get_fixed_point_scale_factor(other_h, this_h);
sf->x_step_q4 = scaled_x(16, sf);
sf->y_step_q4 = scaled_y(16, sf);
if (vp9_is_scaled(sf)) {
sf->scale_value_x = scaled_x;
sf->scale_value_y = scaled_y;
} else {
sf->scale_value_x = unscaled_value;
sf->scale_value_y = unscaled_value;
}
// TODO(agrange): Investigate the best choice of functions to use here
// for EIGHTTAP_SMOOTH. Since it is not interpolating, need to choose what
// to do at full-pel offsets. The current selection, where the filter is
// applied in one direction only, and not at all for 0,0, seems to give the
// best quality, but it may be worth trying an additional mode that does
// do the filtering on full-pel.
if (sf->x_step_q4 == 16) {
if (sf->y_step_q4 == 16) {
// No scaling in either direction.
sf->predict[0][0][0] = vpx_convolve_copy;
sf->predict[0][0][1] = vpx_convolve_avg;
sf->predict[0][1][0] = vpx_convolve8_vert;
sf->predict[0][1][1] = vpx_convolve8_avg_vert;
sf->predict[1][0][0] = vpx_convolve8_horiz;
sf->predict[1][0][1] = vpx_convolve8_avg_horiz;
} else {
// No scaling in x direction. Must always scale in the y direction.
sf->predict[0][0][0] = vpx_scaled_vert;
sf->predict[0][0][1] = vpx_scaled_avg_vert;
sf->predict[0][1][0] = vpx_scaled_vert;
sf->predict[0][1][1] = vpx_scaled_avg_vert;
sf->predict[1][0][0] = vpx_scaled_2d;
sf->predict[1][0][1] = vpx_scaled_avg_2d;
}
} else {
if (sf->y_step_q4 == 16) {
// No scaling in the y direction. Must always scale in the x direction.
sf->predict[0][0][0] = vpx_scaled_horiz;
sf->predict[0][0][1] = vpx_scaled_avg_horiz;
sf->predict[0][1][0] = vpx_scaled_2d;
sf->predict[0][1][1] = vpx_scaled_avg_2d;
sf->predict[1][0][0] = vpx_scaled_horiz;
sf->predict[1][0][1] = vpx_scaled_avg_horiz;
} else {
// Must always scale in both directions.
sf->predict[0][0][0] = vpx_scaled_2d;
sf->predict[0][0][1] = vpx_scaled_avg_2d;
sf->predict[0][1][0] = vpx_scaled_2d;
sf->predict[0][1][1] = vpx_scaled_avg_2d;
sf->predict[1][0][0] = vpx_scaled_2d;
sf->predict[1][0][1] = vpx_scaled_avg_2d;
}
}
// 2D subpel motion always gets filtered in both directions
if ((sf->x_step_q4 != 16) || (sf->y_step_q4 != 16)) {
sf->predict[1][1][0] = vpx_scaled_2d;
sf->predict[1][1][1] = vpx_scaled_avg_2d;
} else {
sf->predict[1][1][0] = vpx_convolve8;
sf->predict[1][1][1] = vpx_convolve8_avg;
}
#if CONFIG_VP9_HIGHBITDEPTH
if (use_highbd) {
if (sf->x_step_q4 == 16) {
if (sf->y_step_q4 == 16) {
// No scaling in either direction.
sf->highbd_predict[0][0][0] = vpx_highbd_convolve_copy;
sf->highbd_predict[0][0][1] = vpx_highbd_convolve_avg;
sf->highbd_predict[0][1][0] = vpx_highbd_convolve8_vert;
sf->highbd_predict[0][1][1] = vpx_highbd_convolve8_avg_vert;
sf->highbd_predict[1][0][0] = vpx_highbd_convolve8_horiz;
sf->highbd_predict[1][0][1] = vpx_highbd_convolve8_avg_horiz;
} else {
// No scaling in x direction. Must always scale in the y direction.
sf->highbd_predict[0][0][0] = vpx_highbd_convolve8_vert;
sf->highbd_predict[0][0][1] = vpx_highbd_convolve8_avg_vert;
sf->highbd_predict[0][1][0] = vpx_highbd_convolve8_vert;
sf->highbd_predict[0][1][1] = vpx_highbd_convolve8_avg_vert;
sf->highbd_predict[1][0][0] = vpx_highbd_convolve8;
sf->highbd_predict[1][0][1] = vpx_highbd_convolve8_avg;
}
} else {
if (sf->y_step_q4 == 16) {
// No scaling in the y direction. Must always scale in the x direction.
sf->highbd_predict[0][0][0] = vpx_highbd_convolve8_horiz;
sf->highbd_predict[0][0][1] = vpx_highbd_convolve8_avg_horiz;
sf->highbd_predict[0][1][0] = vpx_highbd_convolve8;
sf->highbd_predict[0][1][1] = vpx_highbd_convolve8_avg;
sf->highbd_predict[1][0][0] = vpx_highbd_convolve8_horiz;
sf->highbd_predict[1][0][1] = vpx_highbd_convolve8_avg_horiz;
} else {
// Must always scale in both directions.
sf->highbd_predict[0][0][0] = vpx_highbd_convolve8;
sf->highbd_predict[0][0][1] = vpx_highbd_convolve8_avg;
sf->highbd_predict[0][1][0] = vpx_highbd_convolve8;
sf->highbd_predict[0][1][1] = vpx_highbd_convolve8_avg;
sf->highbd_predict[1][0][0] = vpx_highbd_convolve8;
sf->highbd_predict[1][0][1] = vpx_highbd_convolve8_avg;
}
}
// 2D subpel motion always gets filtered in both directions.
sf->highbd_predict[1][1][0] = vpx_highbd_convolve8;
sf->highbd_predict[1][1][1] = vpx_highbd_convolve8_avg;
}
#endif
}
|