xref: /aosp_15_r20/external/libavc/common/svc/isvc_intra_resample.h (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
1 /******************************************************************************
2  *
3  * Copyright (C) 2022 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19  */
20 
21 #ifndef _ISVC_INTRA_RESAMPLE_H_
22 #define _ISVC_INTRA_RESAMPLE_H_
23 
24 #include "ih264_typedefs.h"
25 #include "isvc_macros.h"
26 #include "ih264_platform_macros.h"
27 #include "isvc_structs.h"
28 
29 #define DYADIC_REF_W_Y 20
30 #define DYADIC_REF_H_Y 20
31 #define DYADIC_REF_W_C 10
32 #define DYADIC_REF_H_C 10
33 
34 #define MAX_NUM_RES_LYRS 4
35 
36 #define MAX_PIX_FILL_LUMA 4
37 #define MAX_PIX_FILL_CHROMA 2
38 
39 #define MAX_REF_ARR_WD_HT 48
40 #define MAX_REF_IDX_ARRAY (MAX_REF_ARR_WD_HT + MB_SIZE)
41 
42 #define CLIPUCHAR(x) CLIP3(0, 255, (x))
43 
44 #define REF_ARRAY_WIDTH 48
45 #define REF_ARRAY_HEIGHT 48
46 
47 typedef void FT_INTERPOLATE_LUMA_2X(UWORD8 *pu1_inp_buf, WORD16 *pi2_tmp_filt_buf,
48                                     UWORD8 *pu1_out_buf, WORD32 i4_out_stride);
49 
50 typedef void FT_VERT_INTERPOLATE_CHROMA_2X(UWORD8 *pu1_inp_buf, WORD16 *pi2_tmp_filt_buf,
51                                            WORD32 i4_phase_0, WORD32 i4_phase_1);
52 
53 typedef void FT_HORZ_INTERPOLATE_CHROMA_2X(WORD16 *pi2_tmp_filt_buf, UWORD8 *pu1_out_buf,
54                                            WORD32 i4_out_stride, WORD32 i4_phase_0,
55                                            WORD32 i4_phase_1);
56 
57 typedef struct mem_element_t
58 {
59     /* Buffer pointer */
60     void *pv_buffer;
61 
62     /* size of the structure or unit */
63     WORD32 i4_element_size;
64 
65     /* Stride of buffer in terms of number of elements.*/
66     WORD32 i4_num_element_stride;
67 } mem_element_t;
68 
69 typedef struct seg_description_t
70 {
71     /* describes segment dimension */
72     UWORD8 u1_seg_dim;
73 
74     /* describes offset from start */
75     UWORD8 u1_seg_off;
76 
77     /* describes whether mb is adjoining the segment
78        0 => not adjoining 1 => adjoining */
79     UWORD8 u1_mb_adjoin;
80 
81     /* distance to nearest MB */
82     WORD8 i1_dist_idx;
83 
84     /* describes the nearest mb boundary
85        +1 => rightMB/bottomMB
86        -1 => leftMB/topMB	*/
87     WORD8 i1_nearst_mb_bdry;
88 } seg_description_t;
89 
90 typedef struct seg_lookup_desc_t
91 {
92     /* place holder to store the number of segments */
93     UWORD8 u1_num_segments;
94 
95     /* this variable indicates where is start locatiion of the segment with
96        respect to less the block_width or greater than block width*/
97     UWORD8 u4_start_pos;
98 
99     /* place holder to store per segment description */
100     seg_description_t s_segments[4];
101 } seg_lookup_desc_t;
102 
103 typedef struct intra_samp_lyr_ctxt
104 {
105     /* mb position */
106     coordinates_t *ps_mb_pos;
107 
108     /* reference layer width in terms luma samples */
109     WORD32 i4_ref_width;
110 
111     /* reference layer height in terms luma samples */
112     WORD32 i4_ref_height;
113 
114     /* Constrained intra resampling flag. Range is [0,1]. */
115     WORD8 i1_constrained_intra_rsmpl_flag;
116 
117     /* Chroma xPhase for even values of x for dyadic cases */
118     WORD32 i4_x_phase_0;
119 
120     /* Chroma xPhase for odd values of x for dyadic cases */
121     WORD32 i4_x_phase_1;
122 
123     /* Chroma yPhase for even values of y for dyadic cases */
124     WORD32 i4_y_phase_0;
125 
126     /* Chroma yPhase for odd values of y for dyadic cases */
127     WORD32 i4_y_phase_1;
128 
129     FT_INTERPOLATE_LUMA_2X *pf_interpolate_luma;
130 
131     FT_VERT_INTERPOLATE_CHROMA_2X *pf_vert_interpol_chroma;
132 
133     FT_HORZ_INTERPOLATE_CHROMA_2X *pf_horz_interpol_chroma;
134 
135     WORD16 i2_x_min_pos;
136 
137     WORD16 i2_x_max_pos;
138 
139     WORD16 i2_y_min_pos;
140 
141     WORD16 i2_y_max_pos;
142 
143     coordinates_t *ps_phase;
144 
145     WORD32 *pi4_ref_array_positions_x;
146 
147     WORD32 *pi4_ref_array_positions_y;
148 
149     coordinates_t *ps_offsets;
150 
151     coordinates_t *ps_ref_array_dims;
152 
153     /* buffers to store lookup for horizontal segment description  */
154     seg_lookup_desc_t as_seg_lookup_horz[MB_SIZE];
155 
156     /* buffers to store lookup for vertical segment description  */
157     seg_lookup_desc_t as_seg_lookup_vert[MB_SIZE];
158 
159     /* buffers to store lookup for x indexes to get
160        availability from 4x4 availability grid */
161     UWORD8 au1_refarray_x_idx[MAX_REF_IDX_ARRAY];
162 
163     /* buffers to store lookup for y indexes to get
164        availability from 4x4 availability grid */
165     UWORD8 au1_refarray_y_idx[MAX_REF_IDX_ARRAY];
166 } intra_samp_lyr_ctxt;
167 
168 typedef struct intra_sampling_ctxt_t
169 {
170     /* Array of resolution layer ctxt. */
171     intra_samp_lyr_ctxt as_res_lyrs[MAX_NUM_RES_LYRS];
172 
173     /* pointer to array of SPS */
174     void *ps_sps;
175 
176     /* buffer to store the reference layer data before intra sampling */
177     UWORD8 *pu1_refarray_buffer;
178 
179     /* buffer to hold the reference layer Cb data before intra
180        resampling (used for dyadic cases only) */
181     UWORD8 *pu1_refarray_cb;
182 
183     /* buffer to hold the reference layer Cr data before intra
184        resampling (used for dyadic cases only) */
185     UWORD8 *pu1_refarray_cr;
186 
187     /* intermideate buffer for interpolation */
188     WORD32 *pi4_temp_interpolation_buffer;
189 
190     /* resolution id of the layer which is to be processed */
191     WORD32 i4_res_lyr_id;
192 
193     /* reference layer width in terms luma samples */
194     WORD32 i4_ref_width;
195 
196     /* reference layer width in terms luma samples */
197     WORD32 i4_refarray_stride;
198 
199     /* reference layer height in terms luma samples */
200     WORD32 i4_ref_height;
201 } intra_sampling_ctxt_t;
202 
203 typedef struct inter_lyr_mb_prms_t
204 {
205     /* NNZs of Chroma. Here each bit corresonds
206        to a NNZs of 4x4 sub block. Lower 4 bits are
207        used for Cb and upper are used for Cr */
208     UWORD8 u1_chroma_nnz;
209 
210     /* NNZs of Luma. Here each bit corresonds
211        to a NNZs of 4x4 sub block in raster scan order. */
212     UWORD16 u2_luma_nnz;
213 
214     /* Packed MB mode transform size of an MB */
215     WORD8 i1_mb_mode;
216 } inter_lyr_mb_prms_t;
217 
218 /* Function declarations */
219 extern void isvc_intra_samp_mb_dyadic(void *pv_intra_samp_ctxt, mem_element_t *ps_ref_luma,
220                                       mem_element_t *ps_ref_chroma,
221                                       mem_element_t *ps_ref_mb_mode_map,
222                                       mem_element_t *ps_curr_luma, mem_element_t *ps_curr_chroma,
223                                       UWORD16 u2_mb_x, UWORD16 u2_mb_y,
224                                       WORD32 i4_scaled_ref_layer_left_offset,
225                                       WORD32 i4_scaled_ref_layer_top_offset);
226 
227 extern void isvc_intra_samp_mb(void *pv_intra_samp_ctxt_luma, void *pv_intra_samp_ctxt_chroma,
228                                mem_element_t *ps_ref_luma, mem_element_t *ps_ref_chroma,
229                                mem_element_t *ps_ref_mb_mode_map, mem_element_t *ps_curr_luma,
230                                mem_element_t *ps_curr_chroma);
231 
232 extern void isvc_intra_resamp_generate_segment_lookup(seg_lookup_desc_t *ps_seg_lookup_table,
233                                                       WORD32 i4_dimension, WORD32 i4_mb_size,
234                                                       WORD32 i4_shift_val);
235 
236 /* C Declarations */
237 extern FT_INTERPOLATE_LUMA_2X isvc_interpolate_base_luma_dyadic;
238 extern FT_VERT_INTERPOLATE_CHROMA_2X isvc_vert_interpol_chroma_dyadic;
239 extern FT_HORZ_INTERPOLATE_CHROMA_2X isvc_horz_interpol_chroma_dyadic;
240 
241 /* SSE42 Declarations */
242 extern FT_INTERPOLATE_LUMA_2X isvc_interpolate_base_luma_dyadic_sse42;
243 extern FT_VERT_INTERPOLATE_CHROMA_2X isvc_vert_interpol_chroma_dyadic_sse42;
244 extern FT_HORZ_INTERPOLATE_CHROMA_2X isvc_horz_interpol_chroma_dyadic_sse42;
245 
246 /* NEON Declarations */
247 extern FT_INTERPOLATE_LUMA_2X isvc_interpolate_base_luma_dyadic_neon;
248 extern FT_VERT_INTERPOLATE_CHROMA_2X isvc_vert_interpol_chroma_dyadic_neon;
249 extern FT_HORZ_INTERPOLATE_CHROMA_2X isvc_horz_interpol_chroma_dyadic_neon;
250 
251 #endif
252