aboutsummaryrefslogtreecommitdiffstats
path: root/vxd_color.h
blob: 7b9ecf0d8968bc512f64309a5a1fa6437a086f7b (plain) (blame)
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
#ifndef __VXD_COLOR_H__INCLUDED__
#define __VXD_COLOR_H__INCLUDED__

DWORD palette_emulation[256] = {0};

static inline void blit16(
	void *src, DWORD src_pitch,
	void *dst, DWORD dst_pitch,
	DWORD blit_x, DWORD blit_y, DWORD blit_w, DWORD blit_h)
{
	const DWORD bottom = blit_y+blit_h;
	DWORD x, y;
	for(y = blit_y; y < bottom; y++)
	{
		WORD *src_ptr = ((WORD*)(((BYTE*)src) + src_pitch*y))+blit_x;
		DWORD *dst_ptr = ((DWORD*)(((BYTE*)dst) + dst_pitch*y))+blit_x;		
		
		for(x = 0; x < blit_w; x++)
		{
			DWORD px = *src_ptr;
			*dst_ptr = ((px & 0xF800) << 8) | ((px & 0x07E0) << 5) | ((px & 0x001F) << 3);
			src_ptr++;
			dst_ptr++;
		}
	}
}

static inline void blit8(
	void *src, DWORD src_pitch,
	void *dst, DWORD dst_pitch,
	DWORD blit_x, DWORD blit_y, DWORD blit_w, DWORD blit_h)
{
	const DWORD bottom = blit_y+blit_h;
	DWORD x, y;
	for(y = blit_y; y < bottom; y++)
	{
		BYTE *src_ptr = (((BYTE*)src) + src_pitch*y)+blit_x;
		DWORD *dst_ptr = ((DWORD*)(((BYTE*)dst) + dst_pitch*y))+blit_x;		
		
		for(x = 0; x < blit_w; x++)
		{
			*dst_ptr = palette_emulation[*src_ptr];
			src_ptr++;
			dst_ptr++;
		}
	}
}

static inline void readback16(
	void *src, DWORD src_pitch,
	void *dst, DWORD dst_pitch,
	DWORD blit_x, DWORD blit_y, DWORD blit_w, DWORD blit_h)
{
	const DWORD bottom = blit_y+blit_h;
	DWORD x, y;
	for(y = blit_y; y < bottom; y++)
	{
		DWORD *src_ptr = ((DWORD*)(((BYTE*)src) + src_pitch*y))+blit_x;
		WORD  *dst_ptr =  ((WORD*)(((BYTE*)dst) + dst_pitch*y))+blit_x;		
		
		for(x = 0; x < blit_w; x++)
		{
			DWORD px = *src_ptr;
			*dst_ptr = ((px & 0xF80000) >> 8) | ((px & 0xFC00) >> 5) | ((px & 0x00F8) >> 3);
			src_ptr++;
			dst_ptr++;
		}
	}
}

#endif /* __VXD_COLOR_H__INCLUDED__ */