media/libvpx/vp9/common/vp9_scale.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial