This repository was archived by the owner on Jul 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 905
/
Copy pathxf_decode.c
136 lines (113 loc) · 3.32 KB
/
xf_decode.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
FreeRDP: A Remote Desktop Protocol client.
UI decode
Copyright (C) Vic Lee 2011
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.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xf_types.h"
#include <freerdp/rfx.h>
#include <freerdp/utils/stream.h>
#include "xf_decode.h"
void
xf_decode_init(xfInfo * xfi)
{
switch (xfi->codec)
{
case XF_CODEC_REMOTEFX:
xfi->rfx_context = rfx_context_new();
break;
default:
break;
}
}
void
xf_decode_uninit(xfInfo * xfi)
{
if (xfi->rfx_context)
rfx_context_free((RFX_CONTEXT *) xfi->rfx_context);
}
static void
xf_decode_frame(xfInfo * xfi, int x, int y, uint8 * bitmapData, uint32 bitmapDataLength)
{
int i;
int tx, ty;
XImage * image;
RFX_MESSAGE * message;
switch (xfi->codec)
{
case XF_CODEC_REMOTEFX:
message = rfx_process_message((RFX_CONTEXT *) xfi->rfx_context, bitmapData, bitmapDataLength);
/* Clip the updated region based on the union of rects, so that pixels outside of the region will not be drawn. */
XSetFunction(xfi->display, xfi->gc, GXcopy);
XSetFillStyle(xfi->display, xfi->gc, FillSolid);
XSetClipRectangles(xfi->display, xfi->gc, x, y, (XRectangle*)message->rects, message->num_rects, YXBanded);
/* Draw the tiles to backstore, each is 64x64. */
for (i = 0; i < message->num_tiles; i++)
{
image = XCreateImage(xfi->display, xfi->visual, 24, ZPixmap, 0,
(char *) message->tiles[i]->data, 64, 64, 32, 0);
tx = message->tiles[i]->x + x;
ty = message->tiles[i]->y + y;
XPutImage(xfi->display, xfi->backstore, xfi->gc, image, 0, 0, tx, ty, 64, 64);
XFree(image);
}
/* Copy the updated region from backstore to the window. */
for (i = 0; i < message->num_rects; i++)
{
tx = message->rects[i].x + x;
ty = message->rects[i].y + y;
XCopyArea(xfi->display, xfi->backstore, xfi->wnd, xfi->gc_default,
tx, ty, message->rects[i].width, message->rects[i].height, tx, ty);
}
rfx_message_free(xfi->rfx_context, message);
XSetClipMask(xfi->display, xfi->gc, None);
break;
default:
printf("xf_decode_frame: no codec defined.\n");
break;
}
}
void
xf_decode_data(xfInfo * xfi, uint8 * data, int data_size)
{
uint16 cmdType;
uint32 bitmapDataLength;
int destLeft;
int destTop;
int size;
while (data_size > 0)
{
cmdType = GET_UINT16(data, 0);
switch (cmdType)
{
case CMDTYPE_SET_SURFACE_BITS:
case CMDTYPE_STREAM_SURFACE_BITS:
destLeft = GET_UINT16(data, 2);
destTop = GET_UINT16(data, 4);
bitmapDataLength = GET_UINT32(data, 18);
xf_decode_frame(xfi, destLeft, destTop, data + 22, bitmapDataLength);
size = 22 + bitmapDataLength;
break;
case CMDTYPE_FRAME_MARKER:
size = 8;
break;
default:
printf("xf_decode_data: unknown cmdType %d\n", cmdType);
size = 2;
break;
}
data_size -= size;
data += size;
}
}