Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | bde4ac8 | 2016-11-28 15:26:06 -0800 | [diff] [blame] | 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AV1_COMMON_SCALE_H_ |
| 13 | #define AV1_COMMON_SCALE_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
| 15 | #include "av1/common/mv.h" |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 16 | #include "aom_dsp/aom_convolve.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 17 | |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
Debargha Mukherjee | 1583614 | 2017-06-27 07:07:31 -0700 | [diff] [blame] | 22 | #define SCALE_DENOMINATOR 16 |
| 23 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 24 | #define REF_SCALE_SHIFT 14 |
| 25 | #define REF_NO_SCALE (1 << REF_SCALE_SHIFT) |
| 26 | #define REF_INVALID_SCALE -1 |
| 27 | |
| 28 | struct scale_factors { |
| 29 | int x_scale_fp; // horizontal fixed point scale factor |
| 30 | int y_scale_fp; // vertical fixed point scale factor |
| 31 | int x_step_q4; |
| 32 | int y_step_q4; |
| 33 | |
| 34 | int (*scale_value_x)(int val, const struct scale_factors *sf); |
| 35 | int (*scale_value_y)(int val, const struct scale_factors *sf); |
| 36 | |
| 37 | convolve_fn_t predict[2][2][2]; // horiz, vert, avg |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 38 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 39 | highbd_convolve_fn_t highbd_predict[2][2][2]; // horiz, vert, avg |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 40 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 43 | MV32 av1_scale_mv(const MV *mv, int x, int y, const struct scale_factors *sf); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 44 | |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 45 | #if CONFIG_HIGHBITDEPTH |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 46 | void av1_setup_scale_factors_for_frame(struct scale_factors *sf, int other_w, |
| 47 | int other_h, int this_w, int this_h, |
| 48 | int use_high); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 49 | #else |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 50 | void av1_setup_scale_factors_for_frame(struct scale_factors *sf, int other_w, |
| 51 | int other_h, int this_w, int this_h); |
Sebastien Alaiwan | 71e8784 | 2017-04-12 16:03:28 +0200 | [diff] [blame] | 52 | #endif // CONFIG_HIGHBITDEPTH |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 53 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 54 | static INLINE int av1_is_valid_scale(const struct scale_factors *sf) { |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 55 | return sf->x_scale_fp != REF_INVALID_SCALE && |
| 56 | sf->y_scale_fp != REF_INVALID_SCALE; |
| 57 | } |
| 58 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 59 | static INLINE int av1_is_scaled(const struct scale_factors *sf) { |
| 60 | return av1_is_valid_scale(sf) && |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 61 | (sf->x_scale_fp != REF_NO_SCALE || sf->y_scale_fp != REF_NO_SCALE); |
| 62 | } |
| 63 | |
| 64 | static INLINE int valid_ref_frame_size(int ref_width, int ref_height, |
| 65 | int this_width, int this_height) { |
| 66 | return 2 * this_width >= ref_width && 2 * this_height >= ref_height && |
| 67 | this_width <= 16 * ref_width && this_height <= 16 * ref_height; |
| 68 | } |
| 69 | |
| 70 | #ifdef __cplusplus |
| 71 | } // extern "C" |
| 72 | #endif |
| 73 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 74 | #endif // AV1_COMMON_SCALE_H_ |