Skip to content

Commit 9268cee

Browse files
committed
[server,shadow] shadow_subsystem_pointer_convert_alpha_pointer_data
the function uses implicit color formats. Replace this with the function shadow_subsystem_pointer_convert_alpha_pointer_data_to_format with explicit source color format. Deprecate the old function.
1 parent fe149f3 commit 9268cee

File tree

3 files changed

+32
-20
lines changed

3 files changed

+32
-20
lines changed

include/freerdp/server/shadow.h

+9-3
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,15 @@ extern "C"
302302
FREERDP_API void shadow_subsystem_set_entry_builtin(const char* name);
303303
FREERDP_API void shadow_subsystem_set_entry(pfnShadowSubsystemEntry pEntry);
304304

305-
FREERDP_API int shadow_subsystem_pointer_convert_alpha_pointer_data(
306-
BYTE* pixels, BOOL premultiplied, UINT32 width, UINT32 height,
307-
SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* pointerColor);
305+
FREERDP_API WINPR_DEPRECATED_VAR(
306+
"Use shadow_subsystem_pointer_convert_alpha_pointer_data_to_format instead",
307+
int shadow_subsystem_pointer_convert_alpha_pointer_data(
308+
const BYTE* WINPR_RESTRICT pixels, BOOL premultiplied, UINT32 width, UINT32 height,
309+
SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* WINPR_RESTRICT pointerColor));
310+
311+
FREERDP_API int shadow_subsystem_pointer_convert_alpha_pointer_data_to_format(
312+
const BYTE* WINPR_RESTRICT pixels, UINT32 format, BOOL premultiplied, UINT32 width,
313+
UINT32 height, SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* WINPR_RESTRICT pointerColor);
308314

309315
FREERDP_API int shadow_server_parse_command_line(rdpShadowServer* server, int argc, char** argv,
310316
COMMAND_LINE_ARGUMENT_A* cargs);

server/shadow/X11/x11_shadow.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,8 @@ static int x11_shadow_pointer_alpha_update(x11ShadowSubsystem* subsystem)
463463
msg->width = subsystem->cursorWidth;
464464
msg->height = subsystem->cursorHeight;
465465

466-
if (shadow_subsystem_pointer_convert_alpha_pointer_data(subsystem->cursorPixels, TRUE,
467-
msg->width, msg->height, msg) < 0)
466+
if (shadow_subsystem_pointer_convert_alpha_pointer_data_to_format(
467+
subsystem->cursorPixels, subsystem->format, TRUE, msg->width, msg->height, msg) < 0)
468468
{
469469
free(msg);
470470
return -1;

server/shadow/shadow_subsystem.c

+21-15
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,23 @@ UINT32 shadow_enum_monitors(MONITOR_DEF* monitors, UINT32 maxMonitors)
190190
* Caller should free the andMaskData and xorMaskData later.
191191
*/
192192
int shadow_subsystem_pointer_convert_alpha_pointer_data(
193-
BYTE* pixels, BOOL premultiplied, UINT32 width, UINT32 height,
193+
const BYTE* WINPR_RESTRICT pixels, BOOL premultiplied, UINT32 width, UINT32 height,
194+
SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* WINPR_RESTRICT pointerColor)
195+
{
196+
return shadow_subsystem_pointer_convert_alpha_pointer_data_to_format(
197+
pixels, PIXEL_FORMAT_BGRX32, premultiplied, width, height, pointerColor);
198+
}
199+
200+
int shadow_subsystem_pointer_convert_alpha_pointer_data_to_format(
201+
const BYTE* pixels, UINT32 format, BOOL premultiplied, UINT32 width, UINT32 height,
194202
SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* pointerColor)
195203
{
196-
BYTE* pSrc8 = NULL;
197-
BYTE* pDst8 = NULL;
198204
UINT32 xorStep = 0;
199205
UINT32 andStep = 0;
200206
UINT32 andBit = 0;
201207
BYTE* andBits = NULL;
202208
UINT32 andPixel = 0;
203-
BYTE A = 0;
204-
BYTE R = 0;
205-
BYTE G = 0;
206-
BYTE B = 0;
209+
const size_t bpp = FreeRDPGetBytesPerPixel(format);
207210

208211
xorStep = (width * 3);
209212
xorStep += (xorStep % 2);
@@ -227,20 +230,23 @@ int shadow_subsystem_pointer_convert_alpha_pointer_data(
227230
return -1;
228231
}
229232

230-
for (UINT32 y = 0; y < height; y++)
233+
for (size_t y = 0; y < height; y++)
231234
{
232-
pSrc8 = &pixels[(width * 4) * (height - 1 - y)];
233-
pDst8 = &(pointerColor->xorMaskData[y * xorStep]);
235+
const BYTE* pSrc8 = &pixels[(width * bpp) * (height - 1 - y)];
236+
BYTE* pDst8 = &(pointerColor->xorMaskData[y * xorStep]);
234237

235238
andBit = 0x80;
236239
andBits = &(pointerColor->andMaskData[andStep * y]);
237240

238-
for (UINT32 x = 0; x < width; x++)
241+
for (size_t x = 0; x < width; x++)
239242
{
240-
B = *pSrc8++;
241-
G = *pSrc8++;
242-
R = *pSrc8++;
243-
A = *pSrc8++;
243+
BYTE B = 0;
244+
BYTE G = 0;
245+
BYTE R = 0;
246+
BYTE A = 0;
247+
248+
const UINT32 color = FreeRDPReadColor(&pSrc8[x * bpp], format);
249+
FreeRDPSplitColor(color, format, &R, &G, &B, &A, NULL);
244250

245251
andPixel = 0;
246252

0 commit comments

Comments
 (0)