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 #ifndef VPX_VP9_COMMON_VP9_SCALE_H_
12 #define VPX_VP9_COMMON_VP9_SCALE_H_
13 
14 #define INLINE __inline
15 
16 #include <stdint.h>
17 #include "vp9_mv.h"
18 #include "vpx_convolve.h"
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
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
38 
39 #if CONFIG_VP9_HIGHBITDEPTH
40   highbd_convolve_fn_t highbd_predict[2][2][2];  // horiz, vert, avg
41 #endif
42 };
43 
44 MV32 eb_vp9_scale_mv(const MV *mv, int x, int y, const struct scale_factors *sf);
45 
46 #if CONFIG_VP9_HIGHBITDEPTH
47 void eb_vp9_setup_scale_factors_for_frame(struct scale_factors *sf, int other_w,
48                                        int other_h, int this_w, int this_h,
49                                        int use_high);
50 #else
51 void eb_vp9_setup_scale_factors_for_frame(struct scale_factors *sf, int other_w,
52                                        int other_h, int this_w, int this_h);
53 #endif
54 
vp9_is_valid_scale(const struct scale_factors * sf)55 static INLINE int vp9_is_valid_scale(const struct scale_factors *sf) {
56   return sf->x_scale_fp != REF_INVALID_SCALE &&
57          sf->y_scale_fp != REF_INVALID_SCALE;
58 }
59 
vp9_is_scaled(const struct scale_factors * sf)60 static INLINE int vp9_is_scaled(const struct scale_factors *sf) {
61   return vp9_is_valid_scale(sf) &&
62          (sf->x_scale_fp != REF_NO_SCALE || sf->y_scale_fp != REF_NO_SCALE);
63 }
64 
valid_ref_frame_size(int ref_width,int ref_height,int this_width,int this_height)65 static INLINE int valid_ref_frame_size(int ref_width, int ref_height,
66                                        int this_width, int this_height) {
67   return 2 * this_width >= ref_width && 2 * this_height >= ref_height &&
68          this_width <= 16 * ref_width && this_height <= 16 * ref_height;
69 }
70 
71 #ifdef __cplusplus
72 }  // extern "C"
73 #endif
74 
75 #endif  // VPX_VP9_COMMON_VP9_SCALE_H_
76