summaryrefslogtreecommitdiffstats
path: root/examples/rotatetemplate.c
blob: 0d7e007a147ec33ad34d0854bbc48a323f7fc29b (plain)
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
#define OUT_T CONCAT3E(uint,OUTBITS,_t)
#define FUNCTION CONCAT2E(FUNCNAME,OUTBITS)

static void FUNCTION(rfbScreenInfoPtr screen)
{
	OUT_T* buffer = (OUT_T*)screen->frameBuffer;
	int i, j, w = screen->width, h = screen->height;
	OUT_T* newBuffer = (OUT_T*)malloc(w * h * sizeof(OUT_T));

	for (j = 0; j < h; j++)
		for (i = 0; i < w; i++)
			newBuffer[FUNC(i, j)] = buffer[i + j * w];

	memcpy(buffer, newBuffer, w * h * sizeof(OUT_T));
	free(newBuffer);

#ifdef SWAPDIMENSIONS
	screen->width = h;
	screen->paddedWidthInBytes = h * OUTBITS / 8;
	screen->height = w;

	{
		rfbClientIteratorPtr iterator;
		rfbClientPtr cl;
		iterator = rfbGetClientIterator(screen);
		while ((cl = rfbClientIteratorNext(iterator)) != NULL)
			cl->newFBSizePending = 1;
	}
#endif

	rfbMarkRectAsModified(screen, 0, 0, screen->width, screen->height);
}

#if OUTBITS == 32
void FUNCNAME(rfbScreenInfoPtr screen) {
	if (screen->serverFormat.bitsPerPixel == 32)
		CONCAT2E(FUNCNAME,32)(screen);
	else if (screen->serverFormat.bitsPerPixel == 16)
		CONCAT2E(FUNCNAME,16)(screen);
	else if (screen->serverFormat.bitsPerPixel == 8)
		CONCAT2E(FUNCNAME,8)(screen);
	else {
		rfbErr("Unsupported pixel depth: %d\n",
			screen->serverFormat.bitsPerPixel);
		return;
	}
}
#endif

#undef FUNCTION
#undef OUTBITS