Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Side by Side Diff: source/libvpx/vp9/common/vp9_scale.c

Issue 23600008: libvpx: Pull from upstream (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp9/common/vp9_scale.h ('k') | source/libvpx/vp9/common/vp9_subpelvar.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2013 The WebM project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "./vp9_rtcd.h"
12 #include "vp9/common/vp9_filter.h"
13 #include "vp9/common/vp9_scale.h"
14
15 static INLINE int scaled_x(int val, const struct scale_factors *scale) {
16 return val * scale->x_scale_fp >> REF_SCALE_SHIFT;
17 }
18
19 static INLINE int scaled_y(int val, const struct scale_factors *scale) {
20 return val * scale->y_scale_fp >> REF_SCALE_SHIFT;
21 }
22
23 static int unscaled_value(int val, const struct scale_factors *scale) {
24 (void) scale;
25 return val;
26 }
27
28 static MV32 scaled_mv(const MV *mv, const struct scale_factors *scale) {
29 const MV32 res = {
30 scaled_y(mv->row, scale) + scale->y_offset_q4,
31 scaled_x(mv->col, scale) + scale->x_offset_q4
32 };
33 return res;
34 }
35
36 static MV32 unscaled_mv(const MV *mv, const struct scale_factors *scale) {
37 const MV32 res = {
38 mv->row,
39 mv->col
40 };
41 return res;
42 }
43
44 static void set_offsets_with_scaling(struct scale_factors *scale,
45 int row, int col) {
46 scale->x_offset_q4 = scaled_x(col << SUBPEL_BITS, scale) & SUBPEL_MASK;
47 scale->y_offset_q4 = scaled_y(row << SUBPEL_BITS, scale) & SUBPEL_MASK;
48 }
49
50 static void set_offsets_without_scaling(struct scale_factors *scale,
51 int row, int col) {
52 scale->x_offset_q4 = 0;
53 scale->y_offset_q4 = 0;
54 }
55
56 static int get_fixed_point_scale_factor(int other_size, int this_size) {
57 // Calculate scaling factor once for each reference frame
58 // and use fixed point scaling factors in decoding and encoding routines.
59 // Hardware implementations can calculate scale factor in device driver
60 // and use multiplication and shifting on hardware instead of division.
61 return (other_size << REF_SCALE_SHIFT) / this_size;
62 }
63
64 static int check_scale_factors(int other_w, int other_h,
65 int this_w, int this_h) {
66 return 2 * this_w >= other_w &&
67 2 * this_h >= other_h &&
68 this_w <= 16 * other_w &&
69 this_h <= 16 * other_h;
70 }
71
72 void vp9_setup_scale_factors_for_frame(struct scale_factors *scale,
73 int other_w, int other_h,
74 int this_w, int this_h) {
75 if (!check_scale_factors(other_w, other_h, this_w, this_h)) {
76 scale->x_scale_fp = REF_INVALID_SCALE;
77 scale->y_scale_fp = REF_INVALID_SCALE;
78 return;
79 }
80
81 scale->x_scale_fp = get_fixed_point_scale_factor(other_w, this_w);
82 scale->y_scale_fp = get_fixed_point_scale_factor(other_h, this_h);
83 scale->x_step_q4 = scaled_x(16, scale);
84 scale->y_step_q4 = scaled_y(16, scale);
85 scale->x_offset_q4 = 0; // calculated per block
86 scale->y_offset_q4 = 0; // calculated per block
87
88 if (vp9_is_scaled(scale)) {
89 scale->scale_value_x = scaled_x;
90 scale->scale_value_y = scaled_y;
91 scale->set_scaled_offsets = set_offsets_with_scaling;
92 scale->scale_mv = scaled_mv;
93 } else {
94 scale->scale_value_x = unscaled_value;
95 scale->scale_value_y = unscaled_value;
96 scale->set_scaled_offsets = set_offsets_without_scaling;
97 scale->scale_mv = unscaled_mv;
98 }
99
100 // TODO(agrange): Investigate the best choice of functions to use here
101 // for EIGHTTAP_SMOOTH. Since it is not interpolating, need to choose what
102 // to do at full-pel offsets. The current selection, where the filter is
103 // applied in one direction only, and not at all for 0,0, seems to give the
104 // best quality, but it may be worth trying an additional mode that does
105 // do the filtering on full-pel.
106 if (scale->x_step_q4 == 16) {
107 if (scale->y_step_q4 == 16) {
108 // No scaling in either direction.
109 scale->predict[0][0][0] = vp9_convolve_copy;
110 scale->predict[0][0][1] = vp9_convolve_avg;
111 scale->predict[0][1][0] = vp9_convolve8_vert;
112 scale->predict[0][1][1] = vp9_convolve8_avg_vert;
113 scale->predict[1][0][0] = vp9_convolve8_horiz;
114 scale->predict[1][0][1] = vp9_convolve8_avg_horiz;
115 } else {
116 // No scaling in x direction. Must always scale in the y direction.
117 scale->predict[0][0][0] = vp9_convolve8_vert;
118 scale->predict[0][0][1] = vp9_convolve8_avg_vert;
119 scale->predict[0][1][0] = vp9_convolve8_vert;
120 scale->predict[0][1][1] = vp9_convolve8_avg_vert;
121 scale->predict[1][0][0] = vp9_convolve8;
122 scale->predict[1][0][1] = vp9_convolve8_avg;
123 }
124 } else {
125 if (scale->y_step_q4 == 16) {
126 // No scaling in the y direction. Must always scale in the x direction.
127 scale->predict[0][0][0] = vp9_convolve8_horiz;
128 scale->predict[0][0][1] = vp9_convolve8_avg_horiz;
129 scale->predict[0][1][0] = vp9_convolve8;
130 scale->predict[0][1][1] = vp9_convolve8_avg;
131 scale->predict[1][0][0] = vp9_convolve8_horiz;
132 scale->predict[1][0][1] = vp9_convolve8_avg_horiz;
133 } else {
134 // Must always scale in both directions.
135 scale->predict[0][0][0] = vp9_convolve8;
136 scale->predict[0][0][1] = vp9_convolve8_avg;
137 scale->predict[0][1][0] = vp9_convolve8;
138 scale->predict[0][1][1] = vp9_convolve8_avg;
139 scale->predict[1][0][0] = vp9_convolve8;
140 scale->predict[1][0][1] = vp9_convolve8_avg;
141 }
142 }
143 // 2D subpel motion always gets filtered in both directions
144 scale->predict[1][1][0] = vp9_convolve8;
145 scale->predict[1][1][1] = vp9_convolve8_avg;
146 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/common/vp9_scale.h ('k') | source/libvpx/vp9/common/vp9_subpelvar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698