-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgist
88 lines (73 loc) · 2.46 KB
/
gist
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
VOID tf_save_dib(rdpContext* context, UINT32 width, UINT32 height,
UINT32 srcFormat, const BYTE* data, BYTE** pdata)
{
BITMAPINFOHEADER infoHeader;
BITMAPFILEHEADER fileHeader;
const int bits = GetBitsPerPixel(srcFormat);
const int bitPerPexcel = (bits / 8);
const int imageSize = ((width * bits + 31) & ~31) / 8 * height;
const int headerSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
infoHeader.biSize = sizeof(BITMAPINFOHEADER);
infoHeader.biWidth = width;
infoHeader.biHeight = -abs((int)height);
infoHeader.biPlanes = 1;
infoHeader.biBitCount = bits;
infoHeader.biCompression = BI_RGB;
infoHeader.biSizeImage = imageSize;
infoHeader.biXPelsPerMeter = 0;
infoHeader.biYPelsPerMeter = 0;
infoHeader.biClrUsed = 0;
infoHeader.biClrImportant = 0;
fileHeader.bfType = 0x4D42;//set the attribute of BITMAPFILEHEADER
fileHeader.bfSize = headerSize + imageSize;
fileHeader.bfReserved1 = 0;
fileHeader.bfReserved2 = 0;
fileHeader.bfOffBits = headerSize;
PCHAR imageData = (PCHAR)malloc(imageSize);
memcpy(imageData, data, width*height * 4);
TCHAR fileName[20];
wsprintf(fileName, TEXT("c://caps//%d.bmp"), index++);
HANDLE pFile = CreateFile(fileName,
GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
ULONG written;
WriteFile(pFile, &fileHeader, sizeof(BITMAPFILEHEADER), &written, NULL);
WriteFile(pFile, &infoHeader, sizeof(BITMAPINFOHEADER), &written, NULL);
WriteFile(pFile, imageData, imageSize, &written, NULL);
CloseHandle(pFile);
free(imageData);
}
static BOOL tf_end_paint(rdpContext* context)
{
rdpGdi* gdi = context->gdi;
if (gdi->primary->hdc->hwnd->invalid->null)
return TRUE;
draw_args *args = new draw_args;
args->x = 0;
args->y = 0;
args->w = gdi->width;
args->h = gdi->height;
args->bpp = 4;
int size = args->w * args->h * args->bpp;
args->buffer = new BYTE[size];
int dest_pos = 0;
for (int i = 0; i < args->h; i++) {
// memcopy only columns that are relevant
int start_pos = (i * gdi->width * args->bpp);
BYTE* src = &gdi->primary_buffer[start_pos];
BYTE* dest = &args->buffer[dest_pos];
for (int j = 0; j < args->w; j++) {
memcpy(dest + j * 4 + 0, src + j * 4 + 3, 1);
memcpy(dest + j * 4 + 1, src + j * 4 + 2, 1);
memcpy(dest + j * 4 + 2, src + j * 4 + 1, 1);
memcpy(dest + j * 4 + 3, src + j * 4 + 0, 1);
dest_pos += args->bpp;
}
}
tf_save_dib(context, args->w, args->h, context->gdi->dstFormat, args->buffer, NULL);
return TRUE;
}