FreeRDP
primitives.h
1 /* primitives.h
2  * vi:ts=4 sw=4
3  *
4  * (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License. You may obtain
7  * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing
12  * permissions and limitations under the License. Algorithms used by
13  * this code may be covered by patents by HP, Microsoft, or other parties.
14  */
15 
16 #ifdef __GNUC__
17 #pragma once
18 #endif
19 
20 #ifndef FREERDP_PRIMITIVES_H
21 #define FREERDP_PRIMITIVES_H
22 
23 #include <winpr/wtypes.h>
24 
25 #include <freerdp/api.h>
26 #include <freerdp/types.h>
27 #include <freerdp/codec/color.h>
28 
29 #include <winpr/platform.h>
30 
31 #ifdef __cplusplus
32 extern "C"
33 {
34 #endif
35 
36  typedef INT32 pstatus_t; /* match IppStatus. */
37 #define PRIMITIVES_SUCCESS (0) /* match ippStsNoErr */
38 
39 /* Simple macro for address of an x,y location in 2d 4-byte memory block */
40 #define PIXMAP4_ADDR(_dst_, _x_, _y_, _span_) \
41  ((void*)(((BYTE*)(_dst_)) + (((_x_) + (_y_) * (_span_)) << 2)))
42 
43 #define PRIM_X86_MMX_AVAILABLE (1U << 0)
44 #define PRIM_X86_3DNOW_AVAILABLE (1U << 1)
45 #define PRIM_X86_3DNOW_PREFETCH_AVAILABLE (1U << 2)
46 #define PRIM_X86_SSE_AVAILABLE (1U << 3)
47 #define PRIM_X86_SSE2_AVAILABLE (1U << 4)
48 #define PRIM_X86_SSE3_AVAILABLE (1U << 5)
49 #define PRIM_X86_SSSE3_AVAILABLE (1U << 6)
50 #define PRIM_X86_SSE41_AVAILABLE (1U << 7)
51 #define PRIM_X86_SSE42_AVAILABLE (1U << 8)
52 #define PRIM_X86_AVX_AVAILABLE (1U << 9)
53 #define PRIM_X86_FMA_AVAILABLE (1U << 10)
54 #define PRIM_X86_AVX_AES_AVAILABLE (1U << 11)
55 #define PRIM_X86_AVX2_AVAILABLE (1U << 12)
56 
57 #define PRIM_ARM_VFP1_AVAILABLE (1U << 0)
58 #define PRIM_ARM_VFP2_AVAILABLE (1U << 1)
59 #define PRIM_ARM_VFP3_AVAILABLE (1U << 2)
60 #define PRIM_ARM_VFP4_AVAILABLE (1U << 3)
61 #define PRIM_ARM_FPA_AVAILABLE (1U << 4)
62 #define PRIM_ARM_FPE_AVAILABLE (1U << 5)
63 #define PRIM_ARM_IWMMXT_AVAILABLE (1U << 6)
64 #define PRIM_ARM_NEON_AVAILABLE (1U << 7)
65 
67 enum
68 {
69  PRIM_FLAGS_HAVE_EXTCPU = (1U << 0), /* primitives are using CPU extensions */
70  PRIM_FLAGS_HAVE_EXTGPU = (1U << 1), /* primitives are using the GPU */
71 };
72 
73 typedef struct
74 {
75  UINT32 width;
76  UINT32 height;
77 } prim_size_t;
78 
79 typedef enum
80 {
81  AVC444_LUMA,
82  AVC444_CHROMAv1,
83  AVC444_CHROMAv2
84 } avc444_frame_type;
85 
86 /* Function prototypes for all of the supported primitives. */
87 typedef pstatus_t (*__copy_t)(const void* WINPR_RESTRICT pSrc, void* WINPR_RESTRICT pDst,
88  INT32 bytes);
89 typedef pstatus_t (*__copy_8u_t)(const BYTE* WINPR_RESTRICT pSrc, BYTE* WINPR_RESTRICT pDst,
90  INT32 len);
91 typedef pstatus_t (*__copy_8u_AC4r_t)(const BYTE* WINPR_RESTRICT pSrc, INT32 srcStep, /* bytes */
92  BYTE* WINPR_RESTRICT pDst, INT32 dstStep, /* bytes */
93  INT32 width, INT32 height); /* pixels */
94 typedef pstatus_t (*__set_8u_t)(BYTE val, BYTE* WINPR_RESTRICT pDst, UINT32 len);
95 typedef pstatus_t (*__set_32s_t)(INT32 val, INT32* WINPR_RESTRICT pDst, UINT32 len);
96 typedef pstatus_t (*__set_32u_t)(UINT32 val, UINT32* WINPR_RESTRICT pDst, UINT32 len);
97 typedef pstatus_t (*__zero_t)(void* WINPR_RESTRICT pDst, size_t bytes);
98 typedef pstatus_t (*__alphaComp_argb_t)(const BYTE* WINPR_RESTRICT pSrc1, UINT32 src1Step,
99  const BYTE* WINPR_RESTRICT pSrc2, UINT32 src2Step,
100  BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, UINT32 width,
101  UINT32 height);
102 typedef pstatus_t (*__add_16s_t)(const INT16* WINPR_RESTRICT pSrc1,
103  const INT16* WINPR_RESTRICT pSrc2, INT16* WINPR_RESTRICT pDst,
104  UINT32 len);
113 typedef pstatus_t (*__add_16s_inplace_t)(INT16* WINPR_RESTRICT pSrcDst1,
114  INT16* WINPR_RESTRICT pSrcDst2, UINT32 len);
115 
136 typedef pstatus_t (*__copy_no_overlap_t)(BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat,
137  UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth,
138  UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData,
139  DWORD SrcFormat, UINT32 nSrcStep, UINT32 nXSrc,
140  UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette,
141  UINT32 flags);
142 typedef pstatus_t (*__lShiftC_16s_inplace_t)(INT16* WINPR_RESTRICT pSrcDst, UINT32 val, UINT32 len);
143 typedef pstatus_t (*__lShiftC_16s_t)(const INT16* pSrc, UINT32 val, INT16* pSrcDst, UINT32 len);
144 typedef pstatus_t (*__lShiftC_16u_t)(const UINT16* pSrc, UINT32 val, UINT16* pSrcDst, UINT32 len);
145 typedef pstatus_t (*__rShiftC_16s_t)(const INT16* pSrc, UINT32 val, INT16* pSrcDst, UINT32 len);
146 typedef pstatus_t (*__rShiftC_16u_t)(const UINT16* pSrc, UINT32 val, UINT16* pSrcDst, UINT32 len);
147 typedef pstatus_t (*__shiftC_16s_t)(const INT16* pSrc, INT32 val, INT16* pSrcDst, UINT32 len);
148 typedef pstatus_t (*__shiftC_16u_t)(const UINT16* pSrc, INT32 val, UINT16* pSrcDst, UINT32 len);
149 typedef pstatus_t (*__sign_16s_t)(const INT16* pSrc, INT16* pSrcDst, UINT32 len);
150 typedef pstatus_t (*__yCbCrToRGB_16s8u_P3AC4R_t)(const INT16* WINPR_RESTRICT pSrc[3],
151  UINT32 srcStep, BYTE* WINPR_RESTRICT pDst,
152  UINT32 dstStep, UINT32 DstFormat,
153  const prim_size_t* WINPR_RESTRICT roi);
154 typedef pstatus_t (*__yCbCrToRGB_16s16s_P3P3_t)(const INT16* WINPR_RESTRICT pSrc[3], INT32 srcStep,
155  INT16* WINPR_RESTRICT pDst[3], INT32 dstStep,
156  const prim_size_t* WINPR_RESTRICT roi);
157 typedef pstatus_t (*__RGBToYCbCr_16s16s_P3P3_t)(const INT16* WINPR_RESTRICT pSrc[3], INT32 srcStep,
158  INT16* WINPR_RESTRICT pDst[3], INT32 dstStep,
159  const prim_size_t* WINPR_RESTRICT roi);
160 typedef pstatus_t (*__RGBToRGB_16s8u_P3AC4R_t)(const INT16* WINPR_RESTRICT pSrc[3], UINT32 srcStep,
161  BYTE* WINPR_RESTRICT pDst, UINT32 dstStep,
162  UINT32 DstFormat,
163  const prim_size_t* WINPR_RESTRICT roi);
164 typedef pstatus_t (*__YCoCgToRGB_8u_AC4R_t)(const BYTE* WINPR_RESTRICT pSrc, INT32 srcStep,
165  BYTE* WINPR_RESTRICT pDst, UINT32 DstFormat,
166  INT32 dstStep, UINT32 width, UINT32 height, UINT8 shift,
167  BOOL withAlpha);
168 typedef pstatus_t (*__RGB565ToARGB_16u32u_C3C4_t)(const UINT16* WINPR_RESTRICT pSrc, INT32 srcStep,
169  UINT32* WINPR_RESTRICT pDst, INT32 dstStep,
170  UINT32 width, UINT32 height, UINT32 format);
171 typedef pstatus_t (*__YUV420ToRGB_8u_P3AC4R_t)(const BYTE* WINPR_RESTRICT pSrc[3],
172  const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst,
173  UINT32 dstStep, UINT32 DstFormat,
174  const prim_size_t* WINPR_RESTRICT roi);
175 typedef pstatus_t (*__YUV444ToRGB_8u_P3AC4R_t)(const BYTE* WINPR_RESTRICT pSrc[3],
176  const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst,
177  UINT32 dstStep, UINT32 DstFormat,
178  const prim_size_t* WINPR_RESTRICT roi);
179 typedef pstatus_t (*__RGBToYUV420_8u_P3AC4R_t)(const BYTE* WINPR_RESTRICT pSrc, UINT32 SrcFormat,
180  UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[3],
181  const UINT32 dstStep[3],
182  const prim_size_t* WINPR_RESTRICT roi);
183 typedef pstatus_t (*__RGBToYUV444_8u_P3AC4R_t)(const BYTE* WINPR_RESTRICT pSrc, UINT32 SrcFormat,
184  UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[3],
185  UINT32 dstStep[3],
186  const prim_size_t* WINPR_RESTRICT roi);
187 typedef pstatus_t (*__YUV420CombineToYUV444_t)(avc444_frame_type type,
188  const BYTE* WINPR_RESTRICT pSrc[3],
189  const UINT32 srcStep[3], UINT32 nWidth,
190  UINT32 nHeight, BYTE* WINPR_RESTRICT pDst[3],
191  const UINT32 dstStep[3],
192  const RECTANGLE_16* WINPR_RESTRICT roi);
193 typedef pstatus_t (*__YUV444SplitToYUV420_t)(
194  const BYTE* WINPR_RESTRICT pSrc[3], const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pMainDst[3],
195  const UINT32 dstMainStep[3], BYTE* WINPR_RESTRICT pAuxDst[3], const UINT32 srcAuxStep[3],
196  const prim_size_t* WINPR_RESTRICT roi);
197 typedef pstatus_t (*__RGBToAVC444YUV_t)(const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat,
198  UINT32 srcStep, BYTE* WINPR_RESTRICT pMainDst[3],
199  const UINT32 dstMainStep[3],
200  BYTE* WINPR_RESTRICT pAuxDst[3], const UINT32 dstAuxStep[3],
201  const prim_size_t* WINPR_RESTRICT roi);
202 typedef pstatus_t (*__andC_32u_t)(const UINT32* WINPR_RESTRICT pSrc, UINT32 val,
203  UINT32* WINPR_RESTRICT pDst, INT32 len);
204 typedef pstatus_t (*__orC_32u_t)(const UINT32* WINPR_RESTRICT pSrc, UINT32 val,
205  UINT32* WINPR_RESTRICT pDst, INT32 len);
206 typedef pstatus_t (*primitives_uninit_t)(void);
207 
208 typedef struct
209 {
210  /* Memory-to-memory copy routines */
211  __copy_t copy; /* memcpy/memmove, basically */
212  __copy_8u_t copy_8u; /* more strongly typed */
213  __copy_8u_AC4r_t copy_8u_AC4r; /* pixel copy function */
214  /* Memory setting routines */
215  __set_8u_t set_8u; /* memset, basically */
216  __set_32s_t set_32s;
217  __set_32u_t set_32u;
218  __zero_t zero; /* bzero or faster */
219  /* Arithmetic functions */
220  __add_16s_t add_16s;
221  /* And/or */
222  __andC_32u_t andC_32u;
223  __orC_32u_t orC_32u;
224  /* Shifts */
225  __lShiftC_16s_t lShiftC_16s;
226  __lShiftC_16u_t lShiftC_16u;
227  __rShiftC_16s_t rShiftC_16s;
228  __rShiftC_16u_t rShiftC_16u;
229  __shiftC_16s_t shiftC_16s;
230  __shiftC_16u_t shiftC_16u;
231  /* Alpha Composition */
232  __alphaComp_argb_t alphaComp_argb;
233  /* Sign */
234  __sign_16s_t sign_16s;
235  /* Color conversions */
236  __yCbCrToRGB_16s8u_P3AC4R_t yCbCrToRGB_16s8u_P3AC4R;
237  __yCbCrToRGB_16s16s_P3P3_t yCbCrToRGB_16s16s_P3P3;
238  __RGBToYCbCr_16s16s_P3P3_t RGBToYCbCr_16s16s_P3P3;
239  __RGBToRGB_16s8u_P3AC4R_t RGBToRGB_16s8u_P3AC4R;
240  __YCoCgToRGB_8u_AC4R_t YCoCgToRGB_8u_AC4R;
241  __YUV420ToRGB_8u_P3AC4R_t YUV420ToRGB_8u_P3AC4R;
242  __RGBToYUV420_8u_P3AC4R_t RGBToYUV420_8u_P3AC4R;
243  __RGBToYUV444_8u_P3AC4R_t RGBToYUV444_8u_P3AC4R;
244  __YUV420CombineToYUV444_t YUV420CombineToYUV444;
245  __YUV444SplitToYUV420_t YUV444SplitToYUV420;
246  __YUV444ToRGB_8u_P3AC4R_t YUV444ToRGB_8u_P3AC4R;
247  __RGBToAVC444YUV_t RGBToAVC444YUV;
248  __RGBToAVC444YUV_t RGBToAVC444YUVv2;
249  /* flags */
250  DWORD flags;
251  primitives_uninit_t uninit;
252 
256  __add_16s_inplace_t add_16s_inplace;
257  __lShiftC_16s_inplace_t lShiftC_16s_inplace;
258  __copy_no_overlap_t copy_no_overlap;
259 } primitives_t;
260 
261 typedef enum
262 {
263  PRIMITIVES_PURE_SOFT,
264  PRIMITIVES_ONLY_CPU,
265  PRIMITIVES_ONLY_GPU,
266  PRIMITIVES_AUTODETECT
267 } primitive_hints;
268 
269  FREERDP_API primitives_t* primitives_get(void);
270  FREERDP_API void primitives_set_hints(primitive_hints hints);
271  FREERDP_API primitive_hints primitives_get_hints(void);
272  FREERDP_API primitives_t* primitives_get_generic(void);
273  FREERDP_API DWORD primitives_flags(primitives_t* p);
274  FREERDP_API BOOL primitives_init(primitives_t* p, primitive_hints hints);
275  FREERDP_API void primitives_uninit(void);
276 
277 #ifdef __cplusplus
278 }
279 #endif
280 
281 #endif /* FREERDP_PRIMITIVES_H */
__lShiftC_16s_inplace_t lShiftC_16s_inplace
Definition: primitives.h:257
__copy_no_overlap_t copy_no_overlap
Definition: primitives.h:258
__add_16s_inplace_t add_16s_inplace
Do vecotor addition, store result in both input buffers pSrcDst1 = pSrcDst2 = pSrcDst1 + pSrcDst2.
Definition: primitives.h:256