1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker *
4*77c1e3ccSAndroid Build Coastguard Worker * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker */
11*77c1e3ccSAndroid Build Coastguard Worker
12*77c1e3ccSAndroid Build Coastguard Worker #include <assert.h>
13*77c1e3ccSAndroid Build Coastguard Worker #include <limits.h>
14*77c1e3ccSAndroid Build Coastguard Worker #include <math.h>
15*77c1e3ccSAndroid Build Coastguard Worker #include <stdbool.h>
16*77c1e3ccSAndroid Build Coastguard Worker #include <stdio.h>
17*77c1e3ccSAndroid Build Coastguard Worker #include <stdlib.h>
18*77c1e3ccSAndroid Build Coastguard Worker #include <string.h>
19*77c1e3ccSAndroid Build Coastguard Worker
20*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_config.h"
21*77c1e3ccSAndroid Build Coastguard Worker #include "config/av1_rtcd.h"
22*77c1e3ccSAndroid Build Coastguard Worker
23*77c1e3ccSAndroid Build Coastguard Worker #include "aom_dsp/aom_dsp_common.h"
24*77c1e3ccSAndroid Build Coastguard Worker #include "aom_dsp/flow_estimation/corner_detect.h"
25*77c1e3ccSAndroid Build Coastguard Worker #include "aom_ports/mem.h"
26*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/common.h"
27*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/resize.h"
28*77c1e3ccSAndroid Build Coastguard Worker
29*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_dsp_rtcd.h"
30*77c1e3ccSAndroid Build Coastguard Worker #include "config/aom_scale_rtcd.h"
31*77c1e3ccSAndroid Build Coastguard Worker
32*77c1e3ccSAndroid Build Coastguard Worker // Filters for interpolation (0.5-band) - note this also filters integer pels.
33*77c1e3ccSAndroid Build Coastguard Worker static const InterpKernel filteredinterp_filters500[(1 << RS_SUBPEL_BITS)] = {
34*77c1e3ccSAndroid Build Coastguard Worker { -3, 0, 35, 64, 35, 0, -3, 0 }, { -3, 0, 34, 64, 36, 0, -3, 0 },
35*77c1e3ccSAndroid Build Coastguard Worker { -3, -1, 34, 64, 36, 1, -3, 0 }, { -3, -1, 33, 64, 37, 1, -3, 0 },
36*77c1e3ccSAndroid Build Coastguard Worker { -3, -1, 32, 64, 38, 1, -3, 0 }, { -3, -1, 31, 64, 39, 1, -3, 0 },
37*77c1e3ccSAndroid Build Coastguard Worker { -3, -1, 31, 63, 39, 2, -3, 0 }, { -2, -2, 30, 63, 40, 2, -3, 0 },
38*77c1e3ccSAndroid Build Coastguard Worker { -2, -2, 29, 63, 41, 2, -3, 0 }, { -2, -2, 29, 63, 41, 3, -4, 0 },
39*77c1e3ccSAndroid Build Coastguard Worker { -2, -2, 28, 63, 42, 3, -4, 0 }, { -2, -2, 27, 63, 43, 3, -4, 0 },
40*77c1e3ccSAndroid Build Coastguard Worker { -2, -3, 27, 63, 43, 4, -4, 0 }, { -2, -3, 26, 62, 44, 5, -4, 0 },
41*77c1e3ccSAndroid Build Coastguard Worker { -2, -3, 25, 62, 45, 5, -4, 0 }, { -2, -3, 25, 62, 45, 5, -4, 0 },
42*77c1e3ccSAndroid Build Coastguard Worker { -2, -3, 24, 62, 46, 5, -4, 0 }, { -2, -3, 23, 61, 47, 6, -4, 0 },
43*77c1e3ccSAndroid Build Coastguard Worker { -2, -3, 23, 61, 47, 6, -4, 0 }, { -2, -3, 22, 61, 48, 7, -4, -1 },
44*77c1e3ccSAndroid Build Coastguard Worker { -2, -3, 21, 60, 49, 7, -4, 0 }, { -1, -4, 20, 60, 49, 8, -4, 0 },
45*77c1e3ccSAndroid Build Coastguard Worker { -1, -4, 20, 60, 50, 8, -4, -1 }, { -1, -4, 19, 59, 51, 9, -4, -1 },
46*77c1e3ccSAndroid Build Coastguard Worker { -1, -4, 19, 59, 51, 9, -4, -1 }, { -1, -4, 18, 58, 52, 10, -4, -1 },
47*77c1e3ccSAndroid Build Coastguard Worker { -1, -4, 17, 58, 52, 11, -4, -1 }, { -1, -4, 16, 58, 53, 11, -4, -1 },
48*77c1e3ccSAndroid Build Coastguard Worker { -1, -4, 16, 57, 53, 12, -4, -1 }, { -1, -4, 15, 57, 54, 12, -4, -1 },
49*77c1e3ccSAndroid Build Coastguard Worker { -1, -4, 15, 56, 54, 13, -4, -1 }, { -1, -4, 14, 56, 55, 13, -4, -1 },
50*77c1e3ccSAndroid Build Coastguard Worker { -1, -4, 14, 55, 55, 14, -4, -1 }, { -1, -4, 13, 55, 56, 14, -4, -1 },
51*77c1e3ccSAndroid Build Coastguard Worker { -1, -4, 13, 54, 56, 15, -4, -1 }, { -1, -4, 12, 54, 57, 15, -4, -1 },
52*77c1e3ccSAndroid Build Coastguard Worker { -1, -4, 12, 53, 57, 16, -4, -1 }, { -1, -4, 11, 53, 58, 16, -4, -1 },
53*77c1e3ccSAndroid Build Coastguard Worker { -1, -4, 11, 52, 58, 17, -4, -1 }, { -1, -4, 10, 52, 58, 18, -4, -1 },
54*77c1e3ccSAndroid Build Coastguard Worker { -1, -4, 9, 51, 59, 19, -4, -1 }, { -1, -4, 9, 51, 59, 19, -4, -1 },
55*77c1e3ccSAndroid Build Coastguard Worker { -1, -4, 8, 50, 60, 20, -4, -1 }, { 0, -4, 8, 49, 60, 20, -4, -1 },
56*77c1e3ccSAndroid Build Coastguard Worker { 0, -4, 7, 49, 60, 21, -3, -2 }, { -1, -4, 7, 48, 61, 22, -3, -2 },
57*77c1e3ccSAndroid Build Coastguard Worker { 0, -4, 6, 47, 61, 23, -3, -2 }, { 0, -4, 6, 47, 61, 23, -3, -2 },
58*77c1e3ccSAndroid Build Coastguard Worker { 0, -4, 5, 46, 62, 24, -3, -2 }, { 0, -4, 5, 45, 62, 25, -3, -2 },
59*77c1e3ccSAndroid Build Coastguard Worker { 0, -4, 5, 45, 62, 25, -3, -2 }, { 0, -4, 5, 44, 62, 26, -3, -2 },
60*77c1e3ccSAndroid Build Coastguard Worker { 0, -4, 4, 43, 63, 27, -3, -2 }, { 0, -4, 3, 43, 63, 27, -2, -2 },
61*77c1e3ccSAndroid Build Coastguard Worker { 0, -4, 3, 42, 63, 28, -2, -2 }, { 0, -4, 3, 41, 63, 29, -2, -2 },
62*77c1e3ccSAndroid Build Coastguard Worker { 0, -3, 2, 41, 63, 29, -2, -2 }, { 0, -3, 2, 40, 63, 30, -2, -2 },
63*77c1e3ccSAndroid Build Coastguard Worker { 0, -3, 2, 39, 63, 31, -1, -3 }, { 0, -3, 1, 39, 64, 31, -1, -3 },
64*77c1e3ccSAndroid Build Coastguard Worker { 0, -3, 1, 38, 64, 32, -1, -3 }, { 0, -3, 1, 37, 64, 33, -1, -3 },
65*77c1e3ccSAndroid Build Coastguard Worker { 0, -3, 1, 36, 64, 34, -1, -3 }, { 0, -3, 0, 36, 64, 34, 0, -3 },
66*77c1e3ccSAndroid Build Coastguard Worker };
67*77c1e3ccSAndroid Build Coastguard Worker
68*77c1e3ccSAndroid Build Coastguard Worker // Filters for interpolation (0.625-band) - note this also filters integer pels.
69*77c1e3ccSAndroid Build Coastguard Worker static const InterpKernel filteredinterp_filters625[(1 << RS_SUBPEL_BITS)] = {
70*77c1e3ccSAndroid Build Coastguard Worker { -1, -8, 33, 80, 33, -8, -1, 0 }, { -1, -8, 31, 80, 34, -8, -1, 1 },
71*77c1e3ccSAndroid Build Coastguard Worker { -1, -8, 30, 80, 35, -8, -1, 1 }, { -1, -8, 29, 80, 36, -7, -2, 1 },
72*77c1e3ccSAndroid Build Coastguard Worker { -1, -8, 28, 80, 37, -7, -2, 1 }, { -1, -8, 27, 80, 38, -7, -2, 1 },
73*77c1e3ccSAndroid Build Coastguard Worker { 0, -8, 26, 79, 39, -7, -2, 1 }, { 0, -8, 25, 79, 40, -7, -2, 1 },
74*77c1e3ccSAndroid Build Coastguard Worker { 0, -8, 24, 79, 41, -7, -2, 1 }, { 0, -8, 23, 78, 42, -6, -2, 1 },
75*77c1e3ccSAndroid Build Coastguard Worker { 0, -8, 22, 78, 43, -6, -2, 1 }, { 0, -8, 21, 78, 44, -6, -2, 1 },
76*77c1e3ccSAndroid Build Coastguard Worker { 0, -8, 20, 78, 45, -5, -3, 1 }, { 0, -8, 19, 77, 47, -5, -3, 1 },
77*77c1e3ccSAndroid Build Coastguard Worker { 0, -8, 18, 77, 48, -5, -3, 1 }, { 0, -8, 17, 77, 49, -5, -3, 1 },
78*77c1e3ccSAndroid Build Coastguard Worker { 0, -8, 16, 76, 50, -4, -3, 1 }, { 0, -8, 15, 76, 51, -4, -3, 1 },
79*77c1e3ccSAndroid Build Coastguard Worker { 0, -8, 15, 75, 52, -3, -4, 1 }, { 0, -7, 14, 74, 53, -3, -4, 1 },
80*77c1e3ccSAndroid Build Coastguard Worker { 0, -7, 13, 74, 54, -3, -4, 1 }, { 0, -7, 12, 73, 55, -2, -4, 1 },
81*77c1e3ccSAndroid Build Coastguard Worker { 0, -7, 11, 73, 56, -2, -4, 1 }, { 0, -7, 10, 72, 57, -1, -4, 1 },
82*77c1e3ccSAndroid Build Coastguard Worker { 1, -7, 10, 71, 58, -1, -5, 1 }, { 0, -7, 9, 71, 59, 0, -5, 1 },
83*77c1e3ccSAndroid Build Coastguard Worker { 1, -7, 8, 70, 60, 0, -5, 1 }, { 1, -7, 7, 69, 61, 1, -5, 1 },
84*77c1e3ccSAndroid Build Coastguard Worker { 1, -6, 6, 68, 62, 1, -5, 1 }, { 0, -6, 6, 68, 62, 2, -5, 1 },
85*77c1e3ccSAndroid Build Coastguard Worker { 1, -6, 5, 67, 63, 2, -5, 1 }, { 1, -6, 5, 66, 64, 3, -6, 1 },
86*77c1e3ccSAndroid Build Coastguard Worker { 1, -6, 4, 65, 65, 4, -6, 1 }, { 1, -6, 3, 64, 66, 5, -6, 1 },
87*77c1e3ccSAndroid Build Coastguard Worker { 1, -5, 2, 63, 67, 5, -6, 1 }, { 1, -5, 2, 62, 68, 6, -6, 0 },
88*77c1e3ccSAndroid Build Coastguard Worker { 1, -5, 1, 62, 68, 6, -6, 1 }, { 1, -5, 1, 61, 69, 7, -7, 1 },
89*77c1e3ccSAndroid Build Coastguard Worker { 1, -5, 0, 60, 70, 8, -7, 1 }, { 1, -5, 0, 59, 71, 9, -7, 0 },
90*77c1e3ccSAndroid Build Coastguard Worker { 1, -5, -1, 58, 71, 10, -7, 1 }, { 1, -4, -1, 57, 72, 10, -7, 0 },
91*77c1e3ccSAndroid Build Coastguard Worker { 1, -4, -2, 56, 73, 11, -7, 0 }, { 1, -4, -2, 55, 73, 12, -7, 0 },
92*77c1e3ccSAndroid Build Coastguard Worker { 1, -4, -3, 54, 74, 13, -7, 0 }, { 1, -4, -3, 53, 74, 14, -7, 0 },
93*77c1e3ccSAndroid Build Coastguard Worker { 1, -4, -3, 52, 75, 15, -8, 0 }, { 1, -3, -4, 51, 76, 15, -8, 0 },
94*77c1e3ccSAndroid Build Coastguard Worker { 1, -3, -4, 50, 76, 16, -8, 0 }, { 1, -3, -5, 49, 77, 17, -8, 0 },
95*77c1e3ccSAndroid Build Coastguard Worker { 1, -3, -5, 48, 77, 18, -8, 0 }, { 1, -3, -5, 47, 77, 19, -8, 0 },
96*77c1e3ccSAndroid Build Coastguard Worker { 1, -3, -5, 45, 78, 20, -8, 0 }, { 1, -2, -6, 44, 78, 21, -8, 0 },
97*77c1e3ccSAndroid Build Coastguard Worker { 1, -2, -6, 43, 78, 22, -8, 0 }, { 1, -2, -6, 42, 78, 23, -8, 0 },
98*77c1e3ccSAndroid Build Coastguard Worker { 1, -2, -7, 41, 79, 24, -8, 0 }, { 1, -2, -7, 40, 79, 25, -8, 0 },
99*77c1e3ccSAndroid Build Coastguard Worker { 1, -2, -7, 39, 79, 26, -8, 0 }, { 1, -2, -7, 38, 80, 27, -8, -1 },
100*77c1e3ccSAndroid Build Coastguard Worker { 1, -2, -7, 37, 80, 28, -8, -1 }, { 1, -2, -7, 36, 80, 29, -8, -1 },
101*77c1e3ccSAndroid Build Coastguard Worker { 1, -1, -8, 35, 80, 30, -8, -1 }, { 1, -1, -8, 34, 80, 31, -8, -1 },
102*77c1e3ccSAndroid Build Coastguard Worker };
103*77c1e3ccSAndroid Build Coastguard Worker
104*77c1e3ccSAndroid Build Coastguard Worker // Filters for interpolation (0.75-band) - note this also filters integer pels.
105*77c1e3ccSAndroid Build Coastguard Worker static const InterpKernel filteredinterp_filters750[(1 << RS_SUBPEL_BITS)] = {
106*77c1e3ccSAndroid Build Coastguard Worker { 2, -11, 25, 96, 25, -11, 2, 0 }, { 2, -11, 24, 96, 26, -11, 2, 0 },
107*77c1e3ccSAndroid Build Coastguard Worker { 2, -11, 22, 96, 28, -11, 2, 0 }, { 2, -10, 21, 96, 29, -12, 2, 0 },
108*77c1e3ccSAndroid Build Coastguard Worker { 2, -10, 19, 96, 31, -12, 2, 0 }, { 2, -10, 18, 95, 32, -11, 2, 0 },
109*77c1e3ccSAndroid Build Coastguard Worker { 2, -10, 17, 95, 34, -12, 2, 0 }, { 2, -9, 15, 95, 35, -12, 2, 0 },
110*77c1e3ccSAndroid Build Coastguard Worker { 2, -9, 14, 94, 37, -12, 2, 0 }, { 2, -9, 13, 94, 38, -12, 2, 0 },
111*77c1e3ccSAndroid Build Coastguard Worker { 2, -8, 12, 93, 40, -12, 1, 0 }, { 2, -8, 11, 93, 41, -12, 1, 0 },
112*77c1e3ccSAndroid Build Coastguard Worker { 2, -8, 9, 92, 43, -12, 1, 1 }, { 2, -8, 8, 92, 44, -12, 1, 1 },
113*77c1e3ccSAndroid Build Coastguard Worker { 2, -7, 7, 91, 46, -12, 1, 0 }, { 2, -7, 6, 90, 47, -12, 1, 1 },
114*77c1e3ccSAndroid Build Coastguard Worker { 2, -7, 5, 90, 49, -12, 1, 0 }, { 2, -6, 4, 89, 50, -12, 1, 0 },
115*77c1e3ccSAndroid Build Coastguard Worker { 2, -6, 3, 88, 52, -12, 0, 1 }, { 2, -6, 2, 87, 54, -12, 0, 1 },
116*77c1e3ccSAndroid Build Coastguard Worker { 2, -5, 1, 86, 55, -12, 0, 1 }, { 2, -5, 0, 85, 57, -12, 0, 1 },
117*77c1e3ccSAndroid Build Coastguard Worker { 2, -5, -1, 84, 58, -11, 0, 1 }, { 2, -5, -2, 83, 60, -11, 0, 1 },
118*77c1e3ccSAndroid Build Coastguard Worker { 2, -4, -2, 82, 61, -11, -1, 1 }, { 1, -4, -3, 81, 63, -10, -1, 1 },
119*77c1e3ccSAndroid Build Coastguard Worker { 2, -4, -4, 80, 64, -10, -1, 1 }, { 1, -4, -4, 79, 66, -10, -1, 1 },
120*77c1e3ccSAndroid Build Coastguard Worker { 1, -3, -5, 77, 67, -9, -1, 1 }, { 1, -3, -6, 76, 69, -9, -1, 1 },
121*77c1e3ccSAndroid Build Coastguard Worker { 1, -3, -6, 75, 70, -8, -2, 1 }, { 1, -2, -7, 74, 71, -8, -2, 1 },
122*77c1e3ccSAndroid Build Coastguard Worker { 1, -2, -7, 72, 72, -7, -2, 1 }, { 1, -2, -8, 71, 74, -7, -2, 1 },
123*77c1e3ccSAndroid Build Coastguard Worker { 1, -2, -8, 70, 75, -6, -3, 1 }, { 1, -1, -9, 69, 76, -6, -3, 1 },
124*77c1e3ccSAndroid Build Coastguard Worker { 1, -1, -9, 67, 77, -5, -3, 1 }, { 1, -1, -10, 66, 79, -4, -4, 1 },
125*77c1e3ccSAndroid Build Coastguard Worker { 1, -1, -10, 64, 80, -4, -4, 2 }, { 1, -1, -10, 63, 81, -3, -4, 1 },
126*77c1e3ccSAndroid Build Coastguard Worker { 1, -1, -11, 61, 82, -2, -4, 2 }, { 1, 0, -11, 60, 83, -2, -5, 2 },
127*77c1e3ccSAndroid Build Coastguard Worker { 1, 0, -11, 58, 84, -1, -5, 2 }, { 1, 0, -12, 57, 85, 0, -5, 2 },
128*77c1e3ccSAndroid Build Coastguard Worker { 1, 0, -12, 55, 86, 1, -5, 2 }, { 1, 0, -12, 54, 87, 2, -6, 2 },
129*77c1e3ccSAndroid Build Coastguard Worker { 1, 0, -12, 52, 88, 3, -6, 2 }, { 0, 1, -12, 50, 89, 4, -6, 2 },
130*77c1e3ccSAndroid Build Coastguard Worker { 0, 1, -12, 49, 90, 5, -7, 2 }, { 1, 1, -12, 47, 90, 6, -7, 2 },
131*77c1e3ccSAndroid Build Coastguard Worker { 0, 1, -12, 46, 91, 7, -7, 2 }, { 1, 1, -12, 44, 92, 8, -8, 2 },
132*77c1e3ccSAndroid Build Coastguard Worker { 1, 1, -12, 43, 92, 9, -8, 2 }, { 0, 1, -12, 41, 93, 11, -8, 2 },
133*77c1e3ccSAndroid Build Coastguard Worker { 0, 1, -12, 40, 93, 12, -8, 2 }, { 0, 2, -12, 38, 94, 13, -9, 2 },
134*77c1e3ccSAndroid Build Coastguard Worker { 0, 2, -12, 37, 94, 14, -9, 2 }, { 0, 2, -12, 35, 95, 15, -9, 2 },
135*77c1e3ccSAndroid Build Coastguard Worker { 0, 2, -12, 34, 95, 17, -10, 2 }, { 0, 2, -11, 32, 95, 18, -10, 2 },
136*77c1e3ccSAndroid Build Coastguard Worker { 0, 2, -12, 31, 96, 19, -10, 2 }, { 0, 2, -12, 29, 96, 21, -10, 2 },
137*77c1e3ccSAndroid Build Coastguard Worker { 0, 2, -11, 28, 96, 22, -11, 2 }, { 0, 2, -11, 26, 96, 24, -11, 2 },
138*77c1e3ccSAndroid Build Coastguard Worker };
139*77c1e3ccSAndroid Build Coastguard Worker
140*77c1e3ccSAndroid Build Coastguard Worker // Filters for interpolation (0.875-band) - note this also filters integer pels.
141*77c1e3ccSAndroid Build Coastguard Worker static const InterpKernel filteredinterp_filters875[(1 << RS_SUBPEL_BITS)] = {
142*77c1e3ccSAndroid Build Coastguard Worker { 3, -8, 13, 112, 13, -8, 3, 0 }, { 2, -7, 12, 112, 15, -8, 3, -1 },
143*77c1e3ccSAndroid Build Coastguard Worker { 3, -7, 10, 112, 17, -9, 3, -1 }, { 2, -6, 8, 112, 19, -9, 3, -1 },
144*77c1e3ccSAndroid Build Coastguard Worker { 2, -6, 7, 112, 21, -10, 3, -1 }, { 2, -5, 6, 111, 22, -10, 3, -1 },
145*77c1e3ccSAndroid Build Coastguard Worker { 2, -5, 4, 111, 24, -10, 3, -1 }, { 2, -4, 3, 110, 26, -11, 3, -1 },
146*77c1e3ccSAndroid Build Coastguard Worker { 2, -4, 1, 110, 28, -11, 3, -1 }, { 2, -4, 0, 109, 30, -12, 4, -1 },
147*77c1e3ccSAndroid Build Coastguard Worker { 1, -3, -1, 108, 32, -12, 4, -1 }, { 1, -3, -2, 108, 34, -13, 4, -1 },
148*77c1e3ccSAndroid Build Coastguard Worker { 1, -2, -4, 107, 36, -13, 4, -1 }, { 1, -2, -5, 106, 38, -13, 4, -1 },
149*77c1e3ccSAndroid Build Coastguard Worker { 1, -1, -6, 105, 40, -14, 4, -1 }, { 1, -1, -7, 104, 42, -14, 4, -1 },
150*77c1e3ccSAndroid Build Coastguard Worker { 1, -1, -7, 103, 44, -15, 4, -1 }, { 1, 0, -8, 101, 46, -15, 4, -1 },
151*77c1e3ccSAndroid Build Coastguard Worker { 1, 0, -9, 100, 48, -15, 4, -1 }, { 1, 0, -10, 99, 50, -15, 4, -1 },
152*77c1e3ccSAndroid Build Coastguard Worker { 1, 1, -11, 97, 53, -16, 4, -1 }, { 0, 1, -11, 96, 55, -16, 4, -1 },
153*77c1e3ccSAndroid Build Coastguard Worker { 0, 1, -12, 95, 57, -16, 4, -1 }, { 0, 2, -13, 93, 59, -16, 4, -1 },
154*77c1e3ccSAndroid Build Coastguard Worker { 0, 2, -13, 91, 61, -16, 4, -1 }, { 0, 2, -14, 90, 63, -16, 4, -1 },
155*77c1e3ccSAndroid Build Coastguard Worker { 0, 2, -14, 88, 65, -16, 4, -1 }, { 0, 2, -15, 86, 67, -16, 4, 0 },
156*77c1e3ccSAndroid Build Coastguard Worker { 0, 3, -15, 84, 69, -17, 4, 0 }, { 0, 3, -16, 83, 71, -17, 4, 0 },
157*77c1e3ccSAndroid Build Coastguard Worker { 0, 3, -16, 81, 73, -16, 3, 0 }, { 0, 3, -16, 79, 75, -16, 3, 0 },
158*77c1e3ccSAndroid Build Coastguard Worker { 0, 3, -16, 77, 77, -16, 3, 0 }, { 0, 3, -16, 75, 79, -16, 3, 0 },
159*77c1e3ccSAndroid Build Coastguard Worker { 0, 3, -16, 73, 81, -16, 3, 0 }, { 0, 4, -17, 71, 83, -16, 3, 0 },
160*77c1e3ccSAndroid Build Coastguard Worker { 0, 4, -17, 69, 84, -15, 3, 0 }, { 0, 4, -16, 67, 86, -15, 2, 0 },
161*77c1e3ccSAndroid Build Coastguard Worker { -1, 4, -16, 65, 88, -14, 2, 0 }, { -1, 4, -16, 63, 90, -14, 2, 0 },
162*77c1e3ccSAndroid Build Coastguard Worker { -1, 4, -16, 61, 91, -13, 2, 0 }, { -1, 4, -16, 59, 93, -13, 2, 0 },
163*77c1e3ccSAndroid Build Coastguard Worker { -1, 4, -16, 57, 95, -12, 1, 0 }, { -1, 4, -16, 55, 96, -11, 1, 0 },
164*77c1e3ccSAndroid Build Coastguard Worker { -1, 4, -16, 53, 97, -11, 1, 1 }, { -1, 4, -15, 50, 99, -10, 0, 1 },
165*77c1e3ccSAndroid Build Coastguard Worker { -1, 4, -15, 48, 100, -9, 0, 1 }, { -1, 4, -15, 46, 101, -8, 0, 1 },
166*77c1e3ccSAndroid Build Coastguard Worker { -1, 4, -15, 44, 103, -7, -1, 1 }, { -1, 4, -14, 42, 104, -7, -1, 1 },
167*77c1e3ccSAndroid Build Coastguard Worker { -1, 4, -14, 40, 105, -6, -1, 1 }, { -1, 4, -13, 38, 106, -5, -2, 1 },
168*77c1e3ccSAndroid Build Coastguard Worker { -1, 4, -13, 36, 107, -4, -2, 1 }, { -1, 4, -13, 34, 108, -2, -3, 1 },
169*77c1e3ccSAndroid Build Coastguard Worker { -1, 4, -12, 32, 108, -1, -3, 1 }, { -1, 4, -12, 30, 109, 0, -4, 2 },
170*77c1e3ccSAndroid Build Coastguard Worker { -1, 3, -11, 28, 110, 1, -4, 2 }, { -1, 3, -11, 26, 110, 3, -4, 2 },
171*77c1e3ccSAndroid Build Coastguard Worker { -1, 3, -10, 24, 111, 4, -5, 2 }, { -1, 3, -10, 22, 111, 6, -5, 2 },
172*77c1e3ccSAndroid Build Coastguard Worker { -1, 3, -10, 21, 112, 7, -6, 2 }, { -1, 3, -9, 19, 112, 8, -6, 2 },
173*77c1e3ccSAndroid Build Coastguard Worker { -1, 3, -9, 17, 112, 10, -7, 3 }, { -1, 3, -8, 15, 112, 12, -7, 2 },
174*77c1e3ccSAndroid Build Coastguard Worker };
175*77c1e3ccSAndroid Build Coastguard Worker
176*77c1e3ccSAndroid Build Coastguard Worker const int16_t av1_resize_filter_normative[(
177*77c1e3ccSAndroid Build Coastguard Worker 1 << RS_SUBPEL_BITS)][UPSCALE_NORMATIVE_TAPS] = {
178*77c1e3ccSAndroid Build Coastguard Worker #if UPSCALE_NORMATIVE_TAPS == 8
179*77c1e3ccSAndroid Build Coastguard Worker { 0, 0, 0, 128, 0, 0, 0, 0 }, { 0, 0, -1, 128, 2, -1, 0, 0 },
180*77c1e3ccSAndroid Build Coastguard Worker { 0, 1, -3, 127, 4, -2, 1, 0 }, { 0, 1, -4, 127, 6, -3, 1, 0 },
181*77c1e3ccSAndroid Build Coastguard Worker { 0, 2, -6, 126, 8, -3, 1, 0 }, { 0, 2, -7, 125, 11, -4, 1, 0 },
182*77c1e3ccSAndroid Build Coastguard Worker { -1, 2, -8, 125, 13, -5, 2, 0 }, { -1, 3, -9, 124, 15, -6, 2, 0 },
183*77c1e3ccSAndroid Build Coastguard Worker { -1, 3, -10, 123, 18, -6, 2, -1 }, { -1, 3, -11, 122, 20, -7, 3, -1 },
184*77c1e3ccSAndroid Build Coastguard Worker { -1, 4, -12, 121, 22, -8, 3, -1 }, { -1, 4, -13, 120, 25, -9, 3, -1 },
185*77c1e3ccSAndroid Build Coastguard Worker { -1, 4, -14, 118, 28, -9, 3, -1 }, { -1, 4, -15, 117, 30, -10, 4, -1 },
186*77c1e3ccSAndroid Build Coastguard Worker { -1, 5, -16, 116, 32, -11, 4, -1 }, { -1, 5, -16, 114, 35, -12, 4, -1 },
187*77c1e3ccSAndroid Build Coastguard Worker { -1, 5, -17, 112, 38, -12, 4, -1 }, { -1, 5, -18, 111, 40, -13, 5, -1 },
188*77c1e3ccSAndroid Build Coastguard Worker { -1, 5, -18, 109, 43, -14, 5, -1 }, { -1, 6, -19, 107, 45, -14, 5, -1 },
189*77c1e3ccSAndroid Build Coastguard Worker { -1, 6, -19, 105, 48, -15, 5, -1 }, { -1, 6, -19, 103, 51, -16, 5, -1 },
190*77c1e3ccSAndroid Build Coastguard Worker { -1, 6, -20, 101, 53, -16, 6, -1 }, { -1, 6, -20, 99, 56, -17, 6, -1 },
191*77c1e3ccSAndroid Build Coastguard Worker { -1, 6, -20, 97, 58, -17, 6, -1 }, { -1, 6, -20, 95, 61, -18, 6, -1 },
192*77c1e3ccSAndroid Build Coastguard Worker { -2, 7, -20, 93, 64, -18, 6, -2 }, { -2, 7, -20, 91, 66, -19, 6, -1 },
193*77c1e3ccSAndroid Build Coastguard Worker { -2, 7, -20, 88, 69, -19, 6, -1 }, { -2, 7, -20, 86, 71, -19, 6, -1 },
194*77c1e3ccSAndroid Build Coastguard Worker { -2, 7, -20, 84, 74, -20, 7, -2 }, { -2, 7, -20, 81, 76, -20, 7, -1 },
195*77c1e3ccSAndroid Build Coastguard Worker { -2, 7, -20, 79, 79, -20, 7, -2 }, { -1, 7, -20, 76, 81, -20, 7, -2 },
196*77c1e3ccSAndroid Build Coastguard Worker { -2, 7, -20, 74, 84, -20, 7, -2 }, { -1, 6, -19, 71, 86, -20, 7, -2 },
197*77c1e3ccSAndroid Build Coastguard Worker { -1, 6, -19, 69, 88, -20, 7, -2 }, { -1, 6, -19, 66, 91, -20, 7, -2 },
198*77c1e3ccSAndroid Build Coastguard Worker { -2, 6, -18, 64, 93, -20, 7, -2 }, { -1, 6, -18, 61, 95, -20, 6, -1 },
199*77c1e3ccSAndroid Build Coastguard Worker { -1, 6, -17, 58, 97, -20, 6, -1 }, { -1, 6, -17, 56, 99, -20, 6, -1 },
200*77c1e3ccSAndroid Build Coastguard Worker { -1, 6, -16, 53, 101, -20, 6, -1 }, { -1, 5, -16, 51, 103, -19, 6, -1 },
201*77c1e3ccSAndroid Build Coastguard Worker { -1, 5, -15, 48, 105, -19, 6, -1 }, { -1, 5, -14, 45, 107, -19, 6, -1 },
202*77c1e3ccSAndroid Build Coastguard Worker { -1, 5, -14, 43, 109, -18, 5, -1 }, { -1, 5, -13, 40, 111, -18, 5, -1 },
203*77c1e3ccSAndroid Build Coastguard Worker { -1, 4, -12, 38, 112, -17, 5, -1 }, { -1, 4, -12, 35, 114, -16, 5, -1 },
204*77c1e3ccSAndroid Build Coastguard Worker { -1, 4, -11, 32, 116, -16, 5, -1 }, { -1, 4, -10, 30, 117, -15, 4, -1 },
205*77c1e3ccSAndroid Build Coastguard Worker { -1, 3, -9, 28, 118, -14, 4, -1 }, { -1, 3, -9, 25, 120, -13, 4, -1 },
206*77c1e3ccSAndroid Build Coastguard Worker { -1, 3, -8, 22, 121, -12, 4, -1 }, { -1, 3, -7, 20, 122, -11, 3, -1 },
207*77c1e3ccSAndroid Build Coastguard Worker { -1, 2, -6, 18, 123, -10, 3, -1 }, { 0, 2, -6, 15, 124, -9, 3, -1 },
208*77c1e3ccSAndroid Build Coastguard Worker { 0, 2, -5, 13, 125, -8, 2, -1 }, { 0, 1, -4, 11, 125, -7, 2, 0 },
209*77c1e3ccSAndroid Build Coastguard Worker { 0, 1, -3, 8, 126, -6, 2, 0 }, { 0, 1, -3, 6, 127, -4, 1, 0 },
210*77c1e3ccSAndroid Build Coastguard Worker { 0, 1, -2, 4, 127, -3, 1, 0 }, { 0, 0, -1, 2, 128, -1, 0, 0 },
211*77c1e3ccSAndroid Build Coastguard Worker #else
212*77c1e3ccSAndroid Build Coastguard Worker #error "Invalid value of UPSCALE_NORMATIVE_TAPS"
213*77c1e3ccSAndroid Build Coastguard Worker #endif // UPSCALE_NORMATIVE_TAPS == 8
214*77c1e3ccSAndroid Build Coastguard Worker };
215*77c1e3ccSAndroid Build Coastguard Worker
216*77c1e3ccSAndroid Build Coastguard Worker // Filters for interpolation (full-band) - no filtering for integer pixels
217*77c1e3ccSAndroid Build Coastguard Worker #define filteredinterp_filters1000 av1_resize_filter_normative
218*77c1e3ccSAndroid Build Coastguard Worker
choose_interp_filter(int in_length,int out_length)219*77c1e3ccSAndroid Build Coastguard Worker static const InterpKernel *choose_interp_filter(int in_length, int out_length) {
220*77c1e3ccSAndroid Build Coastguard Worker int out_length16 = out_length * 16;
221*77c1e3ccSAndroid Build Coastguard Worker if (out_length16 >= in_length * 16)
222*77c1e3ccSAndroid Build Coastguard Worker return filteredinterp_filters1000;
223*77c1e3ccSAndroid Build Coastguard Worker else if (out_length16 >= in_length * 13)
224*77c1e3ccSAndroid Build Coastguard Worker return filteredinterp_filters875;
225*77c1e3ccSAndroid Build Coastguard Worker else if (out_length16 >= in_length * 11)
226*77c1e3ccSAndroid Build Coastguard Worker return filteredinterp_filters750;
227*77c1e3ccSAndroid Build Coastguard Worker else if (out_length16 >= in_length * 9)
228*77c1e3ccSAndroid Build Coastguard Worker return filteredinterp_filters625;
229*77c1e3ccSAndroid Build Coastguard Worker else
230*77c1e3ccSAndroid Build Coastguard Worker return filteredinterp_filters500;
231*77c1e3ccSAndroid Build Coastguard Worker }
232*77c1e3ccSAndroid Build Coastguard Worker
interpolate_core(const uint8_t * const input,int in_length,uint8_t * output,int out_length,const int16_t * interp_filters,int interp_taps)233*77c1e3ccSAndroid Build Coastguard Worker static void interpolate_core(const uint8_t *const input, int in_length,
234*77c1e3ccSAndroid Build Coastguard Worker uint8_t *output, int out_length,
235*77c1e3ccSAndroid Build Coastguard Worker const int16_t *interp_filters, int interp_taps) {
236*77c1e3ccSAndroid Build Coastguard Worker const int32_t delta =
237*77c1e3ccSAndroid Build Coastguard Worker (((uint32_t)in_length << RS_SCALE_SUBPEL_BITS) + out_length / 2) /
238*77c1e3ccSAndroid Build Coastguard Worker out_length;
239*77c1e3ccSAndroid Build Coastguard Worker const int32_t offset =
240*77c1e3ccSAndroid Build Coastguard Worker in_length > out_length
241*77c1e3ccSAndroid Build Coastguard Worker ? (((int32_t)(in_length - out_length) << (RS_SCALE_SUBPEL_BITS - 1)) +
242*77c1e3ccSAndroid Build Coastguard Worker out_length / 2) /
243*77c1e3ccSAndroid Build Coastguard Worker out_length
244*77c1e3ccSAndroid Build Coastguard Worker : -(((int32_t)(out_length - in_length)
245*77c1e3ccSAndroid Build Coastguard Worker << (RS_SCALE_SUBPEL_BITS - 1)) +
246*77c1e3ccSAndroid Build Coastguard Worker out_length / 2) /
247*77c1e3ccSAndroid Build Coastguard Worker out_length;
248*77c1e3ccSAndroid Build Coastguard Worker uint8_t *optr = output;
249*77c1e3ccSAndroid Build Coastguard Worker int x, x1, x2, sum, k, int_pel, sub_pel;
250*77c1e3ccSAndroid Build Coastguard Worker int32_t y;
251*77c1e3ccSAndroid Build Coastguard Worker
252*77c1e3ccSAndroid Build Coastguard Worker x = 0;
253*77c1e3ccSAndroid Build Coastguard Worker y = offset + RS_SCALE_EXTRA_OFF;
254*77c1e3ccSAndroid Build Coastguard Worker while ((y >> RS_SCALE_SUBPEL_BITS) < (interp_taps / 2 - 1)) {
255*77c1e3ccSAndroid Build Coastguard Worker x++;
256*77c1e3ccSAndroid Build Coastguard Worker y += delta;
257*77c1e3ccSAndroid Build Coastguard Worker }
258*77c1e3ccSAndroid Build Coastguard Worker x1 = x;
259*77c1e3ccSAndroid Build Coastguard Worker x = out_length - 1;
260*77c1e3ccSAndroid Build Coastguard Worker y = delta * x + offset + RS_SCALE_EXTRA_OFF;
261*77c1e3ccSAndroid Build Coastguard Worker while ((y >> RS_SCALE_SUBPEL_BITS) + (int32_t)(interp_taps / 2) >=
262*77c1e3ccSAndroid Build Coastguard Worker in_length) {
263*77c1e3ccSAndroid Build Coastguard Worker x--;
264*77c1e3ccSAndroid Build Coastguard Worker y -= delta;
265*77c1e3ccSAndroid Build Coastguard Worker }
266*77c1e3ccSAndroid Build Coastguard Worker x2 = x;
267*77c1e3ccSAndroid Build Coastguard Worker if (x1 > x2) {
268*77c1e3ccSAndroid Build Coastguard Worker for (x = 0, y = offset + RS_SCALE_EXTRA_OFF; x < out_length;
269*77c1e3ccSAndroid Build Coastguard Worker ++x, y += delta) {
270*77c1e3ccSAndroid Build Coastguard Worker int_pel = y >> RS_SCALE_SUBPEL_BITS;
271*77c1e3ccSAndroid Build Coastguard Worker sub_pel = (y >> RS_SCALE_EXTRA_BITS) & RS_SUBPEL_MASK;
272*77c1e3ccSAndroid Build Coastguard Worker const int16_t *filter = &interp_filters[sub_pel * interp_taps];
273*77c1e3ccSAndroid Build Coastguard Worker sum = 0;
274*77c1e3ccSAndroid Build Coastguard Worker for (k = 0; k < interp_taps; ++k) {
275*77c1e3ccSAndroid Build Coastguard Worker const int pk = int_pel - interp_taps / 2 + 1 + k;
276*77c1e3ccSAndroid Build Coastguard Worker sum += filter[k] * input[AOMMAX(AOMMIN(pk, in_length - 1), 0)];
277*77c1e3ccSAndroid Build Coastguard Worker }
278*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS));
279*77c1e3ccSAndroid Build Coastguard Worker }
280*77c1e3ccSAndroid Build Coastguard Worker } else {
281*77c1e3ccSAndroid Build Coastguard Worker // Initial part.
282*77c1e3ccSAndroid Build Coastguard Worker for (x = 0, y = offset + RS_SCALE_EXTRA_OFF; x < x1; ++x, y += delta) {
283*77c1e3ccSAndroid Build Coastguard Worker int_pel = y >> RS_SCALE_SUBPEL_BITS;
284*77c1e3ccSAndroid Build Coastguard Worker sub_pel = (y >> RS_SCALE_EXTRA_BITS) & RS_SUBPEL_MASK;
285*77c1e3ccSAndroid Build Coastguard Worker const int16_t *filter = &interp_filters[sub_pel * interp_taps];
286*77c1e3ccSAndroid Build Coastguard Worker sum = 0;
287*77c1e3ccSAndroid Build Coastguard Worker for (k = 0; k < interp_taps; ++k)
288*77c1e3ccSAndroid Build Coastguard Worker sum += filter[k] * input[AOMMAX(int_pel - interp_taps / 2 + 1 + k, 0)];
289*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS));
290*77c1e3ccSAndroid Build Coastguard Worker }
291*77c1e3ccSAndroid Build Coastguard Worker // Middle part.
292*77c1e3ccSAndroid Build Coastguard Worker for (; x <= x2; ++x, y += delta) {
293*77c1e3ccSAndroid Build Coastguard Worker int_pel = y >> RS_SCALE_SUBPEL_BITS;
294*77c1e3ccSAndroid Build Coastguard Worker sub_pel = (y >> RS_SCALE_EXTRA_BITS) & RS_SUBPEL_MASK;
295*77c1e3ccSAndroid Build Coastguard Worker const int16_t *filter = &interp_filters[sub_pel * interp_taps];
296*77c1e3ccSAndroid Build Coastguard Worker sum = 0;
297*77c1e3ccSAndroid Build Coastguard Worker for (k = 0; k < interp_taps; ++k)
298*77c1e3ccSAndroid Build Coastguard Worker sum += filter[k] * input[int_pel - interp_taps / 2 + 1 + k];
299*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS));
300*77c1e3ccSAndroid Build Coastguard Worker }
301*77c1e3ccSAndroid Build Coastguard Worker // End part.
302*77c1e3ccSAndroid Build Coastguard Worker for (; x < out_length; ++x, y += delta) {
303*77c1e3ccSAndroid Build Coastguard Worker int_pel = y >> RS_SCALE_SUBPEL_BITS;
304*77c1e3ccSAndroid Build Coastguard Worker sub_pel = (y >> RS_SCALE_EXTRA_BITS) & RS_SUBPEL_MASK;
305*77c1e3ccSAndroid Build Coastguard Worker const int16_t *filter = &interp_filters[sub_pel * interp_taps];
306*77c1e3ccSAndroid Build Coastguard Worker sum = 0;
307*77c1e3ccSAndroid Build Coastguard Worker for (k = 0; k < interp_taps; ++k)
308*77c1e3ccSAndroid Build Coastguard Worker sum += filter[k] *
309*77c1e3ccSAndroid Build Coastguard Worker input[AOMMIN(int_pel - interp_taps / 2 + 1 + k, in_length - 1)];
310*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel(ROUND_POWER_OF_TWO(sum, FILTER_BITS));
311*77c1e3ccSAndroid Build Coastguard Worker }
312*77c1e3ccSAndroid Build Coastguard Worker }
313*77c1e3ccSAndroid Build Coastguard Worker }
314*77c1e3ccSAndroid Build Coastguard Worker
interpolate(const uint8_t * const input,int in_length,uint8_t * output,int out_length)315*77c1e3ccSAndroid Build Coastguard Worker static void interpolate(const uint8_t *const input, int in_length,
316*77c1e3ccSAndroid Build Coastguard Worker uint8_t *output, int out_length) {
317*77c1e3ccSAndroid Build Coastguard Worker const InterpKernel *interp_filters =
318*77c1e3ccSAndroid Build Coastguard Worker choose_interp_filter(in_length, out_length);
319*77c1e3ccSAndroid Build Coastguard Worker
320*77c1e3ccSAndroid Build Coastguard Worker interpolate_core(input, in_length, output, out_length, &interp_filters[0][0],
321*77c1e3ccSAndroid Build Coastguard Worker SUBPEL_TAPS);
322*77c1e3ccSAndroid Build Coastguard Worker }
323*77c1e3ccSAndroid Build Coastguard Worker
av1_get_upscale_convolve_step(int in_length,int out_length)324*77c1e3ccSAndroid Build Coastguard Worker int32_t av1_get_upscale_convolve_step(int in_length, int out_length) {
325*77c1e3ccSAndroid Build Coastguard Worker return ((in_length << RS_SCALE_SUBPEL_BITS) + out_length / 2) / out_length;
326*77c1e3ccSAndroid Build Coastguard Worker }
327*77c1e3ccSAndroid Build Coastguard Worker
get_upscale_convolve_x0(int in_length,int out_length,int32_t x_step_qn)328*77c1e3ccSAndroid Build Coastguard Worker static int32_t get_upscale_convolve_x0(int in_length, int out_length,
329*77c1e3ccSAndroid Build Coastguard Worker int32_t x_step_qn) {
330*77c1e3ccSAndroid Build Coastguard Worker const int err = out_length * x_step_qn - (in_length << RS_SCALE_SUBPEL_BITS);
331*77c1e3ccSAndroid Build Coastguard Worker const int32_t x0 =
332*77c1e3ccSAndroid Build Coastguard Worker (-((out_length - in_length) << (RS_SCALE_SUBPEL_BITS - 1)) +
333*77c1e3ccSAndroid Build Coastguard Worker out_length / 2) /
334*77c1e3ccSAndroid Build Coastguard Worker out_length +
335*77c1e3ccSAndroid Build Coastguard Worker RS_SCALE_EXTRA_OFF - err / 2;
336*77c1e3ccSAndroid Build Coastguard Worker return (int32_t)((uint32_t)x0 & RS_SCALE_SUBPEL_MASK);
337*77c1e3ccSAndroid Build Coastguard Worker }
338*77c1e3ccSAndroid Build Coastguard Worker
down2_symeven(const uint8_t * const input,int length,uint8_t * output,int start_offset)339*77c1e3ccSAndroid Build Coastguard Worker void down2_symeven(const uint8_t *const input, int length, uint8_t *output,
340*77c1e3ccSAndroid Build Coastguard Worker int start_offset) {
341*77c1e3ccSAndroid Build Coastguard Worker // Actual filter len = 2 * filter_len_half.
342*77c1e3ccSAndroid Build Coastguard Worker const int16_t *filter = av1_down2_symeven_half_filter;
343*77c1e3ccSAndroid Build Coastguard Worker const int filter_len_half = sizeof(av1_down2_symeven_half_filter) / 2;
344*77c1e3ccSAndroid Build Coastguard Worker int i, j;
345*77c1e3ccSAndroid Build Coastguard Worker uint8_t *optr = output;
346*77c1e3ccSAndroid Build Coastguard Worker int l1 = filter_len_half;
347*77c1e3ccSAndroid Build Coastguard Worker int l2 = (length - filter_len_half);
348*77c1e3ccSAndroid Build Coastguard Worker l1 += (l1 & 1);
349*77c1e3ccSAndroid Build Coastguard Worker l2 += (l2 & 1);
350*77c1e3ccSAndroid Build Coastguard Worker if (l1 > l2) {
351*77c1e3ccSAndroid Build Coastguard Worker // Short input length.
352*77c1e3ccSAndroid Build Coastguard Worker for (i = start_offset; i < length; i += 2) {
353*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1));
354*77c1e3ccSAndroid Build Coastguard Worker for (j = 0; j < filter_len_half; ++j) {
355*77c1e3ccSAndroid Build Coastguard Worker sum +=
356*77c1e3ccSAndroid Build Coastguard Worker (input[AOMMAX(i - j, 0)] + input[AOMMIN(i + 1 + j, length - 1)]) *
357*77c1e3ccSAndroid Build Coastguard Worker filter[j];
358*77c1e3ccSAndroid Build Coastguard Worker }
359*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
360*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel(sum);
361*77c1e3ccSAndroid Build Coastguard Worker }
362*77c1e3ccSAndroid Build Coastguard Worker } else {
363*77c1e3ccSAndroid Build Coastguard Worker // Initial part.
364*77c1e3ccSAndroid Build Coastguard Worker for (i = start_offset; i < l1; i += 2) {
365*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1));
366*77c1e3ccSAndroid Build Coastguard Worker for (j = 0; j < filter_len_half; ++j) {
367*77c1e3ccSAndroid Build Coastguard Worker sum += (input[AOMMAX(i - j, 0)] + input[i + 1 + j]) * filter[j];
368*77c1e3ccSAndroid Build Coastguard Worker }
369*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
370*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel(sum);
371*77c1e3ccSAndroid Build Coastguard Worker }
372*77c1e3ccSAndroid Build Coastguard Worker // Middle part.
373*77c1e3ccSAndroid Build Coastguard Worker for (; i < l2; i += 2) {
374*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1));
375*77c1e3ccSAndroid Build Coastguard Worker for (j = 0; j < filter_len_half; ++j) {
376*77c1e3ccSAndroid Build Coastguard Worker sum += (input[i - j] + input[i + 1 + j]) * filter[j];
377*77c1e3ccSAndroid Build Coastguard Worker }
378*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
379*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel(sum);
380*77c1e3ccSAndroid Build Coastguard Worker }
381*77c1e3ccSAndroid Build Coastguard Worker // End part.
382*77c1e3ccSAndroid Build Coastguard Worker for (; i < length; i += 2) {
383*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1));
384*77c1e3ccSAndroid Build Coastguard Worker for (j = 0; j < filter_len_half; ++j) {
385*77c1e3ccSAndroid Build Coastguard Worker sum +=
386*77c1e3ccSAndroid Build Coastguard Worker (input[i - j] + input[AOMMIN(i + 1 + j, length - 1)]) * filter[j];
387*77c1e3ccSAndroid Build Coastguard Worker }
388*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
389*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel(sum);
390*77c1e3ccSAndroid Build Coastguard Worker }
391*77c1e3ccSAndroid Build Coastguard Worker }
392*77c1e3ccSAndroid Build Coastguard Worker }
393*77c1e3ccSAndroid Build Coastguard Worker
down2_symodd(const uint8_t * const input,int length,uint8_t * output)394*77c1e3ccSAndroid Build Coastguard Worker static void down2_symodd(const uint8_t *const input, int length,
395*77c1e3ccSAndroid Build Coastguard Worker uint8_t *output) {
396*77c1e3ccSAndroid Build Coastguard Worker // Actual filter len = 2 * filter_len_half - 1.
397*77c1e3ccSAndroid Build Coastguard Worker const int16_t *filter = av1_down2_symodd_half_filter;
398*77c1e3ccSAndroid Build Coastguard Worker const int filter_len_half = sizeof(av1_down2_symodd_half_filter) / 2;
399*77c1e3ccSAndroid Build Coastguard Worker int i, j;
400*77c1e3ccSAndroid Build Coastguard Worker uint8_t *optr = output;
401*77c1e3ccSAndroid Build Coastguard Worker int l1 = filter_len_half - 1;
402*77c1e3ccSAndroid Build Coastguard Worker int l2 = (length - filter_len_half + 1);
403*77c1e3ccSAndroid Build Coastguard Worker l1 += (l1 & 1);
404*77c1e3ccSAndroid Build Coastguard Worker l2 += (l2 & 1);
405*77c1e3ccSAndroid Build Coastguard Worker if (l1 > l2) {
406*77c1e3ccSAndroid Build Coastguard Worker // Short input length.
407*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < length; i += 2) {
408*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
409*77c1e3ccSAndroid Build Coastguard Worker for (j = 1; j < filter_len_half; ++j) {
410*77c1e3ccSAndroid Build Coastguard Worker sum += (input[(i - j < 0 ? 0 : i - j)] +
411*77c1e3ccSAndroid Build Coastguard Worker input[(i + j >= length ? length - 1 : i + j)]) *
412*77c1e3ccSAndroid Build Coastguard Worker filter[j];
413*77c1e3ccSAndroid Build Coastguard Worker }
414*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
415*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel(sum);
416*77c1e3ccSAndroid Build Coastguard Worker }
417*77c1e3ccSAndroid Build Coastguard Worker } else {
418*77c1e3ccSAndroid Build Coastguard Worker // Initial part.
419*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < l1; i += 2) {
420*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
421*77c1e3ccSAndroid Build Coastguard Worker for (j = 1; j < filter_len_half; ++j) {
422*77c1e3ccSAndroid Build Coastguard Worker sum += (input[(i - j < 0 ? 0 : i - j)] + input[i + j]) * filter[j];
423*77c1e3ccSAndroid Build Coastguard Worker }
424*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
425*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel(sum);
426*77c1e3ccSAndroid Build Coastguard Worker }
427*77c1e3ccSAndroid Build Coastguard Worker // Middle part.
428*77c1e3ccSAndroid Build Coastguard Worker for (; i < l2; i += 2) {
429*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
430*77c1e3ccSAndroid Build Coastguard Worker for (j = 1; j < filter_len_half; ++j) {
431*77c1e3ccSAndroid Build Coastguard Worker sum += (input[i - j] + input[i + j]) * filter[j];
432*77c1e3ccSAndroid Build Coastguard Worker }
433*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
434*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel(sum);
435*77c1e3ccSAndroid Build Coastguard Worker }
436*77c1e3ccSAndroid Build Coastguard Worker // End part.
437*77c1e3ccSAndroid Build Coastguard Worker for (; i < length; i += 2) {
438*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
439*77c1e3ccSAndroid Build Coastguard Worker for (j = 1; j < filter_len_half; ++j) {
440*77c1e3ccSAndroid Build Coastguard Worker sum += (input[i - j] + input[(i + j >= length ? length - 1 : i + j)]) *
441*77c1e3ccSAndroid Build Coastguard Worker filter[j];
442*77c1e3ccSAndroid Build Coastguard Worker }
443*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
444*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel(sum);
445*77c1e3ccSAndroid Build Coastguard Worker }
446*77c1e3ccSAndroid Build Coastguard Worker }
447*77c1e3ccSAndroid Build Coastguard Worker }
448*77c1e3ccSAndroid Build Coastguard Worker
get_down2_length(int length,int steps)449*77c1e3ccSAndroid Build Coastguard Worker static int get_down2_length(int length, int steps) {
450*77c1e3ccSAndroid Build Coastguard Worker for (int s = 0; s < steps; ++s) length = (length + 1) >> 1;
451*77c1e3ccSAndroid Build Coastguard Worker return length;
452*77c1e3ccSAndroid Build Coastguard Worker }
453*77c1e3ccSAndroid Build Coastguard Worker
get_down2_steps(int in_length,int out_length)454*77c1e3ccSAndroid Build Coastguard Worker static int get_down2_steps(int in_length, int out_length) {
455*77c1e3ccSAndroid Build Coastguard Worker int steps = 0;
456*77c1e3ccSAndroid Build Coastguard Worker int proj_in_length;
457*77c1e3ccSAndroid Build Coastguard Worker while ((proj_in_length = get_down2_length(in_length, 1)) >= out_length) {
458*77c1e3ccSAndroid Build Coastguard Worker ++steps;
459*77c1e3ccSAndroid Build Coastguard Worker in_length = proj_in_length;
460*77c1e3ccSAndroid Build Coastguard Worker if (in_length == 1) {
461*77c1e3ccSAndroid Build Coastguard Worker // Special case: we break because any further calls to get_down2_length()
462*77c1e3ccSAndroid Build Coastguard Worker // with be with length == 1, which return 1, resulting in an infinite
463*77c1e3ccSAndroid Build Coastguard Worker // loop.
464*77c1e3ccSAndroid Build Coastguard Worker break;
465*77c1e3ccSAndroid Build Coastguard Worker }
466*77c1e3ccSAndroid Build Coastguard Worker }
467*77c1e3ccSAndroid Build Coastguard Worker return steps;
468*77c1e3ccSAndroid Build Coastguard Worker }
469*77c1e3ccSAndroid Build Coastguard Worker
resize_multistep(const uint8_t * const input,int length,uint8_t * output,int olength,uint8_t * otmp)470*77c1e3ccSAndroid Build Coastguard Worker static void resize_multistep(const uint8_t *const input, int length,
471*77c1e3ccSAndroid Build Coastguard Worker uint8_t *output, int olength, uint8_t *otmp) {
472*77c1e3ccSAndroid Build Coastguard Worker if (length == olength) {
473*77c1e3ccSAndroid Build Coastguard Worker memcpy(output, input, sizeof(output[0]) * length);
474*77c1e3ccSAndroid Build Coastguard Worker return;
475*77c1e3ccSAndroid Build Coastguard Worker }
476*77c1e3ccSAndroid Build Coastguard Worker const int steps = get_down2_steps(length, olength);
477*77c1e3ccSAndroid Build Coastguard Worker
478*77c1e3ccSAndroid Build Coastguard Worker if (steps > 0) {
479*77c1e3ccSAndroid Build Coastguard Worker uint8_t *out = NULL;
480*77c1e3ccSAndroid Build Coastguard Worker int filteredlength = length;
481*77c1e3ccSAndroid Build Coastguard Worker
482*77c1e3ccSAndroid Build Coastguard Worker assert(otmp != NULL);
483*77c1e3ccSAndroid Build Coastguard Worker uint8_t *otmp2 = otmp + get_down2_length(length, 1);
484*77c1e3ccSAndroid Build Coastguard Worker for (int s = 0; s < steps; ++s) {
485*77c1e3ccSAndroid Build Coastguard Worker const int proj_filteredlength = get_down2_length(filteredlength, 1);
486*77c1e3ccSAndroid Build Coastguard Worker const uint8_t *const in = (s == 0 ? input : out);
487*77c1e3ccSAndroid Build Coastguard Worker if (s == steps - 1 && proj_filteredlength == olength)
488*77c1e3ccSAndroid Build Coastguard Worker out = output;
489*77c1e3ccSAndroid Build Coastguard Worker else
490*77c1e3ccSAndroid Build Coastguard Worker out = (s & 1 ? otmp2 : otmp);
491*77c1e3ccSAndroid Build Coastguard Worker if (filteredlength & 1)
492*77c1e3ccSAndroid Build Coastguard Worker down2_symodd(in, filteredlength, out);
493*77c1e3ccSAndroid Build Coastguard Worker else
494*77c1e3ccSAndroid Build Coastguard Worker down2_symeven(in, filteredlength, out, 0);
495*77c1e3ccSAndroid Build Coastguard Worker filteredlength = proj_filteredlength;
496*77c1e3ccSAndroid Build Coastguard Worker }
497*77c1e3ccSAndroid Build Coastguard Worker if (filteredlength != olength) {
498*77c1e3ccSAndroid Build Coastguard Worker interpolate(out, filteredlength, output, olength);
499*77c1e3ccSAndroid Build Coastguard Worker }
500*77c1e3ccSAndroid Build Coastguard Worker } else {
501*77c1e3ccSAndroid Build Coastguard Worker interpolate(input, length, output, olength);
502*77c1e3ccSAndroid Build Coastguard Worker }
503*77c1e3ccSAndroid Build Coastguard Worker }
504*77c1e3ccSAndroid Build Coastguard Worker
fill_col_to_arr(uint8_t * img,int stride,int len,uint8_t * arr)505*77c1e3ccSAndroid Build Coastguard Worker static void fill_col_to_arr(uint8_t *img, int stride, int len, uint8_t *arr) {
506*77c1e3ccSAndroid Build Coastguard Worker int i;
507*77c1e3ccSAndroid Build Coastguard Worker uint8_t *iptr = img;
508*77c1e3ccSAndroid Build Coastguard Worker uint8_t *aptr = arr;
509*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < len; ++i, iptr += stride) {
510*77c1e3ccSAndroid Build Coastguard Worker *aptr++ = *iptr;
511*77c1e3ccSAndroid Build Coastguard Worker }
512*77c1e3ccSAndroid Build Coastguard Worker }
513*77c1e3ccSAndroid Build Coastguard Worker
fill_arr_to_col(uint8_t * img,int stride,int len,uint8_t * arr)514*77c1e3ccSAndroid Build Coastguard Worker static void fill_arr_to_col(uint8_t *img, int stride, int len, uint8_t *arr) {
515*77c1e3ccSAndroid Build Coastguard Worker int i;
516*77c1e3ccSAndroid Build Coastguard Worker uint8_t *iptr = img;
517*77c1e3ccSAndroid Build Coastguard Worker uint8_t *aptr = arr;
518*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < len; ++i, iptr += stride) {
519*77c1e3ccSAndroid Build Coastguard Worker *iptr = *aptr++;
520*77c1e3ccSAndroid Build Coastguard Worker }
521*77c1e3ccSAndroid Build Coastguard Worker }
522*77c1e3ccSAndroid Build Coastguard Worker
av1_resize_vert_dir_c(uint8_t * intbuf,uint8_t * output,int out_stride,int height,int height2,int width2,int start_col)523*77c1e3ccSAndroid Build Coastguard Worker bool av1_resize_vert_dir_c(uint8_t *intbuf, uint8_t *output, int out_stride,
524*77c1e3ccSAndroid Build Coastguard Worker int height, int height2, int width2, int start_col) {
525*77c1e3ccSAndroid Build Coastguard Worker bool mem_status = true;
526*77c1e3ccSAndroid Build Coastguard Worker uint8_t *arrbuf = (uint8_t *)aom_malloc(sizeof(*arrbuf) * height);
527*77c1e3ccSAndroid Build Coastguard Worker uint8_t *arrbuf2 = (uint8_t *)aom_malloc(sizeof(*arrbuf2) * height2);
528*77c1e3ccSAndroid Build Coastguard Worker if (arrbuf == NULL || arrbuf2 == NULL) {
529*77c1e3ccSAndroid Build Coastguard Worker mem_status = false;
530*77c1e3ccSAndroid Build Coastguard Worker goto Error;
531*77c1e3ccSAndroid Build Coastguard Worker }
532*77c1e3ccSAndroid Build Coastguard Worker
533*77c1e3ccSAndroid Build Coastguard Worker for (int i = start_col; i < width2; ++i) {
534*77c1e3ccSAndroid Build Coastguard Worker fill_col_to_arr(intbuf + i, width2, height, arrbuf);
535*77c1e3ccSAndroid Build Coastguard Worker down2_symeven(arrbuf, height, arrbuf2, 0);
536*77c1e3ccSAndroid Build Coastguard Worker fill_arr_to_col(output + i, out_stride, height2, arrbuf2);
537*77c1e3ccSAndroid Build Coastguard Worker }
538*77c1e3ccSAndroid Build Coastguard Worker
539*77c1e3ccSAndroid Build Coastguard Worker Error:
540*77c1e3ccSAndroid Build Coastguard Worker aom_free(arrbuf);
541*77c1e3ccSAndroid Build Coastguard Worker aom_free(arrbuf2);
542*77c1e3ccSAndroid Build Coastguard Worker return mem_status;
543*77c1e3ccSAndroid Build Coastguard Worker }
544*77c1e3ccSAndroid Build Coastguard Worker
av1_resize_horz_dir_c(const uint8_t * const input,int in_stride,uint8_t * intbuf,int height,int filtered_length,int width2)545*77c1e3ccSAndroid Build Coastguard Worker void av1_resize_horz_dir_c(const uint8_t *const input, int in_stride,
546*77c1e3ccSAndroid Build Coastguard Worker uint8_t *intbuf, int height, int filtered_length,
547*77c1e3ccSAndroid Build Coastguard Worker int width2) {
548*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < height; ++i)
549*77c1e3ccSAndroid Build Coastguard Worker down2_symeven(input + in_stride * i, filtered_length, intbuf + width2 * i,
550*77c1e3ccSAndroid Build Coastguard Worker 0);
551*77c1e3ccSAndroid Build Coastguard Worker }
552*77c1e3ccSAndroid Build Coastguard Worker
av1_resize_plane_to_half(const uint8_t * const input,int height,int width,int in_stride,uint8_t * output,int height2,int width2,int out_stride)553*77c1e3ccSAndroid Build Coastguard Worker bool av1_resize_plane_to_half(const uint8_t *const input, int height, int width,
554*77c1e3ccSAndroid Build Coastguard Worker int in_stride, uint8_t *output, int height2,
555*77c1e3ccSAndroid Build Coastguard Worker int width2, int out_stride) {
556*77c1e3ccSAndroid Build Coastguard Worker uint8_t *intbuf = (uint8_t *)aom_malloc(sizeof(*intbuf) * width2 * height);
557*77c1e3ccSAndroid Build Coastguard Worker if (intbuf == NULL) {
558*77c1e3ccSAndroid Build Coastguard Worker return false;
559*77c1e3ccSAndroid Build Coastguard Worker }
560*77c1e3ccSAndroid Build Coastguard Worker
561*77c1e3ccSAndroid Build Coastguard Worker // Resize in the horizontal direction
562*77c1e3ccSAndroid Build Coastguard Worker av1_resize_horz_dir(input, in_stride, intbuf, height, width, width2);
563*77c1e3ccSAndroid Build Coastguard Worker // Resize in the vertical direction
564*77c1e3ccSAndroid Build Coastguard Worker bool mem_status = av1_resize_vert_dir(intbuf, output, out_stride, height,
565*77c1e3ccSAndroid Build Coastguard Worker height2, width2, 0 /*start_col*/);
566*77c1e3ccSAndroid Build Coastguard Worker aom_free(intbuf);
567*77c1e3ccSAndroid Build Coastguard Worker return mem_status;
568*77c1e3ccSAndroid Build Coastguard Worker }
569*77c1e3ccSAndroid Build Coastguard Worker
570*77c1e3ccSAndroid Build Coastguard Worker // Check if both the output width and height are half of input width and
571*77c1e3ccSAndroid Build Coastguard Worker // height respectively.
should_resize_by_half(int height,int width,int height2,int width2)572*77c1e3ccSAndroid Build Coastguard Worker bool should_resize_by_half(int height, int width, int height2, int width2) {
573*77c1e3ccSAndroid Build Coastguard Worker const bool is_width_by_2 = get_down2_length(width, 1) == width2;
574*77c1e3ccSAndroid Build Coastguard Worker const bool is_height_by_2 = get_down2_length(height, 1) == height2;
575*77c1e3ccSAndroid Build Coastguard Worker return (is_width_by_2 && is_height_by_2);
576*77c1e3ccSAndroid Build Coastguard Worker }
577*77c1e3ccSAndroid Build Coastguard Worker
av1_resize_plane(const uint8_t * input,int height,int width,int in_stride,uint8_t * output,int height2,int width2,int out_stride)578*77c1e3ccSAndroid Build Coastguard Worker bool av1_resize_plane(const uint8_t *input, int height, int width,
579*77c1e3ccSAndroid Build Coastguard Worker int in_stride, uint8_t *output, int height2, int width2,
580*77c1e3ccSAndroid Build Coastguard Worker int out_stride) {
581*77c1e3ccSAndroid Build Coastguard Worker int i;
582*77c1e3ccSAndroid Build Coastguard Worker bool mem_status = true;
583*77c1e3ccSAndroid Build Coastguard Worker uint8_t *intbuf = (uint8_t *)aom_malloc(sizeof(uint8_t) * width2 * height);
584*77c1e3ccSAndroid Build Coastguard Worker uint8_t *tmpbuf =
585*77c1e3ccSAndroid Build Coastguard Worker (uint8_t *)aom_malloc(sizeof(uint8_t) * AOMMAX(width, height));
586*77c1e3ccSAndroid Build Coastguard Worker uint8_t *arrbuf = (uint8_t *)aom_malloc(sizeof(uint8_t) * height);
587*77c1e3ccSAndroid Build Coastguard Worker uint8_t *arrbuf2 = (uint8_t *)aom_malloc(sizeof(uint8_t) * height2);
588*77c1e3ccSAndroid Build Coastguard Worker if (intbuf == NULL || tmpbuf == NULL || arrbuf == NULL || arrbuf2 == NULL) {
589*77c1e3ccSAndroid Build Coastguard Worker mem_status = false;
590*77c1e3ccSAndroid Build Coastguard Worker goto Error;
591*77c1e3ccSAndroid Build Coastguard Worker }
592*77c1e3ccSAndroid Build Coastguard Worker assert(width > 0);
593*77c1e3ccSAndroid Build Coastguard Worker assert(height > 0);
594*77c1e3ccSAndroid Build Coastguard Worker assert(width2 > 0);
595*77c1e3ccSAndroid Build Coastguard Worker assert(height2 > 0);
596*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < height; ++i)
597*77c1e3ccSAndroid Build Coastguard Worker resize_multistep(input + in_stride * i, width, intbuf + width2 * i, width2,
598*77c1e3ccSAndroid Build Coastguard Worker tmpbuf);
599*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < width2; ++i) {
600*77c1e3ccSAndroid Build Coastguard Worker fill_col_to_arr(intbuf + i, width2, height, arrbuf);
601*77c1e3ccSAndroid Build Coastguard Worker resize_multistep(arrbuf, height, arrbuf2, height2, tmpbuf);
602*77c1e3ccSAndroid Build Coastguard Worker fill_arr_to_col(output + i, out_stride, height2, arrbuf2);
603*77c1e3ccSAndroid Build Coastguard Worker }
604*77c1e3ccSAndroid Build Coastguard Worker
605*77c1e3ccSAndroid Build Coastguard Worker Error:
606*77c1e3ccSAndroid Build Coastguard Worker aom_free(intbuf);
607*77c1e3ccSAndroid Build Coastguard Worker aom_free(tmpbuf);
608*77c1e3ccSAndroid Build Coastguard Worker aom_free(arrbuf);
609*77c1e3ccSAndroid Build Coastguard Worker aom_free(arrbuf2);
610*77c1e3ccSAndroid Build Coastguard Worker return mem_status;
611*77c1e3ccSAndroid Build Coastguard Worker }
612*77c1e3ccSAndroid Build Coastguard Worker
upscale_normative_rect(const uint8_t * const input,int height,int width,int in_stride,uint8_t * output,int height2,int width2,int out_stride,int x_step_qn,int x0_qn,int pad_left,int pad_right)613*77c1e3ccSAndroid Build Coastguard Worker static bool upscale_normative_rect(const uint8_t *const input, int height,
614*77c1e3ccSAndroid Build Coastguard Worker int width, int in_stride, uint8_t *output,
615*77c1e3ccSAndroid Build Coastguard Worker int height2, int width2, int out_stride,
616*77c1e3ccSAndroid Build Coastguard Worker int x_step_qn, int x0_qn, int pad_left,
617*77c1e3ccSAndroid Build Coastguard Worker int pad_right) {
618*77c1e3ccSAndroid Build Coastguard Worker assert(width > 0);
619*77c1e3ccSAndroid Build Coastguard Worker assert(height > 0);
620*77c1e3ccSAndroid Build Coastguard Worker assert(width2 > 0);
621*77c1e3ccSAndroid Build Coastguard Worker assert(height2 > 0);
622*77c1e3ccSAndroid Build Coastguard Worker assert(height2 == height);
623*77c1e3ccSAndroid Build Coastguard Worker
624*77c1e3ccSAndroid Build Coastguard Worker // Extend the left/right pixels of the tile column if needed
625*77c1e3ccSAndroid Build Coastguard Worker // (either because we can't sample from other tiles, or because we're at
626*77c1e3ccSAndroid Build Coastguard Worker // a frame edge).
627*77c1e3ccSAndroid Build Coastguard Worker // Save the overwritten pixels into tmp_left and tmp_right.
628*77c1e3ccSAndroid Build Coastguard Worker // Note: Because we pass input-1 to av1_convolve_horiz_rs, we need one extra
629*77c1e3ccSAndroid Build Coastguard Worker // column of border pixels compared to what we'd naively think.
630*77c1e3ccSAndroid Build Coastguard Worker const int border_cols = UPSCALE_NORMATIVE_TAPS / 2 + 1;
631*77c1e3ccSAndroid Build Coastguard Worker uint8_t *tmp_left =
632*77c1e3ccSAndroid Build Coastguard Worker NULL; // Silence spurious "may be used uninitialized" warnings
633*77c1e3ccSAndroid Build Coastguard Worker uint8_t *tmp_right = NULL;
634*77c1e3ccSAndroid Build Coastguard Worker uint8_t *const in_tl = (uint8_t *)(input - border_cols); // Cast off 'const'
635*77c1e3ccSAndroid Build Coastguard Worker uint8_t *const in_tr = (uint8_t *)(input + width);
636*77c1e3ccSAndroid Build Coastguard Worker if (pad_left) {
637*77c1e3ccSAndroid Build Coastguard Worker tmp_left = (uint8_t *)aom_malloc(sizeof(*tmp_left) * border_cols * height);
638*77c1e3ccSAndroid Build Coastguard Worker if (!tmp_left) return false;
639*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < height; i++) {
640*77c1e3ccSAndroid Build Coastguard Worker memcpy(tmp_left + i * border_cols, in_tl + i * in_stride, border_cols);
641*77c1e3ccSAndroid Build Coastguard Worker memset(in_tl + i * in_stride, input[i * in_stride], border_cols);
642*77c1e3ccSAndroid Build Coastguard Worker }
643*77c1e3ccSAndroid Build Coastguard Worker }
644*77c1e3ccSAndroid Build Coastguard Worker if (pad_right) {
645*77c1e3ccSAndroid Build Coastguard Worker tmp_right =
646*77c1e3ccSAndroid Build Coastguard Worker (uint8_t *)aom_malloc(sizeof(*tmp_right) * border_cols * height);
647*77c1e3ccSAndroid Build Coastguard Worker if (!tmp_right) {
648*77c1e3ccSAndroid Build Coastguard Worker aom_free(tmp_left);
649*77c1e3ccSAndroid Build Coastguard Worker return false;
650*77c1e3ccSAndroid Build Coastguard Worker }
651*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < height; i++) {
652*77c1e3ccSAndroid Build Coastguard Worker memcpy(tmp_right + i * border_cols, in_tr + i * in_stride, border_cols);
653*77c1e3ccSAndroid Build Coastguard Worker memset(in_tr + i * in_stride, input[i * in_stride + width - 1],
654*77c1e3ccSAndroid Build Coastguard Worker border_cols);
655*77c1e3ccSAndroid Build Coastguard Worker }
656*77c1e3ccSAndroid Build Coastguard Worker }
657*77c1e3ccSAndroid Build Coastguard Worker
658*77c1e3ccSAndroid Build Coastguard Worker av1_convolve_horiz_rs(input - 1, in_stride, output, out_stride, width2,
659*77c1e3ccSAndroid Build Coastguard Worker height2, &av1_resize_filter_normative[0][0], x0_qn,
660*77c1e3ccSAndroid Build Coastguard Worker x_step_qn);
661*77c1e3ccSAndroid Build Coastguard Worker
662*77c1e3ccSAndroid Build Coastguard Worker // Restore the left/right border pixels
663*77c1e3ccSAndroid Build Coastguard Worker if (pad_left) {
664*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < height; i++) {
665*77c1e3ccSAndroid Build Coastguard Worker memcpy(in_tl + i * in_stride, tmp_left + i * border_cols, border_cols);
666*77c1e3ccSAndroid Build Coastguard Worker }
667*77c1e3ccSAndroid Build Coastguard Worker aom_free(tmp_left);
668*77c1e3ccSAndroid Build Coastguard Worker }
669*77c1e3ccSAndroid Build Coastguard Worker if (pad_right) {
670*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < height; i++) {
671*77c1e3ccSAndroid Build Coastguard Worker memcpy(in_tr + i * in_stride, tmp_right + i * border_cols, border_cols);
672*77c1e3ccSAndroid Build Coastguard Worker }
673*77c1e3ccSAndroid Build Coastguard Worker aom_free(tmp_right);
674*77c1e3ccSAndroid Build Coastguard Worker }
675*77c1e3ccSAndroid Build Coastguard Worker return true;
676*77c1e3ccSAndroid Build Coastguard Worker }
677*77c1e3ccSAndroid Build Coastguard Worker
678*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
highbd_interpolate_core(const uint16_t * const input,int in_length,uint16_t * output,int out_length,int bd,const int16_t * interp_filters,int interp_taps)679*77c1e3ccSAndroid Build Coastguard Worker static void highbd_interpolate_core(const uint16_t *const input, int in_length,
680*77c1e3ccSAndroid Build Coastguard Worker uint16_t *output, int out_length, int bd,
681*77c1e3ccSAndroid Build Coastguard Worker const int16_t *interp_filters,
682*77c1e3ccSAndroid Build Coastguard Worker int interp_taps) {
683*77c1e3ccSAndroid Build Coastguard Worker const int32_t delta =
684*77c1e3ccSAndroid Build Coastguard Worker (((uint32_t)in_length << RS_SCALE_SUBPEL_BITS) + out_length / 2) /
685*77c1e3ccSAndroid Build Coastguard Worker out_length;
686*77c1e3ccSAndroid Build Coastguard Worker const int32_t offset =
687*77c1e3ccSAndroid Build Coastguard Worker in_length > out_length
688*77c1e3ccSAndroid Build Coastguard Worker ? (((int32_t)(in_length - out_length) << (RS_SCALE_SUBPEL_BITS - 1)) +
689*77c1e3ccSAndroid Build Coastguard Worker out_length / 2) /
690*77c1e3ccSAndroid Build Coastguard Worker out_length
691*77c1e3ccSAndroid Build Coastguard Worker : -(((int32_t)(out_length - in_length)
692*77c1e3ccSAndroid Build Coastguard Worker << (RS_SCALE_SUBPEL_BITS - 1)) +
693*77c1e3ccSAndroid Build Coastguard Worker out_length / 2) /
694*77c1e3ccSAndroid Build Coastguard Worker out_length;
695*77c1e3ccSAndroid Build Coastguard Worker uint16_t *optr = output;
696*77c1e3ccSAndroid Build Coastguard Worker int x, x1, x2, sum, k, int_pel, sub_pel;
697*77c1e3ccSAndroid Build Coastguard Worker int32_t y;
698*77c1e3ccSAndroid Build Coastguard Worker
699*77c1e3ccSAndroid Build Coastguard Worker x = 0;
700*77c1e3ccSAndroid Build Coastguard Worker y = offset + RS_SCALE_EXTRA_OFF;
701*77c1e3ccSAndroid Build Coastguard Worker while ((y >> RS_SCALE_SUBPEL_BITS) < (interp_taps / 2 - 1)) {
702*77c1e3ccSAndroid Build Coastguard Worker x++;
703*77c1e3ccSAndroid Build Coastguard Worker y += delta;
704*77c1e3ccSAndroid Build Coastguard Worker }
705*77c1e3ccSAndroid Build Coastguard Worker x1 = x;
706*77c1e3ccSAndroid Build Coastguard Worker x = out_length - 1;
707*77c1e3ccSAndroid Build Coastguard Worker y = delta * x + offset + RS_SCALE_EXTRA_OFF;
708*77c1e3ccSAndroid Build Coastguard Worker while ((y >> RS_SCALE_SUBPEL_BITS) + (int32_t)(interp_taps / 2) >=
709*77c1e3ccSAndroid Build Coastguard Worker in_length) {
710*77c1e3ccSAndroid Build Coastguard Worker x--;
711*77c1e3ccSAndroid Build Coastguard Worker y -= delta;
712*77c1e3ccSAndroid Build Coastguard Worker }
713*77c1e3ccSAndroid Build Coastguard Worker x2 = x;
714*77c1e3ccSAndroid Build Coastguard Worker if (x1 > x2) {
715*77c1e3ccSAndroid Build Coastguard Worker for (x = 0, y = offset + RS_SCALE_EXTRA_OFF; x < out_length;
716*77c1e3ccSAndroid Build Coastguard Worker ++x, y += delta) {
717*77c1e3ccSAndroid Build Coastguard Worker int_pel = y >> RS_SCALE_SUBPEL_BITS;
718*77c1e3ccSAndroid Build Coastguard Worker sub_pel = (y >> RS_SCALE_EXTRA_BITS) & RS_SUBPEL_MASK;
719*77c1e3ccSAndroid Build Coastguard Worker const int16_t *filter = &interp_filters[sub_pel * interp_taps];
720*77c1e3ccSAndroid Build Coastguard Worker sum = 0;
721*77c1e3ccSAndroid Build Coastguard Worker for (k = 0; k < interp_taps; ++k) {
722*77c1e3ccSAndroid Build Coastguard Worker const int pk = int_pel - interp_taps / 2 + 1 + k;
723*77c1e3ccSAndroid Build Coastguard Worker sum += filter[k] * input[AOMMAX(AOMMIN(pk, in_length - 1), 0)];
724*77c1e3ccSAndroid Build Coastguard Worker }
725*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd);
726*77c1e3ccSAndroid Build Coastguard Worker }
727*77c1e3ccSAndroid Build Coastguard Worker } else {
728*77c1e3ccSAndroid Build Coastguard Worker // Initial part.
729*77c1e3ccSAndroid Build Coastguard Worker for (x = 0, y = offset + RS_SCALE_EXTRA_OFF; x < x1; ++x, y += delta) {
730*77c1e3ccSAndroid Build Coastguard Worker int_pel = y >> RS_SCALE_SUBPEL_BITS;
731*77c1e3ccSAndroid Build Coastguard Worker sub_pel = (y >> RS_SCALE_EXTRA_BITS) & RS_SUBPEL_MASK;
732*77c1e3ccSAndroid Build Coastguard Worker const int16_t *filter = &interp_filters[sub_pel * interp_taps];
733*77c1e3ccSAndroid Build Coastguard Worker sum = 0;
734*77c1e3ccSAndroid Build Coastguard Worker for (k = 0; k < interp_taps; ++k)
735*77c1e3ccSAndroid Build Coastguard Worker sum += filter[k] * input[AOMMAX(int_pel - interp_taps / 2 + 1 + k, 0)];
736*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd);
737*77c1e3ccSAndroid Build Coastguard Worker }
738*77c1e3ccSAndroid Build Coastguard Worker // Middle part.
739*77c1e3ccSAndroid Build Coastguard Worker for (; x <= x2; ++x, y += delta) {
740*77c1e3ccSAndroid Build Coastguard Worker int_pel = y >> RS_SCALE_SUBPEL_BITS;
741*77c1e3ccSAndroid Build Coastguard Worker sub_pel = (y >> RS_SCALE_EXTRA_BITS) & RS_SUBPEL_MASK;
742*77c1e3ccSAndroid Build Coastguard Worker const int16_t *filter = &interp_filters[sub_pel * interp_taps];
743*77c1e3ccSAndroid Build Coastguard Worker sum = 0;
744*77c1e3ccSAndroid Build Coastguard Worker for (k = 0; k < interp_taps; ++k)
745*77c1e3ccSAndroid Build Coastguard Worker sum += filter[k] * input[int_pel - interp_taps / 2 + 1 + k];
746*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd);
747*77c1e3ccSAndroid Build Coastguard Worker }
748*77c1e3ccSAndroid Build Coastguard Worker // End part.
749*77c1e3ccSAndroid Build Coastguard Worker for (; x < out_length; ++x, y += delta) {
750*77c1e3ccSAndroid Build Coastguard Worker int_pel = y >> RS_SCALE_SUBPEL_BITS;
751*77c1e3ccSAndroid Build Coastguard Worker sub_pel = (y >> RS_SCALE_EXTRA_BITS) & RS_SUBPEL_MASK;
752*77c1e3ccSAndroid Build Coastguard Worker const int16_t *filter = &interp_filters[sub_pel * interp_taps];
753*77c1e3ccSAndroid Build Coastguard Worker sum = 0;
754*77c1e3ccSAndroid Build Coastguard Worker for (k = 0; k < interp_taps; ++k)
755*77c1e3ccSAndroid Build Coastguard Worker sum += filter[k] *
756*77c1e3ccSAndroid Build Coastguard Worker input[AOMMIN(int_pel - interp_taps / 2 + 1 + k, in_length - 1)];
757*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel_highbd(ROUND_POWER_OF_TWO(sum, FILTER_BITS), bd);
758*77c1e3ccSAndroid Build Coastguard Worker }
759*77c1e3ccSAndroid Build Coastguard Worker }
760*77c1e3ccSAndroid Build Coastguard Worker }
761*77c1e3ccSAndroid Build Coastguard Worker
highbd_interpolate(const uint16_t * const input,int in_length,uint16_t * output,int out_length,int bd)762*77c1e3ccSAndroid Build Coastguard Worker static void highbd_interpolate(const uint16_t *const input, int in_length,
763*77c1e3ccSAndroid Build Coastguard Worker uint16_t *output, int out_length, int bd) {
764*77c1e3ccSAndroid Build Coastguard Worker const InterpKernel *interp_filters =
765*77c1e3ccSAndroid Build Coastguard Worker choose_interp_filter(in_length, out_length);
766*77c1e3ccSAndroid Build Coastguard Worker
767*77c1e3ccSAndroid Build Coastguard Worker highbd_interpolate_core(input, in_length, output, out_length, bd,
768*77c1e3ccSAndroid Build Coastguard Worker &interp_filters[0][0], SUBPEL_TAPS);
769*77c1e3ccSAndroid Build Coastguard Worker }
770*77c1e3ccSAndroid Build Coastguard Worker
highbd_down2_symeven(const uint16_t * const input,int length,uint16_t * output,int bd)771*77c1e3ccSAndroid Build Coastguard Worker static void highbd_down2_symeven(const uint16_t *const input, int length,
772*77c1e3ccSAndroid Build Coastguard Worker uint16_t *output, int bd) {
773*77c1e3ccSAndroid Build Coastguard Worker // Actual filter len = 2 * filter_len_half.
774*77c1e3ccSAndroid Build Coastguard Worker static const int16_t *filter = av1_down2_symeven_half_filter;
775*77c1e3ccSAndroid Build Coastguard Worker const int filter_len_half = sizeof(av1_down2_symeven_half_filter) / 2;
776*77c1e3ccSAndroid Build Coastguard Worker int i, j;
777*77c1e3ccSAndroid Build Coastguard Worker uint16_t *optr = output;
778*77c1e3ccSAndroid Build Coastguard Worker int l1 = filter_len_half;
779*77c1e3ccSAndroid Build Coastguard Worker int l2 = (length - filter_len_half);
780*77c1e3ccSAndroid Build Coastguard Worker l1 += (l1 & 1);
781*77c1e3ccSAndroid Build Coastguard Worker l2 += (l2 & 1);
782*77c1e3ccSAndroid Build Coastguard Worker if (l1 > l2) {
783*77c1e3ccSAndroid Build Coastguard Worker // Short input length.
784*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < length; i += 2) {
785*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1));
786*77c1e3ccSAndroid Build Coastguard Worker for (j = 0; j < filter_len_half; ++j) {
787*77c1e3ccSAndroid Build Coastguard Worker sum +=
788*77c1e3ccSAndroid Build Coastguard Worker (input[AOMMAX(0, i - j)] + input[AOMMIN(i + 1 + j, length - 1)]) *
789*77c1e3ccSAndroid Build Coastguard Worker filter[j];
790*77c1e3ccSAndroid Build Coastguard Worker }
791*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
792*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel_highbd(sum, bd);
793*77c1e3ccSAndroid Build Coastguard Worker }
794*77c1e3ccSAndroid Build Coastguard Worker } else {
795*77c1e3ccSAndroid Build Coastguard Worker // Initial part.
796*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < l1; i += 2) {
797*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1));
798*77c1e3ccSAndroid Build Coastguard Worker for (j = 0; j < filter_len_half; ++j) {
799*77c1e3ccSAndroid Build Coastguard Worker sum += (input[AOMMAX(0, i - j)] + input[i + 1 + j]) * filter[j];
800*77c1e3ccSAndroid Build Coastguard Worker }
801*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
802*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel_highbd(sum, bd);
803*77c1e3ccSAndroid Build Coastguard Worker }
804*77c1e3ccSAndroid Build Coastguard Worker // Middle part.
805*77c1e3ccSAndroid Build Coastguard Worker for (; i < l2; i += 2) {
806*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1));
807*77c1e3ccSAndroid Build Coastguard Worker for (j = 0; j < filter_len_half; ++j) {
808*77c1e3ccSAndroid Build Coastguard Worker sum += (input[i - j] + input[i + 1 + j]) * filter[j];
809*77c1e3ccSAndroid Build Coastguard Worker }
810*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
811*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel_highbd(sum, bd);
812*77c1e3ccSAndroid Build Coastguard Worker }
813*77c1e3ccSAndroid Build Coastguard Worker // End part.
814*77c1e3ccSAndroid Build Coastguard Worker for (; i < length; i += 2) {
815*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1));
816*77c1e3ccSAndroid Build Coastguard Worker for (j = 0; j < filter_len_half; ++j) {
817*77c1e3ccSAndroid Build Coastguard Worker sum +=
818*77c1e3ccSAndroid Build Coastguard Worker (input[i - j] + input[AOMMIN(i + 1 + j, length - 1)]) * filter[j];
819*77c1e3ccSAndroid Build Coastguard Worker }
820*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
821*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel_highbd(sum, bd);
822*77c1e3ccSAndroid Build Coastguard Worker }
823*77c1e3ccSAndroid Build Coastguard Worker }
824*77c1e3ccSAndroid Build Coastguard Worker }
825*77c1e3ccSAndroid Build Coastguard Worker
highbd_down2_symodd(const uint16_t * const input,int length,uint16_t * output,int bd)826*77c1e3ccSAndroid Build Coastguard Worker static void highbd_down2_symodd(const uint16_t *const input, int length,
827*77c1e3ccSAndroid Build Coastguard Worker uint16_t *output, int bd) {
828*77c1e3ccSAndroid Build Coastguard Worker // Actual filter len = 2 * filter_len_half - 1.
829*77c1e3ccSAndroid Build Coastguard Worker static const int16_t *filter = av1_down2_symodd_half_filter;
830*77c1e3ccSAndroid Build Coastguard Worker const int filter_len_half = sizeof(av1_down2_symodd_half_filter) / 2;
831*77c1e3ccSAndroid Build Coastguard Worker int i, j;
832*77c1e3ccSAndroid Build Coastguard Worker uint16_t *optr = output;
833*77c1e3ccSAndroid Build Coastguard Worker int l1 = filter_len_half - 1;
834*77c1e3ccSAndroid Build Coastguard Worker int l2 = (length - filter_len_half + 1);
835*77c1e3ccSAndroid Build Coastguard Worker l1 += (l1 & 1);
836*77c1e3ccSAndroid Build Coastguard Worker l2 += (l2 & 1);
837*77c1e3ccSAndroid Build Coastguard Worker if (l1 > l2) {
838*77c1e3ccSAndroid Build Coastguard Worker // Short input length.
839*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < length; i += 2) {
840*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
841*77c1e3ccSAndroid Build Coastguard Worker for (j = 1; j < filter_len_half; ++j) {
842*77c1e3ccSAndroid Build Coastguard Worker sum += (input[AOMMAX(i - j, 0)] + input[AOMMIN(i + j, length - 1)]) *
843*77c1e3ccSAndroid Build Coastguard Worker filter[j];
844*77c1e3ccSAndroid Build Coastguard Worker }
845*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
846*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel_highbd(sum, bd);
847*77c1e3ccSAndroid Build Coastguard Worker }
848*77c1e3ccSAndroid Build Coastguard Worker } else {
849*77c1e3ccSAndroid Build Coastguard Worker // Initial part.
850*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < l1; i += 2) {
851*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
852*77c1e3ccSAndroid Build Coastguard Worker for (j = 1; j < filter_len_half; ++j) {
853*77c1e3ccSAndroid Build Coastguard Worker sum += (input[AOMMAX(i - j, 0)] + input[i + j]) * filter[j];
854*77c1e3ccSAndroid Build Coastguard Worker }
855*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
856*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel_highbd(sum, bd);
857*77c1e3ccSAndroid Build Coastguard Worker }
858*77c1e3ccSAndroid Build Coastguard Worker // Middle part.
859*77c1e3ccSAndroid Build Coastguard Worker for (; i < l2; i += 2) {
860*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
861*77c1e3ccSAndroid Build Coastguard Worker for (j = 1; j < filter_len_half; ++j) {
862*77c1e3ccSAndroid Build Coastguard Worker sum += (input[i - j] + input[i + j]) * filter[j];
863*77c1e3ccSAndroid Build Coastguard Worker }
864*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
865*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel_highbd(sum, bd);
866*77c1e3ccSAndroid Build Coastguard Worker }
867*77c1e3ccSAndroid Build Coastguard Worker // End part.
868*77c1e3ccSAndroid Build Coastguard Worker for (; i < length; i += 2) {
869*77c1e3ccSAndroid Build Coastguard Worker int sum = (1 << (FILTER_BITS - 1)) + input[i] * filter[0];
870*77c1e3ccSAndroid Build Coastguard Worker for (j = 1; j < filter_len_half; ++j) {
871*77c1e3ccSAndroid Build Coastguard Worker sum += (input[i - j] + input[AOMMIN(i + j, length - 1)]) * filter[j];
872*77c1e3ccSAndroid Build Coastguard Worker }
873*77c1e3ccSAndroid Build Coastguard Worker sum >>= FILTER_BITS;
874*77c1e3ccSAndroid Build Coastguard Worker *optr++ = clip_pixel_highbd(sum, bd);
875*77c1e3ccSAndroid Build Coastguard Worker }
876*77c1e3ccSAndroid Build Coastguard Worker }
877*77c1e3ccSAndroid Build Coastguard Worker }
878*77c1e3ccSAndroid Build Coastguard Worker
highbd_resize_multistep(const uint16_t * const input,int length,uint16_t * output,int olength,uint16_t * otmp,int bd)879*77c1e3ccSAndroid Build Coastguard Worker static void highbd_resize_multistep(const uint16_t *const input, int length,
880*77c1e3ccSAndroid Build Coastguard Worker uint16_t *output, int olength,
881*77c1e3ccSAndroid Build Coastguard Worker uint16_t *otmp, int bd) {
882*77c1e3ccSAndroid Build Coastguard Worker if (length == olength) {
883*77c1e3ccSAndroid Build Coastguard Worker memcpy(output, input, sizeof(output[0]) * length);
884*77c1e3ccSAndroid Build Coastguard Worker return;
885*77c1e3ccSAndroid Build Coastguard Worker }
886*77c1e3ccSAndroid Build Coastguard Worker const int steps = get_down2_steps(length, olength);
887*77c1e3ccSAndroid Build Coastguard Worker
888*77c1e3ccSAndroid Build Coastguard Worker if (steps > 0) {
889*77c1e3ccSAndroid Build Coastguard Worker uint16_t *out = NULL;
890*77c1e3ccSAndroid Build Coastguard Worker int filteredlength = length;
891*77c1e3ccSAndroid Build Coastguard Worker
892*77c1e3ccSAndroid Build Coastguard Worker assert(otmp != NULL);
893*77c1e3ccSAndroid Build Coastguard Worker uint16_t *otmp2 = otmp + get_down2_length(length, 1);
894*77c1e3ccSAndroid Build Coastguard Worker for (int s = 0; s < steps; ++s) {
895*77c1e3ccSAndroid Build Coastguard Worker const int proj_filteredlength = get_down2_length(filteredlength, 1);
896*77c1e3ccSAndroid Build Coastguard Worker const uint16_t *const in = (s == 0 ? input : out);
897*77c1e3ccSAndroid Build Coastguard Worker if (s == steps - 1 && proj_filteredlength == olength)
898*77c1e3ccSAndroid Build Coastguard Worker out = output;
899*77c1e3ccSAndroid Build Coastguard Worker else
900*77c1e3ccSAndroid Build Coastguard Worker out = (s & 1 ? otmp2 : otmp);
901*77c1e3ccSAndroid Build Coastguard Worker if (filteredlength & 1)
902*77c1e3ccSAndroid Build Coastguard Worker highbd_down2_symodd(in, filteredlength, out, bd);
903*77c1e3ccSAndroid Build Coastguard Worker else
904*77c1e3ccSAndroid Build Coastguard Worker highbd_down2_symeven(in, filteredlength, out, bd);
905*77c1e3ccSAndroid Build Coastguard Worker filteredlength = proj_filteredlength;
906*77c1e3ccSAndroid Build Coastguard Worker }
907*77c1e3ccSAndroid Build Coastguard Worker if (filteredlength != olength) {
908*77c1e3ccSAndroid Build Coastguard Worker highbd_interpolate(out, filteredlength, output, olength, bd);
909*77c1e3ccSAndroid Build Coastguard Worker }
910*77c1e3ccSAndroid Build Coastguard Worker } else {
911*77c1e3ccSAndroid Build Coastguard Worker highbd_interpolate(input, length, output, olength, bd);
912*77c1e3ccSAndroid Build Coastguard Worker }
913*77c1e3ccSAndroid Build Coastguard Worker }
914*77c1e3ccSAndroid Build Coastguard Worker
highbd_fill_col_to_arr(uint16_t * img,int stride,int len,uint16_t * arr)915*77c1e3ccSAndroid Build Coastguard Worker static void highbd_fill_col_to_arr(uint16_t *img, int stride, int len,
916*77c1e3ccSAndroid Build Coastguard Worker uint16_t *arr) {
917*77c1e3ccSAndroid Build Coastguard Worker int i;
918*77c1e3ccSAndroid Build Coastguard Worker uint16_t *iptr = img;
919*77c1e3ccSAndroid Build Coastguard Worker uint16_t *aptr = arr;
920*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < len; ++i, iptr += stride) {
921*77c1e3ccSAndroid Build Coastguard Worker *aptr++ = *iptr;
922*77c1e3ccSAndroid Build Coastguard Worker }
923*77c1e3ccSAndroid Build Coastguard Worker }
924*77c1e3ccSAndroid Build Coastguard Worker
highbd_fill_arr_to_col(uint16_t * img,int stride,int len,uint16_t * arr)925*77c1e3ccSAndroid Build Coastguard Worker static void highbd_fill_arr_to_col(uint16_t *img, int stride, int len,
926*77c1e3ccSAndroid Build Coastguard Worker uint16_t *arr) {
927*77c1e3ccSAndroid Build Coastguard Worker int i;
928*77c1e3ccSAndroid Build Coastguard Worker uint16_t *iptr = img;
929*77c1e3ccSAndroid Build Coastguard Worker uint16_t *aptr = arr;
930*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < len; ++i, iptr += stride) {
931*77c1e3ccSAndroid Build Coastguard Worker *iptr = *aptr++;
932*77c1e3ccSAndroid Build Coastguard Worker }
933*77c1e3ccSAndroid Build Coastguard Worker }
934*77c1e3ccSAndroid Build Coastguard Worker
av1_highbd_resize_plane(const uint8_t * input,int height,int width,int in_stride,uint8_t * output,int height2,int width2,int out_stride,int bd)935*77c1e3ccSAndroid Build Coastguard Worker void av1_highbd_resize_plane(const uint8_t *input, int height, int width,
936*77c1e3ccSAndroid Build Coastguard Worker int in_stride, uint8_t *output, int height2,
937*77c1e3ccSAndroid Build Coastguard Worker int width2, int out_stride, int bd) {
938*77c1e3ccSAndroid Build Coastguard Worker int i;
939*77c1e3ccSAndroid Build Coastguard Worker uint16_t *intbuf = (uint16_t *)aom_malloc(sizeof(uint16_t) * width2 * height);
940*77c1e3ccSAndroid Build Coastguard Worker uint16_t *tmpbuf =
941*77c1e3ccSAndroid Build Coastguard Worker (uint16_t *)aom_malloc(sizeof(uint16_t) * AOMMAX(width, height));
942*77c1e3ccSAndroid Build Coastguard Worker uint16_t *arrbuf = (uint16_t *)aom_malloc(sizeof(uint16_t) * height);
943*77c1e3ccSAndroid Build Coastguard Worker uint16_t *arrbuf2 = (uint16_t *)aom_malloc(sizeof(uint16_t) * height2);
944*77c1e3ccSAndroid Build Coastguard Worker if (intbuf == NULL || tmpbuf == NULL || arrbuf == NULL || arrbuf2 == NULL)
945*77c1e3ccSAndroid Build Coastguard Worker goto Error;
946*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < height; ++i) {
947*77c1e3ccSAndroid Build Coastguard Worker highbd_resize_multistep(CONVERT_TO_SHORTPTR(input + in_stride * i), width,
948*77c1e3ccSAndroid Build Coastguard Worker intbuf + width2 * i, width2, tmpbuf, bd);
949*77c1e3ccSAndroid Build Coastguard Worker }
950*77c1e3ccSAndroid Build Coastguard Worker for (i = 0; i < width2; ++i) {
951*77c1e3ccSAndroid Build Coastguard Worker highbd_fill_col_to_arr(intbuf + i, width2, height, arrbuf);
952*77c1e3ccSAndroid Build Coastguard Worker highbd_resize_multistep(arrbuf, height, arrbuf2, height2, tmpbuf, bd);
953*77c1e3ccSAndroid Build Coastguard Worker highbd_fill_arr_to_col(CONVERT_TO_SHORTPTR(output + i), out_stride, height2,
954*77c1e3ccSAndroid Build Coastguard Worker arrbuf2);
955*77c1e3ccSAndroid Build Coastguard Worker }
956*77c1e3ccSAndroid Build Coastguard Worker
957*77c1e3ccSAndroid Build Coastguard Worker Error:
958*77c1e3ccSAndroid Build Coastguard Worker aom_free(intbuf);
959*77c1e3ccSAndroid Build Coastguard Worker aom_free(tmpbuf);
960*77c1e3ccSAndroid Build Coastguard Worker aom_free(arrbuf);
961*77c1e3ccSAndroid Build Coastguard Worker aom_free(arrbuf2);
962*77c1e3ccSAndroid Build Coastguard Worker }
963*77c1e3ccSAndroid Build Coastguard Worker
highbd_upscale_normative_rect(const uint8_t * const input,int height,int width,int in_stride,uint8_t * output,int height2,int width2,int out_stride,int x_step_qn,int x0_qn,int pad_left,int pad_right,int bd)964*77c1e3ccSAndroid Build Coastguard Worker static bool highbd_upscale_normative_rect(const uint8_t *const input,
965*77c1e3ccSAndroid Build Coastguard Worker int height, int width, int in_stride,
966*77c1e3ccSAndroid Build Coastguard Worker uint8_t *output, int height2,
967*77c1e3ccSAndroid Build Coastguard Worker int width2, int out_stride,
968*77c1e3ccSAndroid Build Coastguard Worker int x_step_qn, int x0_qn,
969*77c1e3ccSAndroid Build Coastguard Worker int pad_left, int pad_right, int bd) {
970*77c1e3ccSAndroid Build Coastguard Worker assert(width > 0);
971*77c1e3ccSAndroid Build Coastguard Worker assert(height > 0);
972*77c1e3ccSAndroid Build Coastguard Worker assert(width2 > 0);
973*77c1e3ccSAndroid Build Coastguard Worker assert(height2 > 0);
974*77c1e3ccSAndroid Build Coastguard Worker assert(height2 == height);
975*77c1e3ccSAndroid Build Coastguard Worker
976*77c1e3ccSAndroid Build Coastguard Worker // Extend the left/right pixels of the tile column if needed
977*77c1e3ccSAndroid Build Coastguard Worker // (either because we can't sample from other tiles, or because we're at
978*77c1e3ccSAndroid Build Coastguard Worker // a frame edge).
979*77c1e3ccSAndroid Build Coastguard Worker // Save the overwritten pixels into tmp_left and tmp_right.
980*77c1e3ccSAndroid Build Coastguard Worker // Note: Because we pass input-1 to av1_convolve_horiz_rs, we need one extra
981*77c1e3ccSAndroid Build Coastguard Worker // column of border pixels compared to what we'd naively think.
982*77c1e3ccSAndroid Build Coastguard Worker const int border_cols = UPSCALE_NORMATIVE_TAPS / 2 + 1;
983*77c1e3ccSAndroid Build Coastguard Worker const int border_size = border_cols * sizeof(uint16_t);
984*77c1e3ccSAndroid Build Coastguard Worker uint16_t *tmp_left =
985*77c1e3ccSAndroid Build Coastguard Worker NULL; // Silence spurious "may be used uninitialized" warnings
986*77c1e3ccSAndroid Build Coastguard Worker uint16_t *tmp_right = NULL;
987*77c1e3ccSAndroid Build Coastguard Worker uint16_t *const input16 = CONVERT_TO_SHORTPTR(input);
988*77c1e3ccSAndroid Build Coastguard Worker uint16_t *const in_tl = input16 - border_cols;
989*77c1e3ccSAndroid Build Coastguard Worker uint16_t *const in_tr = input16 + width;
990*77c1e3ccSAndroid Build Coastguard Worker if (pad_left) {
991*77c1e3ccSAndroid Build Coastguard Worker tmp_left = (uint16_t *)aom_malloc(sizeof(*tmp_left) * border_cols * height);
992*77c1e3ccSAndroid Build Coastguard Worker if (!tmp_left) return false;
993*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < height; i++) {
994*77c1e3ccSAndroid Build Coastguard Worker memcpy(tmp_left + i * border_cols, in_tl + i * in_stride, border_size);
995*77c1e3ccSAndroid Build Coastguard Worker aom_memset16(in_tl + i * in_stride, input16[i * in_stride], border_cols);
996*77c1e3ccSAndroid Build Coastguard Worker }
997*77c1e3ccSAndroid Build Coastguard Worker }
998*77c1e3ccSAndroid Build Coastguard Worker if (pad_right) {
999*77c1e3ccSAndroid Build Coastguard Worker tmp_right =
1000*77c1e3ccSAndroid Build Coastguard Worker (uint16_t *)aom_malloc(sizeof(*tmp_right) * border_cols * height);
1001*77c1e3ccSAndroid Build Coastguard Worker if (!tmp_right) {
1002*77c1e3ccSAndroid Build Coastguard Worker aom_free(tmp_left);
1003*77c1e3ccSAndroid Build Coastguard Worker return false;
1004*77c1e3ccSAndroid Build Coastguard Worker }
1005*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < height; i++) {
1006*77c1e3ccSAndroid Build Coastguard Worker memcpy(tmp_right + i * border_cols, in_tr + i * in_stride, border_size);
1007*77c1e3ccSAndroid Build Coastguard Worker aom_memset16(in_tr + i * in_stride, input16[i * in_stride + width - 1],
1008*77c1e3ccSAndroid Build Coastguard Worker border_cols);
1009*77c1e3ccSAndroid Build Coastguard Worker }
1010*77c1e3ccSAndroid Build Coastguard Worker }
1011*77c1e3ccSAndroid Build Coastguard Worker
1012*77c1e3ccSAndroid Build Coastguard Worker av1_highbd_convolve_horiz_rs(CONVERT_TO_SHORTPTR(input - 1), in_stride,
1013*77c1e3ccSAndroid Build Coastguard Worker CONVERT_TO_SHORTPTR(output), out_stride, width2,
1014*77c1e3ccSAndroid Build Coastguard Worker height2, &av1_resize_filter_normative[0][0],
1015*77c1e3ccSAndroid Build Coastguard Worker x0_qn, x_step_qn, bd);
1016*77c1e3ccSAndroid Build Coastguard Worker
1017*77c1e3ccSAndroid Build Coastguard Worker // Restore the left/right border pixels
1018*77c1e3ccSAndroid Build Coastguard Worker if (pad_left) {
1019*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < height; i++) {
1020*77c1e3ccSAndroid Build Coastguard Worker memcpy(in_tl + i * in_stride, tmp_left + i * border_cols, border_size);
1021*77c1e3ccSAndroid Build Coastguard Worker }
1022*77c1e3ccSAndroid Build Coastguard Worker aom_free(tmp_left);
1023*77c1e3ccSAndroid Build Coastguard Worker }
1024*77c1e3ccSAndroid Build Coastguard Worker if (pad_right) {
1025*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < height; i++) {
1026*77c1e3ccSAndroid Build Coastguard Worker memcpy(in_tr + i * in_stride, tmp_right + i * border_cols, border_size);
1027*77c1e3ccSAndroid Build Coastguard Worker }
1028*77c1e3ccSAndroid Build Coastguard Worker aom_free(tmp_right);
1029*77c1e3ccSAndroid Build Coastguard Worker }
1030*77c1e3ccSAndroid Build Coastguard Worker return true;
1031*77c1e3ccSAndroid Build Coastguard Worker }
1032*77c1e3ccSAndroid Build Coastguard Worker #endif // CONFIG_AV1_HIGHBITDEPTH
1033*77c1e3ccSAndroid Build Coastguard Worker
av1_resize_and_extend_frame_c(const YV12_BUFFER_CONFIG * src,YV12_BUFFER_CONFIG * dst,const InterpFilter filter,const int phase_scaler,const int num_planes)1034*77c1e3ccSAndroid Build Coastguard Worker void av1_resize_and_extend_frame_c(const YV12_BUFFER_CONFIG *src,
1035*77c1e3ccSAndroid Build Coastguard Worker YV12_BUFFER_CONFIG *dst,
1036*77c1e3ccSAndroid Build Coastguard Worker const InterpFilter filter,
1037*77c1e3ccSAndroid Build Coastguard Worker const int phase_scaler,
1038*77c1e3ccSAndroid Build Coastguard Worker const int num_planes) {
1039*77c1e3ccSAndroid Build Coastguard Worker assert(filter == BILINEAR || filter == EIGHTTAP_SMOOTH ||
1040*77c1e3ccSAndroid Build Coastguard Worker filter == EIGHTTAP_REGULAR);
1041*77c1e3ccSAndroid Build Coastguard Worker const InterpKernel *const kernel =
1042*77c1e3ccSAndroid Build Coastguard Worker (const InterpKernel *)av1_interp_filter_params_list[filter].filter_ptr;
1043*77c1e3ccSAndroid Build Coastguard Worker
1044*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < AOMMIN(num_planes, MAX_MB_PLANE); ++i) {
1045*77c1e3ccSAndroid Build Coastguard Worker const int is_uv = i > 0;
1046*77c1e3ccSAndroid Build Coastguard Worker const int src_w = src->crop_widths[is_uv];
1047*77c1e3ccSAndroid Build Coastguard Worker const int src_h = src->crop_heights[is_uv];
1048*77c1e3ccSAndroid Build Coastguard Worker const uint8_t *src_buffer = src->buffers[i];
1049*77c1e3ccSAndroid Build Coastguard Worker const int src_stride = src->strides[is_uv];
1050*77c1e3ccSAndroid Build Coastguard Worker const int dst_w = dst->crop_widths[is_uv];
1051*77c1e3ccSAndroid Build Coastguard Worker const int dst_h = dst->crop_heights[is_uv];
1052*77c1e3ccSAndroid Build Coastguard Worker uint8_t *dst_buffer = dst->buffers[i];
1053*77c1e3ccSAndroid Build Coastguard Worker const int dst_stride = dst->strides[is_uv];
1054*77c1e3ccSAndroid Build Coastguard Worker for (int y = 0; y < dst_h; y += 16) {
1055*77c1e3ccSAndroid Build Coastguard Worker const int y_q4 =
1056*77c1e3ccSAndroid Build Coastguard Worker src_h == dst_h ? 0 : y * 16 * src_h / dst_h + phase_scaler;
1057*77c1e3ccSAndroid Build Coastguard Worker for (int x = 0; x < dst_w; x += 16) {
1058*77c1e3ccSAndroid Build Coastguard Worker const int x_q4 =
1059*77c1e3ccSAndroid Build Coastguard Worker src_w == dst_w ? 0 : x * 16 * src_w / dst_w + phase_scaler;
1060*77c1e3ccSAndroid Build Coastguard Worker const uint8_t *src_ptr =
1061*77c1e3ccSAndroid Build Coastguard Worker src_buffer + y * src_h / dst_h * src_stride + x * src_w / dst_w;
1062*77c1e3ccSAndroid Build Coastguard Worker uint8_t *dst_ptr = dst_buffer + y * dst_stride + x;
1063*77c1e3ccSAndroid Build Coastguard Worker
1064*77c1e3ccSAndroid Build Coastguard Worker // Width and height of the actual working area.
1065*77c1e3ccSAndroid Build Coastguard Worker const int work_w = AOMMIN(16, dst_w - x);
1066*77c1e3ccSAndroid Build Coastguard Worker const int work_h = AOMMIN(16, dst_h - y);
1067*77c1e3ccSAndroid Build Coastguard Worker // SIMD versions of aom_scaled_2d() have some trouble handling
1068*77c1e3ccSAndroid Build Coastguard Worker // nonstandard sizes, so fall back on the C version to handle borders.
1069*77c1e3ccSAndroid Build Coastguard Worker if (work_w != 16 || work_h != 16) {
1070*77c1e3ccSAndroid Build Coastguard Worker aom_scaled_2d_c(src_ptr, src_stride, dst_ptr, dst_stride, kernel,
1071*77c1e3ccSAndroid Build Coastguard Worker x_q4 & 0xf, 16 * src_w / dst_w, y_q4 & 0xf,
1072*77c1e3ccSAndroid Build Coastguard Worker 16 * src_h / dst_h, work_w, work_h);
1073*77c1e3ccSAndroid Build Coastguard Worker } else {
1074*77c1e3ccSAndroid Build Coastguard Worker aom_scaled_2d(src_ptr, src_stride, dst_ptr, dst_stride, kernel,
1075*77c1e3ccSAndroid Build Coastguard Worker x_q4 & 0xf, 16 * src_w / dst_w, y_q4 & 0xf,
1076*77c1e3ccSAndroid Build Coastguard Worker 16 * src_h / dst_h, 16, 16);
1077*77c1e3ccSAndroid Build Coastguard Worker }
1078*77c1e3ccSAndroid Build Coastguard Worker }
1079*77c1e3ccSAndroid Build Coastguard Worker }
1080*77c1e3ccSAndroid Build Coastguard Worker }
1081*77c1e3ccSAndroid Build Coastguard Worker aom_extend_frame_borders(dst, num_planes);
1082*77c1e3ccSAndroid Build Coastguard Worker }
1083*77c1e3ccSAndroid Build Coastguard Worker
av1_resize_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG * src,YV12_BUFFER_CONFIG * dst,int bd,int num_planes)1084*77c1e3ccSAndroid Build Coastguard Worker bool av1_resize_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src,
1085*77c1e3ccSAndroid Build Coastguard Worker YV12_BUFFER_CONFIG *dst, int bd,
1086*77c1e3ccSAndroid Build Coastguard Worker int num_planes) {
1087*77c1e3ccSAndroid Build Coastguard Worker // TODO(dkovalev): replace YV12_BUFFER_CONFIG with aom_image_t
1088*77c1e3ccSAndroid Build Coastguard Worker
1089*77c1e3ccSAndroid Build Coastguard Worker // We use AOMMIN(num_planes, MAX_MB_PLANE) instead of num_planes to quiet
1090*77c1e3ccSAndroid Build Coastguard Worker // the static analysis warnings.
1091*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < AOMMIN(num_planes, MAX_MB_PLANE); ++i) {
1092*77c1e3ccSAndroid Build Coastguard Worker const int is_uv = i > 0;
1093*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
1094*77c1e3ccSAndroid Build Coastguard Worker if (src->flags & YV12_FLAG_HIGHBITDEPTH) {
1095*77c1e3ccSAndroid Build Coastguard Worker av1_highbd_resize_plane(src->buffers[i], src->crop_heights[is_uv],
1096*77c1e3ccSAndroid Build Coastguard Worker src->crop_widths[is_uv], src->strides[is_uv],
1097*77c1e3ccSAndroid Build Coastguard Worker dst->buffers[i], dst->crop_heights[is_uv],
1098*77c1e3ccSAndroid Build Coastguard Worker dst->crop_widths[is_uv], dst->strides[is_uv], bd);
1099*77c1e3ccSAndroid Build Coastguard Worker } else if (!av1_resize_plane(src->buffers[i], src->crop_heights[is_uv],
1100*77c1e3ccSAndroid Build Coastguard Worker src->crop_widths[is_uv], src->strides[is_uv],
1101*77c1e3ccSAndroid Build Coastguard Worker dst->buffers[i], dst->crop_heights[is_uv],
1102*77c1e3ccSAndroid Build Coastguard Worker dst->crop_widths[is_uv],
1103*77c1e3ccSAndroid Build Coastguard Worker dst->strides[is_uv])) {
1104*77c1e3ccSAndroid Build Coastguard Worker return false;
1105*77c1e3ccSAndroid Build Coastguard Worker }
1106*77c1e3ccSAndroid Build Coastguard Worker #else
1107*77c1e3ccSAndroid Build Coastguard Worker (void)bd;
1108*77c1e3ccSAndroid Build Coastguard Worker if (!av1_resize_plane(src->buffers[i], src->crop_heights[is_uv],
1109*77c1e3ccSAndroid Build Coastguard Worker src->crop_widths[is_uv], src->strides[is_uv],
1110*77c1e3ccSAndroid Build Coastguard Worker dst->buffers[i], dst->crop_heights[is_uv],
1111*77c1e3ccSAndroid Build Coastguard Worker dst->crop_widths[is_uv], dst->strides[is_uv]))
1112*77c1e3ccSAndroid Build Coastguard Worker return false;
1113*77c1e3ccSAndroid Build Coastguard Worker #endif
1114*77c1e3ccSAndroid Build Coastguard Worker }
1115*77c1e3ccSAndroid Build Coastguard Worker aom_extend_frame_borders(dst, num_planes);
1116*77c1e3ccSAndroid Build Coastguard Worker return true;
1117*77c1e3ccSAndroid Build Coastguard Worker }
1118*77c1e3ccSAndroid Build Coastguard Worker
av1_upscale_normative_rows(const AV1_COMMON * cm,const uint8_t * src,int src_stride,uint8_t * dst,int dst_stride,int plane,int rows)1119*77c1e3ccSAndroid Build Coastguard Worker void av1_upscale_normative_rows(const AV1_COMMON *cm, const uint8_t *src,
1120*77c1e3ccSAndroid Build Coastguard Worker int src_stride, uint8_t *dst, int dst_stride,
1121*77c1e3ccSAndroid Build Coastguard Worker int plane, int rows) {
1122*77c1e3ccSAndroid Build Coastguard Worker const int is_uv = (plane > 0);
1123*77c1e3ccSAndroid Build Coastguard Worker const int ss_x = is_uv && cm->seq_params->subsampling_x;
1124*77c1e3ccSAndroid Build Coastguard Worker const int downscaled_plane_width = ROUND_POWER_OF_TWO(cm->width, ss_x);
1125*77c1e3ccSAndroid Build Coastguard Worker const int upscaled_plane_width =
1126*77c1e3ccSAndroid Build Coastguard Worker ROUND_POWER_OF_TWO(cm->superres_upscaled_width, ss_x);
1127*77c1e3ccSAndroid Build Coastguard Worker const int superres_denom = cm->superres_scale_denominator;
1128*77c1e3ccSAndroid Build Coastguard Worker
1129*77c1e3ccSAndroid Build Coastguard Worker TileInfo tile_col;
1130*77c1e3ccSAndroid Build Coastguard Worker const int32_t x_step_qn = av1_get_upscale_convolve_step(
1131*77c1e3ccSAndroid Build Coastguard Worker downscaled_plane_width, upscaled_plane_width);
1132*77c1e3ccSAndroid Build Coastguard Worker int32_t x0_qn = get_upscale_convolve_x0(downscaled_plane_width,
1133*77c1e3ccSAndroid Build Coastguard Worker upscaled_plane_width, x_step_qn);
1134*77c1e3ccSAndroid Build Coastguard Worker
1135*77c1e3ccSAndroid Build Coastguard Worker for (int j = 0; j < cm->tiles.cols; j++) {
1136*77c1e3ccSAndroid Build Coastguard Worker av1_tile_set_col(&tile_col, cm, j);
1137*77c1e3ccSAndroid Build Coastguard Worker // Determine the limits of this tile column in both the source
1138*77c1e3ccSAndroid Build Coastguard Worker // and destination images.
1139*77c1e3ccSAndroid Build Coastguard Worker // Note: The actual location which we start sampling from is
1140*77c1e3ccSAndroid Build Coastguard Worker // (downscaled_x0 - 1 + (x0_qn/2^14)), and this quantity increases
1141*77c1e3ccSAndroid Build Coastguard Worker // by exactly dst_width * (x_step_qn/2^14) pixels each iteration.
1142*77c1e3ccSAndroid Build Coastguard Worker const int downscaled_x0 = tile_col.mi_col_start << (MI_SIZE_LOG2 - ss_x);
1143*77c1e3ccSAndroid Build Coastguard Worker const int downscaled_x1 = tile_col.mi_col_end << (MI_SIZE_LOG2 - ss_x);
1144*77c1e3ccSAndroid Build Coastguard Worker const int src_width = downscaled_x1 - downscaled_x0;
1145*77c1e3ccSAndroid Build Coastguard Worker
1146*77c1e3ccSAndroid Build Coastguard Worker const int upscaled_x0 = (downscaled_x0 * superres_denom) / SCALE_NUMERATOR;
1147*77c1e3ccSAndroid Build Coastguard Worker int upscaled_x1;
1148*77c1e3ccSAndroid Build Coastguard Worker if (j == cm->tiles.cols - 1) {
1149*77c1e3ccSAndroid Build Coastguard Worker // Note that we can't just use AOMMIN here - due to rounding,
1150*77c1e3ccSAndroid Build Coastguard Worker // (downscaled_x1 * superres_denom) / SCALE_NUMERATOR may be less than
1151*77c1e3ccSAndroid Build Coastguard Worker // upscaled_plane_width.
1152*77c1e3ccSAndroid Build Coastguard Worker upscaled_x1 = upscaled_plane_width;
1153*77c1e3ccSAndroid Build Coastguard Worker } else {
1154*77c1e3ccSAndroid Build Coastguard Worker upscaled_x1 = (downscaled_x1 * superres_denom) / SCALE_NUMERATOR;
1155*77c1e3ccSAndroid Build Coastguard Worker }
1156*77c1e3ccSAndroid Build Coastguard Worker
1157*77c1e3ccSAndroid Build Coastguard Worker const uint8_t *const src_ptr = src + downscaled_x0;
1158*77c1e3ccSAndroid Build Coastguard Worker uint8_t *const dst_ptr = dst + upscaled_x0;
1159*77c1e3ccSAndroid Build Coastguard Worker const int dst_width = upscaled_x1 - upscaled_x0;
1160*77c1e3ccSAndroid Build Coastguard Worker
1161*77c1e3ccSAndroid Build Coastguard Worker const int pad_left = (j == 0);
1162*77c1e3ccSAndroid Build Coastguard Worker const int pad_right = (j == cm->tiles.cols - 1);
1163*77c1e3ccSAndroid Build Coastguard Worker
1164*77c1e3ccSAndroid Build Coastguard Worker bool success;
1165*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
1166*77c1e3ccSAndroid Build Coastguard Worker if (cm->seq_params->use_highbitdepth)
1167*77c1e3ccSAndroid Build Coastguard Worker success = highbd_upscale_normative_rect(
1168*77c1e3ccSAndroid Build Coastguard Worker src_ptr, rows, src_width, src_stride, dst_ptr, rows, dst_width,
1169*77c1e3ccSAndroid Build Coastguard Worker dst_stride, x_step_qn, x0_qn, pad_left, pad_right,
1170*77c1e3ccSAndroid Build Coastguard Worker cm->seq_params->bit_depth);
1171*77c1e3ccSAndroid Build Coastguard Worker else
1172*77c1e3ccSAndroid Build Coastguard Worker success = upscale_normative_rect(src_ptr, rows, src_width, src_stride,
1173*77c1e3ccSAndroid Build Coastguard Worker dst_ptr, rows, dst_width, dst_stride,
1174*77c1e3ccSAndroid Build Coastguard Worker x_step_qn, x0_qn, pad_left, pad_right);
1175*77c1e3ccSAndroid Build Coastguard Worker #else
1176*77c1e3ccSAndroid Build Coastguard Worker success = upscale_normative_rect(src_ptr, rows, src_width, src_stride,
1177*77c1e3ccSAndroid Build Coastguard Worker dst_ptr, rows, dst_width, dst_stride,
1178*77c1e3ccSAndroid Build Coastguard Worker x_step_qn, x0_qn, pad_left, pad_right);
1179*77c1e3ccSAndroid Build Coastguard Worker #endif
1180*77c1e3ccSAndroid Build Coastguard Worker if (!success) {
1181*77c1e3ccSAndroid Build Coastguard Worker aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR,
1182*77c1e3ccSAndroid Build Coastguard Worker "Error upscaling frame");
1183*77c1e3ccSAndroid Build Coastguard Worker }
1184*77c1e3ccSAndroid Build Coastguard Worker // Update the fractional pixel offset to prepare for the next tile column.
1185*77c1e3ccSAndroid Build Coastguard Worker x0_qn += (dst_width * x_step_qn) - (src_width << RS_SCALE_SUBPEL_BITS);
1186*77c1e3ccSAndroid Build Coastguard Worker }
1187*77c1e3ccSAndroid Build Coastguard Worker }
1188*77c1e3ccSAndroid Build Coastguard Worker
upscale_normative_and_extend_frame(const AV1_COMMON * cm,const YV12_BUFFER_CONFIG * src,YV12_BUFFER_CONFIG * dst)1189*77c1e3ccSAndroid Build Coastguard Worker static void upscale_normative_and_extend_frame(const AV1_COMMON *cm,
1190*77c1e3ccSAndroid Build Coastguard Worker const YV12_BUFFER_CONFIG *src,
1191*77c1e3ccSAndroid Build Coastguard Worker YV12_BUFFER_CONFIG *dst) {
1192*77c1e3ccSAndroid Build Coastguard Worker const int num_planes = av1_num_planes(cm);
1193*77c1e3ccSAndroid Build Coastguard Worker for (int i = 0; i < num_planes; ++i) {
1194*77c1e3ccSAndroid Build Coastguard Worker const int is_uv = (i > 0);
1195*77c1e3ccSAndroid Build Coastguard Worker av1_upscale_normative_rows(cm, src->buffers[i], src->strides[is_uv],
1196*77c1e3ccSAndroid Build Coastguard Worker dst->buffers[i], dst->strides[is_uv], i,
1197*77c1e3ccSAndroid Build Coastguard Worker src->crop_heights[is_uv]);
1198*77c1e3ccSAndroid Build Coastguard Worker }
1199*77c1e3ccSAndroid Build Coastguard Worker
1200*77c1e3ccSAndroid Build Coastguard Worker aom_extend_frame_borders(dst, num_planes);
1201*77c1e3ccSAndroid Build Coastguard Worker }
1202*77c1e3ccSAndroid Build Coastguard Worker
av1_realloc_and_scale_if_required(AV1_COMMON * cm,YV12_BUFFER_CONFIG * unscaled,YV12_BUFFER_CONFIG * scaled,const InterpFilter filter,const int phase,const bool use_optimized_scaler,const bool for_psnr,const int border_in_pixels,const bool alloc_pyramid)1203*77c1e3ccSAndroid Build Coastguard Worker YV12_BUFFER_CONFIG *av1_realloc_and_scale_if_required(
1204*77c1e3ccSAndroid Build Coastguard Worker AV1_COMMON *cm, YV12_BUFFER_CONFIG *unscaled, YV12_BUFFER_CONFIG *scaled,
1205*77c1e3ccSAndroid Build Coastguard Worker const InterpFilter filter, const int phase, const bool use_optimized_scaler,
1206*77c1e3ccSAndroid Build Coastguard Worker const bool for_psnr, const int border_in_pixels, const bool alloc_pyramid) {
1207*77c1e3ccSAndroid Build Coastguard Worker // If scaling is performed for the sole purpose of calculating PSNR, then our
1208*77c1e3ccSAndroid Build Coastguard Worker // target dimensions are superres upscaled width/height. Otherwise our target
1209*77c1e3ccSAndroid Build Coastguard Worker // dimensions are coded width/height.
1210*77c1e3ccSAndroid Build Coastguard Worker const int scaled_width = for_psnr ? cm->superres_upscaled_width : cm->width;
1211*77c1e3ccSAndroid Build Coastguard Worker const int scaled_height =
1212*77c1e3ccSAndroid Build Coastguard Worker for_psnr ? cm->superres_upscaled_height : cm->height;
1213*77c1e3ccSAndroid Build Coastguard Worker const bool scaling_required = (scaled_width != unscaled->y_crop_width) ||
1214*77c1e3ccSAndroid Build Coastguard Worker (scaled_height != unscaled->y_crop_height);
1215*77c1e3ccSAndroid Build Coastguard Worker
1216*77c1e3ccSAndroid Build Coastguard Worker if (scaling_required) {
1217*77c1e3ccSAndroid Build Coastguard Worker const int num_planes = av1_num_planes(cm);
1218*77c1e3ccSAndroid Build Coastguard Worker const SequenceHeader *seq_params = cm->seq_params;
1219*77c1e3ccSAndroid Build Coastguard Worker
1220*77c1e3ccSAndroid Build Coastguard Worker // Reallocate the frame buffer based on the target dimensions when scaling
1221*77c1e3ccSAndroid Build Coastguard Worker // is required.
1222*77c1e3ccSAndroid Build Coastguard Worker if (aom_realloc_frame_buffer(
1223*77c1e3ccSAndroid Build Coastguard Worker scaled, scaled_width, scaled_height, seq_params->subsampling_x,
1224*77c1e3ccSAndroid Build Coastguard Worker seq_params->subsampling_y, seq_params->use_highbitdepth,
1225*77c1e3ccSAndroid Build Coastguard Worker border_in_pixels, cm->features.byte_alignment, NULL, NULL, NULL,
1226*77c1e3ccSAndroid Build Coastguard Worker alloc_pyramid, 0))
1227*77c1e3ccSAndroid Build Coastguard Worker aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR,
1228*77c1e3ccSAndroid Build Coastguard Worker "Failed to allocate scaled buffer");
1229*77c1e3ccSAndroid Build Coastguard Worker
1230*77c1e3ccSAndroid Build Coastguard Worker bool has_optimized_scaler = av1_has_optimized_scaler(
1231*77c1e3ccSAndroid Build Coastguard Worker unscaled->y_crop_width, unscaled->y_crop_height, scaled_width,
1232*77c1e3ccSAndroid Build Coastguard Worker scaled_height);
1233*77c1e3ccSAndroid Build Coastguard Worker if (num_planes > 1) {
1234*77c1e3ccSAndroid Build Coastguard Worker has_optimized_scaler = has_optimized_scaler &&
1235*77c1e3ccSAndroid Build Coastguard Worker av1_has_optimized_scaler(unscaled->uv_crop_width,
1236*77c1e3ccSAndroid Build Coastguard Worker unscaled->uv_crop_height,
1237*77c1e3ccSAndroid Build Coastguard Worker scaled->uv_crop_width,
1238*77c1e3ccSAndroid Build Coastguard Worker scaled->uv_crop_height);
1239*77c1e3ccSAndroid Build Coastguard Worker }
1240*77c1e3ccSAndroid Build Coastguard Worker
1241*77c1e3ccSAndroid Build Coastguard Worker #if CONFIG_AV1_HIGHBITDEPTH
1242*77c1e3ccSAndroid Build Coastguard Worker if (use_optimized_scaler && has_optimized_scaler &&
1243*77c1e3ccSAndroid Build Coastguard Worker cm->seq_params->bit_depth == AOM_BITS_8) {
1244*77c1e3ccSAndroid Build Coastguard Worker av1_resize_and_extend_frame(unscaled, scaled, filter, phase, num_planes);
1245*77c1e3ccSAndroid Build Coastguard Worker } else {
1246*77c1e3ccSAndroid Build Coastguard Worker if (!av1_resize_and_extend_frame_nonnormative(
1247*77c1e3ccSAndroid Build Coastguard Worker unscaled, scaled, (int)cm->seq_params->bit_depth, num_planes))
1248*77c1e3ccSAndroid Build Coastguard Worker aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR,
1249*77c1e3ccSAndroid Build Coastguard Worker "Failed to allocate buffers during resize");
1250*77c1e3ccSAndroid Build Coastguard Worker }
1251*77c1e3ccSAndroid Build Coastguard Worker #else
1252*77c1e3ccSAndroid Build Coastguard Worker if (use_optimized_scaler && has_optimized_scaler) {
1253*77c1e3ccSAndroid Build Coastguard Worker av1_resize_and_extend_frame(unscaled, scaled, filter, phase, num_planes);
1254*77c1e3ccSAndroid Build Coastguard Worker } else {
1255*77c1e3ccSAndroid Build Coastguard Worker if (!av1_resize_and_extend_frame_nonnormative(
1256*77c1e3ccSAndroid Build Coastguard Worker unscaled, scaled, (int)cm->seq_params->bit_depth, num_planes))
1257*77c1e3ccSAndroid Build Coastguard Worker aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR,
1258*77c1e3ccSAndroid Build Coastguard Worker "Failed to allocate buffers during resize");
1259*77c1e3ccSAndroid Build Coastguard Worker }
1260*77c1e3ccSAndroid Build Coastguard Worker #endif
1261*77c1e3ccSAndroid Build Coastguard Worker return scaled;
1262*77c1e3ccSAndroid Build Coastguard Worker }
1263*77c1e3ccSAndroid Build Coastguard Worker return unscaled;
1264*77c1e3ccSAndroid Build Coastguard Worker }
1265*77c1e3ccSAndroid Build Coastguard Worker
1266*77c1e3ccSAndroid Build Coastguard Worker // Calculates the scaled dimension given the original dimension and the scale
1267*77c1e3ccSAndroid Build Coastguard Worker // denominator.
calculate_scaled_size_helper(int * dim,int denom)1268*77c1e3ccSAndroid Build Coastguard Worker static void calculate_scaled_size_helper(int *dim, int denom) {
1269*77c1e3ccSAndroid Build Coastguard Worker if (denom != SCALE_NUMERATOR) {
1270*77c1e3ccSAndroid Build Coastguard Worker // We need to ensure the constraint in "Appendix A" of the spec:
1271*77c1e3ccSAndroid Build Coastguard Worker // * FrameWidth is greater than or equal to 16
1272*77c1e3ccSAndroid Build Coastguard Worker // * FrameHeight is greater than or equal to 16
1273*77c1e3ccSAndroid Build Coastguard Worker // For this, we clamp the downscaled dimension to at least 16. One
1274*77c1e3ccSAndroid Build Coastguard Worker // exception: if original dimension itself was < 16, then we keep the
1275*77c1e3ccSAndroid Build Coastguard Worker // downscaled dimension to be same as the original, to ensure that resizing
1276*77c1e3ccSAndroid Build Coastguard Worker // is valid.
1277*77c1e3ccSAndroid Build Coastguard Worker const int min_dim = AOMMIN(16, *dim);
1278*77c1e3ccSAndroid Build Coastguard Worker // Use this version if we need *dim to be even
1279*77c1e3ccSAndroid Build Coastguard Worker // *width = (*width * SCALE_NUMERATOR + denom) / (2 * denom);
1280*77c1e3ccSAndroid Build Coastguard Worker // *width <<= 1;
1281*77c1e3ccSAndroid Build Coastguard Worker *dim = (*dim * SCALE_NUMERATOR + denom / 2) / (denom);
1282*77c1e3ccSAndroid Build Coastguard Worker *dim = AOMMAX(*dim, min_dim);
1283*77c1e3ccSAndroid Build Coastguard Worker }
1284*77c1e3ccSAndroid Build Coastguard Worker }
1285*77c1e3ccSAndroid Build Coastguard Worker
av1_calculate_scaled_size(int * width,int * height,int resize_denom)1286*77c1e3ccSAndroid Build Coastguard Worker void av1_calculate_scaled_size(int *width, int *height, int resize_denom) {
1287*77c1e3ccSAndroid Build Coastguard Worker calculate_scaled_size_helper(width, resize_denom);
1288*77c1e3ccSAndroid Build Coastguard Worker calculate_scaled_size_helper(height, resize_denom);
1289*77c1e3ccSAndroid Build Coastguard Worker }
1290*77c1e3ccSAndroid Build Coastguard Worker
av1_calculate_scaled_superres_size(int * width,int * height,int superres_denom)1291*77c1e3ccSAndroid Build Coastguard Worker void av1_calculate_scaled_superres_size(int *width, int *height,
1292*77c1e3ccSAndroid Build Coastguard Worker int superres_denom) {
1293*77c1e3ccSAndroid Build Coastguard Worker (void)height;
1294*77c1e3ccSAndroid Build Coastguard Worker calculate_scaled_size_helper(width, superres_denom);
1295*77c1e3ccSAndroid Build Coastguard Worker }
1296*77c1e3ccSAndroid Build Coastguard Worker
av1_calculate_unscaled_superres_size(int * width,int * height,int denom)1297*77c1e3ccSAndroid Build Coastguard Worker void av1_calculate_unscaled_superres_size(int *width, int *height, int denom) {
1298*77c1e3ccSAndroid Build Coastguard Worker if (denom != SCALE_NUMERATOR) {
1299*77c1e3ccSAndroid Build Coastguard Worker // Note: av1_calculate_scaled_superres_size() rounds *up* after division
1300*77c1e3ccSAndroid Build Coastguard Worker // when the resulting dimensions are odd. So here, we round *down*.
1301*77c1e3ccSAndroid Build Coastguard Worker *width = *width * denom / SCALE_NUMERATOR;
1302*77c1e3ccSAndroid Build Coastguard Worker (void)height;
1303*77c1e3ccSAndroid Build Coastguard Worker }
1304*77c1e3ccSAndroid Build Coastguard Worker }
1305*77c1e3ccSAndroid Build Coastguard Worker
1306*77c1e3ccSAndroid Build Coastguard Worker // Copy only the config data from 'src' to 'dst'.
copy_buffer_config(const YV12_BUFFER_CONFIG * const src,YV12_BUFFER_CONFIG * const dst)1307*77c1e3ccSAndroid Build Coastguard Worker static void copy_buffer_config(const YV12_BUFFER_CONFIG *const src,
1308*77c1e3ccSAndroid Build Coastguard Worker YV12_BUFFER_CONFIG *const dst) {
1309*77c1e3ccSAndroid Build Coastguard Worker dst->bit_depth = src->bit_depth;
1310*77c1e3ccSAndroid Build Coastguard Worker dst->color_primaries = src->color_primaries;
1311*77c1e3ccSAndroid Build Coastguard Worker dst->transfer_characteristics = src->transfer_characteristics;
1312*77c1e3ccSAndroid Build Coastguard Worker dst->matrix_coefficients = src->matrix_coefficients;
1313*77c1e3ccSAndroid Build Coastguard Worker dst->monochrome = src->monochrome;
1314*77c1e3ccSAndroid Build Coastguard Worker dst->chroma_sample_position = src->chroma_sample_position;
1315*77c1e3ccSAndroid Build Coastguard Worker dst->color_range = src->color_range;
1316*77c1e3ccSAndroid Build Coastguard Worker }
1317*77c1e3ccSAndroid Build Coastguard Worker
1318*77c1e3ccSAndroid Build Coastguard Worker // TODO(afergs): Look for in-place upscaling
1319*77c1e3ccSAndroid Build Coastguard Worker // TODO(afergs): aom_ vs av1_ functions? Which can I use?
1320*77c1e3ccSAndroid Build Coastguard Worker // Upscale decoded image.
av1_superres_upscale(AV1_COMMON * cm,BufferPool * const pool,bool alloc_pyramid)1321*77c1e3ccSAndroid Build Coastguard Worker void av1_superres_upscale(AV1_COMMON *cm, BufferPool *const pool,
1322*77c1e3ccSAndroid Build Coastguard Worker bool alloc_pyramid) {
1323*77c1e3ccSAndroid Build Coastguard Worker const int num_planes = av1_num_planes(cm);
1324*77c1e3ccSAndroid Build Coastguard Worker if (!av1_superres_scaled(cm)) return;
1325*77c1e3ccSAndroid Build Coastguard Worker const SequenceHeader *const seq_params = cm->seq_params;
1326*77c1e3ccSAndroid Build Coastguard Worker const int byte_alignment = cm->features.byte_alignment;
1327*77c1e3ccSAndroid Build Coastguard Worker
1328*77c1e3ccSAndroid Build Coastguard Worker YV12_BUFFER_CONFIG copy_buffer;
1329*77c1e3ccSAndroid Build Coastguard Worker memset(©_buffer, 0, sizeof(copy_buffer));
1330*77c1e3ccSAndroid Build Coastguard Worker
1331*77c1e3ccSAndroid Build Coastguard Worker YV12_BUFFER_CONFIG *const frame_to_show = &cm->cur_frame->buf;
1332*77c1e3ccSAndroid Build Coastguard Worker
1333*77c1e3ccSAndroid Build Coastguard Worker const int aligned_width = ALIGN_POWER_OF_TWO(cm->width, 3);
1334*77c1e3ccSAndroid Build Coastguard Worker if (aom_alloc_frame_buffer(
1335*77c1e3ccSAndroid Build Coastguard Worker ©_buffer, aligned_width, cm->height, seq_params->subsampling_x,
1336*77c1e3ccSAndroid Build Coastguard Worker seq_params->subsampling_y, seq_params->use_highbitdepth,
1337*77c1e3ccSAndroid Build Coastguard Worker AOM_BORDER_IN_PIXELS, byte_alignment, false, 0))
1338*77c1e3ccSAndroid Build Coastguard Worker aom_internal_error(cm->error, AOM_CODEC_MEM_ERROR,
1339*77c1e3ccSAndroid Build Coastguard Worker "Failed to allocate copy buffer for superres upscaling");
1340*77c1e3ccSAndroid Build Coastguard Worker
1341*77c1e3ccSAndroid Build Coastguard Worker // Copy function assumes the frames are the same size.
1342*77c1e3ccSAndroid Build Coastguard Worker // Note that it does not copy YV12_BUFFER_CONFIG config data.
1343*77c1e3ccSAndroid Build Coastguard Worker aom_yv12_copy_frame(frame_to_show, ©_buffer, num_planes);
1344*77c1e3ccSAndroid Build Coastguard Worker
1345*77c1e3ccSAndroid Build Coastguard Worker assert(copy_buffer.y_crop_width == aligned_width);
1346*77c1e3ccSAndroid Build Coastguard Worker assert(copy_buffer.y_crop_height == cm->height);
1347*77c1e3ccSAndroid Build Coastguard Worker
1348*77c1e3ccSAndroid Build Coastguard Worker // Realloc the current frame buffer at a higher resolution in place.
1349*77c1e3ccSAndroid Build Coastguard Worker if (pool != NULL) {
1350*77c1e3ccSAndroid Build Coastguard Worker // Use callbacks if on the decoder.
1351*77c1e3ccSAndroid Build Coastguard Worker aom_codec_frame_buffer_t *fb = &cm->cur_frame->raw_frame_buffer;
1352*77c1e3ccSAndroid Build Coastguard Worker aom_release_frame_buffer_cb_fn_t release_fb_cb = pool->release_fb_cb;
1353*77c1e3ccSAndroid Build Coastguard Worker aom_get_frame_buffer_cb_fn_t cb = pool->get_fb_cb;
1354*77c1e3ccSAndroid Build Coastguard Worker void *cb_priv = pool->cb_priv;
1355*77c1e3ccSAndroid Build Coastguard Worker
1356*77c1e3ccSAndroid Build Coastguard Worker lock_buffer_pool(pool);
1357*77c1e3ccSAndroid Build Coastguard Worker // Realloc with callback does not release the frame buffer - release first.
1358*77c1e3ccSAndroid Build Coastguard Worker if (release_fb_cb(cb_priv, fb)) {
1359*77c1e3ccSAndroid Build Coastguard Worker unlock_buffer_pool(pool);
1360*77c1e3ccSAndroid Build Coastguard Worker aom_internal_error(
1361*77c1e3ccSAndroid Build Coastguard Worker cm->error, AOM_CODEC_MEM_ERROR,
1362*77c1e3ccSAndroid Build Coastguard Worker "Failed to free current frame buffer before superres upscaling");
1363*77c1e3ccSAndroid Build Coastguard Worker }
1364*77c1e3ccSAndroid Build Coastguard Worker // aom_realloc_frame_buffer() leaves config data for frame_to_show intact
1365*77c1e3ccSAndroid Build Coastguard Worker if (aom_realloc_frame_buffer(
1366*77c1e3ccSAndroid Build Coastguard Worker frame_to_show, cm->superres_upscaled_width,
1367*77c1e3ccSAndroid Build Coastguard Worker cm->superres_upscaled_height, seq_params->subsampling_x,
1368*77c1e3ccSAndroid Build Coastguard Worker seq_params->subsampling_y, seq_params->use_highbitdepth,
1369*77c1e3ccSAndroid Build Coastguard Worker AOM_BORDER_IN_PIXELS, byte_alignment, fb, cb, cb_priv,
1370*77c1e3ccSAndroid Build Coastguard Worker alloc_pyramid, 0)) {
1371*77c1e3ccSAndroid Build Coastguard Worker unlock_buffer_pool(pool);
1372*77c1e3ccSAndroid Build Coastguard Worker aom_internal_error(
1373*77c1e3ccSAndroid Build Coastguard Worker cm->error, AOM_CODEC_MEM_ERROR,
1374*77c1e3ccSAndroid Build Coastguard Worker "Failed to allocate current frame buffer for superres upscaling");
1375*77c1e3ccSAndroid Build Coastguard Worker }
1376*77c1e3ccSAndroid Build Coastguard Worker unlock_buffer_pool(pool);
1377*77c1e3ccSAndroid Build Coastguard Worker } else {
1378*77c1e3ccSAndroid Build Coastguard Worker // Make a copy of the config data for frame_to_show in copy_buffer
1379*77c1e3ccSAndroid Build Coastguard Worker copy_buffer_config(frame_to_show, ©_buffer);
1380*77c1e3ccSAndroid Build Coastguard Worker
1381*77c1e3ccSAndroid Build Coastguard Worker // Don't use callbacks on the encoder.
1382*77c1e3ccSAndroid Build Coastguard Worker // aom_alloc_frame_buffer() clears the config data for frame_to_show
1383*77c1e3ccSAndroid Build Coastguard Worker if (aom_alloc_frame_buffer(
1384*77c1e3ccSAndroid Build Coastguard Worker frame_to_show, cm->superres_upscaled_width,
1385*77c1e3ccSAndroid Build Coastguard Worker cm->superres_upscaled_height, seq_params->subsampling_x,
1386*77c1e3ccSAndroid Build Coastguard Worker seq_params->subsampling_y, seq_params->use_highbitdepth,
1387*77c1e3ccSAndroid Build Coastguard Worker AOM_BORDER_IN_PIXELS, byte_alignment, alloc_pyramid, 0))
1388*77c1e3ccSAndroid Build Coastguard Worker aom_internal_error(
1389*77c1e3ccSAndroid Build Coastguard Worker cm->error, AOM_CODEC_MEM_ERROR,
1390*77c1e3ccSAndroid Build Coastguard Worker "Failed to reallocate current frame buffer for superres upscaling");
1391*77c1e3ccSAndroid Build Coastguard Worker
1392*77c1e3ccSAndroid Build Coastguard Worker // Restore config data back to frame_to_show
1393*77c1e3ccSAndroid Build Coastguard Worker copy_buffer_config(©_buffer, frame_to_show);
1394*77c1e3ccSAndroid Build Coastguard Worker }
1395*77c1e3ccSAndroid Build Coastguard Worker // TODO(afergs): verify frame_to_show is correct after realloc
1396*77c1e3ccSAndroid Build Coastguard Worker // encoder:
1397*77c1e3ccSAndroid Build Coastguard Worker // decoder:
1398*77c1e3ccSAndroid Build Coastguard Worker
1399*77c1e3ccSAndroid Build Coastguard Worker assert(frame_to_show->y_crop_width == cm->superres_upscaled_width);
1400*77c1e3ccSAndroid Build Coastguard Worker assert(frame_to_show->y_crop_height == cm->superres_upscaled_height);
1401*77c1e3ccSAndroid Build Coastguard Worker
1402*77c1e3ccSAndroid Build Coastguard Worker // Scale up and back into frame_to_show.
1403*77c1e3ccSAndroid Build Coastguard Worker assert(frame_to_show->y_crop_width != cm->width);
1404*77c1e3ccSAndroid Build Coastguard Worker upscale_normative_and_extend_frame(cm, ©_buffer, frame_to_show);
1405*77c1e3ccSAndroid Build Coastguard Worker
1406*77c1e3ccSAndroid Build Coastguard Worker // Free the copy buffer
1407*77c1e3ccSAndroid Build Coastguard Worker aom_free_frame_buffer(©_buffer);
1408*77c1e3ccSAndroid Build Coastguard Worker }
1409