1 /*
2 * graph_cg.c surface �� �ºݤ�cg�ǡ���������
3 *
4 * Copyright (C) 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp>
5 * 1998- <masaki-c@is.aist-nara.ac.jp>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22 /* $Id: graph_cg.c,v 1.2 2003/08/30 21:29:16 chikama Exp $ */
23
24 #include "config.h"
25
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include "portab.h"
30 #include "surface.h"
31 #include "cg.h"
32 #include "ags.h"
33 #include "ngraph.h"
34
35 /**
36 * surface �� 24bpp CG (QNT)������
37 *
38 * @param ds: ���� surface
39 * @param cg: ���褹��CG�ǡ���
40 * @param x: ����غ�ɸ
41 * @param y: ����ٺ�ɸ
42 */
gr_drawimage24(surface_t * ds,cgdata * cg,int x,int y)43 void gr_drawimage24(surface_t *ds, cgdata *cg, int x, int y) {
44 int dx, dy, dw, dh;
45 BYTE *sp, *dp, r, g, b;
46
47 dx = x;
48 dy = y;
49 dw = cg->width;
50 dh = cg->height;
51
52 if (!gr_clip_xywh(ds, &dx, &dy, &dw, &dh)) return;
53
54 cg->data_offset = (abs(dy - y) * cg->width + abs(dx - x)) * 3;
55
56 sp = (BYTE *)(cg->pic + cg->data_offset);
57 dp = GETOFFSET_PIXEL(ds, dx, dy);
58
59 switch(ds->depth) {
60 case 15:
61 {
62 WORD *yl;
63
64 for (y = 0; y < dh; y++) {
65 yl = (WORD *)(dp + y * ds->bytes_per_line);
66 for (x = 0; x < dw; x++) {
67 r = *sp;
68 g = *(sp +1);
69 b = *(sp +2);
70 *yl = PIX15(r, g, b);
71 yl++; sp += 3;
72 }
73 sp += ((cg->width - dw) * 3);
74 }
75 break;
76 }
77 case 16:
78 {
79 WORD *yl;
80
81 for (y = 0; y < dh; y++) {
82 yl = (WORD *)(dp + y * ds->bytes_per_line);
83 for (x = 0; x < dw; x++) {
84 r = *sp;
85 g = *(sp +1);
86 b = *(sp +2);
87 *yl = PIX16(r, g, b);
88 yl++; sp += 3;
89 }
90 sp += ((cg->width - dw) * 3);
91 }
92 break;
93
94 }
95 case 24:
96 case 32:
97 {
98 DWORD *yl;
99
100 for (y = 0; y < dh; y++) {
101 yl = (DWORD *)(dp + y * ds->bytes_per_line);
102 for (x = 0; x < dw; x++) {
103 r = *sp;
104 g = *(sp +1);
105 b = *(sp +2);
106 *yl = PIX24(r, g, b);
107 yl++; sp += 3;
108 }
109 sp += ((cg->width - dw) * 3);
110 }
111 break;
112 }}
113 }
114
115 /**
116 * surface �� 16bpp CG (PMS16/BMP)������
117 *
118 * @param ds: ���� surface
119 * @param cg: ���褹��CG�ǡ���
120 * @param x: ����غ�ɸ
121 * @param y: ����ٺ�ɸ
122 */
gr_drawimage16(surface_t * ds,cgdata * cg,int x,int y)123 void gr_drawimage16(surface_t *ds, cgdata *cg, int x, int y) {
124 int dx, dy, dw, dh;
125 BYTE *dp;
126 WORD pic16, *sp;
127
128 dx = x;
129 dy = y;
130 dw = cg->width;
131 dh = cg->height;
132
133 if (!gr_clip_xywh(ds, &dx, &dy, &dw, &dh)) return;
134
135 cg->data_offset = (abs(dy - y) * cg->width + abs(dx - x)) * 2;
136
137 sp = (WORD *)(cg->pic + cg->data_offset);
138 dp = GETOFFSET_PIXEL(ds, dx, dy);
139
140 switch(ds->depth) {
141 case 15:
142 {
143 WORD *yl;
144
145 for (y = 0; y < dh; y++) {
146 yl = (WORD *)(dp + y * ds->bytes_per_line);
147 for (x = 0; x < dw; x++) {
148 pic16 = *sp;
149 *yl = PIX15(RGB_PIXR16(pic16), RGB_PIXG16(pic16), RGB_PIXB16(pic16));
150 yl++; sp ++;
151 }
152 sp += (cg->width - dw);
153 }
154 break;
155 }
156 case 16:
157 {
158 for (y = 0; y < dh; y++) {
159 memcpy(dp, sp, dw * 2);
160 sp += cg->width;
161 dp += ds->bytes_per_line;
162 }
163 break;
164
165 }
166 case 24:
167 case 32:
168 {
169 DWORD *yl;
170
171 for (y = 0; y < dh; y++) {
172 yl = (DWORD *)(dp + y * ds->bytes_per_line);
173 for (x = 0; x < dw; x++) {
174 pic16 = *sp;
175 *yl = PIX24(RGB_PIXR16(pic16), RGB_PIXG16(pic16), RGB_PIXB16(pic16));
176 yl++; sp++;
177 }
178 sp += (cg->width - dw);
179 }
180 break;
181 }}
182 }
183