Line data Source code
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 EbWarpedMotion_h
13 : #define EbWarpedMotion_h
14 :
15 : #include "EbUtility.h"
16 : #include "EbPictureControlSet.h"
17 : #include "EbCodingUnit.h"
18 : #include "EbPredictionUnit.h"
19 : #include "EbNeighborArrays.h"
20 : #include "EbMvMerge.h"
21 : #include "EbDefinitions.h"
22 : #ifdef __cplusplus
23 : extern "C" {
24 : #endif
25 :
26 : #include <stdio.h>
27 : #include <stdlib.h>
28 : #include <memory.h>
29 : #include <math.h>
30 : #include <assert.h>
31 : #include "convolve.h"
32 :
33 : // Bits of precision used for the model
34 : #define WARPEDMODEL_PREC_BITS 16
35 : #define WARPEDMODEL_ROW3HOMO_PREC_BITS 16
36 :
37 : #define WARPEDMODEL_TRANS_CLAMP (128 << WARPEDMODEL_PREC_BITS)
38 : #define WARPEDMODEL_NONDIAGAFFINE_CLAMP (1 << (WARPEDMODEL_PREC_BITS - 3))
39 : #define WARPEDMODEL_ROW3HOMO_CLAMP (1 << (WARPEDMODEL_PREC_BITS - 2))
40 :
41 : // Bits of subpel precision for warped interpolation
42 : #define WARPEDPIXEL_PREC_BITS 6
43 : #define WARPEDPIXEL_PREC_SHIFTS (1 << WARPEDPIXEL_PREC_BITS)
44 :
45 : #define WARP_PARAM_REDUCE_BITS 6
46 :
47 : #define WARPEDDIFF_PREC_BITS (WARPEDMODEL_PREC_BITS - WARPEDPIXEL_PREC_BITS)
48 :
49 : #define MAX_PARAMDIM 9
50 : #define LEAST_SQUARES_SAMPLES_MAX_BITS 3
51 : #define LEAST_SQUARES_SAMPLES_MAX (1 << LEAST_SQUARES_SAMPLES_MAX_BITS)
52 : #define SAMPLES_ARRAY_SIZE (LEAST_SQUARES_SAMPLES_MAX * 2)
53 : #define WARPED_MOTION_DEBUG 0
54 : #define DEFAULT_WMTYPE AFFINE
55 :
56 : extern const int16_t eb_warped_filter[WARPEDPIXEL_PREC_SHIFTS * 3 + 1][8];
57 : extern const int error_measure_lut[512];
58 :
59 : EB_ALIGN(16) static const uint8_t warp_pad_left[14][16] = {
60 : { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
61 : { 2, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
62 : { 3, 3, 3, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
63 : { 4, 4, 4, 4, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
64 : { 5, 5, 5, 5, 5, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
65 : { 6, 6, 6, 6, 6, 6, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
66 : { 7, 7, 7, 7, 7, 7, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
67 : { 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 10, 11, 12, 13, 14, 15 },
68 : { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 11, 12, 13, 14, 15 },
69 : { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 12, 13, 14, 15 },
70 : { 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 13, 14, 15 },
71 : { 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 14, 15 },
72 : { 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 15 },
73 : { 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15 },
74 : };
75 :
76 : EB_ALIGN(16) static const uint8_t warp_pad_right[14][16] = {
77 : { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 14 },
78 : { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 13 },
79 : { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 12, 12, 12 },
80 : { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 11, 11, 11 },
81 : { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10, 10, 10 },
82 : { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9 },
83 : { 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 8, 8 },
84 : { 0, 1, 2, 3, 4, 5, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7 },
85 : { 0, 1, 2, 3, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 },
86 : { 0, 1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 },
87 : { 0, 1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 },
88 : { 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 },
89 : { 0, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
90 : { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
91 : };
92 :
93 0 : static INLINE int error_measure(int err) {
94 0 : return error_measure_lut[255 + err];
95 : }
96 :
97 : // Returns the error between the result of applying motion 'wm' to the frame
98 : // described by 'ref' and the frame described by 'dst'.
99 : int64_t eb_av1_warp_error(
100 : EbWarpedMotionParams *wm,
101 : int use_hbd,
102 : int bd,
103 : const uint8_t *ref,
104 : int width,
105 : int height,
106 : int stride,
107 : uint8_t *dst,
108 : int p_col,
109 : int p_row,
110 : int p_width,
111 : int p_height,
112 : int p_stride,
113 : int subsampling_x,
114 : int subsampling_y,
115 : int64_t best_error);
116 :
117 : // Returns the error between the frame described by 'ref' and the frame
118 : // described by 'dst'.
119 : int64_t eb_av1_frame_error(
120 : int use_hbd,
121 : int bd,
122 : const uint8_t *ref,
123 : int stride,
124 : uint8_t *dst,
125 : int p_width,
126 : int p_height,
127 : int p_stride);
128 :
129 : void eb_av1_warp_plane(
130 : EbWarpedMotionParams *wm,
131 : int use_hbd,
132 : int bd,
133 : const uint8_t *ref,
134 : int width,
135 : int height,
136 : int stride,
137 : uint8_t *pred,
138 : int p_col,
139 : int p_row,
140 : int p_width,
141 : int p_height,
142 : int p_stride,
143 : int subsampling_x,
144 : int subsampling_y,
145 : ConvolveParams *conv_params);
146 :
147 : EbBool eb_find_projection(
148 : int np,
149 : int *pts1,
150 : int *pts2,
151 : BlockSize bsize,
152 : int mvy,
153 : int mvx,
154 : EbWarpedMotionParams *wm_params,
155 : int mi_row,
156 : int mi_col);
157 :
158 : int eb_get_shear_params(EbWarpedMotionParams *wm);
159 :
160 : #ifdef __cplusplus
161 : }
162 : #endif
163 : #endif // EbWarpedMotion_h
|