17 #ifndef FREERDP_LIB_PRIM_INTERNAL_H
18 #define FREERDP_LIB_PRIM_INTERNAL_H
20 #include <winpr/platform.h>
21 #include <freerdp/config.h>
23 #include <freerdp/primitives.h>
24 #include <freerdp/api.h>
26 #include <freerdp/log.h>
27 #define PRIM_TAG FREERDP_TAG("primitives")
30 #define PRIM_ALIGN_128 __attribute__((aligned(16)))
33 #define PRIM_ALIGN_128 __declspec(align(16))
37 #if defined(WITH_SSE2)
38 #if defined(_M_IX86) || defined(_M_AMD64) || defined(_M_IA64) || defined(_M_IX86_AMD64)
43 #if defined(WITH_NEON)
44 #if defined(_M_ARM64) || defined(_M_ARM)
49 #if defined(SSE2_ENABLED) || defined(NEON_ENABLED) || defined(WITH_OPENCL)
50 #define HAVE_OPTIMIZED_PRIMITIVES 1
53 #if defined(SSE2_ENABLED) || defined(NEON_ENABLED)
54 #define HAVE_CPU_OPTIMIZED_PRIMITIVES 1
57 #if defined(SSE2_ENABLED)
59 #define LOAD_SI128(_ptr_) \
60 (((const ULONG_PTR)(_ptr_)&0x0f) ? _mm_lddqu_si128((const __m128i*)(_ptr_)) \
61 : _mm_load_si128((const __m128i*)(_ptr_)))
64 static INLINE BYTE* writePixelBGRA(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
67 WINPR_UNUSED(formatSize);
77 static INLINE BYTE* writePixelBGRX(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
80 WINPR_UNUSED(formatSize);
92 static INLINE BYTE* writePixelRGBA(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
95 WINPR_UNUSED(formatSize);
105 static INLINE BYTE* writePixelRGBX(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
108 WINPR_UNUSED(formatSize);
109 WINPR_UNUSED(format);
120 static INLINE BYTE* writePixelABGR(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
123 WINPR_UNUSED(formatSize);
124 WINPR_UNUSED(format);
133 static INLINE BYTE* writePixelXBGR(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
136 WINPR_UNUSED(formatSize);
137 WINPR_UNUSED(format);
147 static INLINE BYTE* writePixelARGB(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
150 WINPR_UNUSED(formatSize);
151 WINPR_UNUSED(format);
160 static INLINE BYTE* writePixelXRGB(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
163 WINPR_UNUSED(formatSize);
164 WINPR_UNUSED(format);
174 static INLINE BYTE* writePixelGenericAlpha(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R,
175 BYTE G, BYTE B, BYTE A)
177 UINT32 color = FreeRDPGetColor(format, R, G, B, A);
178 FreeRDPWriteColor(dst, format, color);
179 return dst + formatSize;
182 static INLINE BYTE* writePixelGeneric(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
185 UINT32 color = FreeRDPGetColor(format, R, G, B, A);
186 FreeRDPWriteColorIgnoreAlpha(dst, format, color);
187 return dst + formatSize;
190 typedef BYTE* (*fkt_writePixel)(BYTE*, DWORD, UINT32, BYTE, BYTE, BYTE, BYTE);
192 static INLINE fkt_writePixel getPixelWriteFunction(DWORD format, BOOL useAlpha)
196 case PIXEL_FORMAT_ARGB32:
197 case PIXEL_FORMAT_XRGB32:
198 return useAlpha ? writePixelARGB : writePixelXRGB;
200 case PIXEL_FORMAT_ABGR32:
201 case PIXEL_FORMAT_XBGR32:
202 return useAlpha ? writePixelABGR : writePixelXBGR;
204 case PIXEL_FORMAT_RGBA32:
205 case PIXEL_FORMAT_RGBX32:
206 return useAlpha ? writePixelRGBA : writePixelRGBX;
208 case PIXEL_FORMAT_BGRA32:
209 case PIXEL_FORMAT_BGRX32:
210 return useAlpha ? writePixelBGRA : writePixelBGRX;
213 return useAlpha ? writePixelGenericAlpha : writePixelGeneric;
217 static INLINE BYTE CLIP(INT64 X)
228 static INLINE BYTE CONDITIONAL_CLIP(INT32 in, BYTE original)
233 diff = out - original;
235 diff = original - out;
246 static INLINE INT32 C(INT32 Y)
251 static INLINE INT32 D(INT32 U)
256 static INLINE INT32 E(INT32 V)
261 static INLINE BYTE YUV2R(INT32 Y, INT32 U, INT32 V)
263 const INT32 r = (256L * C(Y) + 0L * D(U) + 403L * E(V));
264 const INT32 r8 = r >> 8L;
268 static INLINE BYTE YUV2G(INT32 Y, INT32 U, INT32 V)
270 const INT32 g = (256L * C(Y) - 48L * D(U) - 120L * E(V));
271 const INT32 g8 = g >> 8L;
275 static INLINE BYTE YUV2B(INT32 Y, INT32 U, INT32 V)
277 const INT32 b = (256L * C(Y) + 475L * D(U) + 0L * E(V));
278 const INT32 b8 = b >> 8L;
283 FREERDP_LOCAL
void primitives_init_copy(
primitives_t* WINPR_RESTRICT prims);
284 FREERDP_LOCAL
void primitives_init_set(
primitives_t* WINPR_RESTRICT prims);
285 FREERDP_LOCAL
void primitives_init_add(
primitives_t* WINPR_RESTRICT prims);
286 FREERDP_LOCAL
void primitives_init_andor(
primitives_t* WINPR_RESTRICT prims);
287 FREERDP_LOCAL
void primitives_init_shift(
primitives_t* WINPR_RESTRICT prims);
288 FREERDP_LOCAL
void primitives_init_sign(
primitives_t* WINPR_RESTRICT prims);
289 FREERDP_LOCAL
void primitives_init_alphaComp(
primitives_t* WINPR_RESTRICT prims);
290 FREERDP_LOCAL
void primitives_init_colors(
primitives_t* WINPR_RESTRICT prims);
291 FREERDP_LOCAL
void primitives_init_YCoCg(
primitives_t* WINPR_RESTRICT prims);
292 FREERDP_LOCAL
void primitives_init_YUV(
primitives_t* WINPR_RESTRICT prims);
294 FREERDP_LOCAL
void primitives_init_copy_opt(
primitives_t* WINPR_RESTRICT prims);
295 FREERDP_LOCAL
void primitives_init_set_opt(
primitives_t* WINPR_RESTRICT prims);
296 FREERDP_LOCAL
void primitives_init_add_opt(
primitives_t* WINPR_RESTRICT prims);
297 FREERDP_LOCAL
void primitives_init_andor_opt(
primitives_t* WINPR_RESTRICT prims);
298 FREERDP_LOCAL
void primitives_init_shift_opt(
primitives_t* WINPR_RESTRICT prims);
299 FREERDP_LOCAL
void primitives_init_sign_opt(
primitives_t* WINPR_RESTRICT prims);
300 FREERDP_LOCAL
void primitives_init_alphaComp_opt(
primitives_t* WINPR_RESTRICT prims);
301 FREERDP_LOCAL
void primitives_init_colors_opt(
primitives_t* WINPR_RESTRICT prims);
302 FREERDP_LOCAL
void primitives_init_YCoCg_opt(
primitives_t* WINPR_RESTRICT prims);
303 FREERDP_LOCAL
void primitives_init_YUV_opt(
primitives_t* WINPR_RESTRICT prims);
305 #if defined(WITH_OPENCL)
306 FREERDP_LOCAL BOOL primitives_init_opencl(
primitives_t* WINPR_RESTRICT prims);
309 FREERDP_LOCAL
primitives_t* primitives_get_by_type(DWORD type);