File: graph_fillrect.c

package info (click to toggle)
xsystem35 1.7.3-pre5-5
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 7,308 kB
  • ctags: 5,685
  • sloc: ansic: 51,002; sh: 11,898; asm: 863; makefile: 407; xml: 281; perl: 142
file content (63 lines) | stat: -rw-r--r-- 942 bytes parent folder | download | duplicates (4)
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
// fill rectangle

#include <string.h>
#include "portab.h"
#include "surface.h"
#include "ngraph.h"
#include "ags.h"

int gr_fill(surface_t *dst, int dx, int dy, int dw, int dh, int r, int g, int b) {
	BYTE *dp, *dp_;
	int x, y;
	
	if (!gr_clip_xywh(dst, &dx, &dy, &dw, &dh)) {
		return NG;
	}
	
	dp = dp_ = GETOFFSET_PIXEL(dst, dx, dy);
	
	switch(dst->depth) {
	case 8:
		memset(dp, r, dw);
		break;
		
	case 15:
	{
		WORD pic15 = PIX15(r, g, b);
		
		for (x = 0; x < dw; x++) {
			*((WORD *)dp + x) = pic15;
		}
		break;
	}
	case 16:
	{
		WORD pic16 = PIX16(r, g, b);
		
		for (x = 0; x < dw; x++) {
			*((WORD *)dp + x) = pic16;
		}
		
		break;
	}
	case 24:
	case 32:
	{
		DWORD pic24 = PIX24(r, g, b);
		
		for (x = 0; x < dw; x++) {
			*((DWORD *)dp + x) = pic24;
		}
		
		break;
	}
	}
	
	dp += dst->bytes_per_line;
	for (y = 1; y < dh; y++) {
		memcpy(dp, dp_, dw * dst->bytes_per_pixel);
		dp += dst->bytes_per_line;
	}

	return OK;
}