blob: 40385e527e056b029efe303d73f27dab3bdb4f95 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xubde4ac82016-11-28 15:26:06 -08002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xubde4ac82016-11-28 15:26:06 -08004 * 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 Xuc27fc142016-08-22 16:08:15 -070010 */
11
Yaowu Xuf883b422016-08-30 14:01:10 -070012#ifndef AV1_COMMON_SCALE_H_
13#define AV1_COMMON_SCALE_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
15#include "av1/common/mv.h"
Yaowu Xuf883b422016-08-30 14:01:10 -070016#include "aom_dsp/aom_convolve.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070017
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#define REF_SCALE_SHIFT 14
23#define REF_NO_SCALE (1 << REF_SCALE_SHIFT)
24#define REF_INVALID_SCALE -1
25
26struct scale_factors {
27 int x_scale_fp; // horizontal fixed point scale factor
28 int y_scale_fp; // vertical fixed point scale factor
29 int x_step_q4;
30 int y_step_q4;
31
32 int (*scale_value_x)(int val, const struct scale_factors *sf);
33 int (*scale_value_y)(int val, const struct scale_factors *sf);
34
35 convolve_fn_t predict[2][2][2]; // horiz, vert, avg
Yaowu Xuf883b422016-08-30 14:01:10 -070036#if CONFIG_AOM_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -070037 highbd_convolve_fn_t highbd_predict[2][2][2]; // horiz, vert, avg
Yaowu Xuf883b422016-08-30 14:01:10 -070038#endif // CONFIG_AOM_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -070039};
40
Yaowu Xuf883b422016-08-30 14:01:10 -070041MV32 av1_scale_mv(const MV *mv, int x, int y, const struct scale_factors *sf);
Yaowu Xuc27fc142016-08-22 16:08:15 -070042
Yaowu Xuf883b422016-08-30 14:01:10 -070043#if CONFIG_AOM_HIGHBITDEPTH
44void av1_setup_scale_factors_for_frame(struct scale_factors *sf, int other_w,
45 int other_h, int this_w, int this_h,
46 int use_high);
Yaowu Xuc27fc142016-08-22 16:08:15 -070047#else
Yaowu Xuf883b422016-08-30 14:01:10 -070048void av1_setup_scale_factors_for_frame(struct scale_factors *sf, int other_w,
49 int other_h, int this_w, int this_h);
50#endif // CONFIG_AOM_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -070051
Yaowu Xuf883b422016-08-30 14:01:10 -070052static INLINE int av1_is_valid_scale(const struct scale_factors *sf) {
Yaowu Xuc27fc142016-08-22 16:08:15 -070053 return sf->x_scale_fp != REF_INVALID_SCALE &&
54 sf->y_scale_fp != REF_INVALID_SCALE;
55}
56
Yaowu Xuf883b422016-08-30 14:01:10 -070057static INLINE int av1_is_scaled(const struct scale_factors *sf) {
58 return av1_is_valid_scale(sf) &&
Yaowu Xuc27fc142016-08-22 16:08:15 -070059 (sf->x_scale_fp != REF_NO_SCALE || sf->y_scale_fp != REF_NO_SCALE);
60}
61
62static INLINE int valid_ref_frame_size(int ref_width, int ref_height,
63 int this_width, int this_height) {
64 return 2 * this_width >= ref_width && 2 * this_height >= ref_height &&
65 this_width <= 16 * ref_width && this_height <= 16 * ref_height;
66}
67
68#ifdef __cplusplus
69} // extern "C"
70#endif
71
Yaowu Xuf883b422016-08-30 14:01:10 -070072#endif // AV1_COMMON_SCALE_H_