File: graph_cg.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 (182 lines) | stat: -rw-r--r-- 3,850 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
 * graph_cg.c  surface  ºݤcgǡ
 *
 * Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
 *               1998-                           <masaki-c@is.aist-nara.ac.jp>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * 
*/
/* $Id: graph_cg.c,v 1.2 2003/08/30 21:29:16 chikama Exp $ */

#include "config.h"

#include <stdlib.h>
#include <string.h>

#include "portab.h"
#include "surface.h"
#include "cg.h"
#include "ags.h"
#include "ngraph.h"

/**
 * surface  24bpp CG (QNT)
 * 
 * @param ds:  surface
 * @param cg: 褹CGǡ
 * @param x: غɸ
 * @param y: ٺɸ
 */
void gr_drawimage24(surface_t *ds, cgdata *cg, int x, int y) {
	int dx, dy, dw, dh;
	BYTE *sp, *dp, r, g, b;
	
	dx = x;
	dy = y;
	dw = cg->width;
	dh = cg->height;

	if (!gr_clip_xywh(ds, &dx, &dy, &dw, &dh)) return;
	
	cg->data_offset = (abs(dy - y) * cg->width + abs(dx - x)) * 3;
	
	sp = (BYTE *)(cg->pic + cg->data_offset);
	dp = GETOFFSET_PIXEL(ds, dx, dy);
	
	switch(ds->depth) {
	case 15:
	{
		WORD *yl;
		
		for (y = 0; y < dh; y++) {
			yl = (WORD *)(dp + y * ds->bytes_per_line);
			for (x = 0; x < dw; x++) {
				r = *sp;
				g = *(sp +1);
				b = *(sp +2);
				*yl = PIX15(r, g, b);
				yl++; sp += 3;
			}
			sp += ((cg->width - dw) * 3);
		}
		break;
	}
	case 16:
	{
		WORD *yl;
		
		for (y = 0; y < dh; y++) {
			yl = (WORD *)(dp + y * ds->bytes_per_line);
			for (x = 0; x < dw; x++) {
				r = *sp;
				g = *(sp +1);
				b = *(sp +2);
				*yl = PIX16(r, g, b);
				yl++; sp += 3;
			}
			sp += ((cg->width - dw) * 3);
		}
		break;
		
	}
	case 24:
	case 32:
	{
		DWORD *yl;
		
		for (y = 0; y < dh; y++) {
			yl = (DWORD *)(dp + y * ds->bytes_per_line);
			for (x = 0; x < dw; x++) {
				r = *sp;
				g = *(sp +1);
				b = *(sp +2);
				*yl = PIX24(r, g, b);
				yl++; sp += 3;
			}
			sp += ((cg->width - dw) * 3);
		}
		break;
	}}
}

/**
 * surface  16bpp CG (PMS16/BMP)
 * 
 * @param ds:  surface
 * @param cg: 褹CGǡ
 * @param x: غɸ
 * @param y: ٺɸ
 */
void gr_drawimage16(surface_t *ds, cgdata *cg, int x, int y) {
	int dx, dy, dw, dh;
	BYTE *dp;
	WORD pic16, *sp;
	
	dx = x;
	dy = y;
	dw = cg->width;
	dh = cg->height;
	
	if (!gr_clip_xywh(ds, &dx, &dy, &dw, &dh)) return;
	
	cg->data_offset = (abs(dy - y) * cg->width + abs(dx - x)) * 2;
	
	sp = (WORD *)(cg->pic + cg->data_offset);
	dp = GETOFFSET_PIXEL(ds, dx, dy);
	
	switch(ds->depth) {
	case 15:
	{
		WORD *yl;
		
		for (y = 0; y < dh; y++) {
			yl = (WORD *)(dp + y * ds->bytes_per_line);
			for (x = 0; x < dw; x++) {
				pic16 = *sp;
				*yl = PIX15(RGB_PIXR16(pic16), RGB_PIXG16(pic16), RGB_PIXB16(pic16));
				yl++; sp ++;
			}
			sp += (cg->width - dw);
		}
		break;
	}
	case 16:
	{
		for (y = 0; y < dh; y++) {
			memcpy(dp, sp, dw * 2);
			sp += cg->width;
			dp += ds->bytes_per_line;
		}
		break;
		
	}
	case 24:
	case 32:
	{
		DWORD *yl;
		
		for (y = 0; y < dh; y++) {
			yl = (DWORD *)(dp + y * ds->bytes_per_line);
			for (x = 0; x < dw; x++) {
				pic16 = *sp;
				*yl = PIX24(RGB_PIXR16(pic16), RGB_PIXG16(pic16), RGB_PIXB16(pic16));
				yl++; sp++;
			}
			sp += (cg->width - dw);
		}
		break;
	}}
}