2013-01-19 02:32:58 +04:00
|
|
|
/* prim_internal.h
|
|
|
|
* vi:ts=4 sw=4
|
|
|
|
*
|
|
|
|
* (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License. You may obtain
|
|
|
|
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
|
|
* or implied. See the License for the specific language governing
|
|
|
|
* permissions and limitations under the License. Algorithms used by
|
|
|
|
* this code may be covered by patents by HP, Microsoft, or other parties.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2017-06-06 15:01:41 +03:00
|
|
|
#ifndef FREERDP_LIB_PRIM_INTERNAL_H
|
|
|
|
#define FREERDP_LIB_PRIM_INTERNAL_H
|
2013-01-19 02:32:58 +04:00
|
|
|
|
2018-01-30 16:51:56 +03:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
2013-01-19 02:32:58 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <freerdp/primitives.h>
|
2016-08-10 10:12:55 +03:00
|
|
|
#include <freerdp/api.h>
|
2013-01-19 02:32:58 +04:00
|
|
|
|
2017-02-03 13:56:44 +03:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define PRIM_ALIGN_128 __attribute__((aligned(16)))
|
|
|
|
#else
|
|
|
|
#ifdef _WIN32
|
|
|
|
#define PRIM_ALIGN_128 __declspec(align(16))
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-01-29 18:20:59 +03:00
|
|
|
#if defined(WITH_SSE2) || defined(WITH_NEON) || defined(WITH_OPENCL)
|
2018-01-30 16:51:56 +03:00
|
|
|
#define HAVE_OPTIMIZED_PRIMITIVES 1
|
|
|
|
#endif
|
|
|
|
|
2018-01-29 18:20:59 +03:00
|
|
|
#if defined(WITH_SSE2) || defined(WITH_NEON)
|
|
|
|
#define HAVE_CPU_OPTIMIZED_PRIMITIVES 1
|
|
|
|
#endif
|
|
|
|
|
2018-01-30 16:51:56 +03:00
|
|
|
#if defined(WITH_SSE2)
|
2013-01-19 02:32:58 +04:00
|
|
|
/* Use lddqu for unaligned; load for 16-byte aligned. */
|
2019-11-06 17:24:51 +03:00
|
|
|
#define LOAD_SI128(_ptr_) \
|
|
|
|
(((ULONG_PTR)(_ptr_)&0x0f) ? _mm_lddqu_si128((__m128i*)(_ptr_)) \
|
|
|
|
: _mm_load_si128((__m128i*)(_ptr_)))
|
2018-01-30 16:51:56 +03:00
|
|
|
#endif
|
2013-01-19 02:32:58 +04:00
|
|
|
|
2021-01-12 11:41:09 +03:00
|
|
|
static INLINE BYTE* writePixelBGRA(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
|
|
|
|
BYTE B, BYTE A)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(formatSize);
|
|
|
|
WINPR_UNUSED(format);
|
|
|
|
|
|
|
|
*dst++ = B;
|
|
|
|
*dst++ = G;
|
|
|
|
*dst++ = R;
|
|
|
|
*dst++ = A;
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static INLINE BYTE* writePixelBGRX(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
|
|
|
|
BYTE B, BYTE A)
|
2016-11-25 14:00:41 +03:00
|
|
|
{
|
2019-05-08 13:20:43 +03:00
|
|
|
WINPR_UNUSED(formatSize);
|
|
|
|
WINPR_UNUSED(format);
|
2021-01-12 11:41:09 +03:00
|
|
|
WINPR_UNUSED(A);
|
|
|
|
|
2016-11-25 14:00:41 +03:00
|
|
|
*dst++ = B;
|
|
|
|
*dst++ = G;
|
|
|
|
*dst++ = R;
|
2021-01-12 11:41:09 +03:00
|
|
|
dst++; /* Do not touch alpha */
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE BYTE* writePixelRGBA(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
|
|
|
|
BYTE B, BYTE A)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(formatSize);
|
|
|
|
WINPR_UNUSED(format);
|
|
|
|
|
|
|
|
*dst++ = R;
|
|
|
|
*dst++ = G;
|
|
|
|
*dst++ = B;
|
2016-11-25 14:00:41 +03:00
|
|
|
*dst++ = A;
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static INLINE BYTE* writePixelRGBX(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
|
|
|
|
BYTE B, BYTE A)
|
2016-11-25 14:00:41 +03:00
|
|
|
{
|
2019-05-08 13:20:43 +03:00
|
|
|
WINPR_UNUSED(formatSize);
|
|
|
|
WINPR_UNUSED(format);
|
2021-01-12 11:41:09 +03:00
|
|
|
WINPR_UNUSED(A);
|
|
|
|
|
2016-11-25 14:00:41 +03:00
|
|
|
*dst++ = R;
|
|
|
|
*dst++ = G;
|
|
|
|
*dst++ = B;
|
2021-01-12 11:41:09 +03:00
|
|
|
dst++; /* Do not touch alpha */
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE BYTE* writePixelABGR(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
|
|
|
|
BYTE B, BYTE A)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(formatSize);
|
|
|
|
WINPR_UNUSED(format);
|
|
|
|
|
2016-11-25 14:00:41 +03:00
|
|
|
*dst++ = A;
|
2021-01-12 11:41:09 +03:00
|
|
|
*dst++ = B;
|
|
|
|
*dst++ = G;
|
|
|
|
*dst++ = R;
|
2016-11-25 14:00:41 +03:00
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static INLINE BYTE* writePixelXBGR(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
|
|
|
|
BYTE B, BYTE A)
|
2016-11-25 14:00:41 +03:00
|
|
|
{
|
2019-05-08 13:20:43 +03:00
|
|
|
WINPR_UNUSED(formatSize);
|
|
|
|
WINPR_UNUSED(format);
|
2021-01-12 11:41:09 +03:00
|
|
|
WINPR_UNUSED(A);
|
|
|
|
|
|
|
|
dst++; /* Do not touch alpha */
|
2016-11-25 14:00:41 +03:00
|
|
|
*dst++ = B;
|
|
|
|
*dst++ = G;
|
|
|
|
*dst++ = R;
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2021-01-12 11:41:09 +03:00
|
|
|
static INLINE BYTE* writePixelARGB(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
|
2019-11-06 17:24:51 +03:00
|
|
|
BYTE B, BYTE A)
|
2016-11-25 14:00:41 +03:00
|
|
|
{
|
2019-05-08 13:20:43 +03:00
|
|
|
WINPR_UNUSED(formatSize);
|
|
|
|
WINPR_UNUSED(format);
|
2021-01-12 11:41:09 +03:00
|
|
|
|
2016-11-25 14:00:41 +03:00
|
|
|
*dst++ = A;
|
|
|
|
*dst++ = R;
|
|
|
|
*dst++ = G;
|
|
|
|
*dst++ = B;
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2021-01-12 11:41:09 +03:00
|
|
|
static INLINE BYTE* writePixelXRGB(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
|
|
|
|
BYTE B, BYTE A)
|
|
|
|
{
|
|
|
|
WINPR_UNUSED(formatSize);
|
|
|
|
WINPR_UNUSED(format);
|
|
|
|
WINPR_UNUSED(A);
|
|
|
|
|
|
|
|
dst++; /* Do not touch alpha */
|
|
|
|
*dst++ = R;
|
|
|
|
*dst++ = G;
|
|
|
|
*dst++ = B;
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE BYTE* writePixelGenericAlpha(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R,
|
|
|
|
BYTE G, BYTE B, BYTE A)
|
|
|
|
{
|
|
|
|
UINT32 color = FreeRDPGetColor(format, R, G, B, A);
|
|
|
|
WriteColor(dst, format, color);
|
|
|
|
return dst + formatSize;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static INLINE BYTE* writePixelGeneric(BYTE* dst, DWORD formatSize, UINT32 format, BYTE R, BYTE G,
|
|
|
|
BYTE B, BYTE A)
|
2016-11-25 14:00:41 +03:00
|
|
|
{
|
2017-11-24 15:19:48 +03:00
|
|
|
UINT32 color = FreeRDPGetColor(format, R, G, B, A);
|
2021-01-12 11:41:09 +03:00
|
|
|
WriteColorIgnoreAlpha(dst, format, color);
|
2016-11-25 14:00:41 +03:00
|
|
|
return dst + formatSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef BYTE* (*fkt_writePixel)(BYTE*, DWORD, UINT32, BYTE, BYTE, BYTE, BYTE);
|
|
|
|
|
2021-01-12 11:41:09 +03:00
|
|
|
static INLINE fkt_writePixel getPixelWriteFunction(DWORD format, BOOL useAlpha)
|
2016-11-25 14:00:41 +03:00
|
|
|
{
|
|
|
|
switch (format)
|
|
|
|
{
|
2017-01-12 17:30:06 +03:00
|
|
|
case PIXEL_FORMAT_ARGB32:
|
|
|
|
case PIXEL_FORMAT_XRGB32:
|
2021-01-12 11:41:09 +03:00
|
|
|
return useAlpha ? writePixelARGB : writePixelXRGB;
|
2016-11-25 14:00:41 +03:00
|
|
|
|
2017-01-12 17:30:06 +03:00
|
|
|
case PIXEL_FORMAT_ABGR32:
|
|
|
|
case PIXEL_FORMAT_XBGR32:
|
2021-01-12 11:41:09 +03:00
|
|
|
return useAlpha ? writePixelABGR : writePixelXBGR;
|
2016-11-25 14:00:41 +03:00
|
|
|
|
2017-01-12 17:30:06 +03:00
|
|
|
case PIXEL_FORMAT_RGBA32:
|
|
|
|
case PIXEL_FORMAT_RGBX32:
|
2021-01-12 11:41:09 +03:00
|
|
|
return useAlpha ? writePixelRGBA : writePixelRGBX;
|
2016-11-25 14:00:41 +03:00
|
|
|
|
2017-01-12 17:30:06 +03:00
|
|
|
case PIXEL_FORMAT_BGRA32:
|
|
|
|
case PIXEL_FORMAT_BGRX32:
|
2021-01-12 11:41:09 +03:00
|
|
|
return useAlpha ? writePixelBGRA : writePixelBGRX;
|
2016-11-25 14:00:41 +03:00
|
|
|
|
2017-01-12 17:30:06 +03:00
|
|
|
default:
|
2021-01-12 11:41:09 +03:00
|
|
|
return useAlpha ? writePixelGenericAlpha : writePixelGeneric;
|
2016-11-25 14:00:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-12 17:30:06 +03:00
|
|
|
static INLINE BYTE CLIP(INT32 X)
|
|
|
|
{
|
|
|
|
if (X > 255L)
|
|
|
|
return 255L;
|
|
|
|
|
|
|
|
if (X < 0L)
|
|
|
|
return 0L;
|
|
|
|
|
|
|
|
return X;
|
|
|
|
}
|
|
|
|
|
2017-02-13 18:00:12 +03:00
|
|
|
/**
|
|
|
|
* | R | ( | 256 0 403 | | Y | )
|
|
|
|
* | G | = ( | 256 -48 -120 | | U - 128 | ) >> 8
|
|
|
|
* | B | ( | 256 475 0 | | V - 128 | )
|
|
|
|
*/
|
|
|
|
static INLINE INT32 C(INT32 Y)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
return (Y)-0L;
|
2017-02-13 18:00:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE INT32 D(INT32 U)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
return (U)-128L;
|
2017-02-13 18:00:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE INT32 E(INT32 V)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
return (V)-128L;
|
2017-02-13 18:00:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE BYTE YUV2R(INT32 Y, INT32 U, INT32 V)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
const INT32 r = (256L * C(Y) + 0L * D(U) + 403L * E(V));
|
2017-02-13 18:00:12 +03:00
|
|
|
const INT32 r8 = r >> 8L;
|
|
|
|
return CLIP(r8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE BYTE YUV2G(INT32 Y, INT32 U, INT32 V)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
const INT32 g = (256L * C(Y) - 48L * D(U) - 120L * E(V));
|
2017-02-13 18:00:12 +03:00
|
|
|
const INT32 g8 = g >> 8L;
|
|
|
|
return CLIP(g8);
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE BYTE YUV2B(INT32 Y, INT32 U, INT32 V)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
const INT32 b = (256L * C(Y) + 475L * D(U) + 0L * E(V));
|
2017-02-13 18:00:12 +03:00
|
|
|
const INT32 b8 = b >> 8L;
|
|
|
|
return CLIP(b8);
|
|
|
|
}
|
|
|
|
|
2013-01-19 02:32:58 +04:00
|
|
|
/* Function prototypes for all the init/deinit routines. */
|
2016-08-10 10:12:55 +03:00
|
|
|
FREERDP_LOCAL void primitives_init_copy(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_set(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_add(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_andor(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_shift(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_sign(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_alphaComp(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_colors(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_YCoCg(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_YUV(primitives_t* prims);
|
|
|
|
|
2018-01-30 16:51:56 +03:00
|
|
|
#if defined(WITH_SSE2) || defined(WITH_NEON)
|
2016-08-10 10:12:55 +03:00
|
|
|
FREERDP_LOCAL void primitives_init_copy_opt(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_set_opt(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_add_opt(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_andor_opt(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_shift_opt(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_sign_opt(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_alphaComp_opt(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_colors_opt(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_YCoCg_opt(primitives_t* prims);
|
|
|
|
FREERDP_LOCAL void primitives_init_YUV_opt(primitives_t* prims);
|
2018-01-30 16:51:56 +03:00
|
|
|
#endif
|
2014-07-03 00:30:04 +04:00
|
|
|
|
2018-01-29 18:20:59 +03:00
|
|
|
#if defined(WITH_OPENCL)
|
2019-11-07 17:19:49 +03:00
|
|
|
FREERDP_LOCAL BOOL primitives_init_opencl(primitives_t* prims);
|
2018-01-29 18:20:59 +03:00
|
|
|
#endif
|
|
|
|
|
2019-11-07 17:19:49 +03:00
|
|
|
FREERDP_LOCAL primitives_t* primitives_get_by_type(DWORD type);
|
|
|
|
|
2017-06-06 15:01:41 +03:00
|
|
|
#endif /* FREERDP_LIB_PRIM_INTERNAL_H */
|