1 /*
2 * Copyright(c) 2018 Intel Corporation
3 * SPDX - License - Identifier: BSD - 2 - Clause - Patent
4 */
5 
6 #ifndef EbSampleAdaptiveOffset_h
7 #define EbSampleAdaptiveOffset_h
8 
9 #include "EbSampleAdaptiveOffset_C.h"
10 #include "EbSampleAdaptiveOffset_SSE2.h"
11 #include "EbSaoApplication_SSSE3.h"
12 
13 #include "EbDefinitions.h"
14 
15 #include "EbPictureControlSet.h"
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 struct PictureControlSet_s;
20 
21 extern EB_ERRORTYPE SaoStatsCtor(SaoStats_t *saoStatsPtr);
22 
23 
24 extern EB_ERRORTYPE SaoGenerationDecision(
25 	SaoStats_t                 *saoStats,
26 	SaoParameters_t            *saoParams,
27 	MdRateEstimationContext_t  *mdRateEstimationPtr,
28 	EB_U64                      fullLambda,
29     EB_U64                      fullChromaLambdaSao,
30     EB_BOOL                     mmSAO,
31     struct PictureControlSet_s *pictureControlSetPtr,
32 	EB_U32                      tbOriginX,
33 	EB_U32                      tbOriginY,
34 	EB_U32                      lcuWidth,
35 	EB_U32                      lcuHeight,
36 	SaoParameters_t            *saoPtr,
37 	SaoParameters_t            *leftSaoPtr,
38 	SaoParameters_t            *upSaoPtr,
39 	EB_S64                     *saoLumaBestCost,
40 	EB_S64                     *saoChromaBestCost);
41 
42 
43 extern EB_ERRORTYPE SaoGenerationDecision16bit(
44     EbPictureBufferDesc_t      *inputLcuPtr,
45     SaoStats_t                 *saoStats,
46     SaoParameters_t            *saoParams,
47     MdRateEstimationContext_t  *mdRateEstimationPtr,
48     EB_U64                      fullLambda,
49 	EB_U64                      fullChromaLambdaSao,
50 	EB_BOOL                     mmSAO,
51     struct PictureControlSet_s *pictureControlSetPtr,
52     EB_U32                      tbOriginX,
53     EB_U32                      tbOriginY,
54     EB_U32                      lcuWidth,
55     EB_U32                      lcuHeight,
56     SaoParameters_t            *saoPtr,
57     SaoParameters_t            *leftSaoPtr,
58     SaoParameters_t            *upSaoPtr,
59     EB_S64                     *saoLumaBestCost,
60     EB_S64                     *saoChromaBestCost);
61 
62 
63 EB_ERRORTYPE GatherSaoStatisticsLcu16bit_SSE2(
64 	EB_U16					*inputSamplePtr,        // input parameter, source Picture Ptr
65 	EB_U32                   inputStride,           // input parameter, source stride
66 	EB_U16                  *reconSamplePtr,        // input parameter, deblocked Picture Ptr
67 	EB_U32                   reconStride,           // input parameter, deblocked stride
68 	EB_U32                   lcuWidth,              // input parameter, LCU width
69 	EB_U32                   lcuHeight,             // input parameter, LCU height
70 	EB_S32                  *boDiff,                // output parameter, used to store Band Offset diff, boDiff[SAO_BO_INTERVALS]
71 	EB_U16                  *boCount,										// output parameter, used to store Band Offset count, boCount[SAO_BO_INTERVALS]
72 	EB_S32                   eoDiff[SAO_EO_TYPES][SAO_EO_CATEGORIES + 1],     // output parameter, used to store Edge Offset diff, eoDiff[SAO_EO_TYPES] [SAO_EO_CATEGORIES]
73 	EB_U16                   eoCount[SAO_EO_TYPES][SAO_EO_CATEGORIES + 1]);    // output parameter, used to store Edge Offset count, eoCount[SAO_EO_TYPES] [SAO_EO_CATEGORIES]
74 
75 
76 typedef EB_ERRORTYPE(*EB_SAOGATHER_FUNC)(
77     EB_U8                   *inputSamplePtr,
78     EB_U32                   inputStride,
79     EB_U8                   *reconSamplePtr,
80     EB_U32                   reconStride,
81     EB_U32                   lcuWidth,
82     EB_U32                   lcuHeight,
83     EB_S32                  *boDiff,
84     EB_U16                  *boCount,
85     EB_S32                   eoDiff[SAO_EO_TYPES][SAO_EO_CATEGORIES + 1],
86     EB_U16                   eoCount[SAO_EO_TYPES][SAO_EO_CATEGORIES + 1]);
87 
88 
89 typedef EB_ERRORTYPE(*EB_SAOGATHER_90_45_135_FUNC)(
90     EB_U8                   *inputSamplePtr,
91     EB_U32                   inputStride,
92     EB_U8                   *reconSamplePtr,
93     EB_U32                   reconStride,
94     EB_U32                   lcuWidth,
95     EB_U32                   lcuHeight,
96     EB_S32                   eoDiff[SAO_EO_TYPES][SAO_EO_CATEGORIES + 1],
97     EB_U16                   eoCount[SAO_EO_TYPES][SAO_EO_CATEGORIES + 1]);
98 
99 typedef EB_ERRORTYPE(*EB_SAOAPPLY_EO_135_45_FUNC)(
100     EB_U8                    *reconSamplePtr,
101     EB_U32                    reconStride,
102     EB_U8                    *temporalBufferLeft,
103     EB_U8                    *temporalBufferUpper,
104     EB_S8                    *saoOffsetPtr,
105     EB_U32                    lcuHeight,
106     EB_U32                    lcuWidth);
107 
108 typedef EB_ERRORTYPE(*EB_SAOGATHER_90_45_135_16bit_SSE2_FUNC)(
109     EB_U16                   *inputSamplePtr,        // input parameter, source Picture Ptr
110     EB_U32                   inputStride,           // input parameter, source stride
111     EB_U16                   *reconSamplePtr,        // input parameter, deblocked Picture Ptr
112     EB_U32                   reconStride,           // input parameter, deblocked stride
113     EB_U32                   lcuWidth,              // input parameter, LCU width
114     EB_U32                   lcuHeight,             // input parameter, LCU height
115     EB_S32                   eoDiff[SAO_EO_TYPES][SAO_EO_CATEGORIES + 1],    // output parameter, used to store Edge Offset diff, eoDiff[SAO_EO_TYPES] [SAO_EO_CATEGORIES]
116     EB_U16                   eoCount[SAO_EO_TYPES][SAO_EO_CATEGORIES + 1]);  // output parameter, used to store Edge Offset count, eoCount[SAO_EO_TYPES] [SAO_EO_CATEGORIES]
117 
118 typedef EB_ERRORTYPE(*EB_SAOAPPLY_BO_FUNC)(
119     EB_U8                    *reconSamplePtr,
120     EB_U32                    reconStride,
121     EB_U32                    bandPosition,
122     EB_S8                    *saoOffset,
123     EB_U32                    lcuWidth,
124     EB_U32                    lcuHeight);
125 
126 typedef EB_ERRORTYPE(*EB_SAOAPPLY_EO_0_90_FUNC)(
127     EB_U8                    *reconSamplePtr,
128     EB_U32                    reconStride,
129     EB_U8                    *temporalBuffer,
130     EB_S8                    *saoOffsetPtr,
131     EB_U32                    lcuHeight,
132     EB_U32                    lcuWidth);
133 
134 typedef EB_ERRORTYPE(*EB_SAOAPPLY_BO_16bit_FUNC)(
135     EB_U16                          *reconSamplePtr,
136     EB_U32                           reconStride,
137     EB_U32                           saoBandPosition,
138     EB_S8                           *saoOffsetPtr,
139     EB_U32                           lcuHeight,
140     EB_U32                           lcuWidth);
141 
142 typedef EB_ERRORTYPE(*EB_SAOAPPLY_EO_0_90_16bit_FUNC)(
143     EB_U16                          *reconSamplePtr,
144     EB_U32                           reconStride,
145     EB_U16                          *temporalBufferLeft,
146     EB_S8                           *saoOffsetPtr,
147     EB_U32                           lcuHeight,
148     EB_U32                           lcuWidth);
149 
150 typedef EB_ERRORTYPE(*EB_SAOAPPLY_EO_135_45_16bit_FUNC)(
151     EB_U16                           *reconSamplePtr,
152     EB_U32                           reconStride,
153     EB_U16                          *temporalBufferLeft,
154     EB_U16                           *temporalBufferUpper,
155     EB_S8                           *saoOffsetPtr,
156     EB_U32                           lcuHeight,
157     EB_U32                           lcuWidth);
158 
159 typedef EB_ERRORTYPE(*EB_SAOGATHER_16bit_FUNC)(
160 	EB_U16					*inputSamplePtr,        // input parameter, source Picture Ptr
161 	EB_U32                   inputStride,           // input parameter, source stride
162 	EB_U16                  *reconSamplePtr,        // input parameter, deblocked Picture Ptr
163 	EB_U32                   reconStride,           // input parameter, deblocked stride
164 	EB_U32                   lcuWidth,              // input parameter, LCU width
165 	EB_U32                   lcuHeight,             // input parameter, LCU height
166 	EB_S32                  *boDiff,                // output parameter, used to store Band Offset diff, boDiff[SAO_BO_INTERVALS]
167 	EB_U16                  *boCount,											// output parameter, used to store Band Offset count, boCount[SAO_BO_INTERVALS]
168 	EB_S32                   eoDiff[SAO_EO_TYPES][SAO_EO_CATEGORIES + 1],		// output parameter, used to store Edge Offset diff, eoDiff[SAO_EO_TYPES] [SAO_EO_CATEGORIES]
169 	EB_U16                   eoCount[SAO_EO_TYPES][SAO_EO_CATEGORIES + 1]);		// output parameter, used to store Edge Offset count, eoCount[SAO_EO_TYPES] [SAO_EO_CATEGORIES]
170 
171 static const EB_SAOGATHER_16bit_FUNC SaoGatherFunctionTabl_16bit[EB_ASM_TYPE_TOTAL] = {
172 	// C_DEFAULT
173 	GatherSaoStatisticsLcu_62x62_16bit,
174 	// AVX2
175 	GatherSaoStatisticsLcu16bit_SSE2,
176 
177 };
178 
179 
180 static const EB_SAOGATHER_FUNC SaoGatherFunctionTableLossy[EB_ASM_TYPE_TOTAL] = {
181     // C_DEFAULT
182     GatherSaoStatisticsLcuLossy_62x62,
183     // AVX2
184     GatherSaoStatisticsLcu_BT_SSE2,
185 };
186 
187 
188 static const EB_SAOGATHER_90_45_135_FUNC SaoGatherFunctionTableLossy_90_45_135[EB_ASM_TYPE_TOTAL]= {
189 	// C_DEFAULT
190     GatherSaoStatisticsLcu_OnlyEo_90_45_135_Lossy,
191 	// AVX2
192 	GatherSaoStatisticsLcu_OnlyEo_90_45_135_BT_SSE2,
193 };
194 
195 static const EB_SAOGATHER_90_45_135_16bit_SSE2_FUNC SaoGatherFunctionTable_90_45_135_16bit_SSE2[EB_ASM_TYPE_TOTAL][2] = {
196 	// C_DEFAULT
197 	{
198         GatherSaoStatisticsLcu_62x62_OnlyEo_90_45_135_16bit,
199         GatherSaoStatisticsLcu_62x62_OnlyEo_90_45_135_16bit,
200 	},
201 	// AVX2
202 	{
203 		GatherSaoStatisticsLcu_62x62_OnlyEo_90_45_135_16bit,
204 		GatherSaoStatisticsLcu_OnlyEo_90_45_135_16bit_SSE2_INTRIN,
205 	},
206 };
207 
208 
209 static const EB_SAOAPPLY_BO_FUNC SaoFunctionTableBo[EB_ASM_TYPE_TOTAL][2] = {
210     // C_DEFAULT
211     {
212         SAOApplyBO,
213         SAOApplyBO
214     },
215     // AVX2
216     {
217 		SAOApplyBO,
218 		SAOApplyBO_BT_SSSE3
219     },
220 };
221 
222 static const EB_SAOAPPLY_EO_0_90_FUNC SaoFunctionTableEO_0_90[EB_ASM_TYPE_TOTAL][2][2] = {
223 	// C_DEFAULT
224     {
225         {
226             SAOApplyEO_0,
227             SAOApplyEO_0
228         },
229         {
230             SAOApplyEO_90,
231             SAOApplyEO_90
232         }
233     },
234 	// AVX2
235     {
236         {
237             SAOApplyEO_0,
238             SAOApplyEO_0_BT_SSSE3
239         },
240         {
241             SAOApplyEO_90,
242             SAOApplyEO_90_BT_SSSE3
243         }
244     },
245 };
246 
247 static const EB_SAOAPPLY_EO_135_45_FUNC SaoFunctionTableEO_135_45[EB_ASM_TYPE_TOTAL][2][2][2] = {
248 	// C_DEFAULT
249 	{
250         {
251 			{
252 			SAOApplyEO_135,
253 			SAOApplyEO_135
254 			},
255 			{
256 			SAOApplyEO_135,
257 			SAOApplyEO_135
258 			}
259         },
260         {
261 			{
262             SAOApplyEO_45,
263             SAOApplyEO_45
264 			},
265 			{
266             SAOApplyEO_45,
267             SAOApplyEO_45
268 			}
269         }
270     },
271 	// AVX2
272 	{
273         {
274 			{
275 				SAOApplyEO_135,
276                 SAOApplyEO_135_BT_SSSE3
277 			},
278 			{
279 				SAOApplyEO_135,
280                 SAOApplyEO_135_BT_SSSE3
281 			}
282 
283         },
284         {
285 			{
286                 SAOApplyEO_45,
287                 SAOApplyEO_45_BT_SSSE3
288 			},
289 			{
290                 SAOApplyEO_45,
291 				SAOApplyEO_45_BT_SSSE3
292 			}
293         }
294     },
295 };
296 
297 static const EB_SAOAPPLY_BO_16bit_FUNC SaoFunctionTableBo_16bit[EB_ASM_TYPE_TOTAL][2] = {
298 	// C_DEFAULT
299 	{
300         SAOApplyBO16bit,
301         SAOApplyBO16bit
302 	},
303 	// AVX2
304 	{
305 		SAOApplyBO16bit,
306 		SAOApplyBO16bit_SSE2_INTRIN
307 	},
308 };
309 
310 static const EB_SAOAPPLY_EO_0_90_16bit_FUNC SaoFunctionTableEO_0_90_16bit[EB_ASM_TYPE_TOTAL][2][2] = {
311 	// C_DEFAULT
312     {
313         {
314          SAOApplyEO_0_16bit,
315          SAOApplyEO_0_16bit
316         },
317         {
318          SAOApplyEO_90_16bit,
319          SAOApplyEO_90_16bit
320         }
321     },
322 	// AVX2
323     {
324         {
325          SAOApplyEO_0_16bit,
326          SAOApplyEO_0_16bit_SSE2_INTRIN
327         },
328         {
329          SAOApplyEO_90_16bit,
330          SAOApplyEO_90_16bit_SSE2_INTRIN
331         }
332     },
333 };
334 
335 static const EB_SAOAPPLY_EO_135_45_16bit_FUNC SaoFunctionTableEO_135_45_16bit[EB_ASM_TYPE_TOTAL][2][2] = {
336 	// C_DEFAULT
337     {
338         {
339 			SAOApplyEO_135_16bit,
340 			SAOApplyEO_135_16bit
341         },
342         {
343             SAOApplyEO_45_16bit,
344             SAOApplyEO_45_16bit
345         }
346     },
347 	// AVX2
348     {
349         {
350 			SAOApplyEO_135_16bit,
351             SAOApplyEO_135_16bit_SSE2_INTRIN
352         },
353         {
354 			SAOApplyEO_45_16bit,
355 			SAOApplyEO_45_16bit_SSE2_INTRIN
356         }
357     },
358 };
359 
360 #ifdef __cplusplus
361 }
362 #endif
363 #endif
364