22 #ifndef FREERDP_CODEC_COLOR_H
23 #define FREERDP_CODEC_COLOR_H
25 #include <winpr/crt.h>
26 #include <freerdp/api.h>
33 #define FREERDP_PIXEL_FORMAT_TYPE_A 0
34 #define FREERDP_PIXEL_FORMAT_TYPE_ARGB 1
35 #define FREERDP_PIXEL_FORMAT_TYPE_ABGR 2
36 #define FREERDP_PIXEL_FORMAT_TYPE_RGBA 3
37 #define FREERDP_PIXEL_FORMAT_TYPE_BGRA 4
39 #define FREERDP_PIXEL_FORMAT_IS_ABGR(_format) \
40 (FREERDP_PIXEL_FORMAT_TYPE(_format) == FREERDP_PIXEL_FORMAT_TYPE_ABGR)
43 enum FREERDP_IMAGE_FLAGS
45 FREERDP_FLIP_NONE = 0,
46 FREERDP_FLIP_VERTICAL = 1,
47 FREERDP_FLIP_HORIZONTAL = 2,
48 FREERDP_KEEP_DST_ALPHA = 4
51 #define FREERDP_PIXEL_FORMAT(_bpp, _type, _a, _r, _g, _b) \
52 ((_bpp << 24) | (_type << 16) | (_a << 12) | (_r << 8) | (_g << 4) | (_b))
54 #define FREERDP_PIXEL_FORMAT_TYPE(_format) (((_format) >> 16) & 0x07)
75 #define PIXEL_FORMAT_ARGB32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 8, 8, 8, 8)
76 #define PIXEL_FORMAT_XRGB32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 8, 8, 8)
77 #define PIXEL_FORMAT_ABGR32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 8, 8, 8, 8)
78 #define PIXEL_FORMAT_XBGR32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 8, 8, 8)
79 #define PIXEL_FORMAT_BGRA32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_BGRA, 8, 8, 8, 8)
80 #define PIXEL_FORMAT_BGRX32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_BGRA, 0, 8, 8, 8)
81 #define PIXEL_FORMAT_RGBA32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_RGBA, 8, 8, 8, 8)
82 #define PIXEL_FORMAT_RGBX32 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_RGBA, 0, 8, 8, 8)
83 #define PIXEL_FORMAT_BGRX32_DEPTH30 \
84 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_BGRA, 0, 10, 10, 10)
85 #define PIXEL_FORMAT_RGBX32_DEPTH30 \
86 FREERDP_PIXEL_FORMAT(32, FREERDP_PIXEL_FORMAT_TYPE_RGBA, 0, 10, 10, 10)
89 #define PIXEL_FORMAT_RGB24 FREERDP_PIXEL_FORMAT(24, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 8, 8, 8)
90 #define PIXEL_FORMAT_BGR24 FREERDP_PIXEL_FORMAT(24, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 8, 8, 8)
93 #define PIXEL_FORMAT_RGB16 FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 5, 6, 5)
94 #define PIXEL_FORMAT_BGR16 FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 5, 6, 5)
95 #define PIXEL_FORMAT_ARGB15 FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 1, 5, 5, 5)
96 #define PIXEL_FORMAT_RGB15 FREERDP_PIXEL_FORMAT(15, FREERDP_PIXEL_FORMAT_TYPE_ARGB, 0, 5, 5, 5)
97 #define PIXEL_FORMAT_ABGR15 FREERDP_PIXEL_FORMAT(16, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 1, 5, 5, 5)
98 #define PIXEL_FORMAT_BGR15 FREERDP_PIXEL_FORMAT(15, FREERDP_PIXEL_FORMAT_TYPE_ABGR, 0, 5, 5, 5)
101 #define PIXEL_FORMAT_RGB8 FREERDP_PIXEL_FORMAT(8, FREERDP_PIXEL_FORMAT_TYPE_A, 8, 0, 0, 0)
104 #define PIXEL_FORMAT_A4 FREERDP_PIXEL_FORMAT(4, FREERDP_PIXEL_FORMAT_TYPE_A, 4, 0, 0, 0)
107 #define PIXEL_FORMAT_MONO FREERDP_PIXEL_FORMAT(1, FREERDP_PIXEL_FORMAT_TYPE_A, 1, 0, 0, 0)
120 FREERDP_API DWORD FreeRDPAreColorFormatsEqualNoAlpha(DWORD first, DWORD second);
132 #if defined(WITH_FREERDP_DEPRECATED)
133 #define GetColorFormatName(...) FreeRDPGetColorFormatName(__VA_ARGS__)
135 FREERDP_API
const char* FreeRDPGetColorFormatName(UINT32 format);
150 #if defined(WITH_FREERDP_DEPRECATED)
151 #define SplitColor(...) FreeRDPSplitColor(__VA_ARGS__)
153 FREERDP_API
void FreeRDPSplitColor(UINT32 color, UINT32 format, BYTE* _r, BYTE* _g, BYTE* _b,
154 BYTE* _a,
const gdiPalette* palette);
169 #if defined(WITH_FREERDP_DEPRECATED)
170 #define GetColor(...) FreeRDPGetColor(__VA_ARGS__)
172 FREERDP_API UINT32 FreeRDPGetColor(UINT32 format, BYTE r, BYTE g, BYTE b, BYTE a);
182 #if defined(WITH_FREERDP_DEPRECATED)
183 #define GetBitsPerPixel(...) FreeRDPGetBitsPerPixel(__VA_ARGS__)
185 static INLINE UINT32 FreeRDPGetBitsPerPixel(UINT32 format)
187 return (((format) >> 24) & 0x3F);
195 #if defined(WITH_FREERDP_DEPRECATED)
196 #define ColorHasAlpha(...) FreeRDPColorHasAlpha(__VA_ARGS__)
198 static INLINE BOOL FreeRDPColorHasAlpha(UINT32 format)
200 UINT32 alpha = (((format) >> 12) & 0x0F);
217 #if defined(WITH_FREERDP_DEPRECATED)
218 #define ReadColor(...) FreeRDPReadColor(__VA_ARGS__)
220 FREERDP_API UINT32 FreeRDPReadColor(
const BYTE* WINPR_RESTRICT src, UINT32 format);
232 #if defined(WITH_FREERDP_DEPRECATED)
233 #define WriteColor(...) FreeRDPWriteColor(__VA_ARGS__)
234 #define WriteColorIgnoreAlpha(...) FreeRDPWriteColorIgnoreAlpha(__VA_ARGS__)
236 FREERDP_API BOOL FreeRDPWriteColor(BYTE* WINPR_RESTRICT dst, UINT32 format, UINT32 color);
237 FREERDP_API BOOL FreeRDPWriteColorIgnoreAlpha(BYTE* WINPR_RESTRICT dst, UINT32 format,
252 #if defined(WITH_FREERDP_DEPRECATED)
253 #define ConvertColor(...) FreeRDPConvertColor(__VA_ARGS__)
255 static INLINE UINT32 FreeRDPConvertColor(UINT32 color, UINT32 srcFormat, UINT32 dstFormat,
256 const gdiPalette* palette)
262 FreeRDPSplitColor(color, srcFormat, &r, &g, &b, &a, palette);
263 return FreeRDPGetColor(dstFormat, r, g, b, a);
274 #if defined(WITH_FREERDP_DEPRECATED)
275 #define GetBytesPerPixel(...) FreeRDPGetBytesPerPixel(__VA_ARGS__)
277 static INLINE UINT32 FreeRDPGetBytesPerPixel(UINT32 format)
279 return (FreeRDPGetBitsPerPixel(format) + 7) / 8;
291 WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
292 FREERDP_API BYTE* freerdp_glyph_convert(UINT32 width, UINT32 height,
293 const BYTE* WINPR_RESTRICT data);
311 FREERDP_API BOOL freerdp_image_copy_from_monochrome(
312 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep, UINT32 nXDst,
313 UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData,
314 UINT32 backColor, UINT32 foreColor, const gdiPalette* WINPR_RESTRICT palette);
335 FREERDP_API BOOL freerdp_image_copy_from_icon_data(
336 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep, UINT32 nXDst,
337 UINT32 nYDst, UINT16 nWidth, UINT16 nHeight, const BYTE* WINPR_RESTRICT bitsColor,
338 UINT16 cbBitsColor, const BYTE* WINPR_RESTRICT bitsMask, UINT16 cbBitsMask,
339 const BYTE* WINPR_RESTRICT colorTable, UINT16 cbColorTable, UINT32 bpp);
359 FREERDP_API BOOL freerdp_image_copy_from_pointer_data(
360 BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep, UINT32 nXDst,
361 UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT xorMask,
362 UINT32 xorMaskLength, const BYTE* WINPR_RESTRICT andMask, UINT32 andMaskLength,
363 UINT32 xorBpp, const gdiPalette* WINPR_RESTRICT palette);
385 FREERDP_API BOOL freerdp_image_copy(BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep,
386 UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight,
387 const BYTE* pSrcData, DWORD SrcFormat, UINT32 nSrcStep,
388 UINT32 nXSrc, UINT32 nYSrc,
389 const gdiPalette* WINPR_RESTRICT palette, UINT32 flags);
395 FREERDP_API BOOL freerdp_image_copy_overlap(
396 BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth,
397 UINT32 nHeight, const BYTE* pSrcData, DWORD SrcFormat, UINT32 nSrcStep, UINT32 nXSrc,
398 UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette, UINT32 flags);
403 FREERDP_API BOOL freerdp_image_copy_no_overlap(
404 BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
405 UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
406 UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette,
428 FREERDP_API BOOL freerdp_image_scale(BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat,
429 UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
430 UINT32 nDstWidth, UINT32 nDstHeight,
431 const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
432 UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
433 UINT32 nSrcWidth, UINT32 nSrcHeight);
449 FREERDP_API BOOL freerdp_image_fill(BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat,
450 UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth,
451 UINT32 nHeight, UINT32 color);