20 #ifndef FREERDP_LIB_CODEC_COLOR_H
21 #define FREERDP_LIB_CODEC_COLOR_H
23 #include <winpr/winpr.h>
24 #include <winpr/wtypes.h>
26 #include <freerdp/codec/color.h>
27 #include <freerdp/log.h>
29 #define INT_COLOR_TAG FREERDP_TAG("codec.color.h")
31 static INLINE DWORD FreeRDPAreColorFormatsEqualNoAlpha_int(DWORD first, DWORD second)
33 const DWORD mask = (DWORD) ~(8UL << 12UL);
34 return (first & mask) == (second & mask);
37 static INLINE BOOL FreeRDPWriteColor_int(BYTE* WINPR_RESTRICT dst, UINT32 format, UINT32 color)
39 switch (FreeRDPGetBitsPerPixel(format))
42 dst[0] = (BYTE)(color >> 24);
43 dst[1] = (BYTE)(color >> 16);
44 dst[2] = (BYTE)(color >> 8);
49 dst[0] = (BYTE)(color >> 16);
50 dst[1] = (BYTE)(color >> 8);
55 dst[1] = (BYTE)(color >> 8);
60 if (!FreeRDPColorHasAlpha(format))
61 color = color & 0x7FFF;
63 dst[1] = (BYTE)(color >> 8);
72 WLog_ERR(INT_COLOR_TAG,
"Unsupported format %s", FreeRDPGetColorFormatName(format));
79 static INLINE BOOL FreeRDPWriteColorIgnoreAlpha_int(BYTE* WINPR_RESTRICT dst, UINT32 format,
84 case PIXEL_FORMAT_XBGR32:
85 case PIXEL_FORMAT_XRGB32:
86 case PIXEL_FORMAT_ABGR32:
87 case PIXEL_FORMAT_ARGB32:
89 const UINT32 tmp = ((UINT32)dst[0] << 24ULL) | (color & 0x00FFFFFFULL);
90 return FreeRDPWriteColor_int(dst, format, tmp);
92 case PIXEL_FORMAT_BGRX32:
93 case PIXEL_FORMAT_RGBX32:
94 case PIXEL_FORMAT_BGRA32:
95 case PIXEL_FORMAT_RGBA32:
97 const UINT32 tmp = ((UINT32)dst[3]) | (color & 0xFFFFFF00ULL);
98 return FreeRDPWriteColor_int(dst, format, tmp);
101 return FreeRDPWriteColor_int(dst, format, color);
105 static INLINE UINT32 FreeRDPReadColor_int(
const BYTE* WINPR_RESTRICT src, UINT32 format)
109 switch (FreeRDPGetBitsPerPixel(format))
113 ((UINT32)src[0] << 24) | ((UINT32)src[1] << 16) | ((UINT32)src[2] << 8) | src[3];
117 color = ((UINT32)src[0] << 16) | ((UINT32)src[1] << 8) | src[2];
121 color = ((UINT32)src[1] << 8) | src[0];
125 color = ((UINT32)src[1] << 8) | src[0];
127 if (!FreeRDPColorHasAlpha(format))
128 color = color & 0x7FFF;
139 WLog_ERR(INT_COLOR_TAG,
"Unsupported format %s", FreeRDPGetColorFormatName(format));