FreeRDP
Loading...
Searching...
No Matches
rdpgfx_common.c
1
22#include <freerdp/config.h>
23
24#include <winpr/crt.h>
25#include <winpr/assert.h>
26#include <winpr/stream.h>
27#include <freerdp/channels/log.h>
28
29#define TAG CHANNELS_TAG("rdpgfx.common")
30
31#include "rdpgfx_common.h"
32
38UINT rdpgfx_read_header(wStream* s, RDPGFX_HEADER* header)
39{
40 WINPR_ASSERT(s);
41 WINPR_ASSERT(header);
42
43 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
44 return CHANNEL_RC_NO_MEMORY;
45
46 Stream_Read_UINT16(s, header->cmdId); /* cmdId (2 bytes) */
47 Stream_Read_UINT16(s, header->flags); /* flags (2 bytes) */
48 Stream_Read_UINT32(s, header->pduLength); /* pduLength (4 bytes) */
49
50 if (header->pduLength < 8)
51 {
52 WLog_ERR(TAG, "header->pduLength %u less than 8!", header->pduLength);
53 return ERROR_INVALID_DATA;
54 }
55 if (!Stream_CheckAndLogRequiredLength(TAG, s, (header->pduLength - 8)))
56 return ERROR_INVALID_DATA;
57
58 return CHANNEL_RC_OK;
59}
60
66UINT rdpgfx_write_header(wStream* s, const RDPGFX_HEADER* header)
67{
68 WINPR_ASSERT(s);
69 WINPR_ASSERT(header);
70
71 if (!Stream_EnsureRemainingCapacity(s, 8))
72 return CHANNEL_RC_NO_MEMORY;
73 Stream_Write_UINT16(s, header->cmdId); /* cmdId (2 bytes) */
74 Stream_Write_UINT16(s, header->flags); /* flags (2 bytes) */
75 Stream_Write_UINT32(s, header->pduLength); /* pduLength (4 bytes) */
76 return CHANNEL_RC_OK;
77}
78
84UINT rdpgfx_read_point16(wStream* s, RDPGFX_POINT16* pt16)
85{
86 WINPR_ASSERT(s);
87 WINPR_ASSERT(pt16);
88
89 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
90 return ERROR_INVALID_DATA;
91
92 Stream_Read_UINT16(s, pt16->x); /* x (2 bytes) */
93 Stream_Read_UINT16(s, pt16->y); /* y (2 bytes) */
94 return CHANNEL_RC_OK;
95}
96
102UINT rdpgfx_write_point16(wStream* s, const RDPGFX_POINT16* point16)
103{
104 WINPR_ASSERT(s);
105 WINPR_ASSERT(point16);
106
107 if (!Stream_EnsureRemainingCapacity(s, 4))
108 return CHANNEL_RC_NO_MEMORY;
109
110 Stream_Write_UINT16(s, point16->x); /* x (2 bytes) */
111 Stream_Write_UINT16(s, point16->y); /* y (2 bytes) */
112 return CHANNEL_RC_OK;
113}
114
120UINT rdpgfx_read_rect16(wStream* s, RECTANGLE_16* rect16)
121{
122 WINPR_ASSERT(s);
123 WINPR_ASSERT(rect16);
124
125 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
126 return ERROR_INVALID_DATA;
127
128 Stream_Read_UINT16(s, rect16->left); /* left (2 bytes) */
129 Stream_Read_UINT16(s, rect16->top); /* top (2 bytes) */
130 Stream_Read_UINT16(s, rect16->right); /* right (2 bytes) */
131 Stream_Read_UINT16(s, rect16->bottom); /* bottom (2 bytes) */
132 if (rect16->left >= rect16->right)
133 return ERROR_INVALID_DATA;
134 if (rect16->top >= rect16->bottom)
135 return ERROR_INVALID_DATA;
136 return CHANNEL_RC_OK;
137}
138
144UINT rdpgfx_write_rect16(wStream* s, const RECTANGLE_16* rect16)
145{
146 WINPR_ASSERT(s);
147 WINPR_ASSERT(rect16);
148
149 if (!Stream_EnsureRemainingCapacity(s, 8))
150 return CHANNEL_RC_NO_MEMORY;
151
152 Stream_Write_UINT16(s, rect16->left); /* left (2 bytes) */
153 Stream_Write_UINT16(s, rect16->top); /* top (2 bytes) */
154 Stream_Write_UINT16(s, rect16->right); /* right (2 bytes) */
155 Stream_Write_UINT16(s, rect16->bottom); /* bottom (2 bytes) */
156 return CHANNEL_RC_OK;
157}
158
164UINT rdpgfx_read_color32(wStream* s, RDPGFX_COLOR32* color32)
165{
166 WINPR_ASSERT(s);
167 WINPR_ASSERT(color32);
168
169 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
170 return ERROR_INVALID_DATA;
171
172 Stream_Read_UINT8(s, color32->B); /* B (1 byte) */
173 Stream_Read_UINT8(s, color32->G); /* G (1 byte) */
174 Stream_Read_UINT8(s, color32->R); /* R (1 byte) */
175 Stream_Read_UINT8(s, color32->XA); /* XA (1 byte) */
176 return CHANNEL_RC_OK;
177}
178
184UINT rdpgfx_write_color32(wStream* s, const RDPGFX_COLOR32* color32)
185{
186 WINPR_ASSERT(s);
187 WINPR_ASSERT(color32);
188
189 if (!Stream_EnsureRemainingCapacity(s, 4))
190 return CHANNEL_RC_NO_MEMORY;
191
192 Stream_Write_UINT8(s, color32->B); /* B (1 byte) */
193 Stream_Write_UINT8(s, color32->G); /* G (1 byte) */
194 Stream_Write_UINT8(s, color32->R); /* R (1 byte) */
195 Stream_Write_UINT8(s, color32->XA); /* XA (1 byte) */
196 return CHANNEL_RC_OK;
197}