• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
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.
10  */
11 
12 #ifndef AOM_AV1_COMMON_RESIZE_H_
13 #define AOM_AV1_COMMON_RESIZE_H_
14 
15 #include <stdio.h>
16 #include "aom/aom_integer.h"
17 #include "av1/common/av1_common_int.h"
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 bool av1_resize_plane(const uint8_t *input, int height, int width,
24                       int in_stride, uint8_t *output, int height2, int width2,
25                       int out_stride);
26 // TODO(aomedia:3228): In libaom 4.0.0, remove av1_resize_frame420 from
27 // av1/exports_com and delete this function.
28 void av1_resize_frame420(const uint8_t *y, int y_stride, const uint8_t *u,
29                          const uint8_t *v, int uv_stride, int height, int width,
30                          uint8_t *oy, int oy_stride, uint8_t *ou, uint8_t *ov,
31                          int ouv_stride, int oheight, int owidth);
32 bool av1_resize_frame422(const uint8_t *y, int y_stride, const uint8_t *u,
33                          const uint8_t *v, int uv_stride, int height, int width,
34                          uint8_t *oy, int oy_stride, uint8_t *ou, uint8_t *ov,
35                          int ouv_stride, int oheight, int owidth);
36 bool av1_resize_frame444(const uint8_t *y, int y_stride, const uint8_t *u,
37                          const uint8_t *v, int uv_stride, int height, int width,
38                          uint8_t *oy, int oy_stride, uint8_t *ou, uint8_t *ov,
39                          int ouv_stride, int oheight, int owidth);
40 
41 void av1_highbd_resize_plane(const uint8_t *input, int height, int width,
42                              int in_stride, uint8_t *output, int height2,
43                              int width2, int out_stride, int bd);
44 void av1_highbd_resize_frame420(const uint8_t *y, int y_stride,
45                                 const uint8_t *u, const uint8_t *v,
46                                 int uv_stride, int height, int width,
47                                 uint8_t *oy, int oy_stride, uint8_t *ou,
48                                 uint8_t *ov, int ouv_stride, int oheight,
49                                 int owidth, int bd);
50 void av1_highbd_resize_frame422(const uint8_t *y, int y_stride,
51                                 const uint8_t *u, const uint8_t *v,
52                                 int uv_stride, int height, int width,
53                                 uint8_t *oy, int oy_stride, uint8_t *ou,
54                                 uint8_t *ov, int ouv_stride, int oheight,
55                                 int owidth, int bd);
56 void av1_highbd_resize_frame444(const uint8_t *y, int y_stride,
57                                 const uint8_t *u, const uint8_t *v,
58                                 int uv_stride, int height, int width,
59                                 uint8_t *oy, int oy_stride, uint8_t *ou,
60                                 uint8_t *ov, int ouv_stride, int oheight,
61                                 int owidth, int bd);
62 
63 void av1_upscale_normative_rows(const AV1_COMMON *cm, const uint8_t *src,
64                                 int src_stride, uint8_t *dst, int dst_stride,
65                                 int plane, int rows);
66 void av1_upscale_normative_and_extend_frame(const AV1_COMMON *cm,
67                                             const YV12_BUFFER_CONFIG *src,
68                                             YV12_BUFFER_CONFIG *dst);
69 
70 YV12_BUFFER_CONFIG *av1_realloc_and_scale_if_required(
71     AV1_COMMON *cm, YV12_BUFFER_CONFIG *unscaled, YV12_BUFFER_CONFIG *scaled,
72     const InterpFilter filter, const int phase, const bool use_optimized_scaler,
73     const bool for_psnr, const int border_in_pixels, const bool alloc_pyramid);
74 
75 bool av1_resize_and_extend_frame_nonnormative(const YV12_BUFFER_CONFIG *src,
76                                               YV12_BUFFER_CONFIG *dst, int bd,
77                                               int num_planes);
78 
79 // Calculates the scaled dimensions from the given original dimensions and the
80 // resize scale denominator.
81 void av1_calculate_scaled_size(int *width, int *height, int resize_denom);
82 
83 // Similar to above, but calculates scaled dimensions after superres from the
84 // given original dimensions and superres scale denominator.
85 void av1_calculate_scaled_superres_size(int *width, int *height,
86                                         int superres_denom);
87 
88 // Inverse of av1_calculate_scaled_superres_size() above: calculates the
89 // original dimensions from the given scaled dimensions and the scale
90 // denominator.
91 void av1_calculate_unscaled_superres_size(int *width, int *height, int denom);
92 
93 void av1_superres_upscale(AV1_COMMON *cm, BufferPool *const pool,
94                           bool alloc_pyramid);
95 
96 // Returns 1 if a superres upscaled frame is scaled and 0 otherwise.
av1_superres_scaled(const AV1_COMMON * cm)97 static INLINE int av1_superres_scaled(const AV1_COMMON *cm) {
98   // Note: for some corner cases (e.g. cm->width of 1), there may be no scaling
99   // required even though cm->superres_scale_denominator != SCALE_NUMERATOR.
100   // So, the following check is more accurate.
101   return (cm->width != cm->superres_upscaled_width);
102 }
103 
104 // The optimized scaler av1_resize_and_extend_frame() can only handle scaling
105 // ratios >= 1/4 and <= 16. See comment in aom_convolve8_c() for detail.
106 // Visual assessment shows that if the scaling ratio or its reciprocal is not a
107 // multiple of 1/16, there are some artifacts in the output of the optimized
108 // scaler, especially on lines, due to non-exact ratio representation. SSSE3
109 // and NEON have a specialized 3/4 version of av1_resize_and_extend_frame()
110 // that does not have this issue.
111 //
112 // Use the non-normative scaler av1_resize_and_extend_frame_nonnormative()
113 // for other scaling ratios.
av1_has_optimized_scaler(const int src_width,const int src_height,const int dst_width,const int dst_height)114 static INLINE bool av1_has_optimized_scaler(const int src_width,
115                                             const int src_height,
116                                             const int dst_width,
117                                             const int dst_height) {
118   bool has_optimized_scaler =
119       (dst_width * 4 >= src_width && dst_height * 4 >= src_height) &&
120       (dst_width <= src_width * 16 && dst_height <= src_height * 16) &&
121       (16 * dst_width % src_width == 0) && (16 * src_width % dst_width == 0) &&
122       (16 * dst_height % src_height == 0) &&
123       (16 * src_height % dst_height == 0);
124 #if HAVE_SSSE3 || HAVE_NEON
125   has_optimized_scaler =
126       has_optimized_scaler ||
127       (4 * dst_width == 3 * src_width && 4 * dst_height == 3 * src_height);
128 #endif
129   return has_optimized_scaler;
130 }
131 
132 #define UPSCALE_NORMATIVE_TAPS 8
133 extern const int16_t av1_resize_filter_normative[1 << RS_SUBPEL_BITS]
134                                                 [UPSCALE_NORMATIVE_TAPS];
135 
136 int32_t av1_get_upscale_convolve_step(int in_length, int out_length);
137 
138 #ifdef __cplusplus
139 }  // extern "C"
140 #endif
141 
142 #endif  // AOM_AV1_COMMON_RESIZE_H_
143