1 #include "config.h"
2
3 #include <stdio.h>
4 #include <glib.h>
5 #include <string.h>
6
7 #include "portab.h"
8 #include "system.h"
9 #include "surface.h"
10 #include "graph.h"
11 #include "ngraph.h"
12 #include "nact.h"
13
14 /*
15 gr_xxxx �ϥ���åԥ���
16 gre_xxxx �ϥ���åԥʤ�
17 */
18
19 #undef WARNING
20 #define WARNING //
21
22 #undef NOTICE
23 #define NOTICE //
24
25
26 /**
27 * surface ���� surface �˥��ԡ��ʤɤ�ݤˡ�ž������ž�����surface
28 * ���礭���䡢ž������ž�����ɸ��ž�������ΰ���礭���ʤɤ��顢�ºݤ�
29 * ���ԡ������ΰ��åԥ���
30 *
31 * @param ss: ž����surface
32 * @param sx: ž�����غ�ɸ
33 * @param sy: ž�����ٺ�ɸ
34 * @param sw: ž����
35 * @param sh: ž���⤵
36 * @param ds: ž����surface
37 * @param dx: ž����غ�ɸ
38 * @param dy: ž����ٺ�ɸ
39 * @return TRUE -> �����ΰ褬����
40 * FALSE-> ž���ΰ�ι⤵���������ʲ��ˤʤä��ꡢž������ž����κ�ɸ��
41 * surface���ϰϳ��ˤʤꡢ�����ΰ褬�ʤ��ʤä���
42 * ���줾��ΰ�����Ŭ���ѹ�����Ƥ���
43 */
gr_clip(surface_t * ss,int * sx,int * sy,int * sw,int * sh,surface_t * ds,int * dx,int * dy)44 boolean gr_clip(surface_t *ss, int *sx, int *sy, int *sw, int *sh, surface_t *ds, int *dx, int *dy) {
45 int w, h;
46
47 if (ss == NULL) {
48 WARNING("ss surface is null\n");
49 return FALSE;
50 }
51 if (ss == NULL) {
52 WARNING("ss surface is null\n");
53 return FALSE;
54 }
55
56 if (*sx > ss->width) {
57 WARNING("sx is too large (sx=%d,width=%d)\n", *sx, ss->width);
58 return FALSE;
59 }
60 if (*sy > ss->height) {
61 WARNING("sy is too large (sy=%d,height=%d)\n", *sy, ss->height);
62 return FALSE;
63 }
64
65 if (*sx < 0) {
66 WARNING("sx is too small (sx=%d)\n", *sx);
67 return FALSE;
68 }
69 if (*sy < 0) {
70 WARNING("sy is too small (sy=%d)\n", *sy);
71 return FALSE;
72 }
73
74 if (*dx > ds->width) {
75 WARNING("dx is too large (dx=%d,width=%d)\n", *dx, ds->width);
76 return FALSE;
77 }
78 if (*dy > ds->height) {
79 WARNING("dy is too large (dy=%d,height=%d)\n", *dy, ds->height);
80 return FALSE;
81 }
82
83 w = *sw;
84 h = *sh;
85
86 if (*dx < 0) {
87 *sx -= *dx; *sw += *dx; *dx = 0;
88 }
89 if (*dy < 0) {
90 *sy -= *dy; *sh += *dy; *dy = 0;
91 }
92
93 *sw = MIN(ss->width - *sx, MIN(ds->width - *dx, *sw));
94 *sh = MIN(ss->height - *sy, MIN(ds->height - *dy, *sh));
95
96 if (*sw <= 0) {
97 WARNING("sw become <=0\n");
98 return FALSE;
99 }
100 if (*sh <= 0) {
101 WARNING("sh become <=0\n");
102 return FALSE;
103 }
104
105 if (*sw != w) {
106 NOTICE("width change %d -> %d\n", w, *sw);
107 }
108 if (*sh != h) {
109 NOTICE("height change %d -> %d\n", h, *sh);
110 }
111
112 return TRUE;
113 }
114
115 /**
116 * surface ��������Ԥ��ݤˡ�surface ���礭���������ΰ��åԥ���
117 *
118 * @param ss: ����surface
119 * @param sx: ���賫�ϣغ�ɸ
120 * @param sy: ���賫�ϣٺ�ɸ
121 * @param sw: ������
122 * @param sh: ����⤵
123 * @return TRUE -> �����ΰ褬����
124 * FALSE-> �����ΰ�ι⤵���������ʲ��ˤʤä��ꡢ���賫�Ϻ�ɸ��
125 * surface���ϰϳ��ˤʤꡢ�����ΰ褬�ʤ��ʤä���
126 * ���줾��ΰ�����Ŭ���ѹ�����Ƥ���
127 */
gr_clip_xywh(surface_t * ss,int * sx,int * sy,int * sw,int * sh)128 boolean gr_clip_xywh(surface_t *ss, int *sx, int *sy, int *sw, int *sh) {
129 int w, h;
130
131 if (ss == NULL) {
132 WARNING("ss surface is null\n");
133 return FALSE;
134 }
135
136 if (*sx > ss->width) {
137 WARNING("sx is too large (sx=%d,width=%d)\n", *sx, ss->width);
138 return FALSE;
139 }
140 if (*sy > ss->height) {
141 WARNING("sy is too large (sy=%d,height=%d)\n", *sy, ss->height);
142 return FALSE;
143 }
144
145 w = *sw;
146 h = *sh;
147
148 if (*sx < 0) {
149 *sw += *sx; *sx = 0;
150 }
151 if (*sy < 0) {
152 *sh += *sy; *sy = 0;
153 }
154
155 *sw = MIN(ss->width - *sx, *sw);
156 *sh = MIN(ss->height - *sy, *sh);
157
158 if (*sw <= 0) {
159 WARNING("sw become <=0\n");
160 return FALSE;
161 }
162 if (*sh <= 0) {
163 WARNING("sh become <=0\n");
164 return FALSE;
165 }
166
167 if (*sw != w) {
168 NOTICE("width change %d -> %d\n", w, *sw);
169 }
170 if (*sh != h) {
171 NOTICE("height change %d -> %d\n", h, *sh);
172 }
173
174 return TRUE;
175 }
176
gr_init()177 void gr_init() {
178 }
179
180
gr_blend(surface_t * dst,int dx,int dy,surface_t * src,int sx,int sy,int width,int height,int lv)181 void gr_blend(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int width, int height, int lv) {
182
183
184 }
185
gr_blend_src_bright(surface_t * dst,int dx,int dy,surface_t * src,int sx,int sy,int width,int height,int alpha,int rate)186 void gr_blend_src_bright(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int width, int height, int alpha, int rate) {
187 }
188
gr_blend_add_satur(surface_t * dst,int dx,int dy,surface_t * src,int sx,int sy,int width,int height)189 void gr_blend_add_satur(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int width, int height) {
190 }
191
192
gr_blend_alpha_map_src_only(surface_t * dst,int dx,int dy,surface_t * src,int sx,int sy,int width,int height)193 void gr_blend_alpha_map_src_only(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int width, int height) {
194 // Dest Pixel = Blend(DestPixel, SrcPixel, SrcAlphaMap);
195 }
196
gr_blend_alpha_map_color(surface_t * dst,int dx,int dy,surface_t * src,int sx,int sy,int width,int height,int r,int g,int b)197 void gr_blend_alpha_map_color(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int width, int height, int r, int g, int b) {
198 // Dest Pixel = Blend(DestPixel, Color, SrcAlphaMap);
199 }
200
gr_blend_alpha_map_color_alpha(surface_t * dst,int dx,int dy,surface_t * src,int sx,int sy,int width,int height,int r,int g,int b,int rate)201 void gr_blend_alpha_map_color_alpha(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int width, int height, int r, int g, int b, int rate) {
202 // Dest Pixel = Blend(DestPixel, Color, SrcAlphaMap x rate);
203 }
204
gr_blend_alpha_map_alpha(surface_t * dst,int dx,int dy,surface_t * src,int sx,int sy,int width,int height,int rate)205 void gr_blend_alpha_map_alpha(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int width, int height, int rate) {
206 // Dest Pixel = Blend(DestPixel, SrcPixel, SrcAlphaMap x rate);
207 }
208
gr_blend_alpha_map_bright(surface_t * dst,int dx,int dy,surface_t * src,int sx,int sy,int width,int height,int lv)209 void gr_blend_alpha_map_bright(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int width, int height, int lv) {
210 // Dest Pixel = Blend(DestPixel, SrcPixel x lv, SrcAlphaMap);
211 }
212
gr_blend_alpha_map_alpha_src_bright(surface_t * dst,int dx,int dy,surface_t * src,int sx,int sy,int width,int height,int rate,int lv)213 void gr_blend_alpha_map_alpha_src_bright(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int width, int height, int rate, int lv) {
214 // Dest Pixel = Blend(DestPixel, SrcPixel x lv, SrcAlphaMap x rate);
215 }
216
gr_blend_use_amap_color(surface_t * dst,int dx,int dy,int width,int height,surface_t * alpha,int ax,int ay,int r,int g,int b,int rate)217 void gr_blend_use_amap_color(surface_t *dst, int dx, int dy, int width, int height, surface_t *alpha, int ax, int ay, int r, int g, int b, int rate) {
218 }
219
gr_blend_multiply(surface_t * dst,int dx,int dy,surface_t * src,int sx,int sy,int w,int h)220 void gr_blend_multiply(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int w, int h) {
221 }
222
gr_blend_screen_alpha(surface_t * dst,int dx,int dy,surface_t * src,int sx,int sy,int w,int h,int rate)223 void gr_blend_screen_alpha(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int w, int h, int rate) {
224 // Screen x rate
225 }
226
227
gr_screen_DA_DAxSA(surface_t * dst,int dx,int dy,surface_t * src,int sx,int sy,int width,int height)228 void gr_screen_DA_DAxSA(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int width, int height) {
229 // DestAlpha = Screen(DestAlpha, SrcAlpha);
230 }
231
gr_add_DA_DAxSA(surface_t * dst,int dx,int dy,surface_t * src,int sx,int sy,int width,int height)232 void gr_add_DA_DAxSA(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int width, int height) {
233 // Dest Alpha = Satur(DestAlpha + SrcAlpha);
234 }
235
gr_copy_texture_wrap()236 void gr_copy_texture_wrap() {
237 }
238
gr_copy_texture_wrap_alpha()239 void gr_copy_texture_wrap_alpha() {
240 }
241
gr_copy_stretch_blend()242 void gr_copy_stretch_blend() {
243 }
244
gr_copy_stretch_blend_alpha_map(surface_t * dst,int dx,int dy,int dw,int dh,surface_t * src,int sx,int sy,int sw,int sh)245 void gr_copy_stretch_blend_alpha_map(surface_t *dst, int dx, int dy, int dw, int dh, surface_t *src, int sx, int sy, int sw, int sh) {
246 float a1, a2, xd, yd;
247 int *row, *col;
248 int x, y;
249 BYTE *sp, *dp, *sa;
250
251 if (!gr_clip_xywh(dst, &dx, &dy, &dw, &dh)) return;
252 if (!gr_clip_xywh(src, &sx, &sy, &sw, &sh)) return;
253
254 sp = GETOFFSET_PIXEL(src, sx, sy);
255 dp = GETOFFSET_PIXEL(dst, dx, dy);
256 sa = GETOFFSET_ALPHA(src, sx, sy);
257
258 a1 = (float)sw / (float)dw;
259 a2 = (float)sh / (float)dh;
260 // src width �� dst width ��Ʊ���Ȥ������꤬����Τ�+1
261 row = g_new0(int, dw+1);
262 // 1�����������ƽ�������ʤ��� col[dw-1]��col[dw]��Ʊ���ˤʤ�
263 // ��ǽ�������롣
264 col = g_new0(int, dh+1);
265
266 for (yd = 0.0, y = 0; y < dh; y++) {
267 col[y] = yd; yd += a2;
268 }
269
270 for (xd = 0.0, x = 0; x < dw; x++) {
271 row[x] = xd; xd += a1;
272 }
273
274 switch(dst->depth) {
275 case 15:
276 {
277 WORD *yls, *yld;
278 BYTE *yla;
279
280 for (y = 0; y < dh; y++) {
281 yls = (WORD *)(sp + *(y + col) * src->bytes_per_line);
282 yld = (WORD *)(dp + y * dst->bytes_per_line);
283 yla = (BYTE *)(sa + *(y + col) * src->width);
284 for (x = 0; x < dw; x++) {
285 *(yld + x) = ALPHABLEND15(*(yls+ *(row + x)), *(yld+x), *(yla+*(row+x)));
286 }
287 while(*(col + y) == *(col + y + 1)) {
288 yld += dst->width;
289 for (x = 0; x < dw; x++) {
290 *(yld + x) = ALPHABLEND15(*(yls+ *(row+x)), *(yld+x), *(yla+*(row+x)));
291 }
292 y++;
293 }
294 }
295 break;
296 }
297 case 16:
298 {
299 WORD *yls, *yld;
300 BYTE *yla;
301
302 for (y = 0; y < dh; y++) {
303 yls = (WORD *)(sp + *(y + col) * src->bytes_per_line);
304 yld = (WORD *)(dp + y * dst->bytes_per_line);
305 yla = (BYTE *)(sa + *(y + col) * src->width);
306 for (x = 0; x < dw; x++) {
307 *(yld + x) = ALPHABLEND16(*(yls+ *(row + x)), *(yld+x), *(yla+*(row+x)));
308 }
309 while(*(col + y) == *(col + y + 1)) {
310 yld += dst->width;
311 for (x = 0; x < dw; x++) {
312 *(yld + x) = ALPHABLEND16(*(yls+ *(row+x)), *(yld+x), *(yla+*(row+x)));
313 }
314 y++;
315 }
316 }
317 break;
318 }
319 case 24:
320 case 32:
321 {
322 DWORD *yls, *yld;
323 BYTE *yla;
324
325 for (y = 0; y < dh; y++) {
326 yls = (DWORD *)(sp + *(y + col) * src->bytes_per_line);
327 yld = (DWORD *)(dp + y * dst->bytes_per_line);
328 yla = (BYTE *)(sa + *(y + col) * src->width);
329 for (x = 0; x < dw; x++) {
330 *(yld + x) = ALPHABLEND24(*(yls+ *(row + x)), *(yld+x), *(yla+*(row+x)));
331 }
332 while(*(col + y) == *(col + y + 1)) {
333 yld += dst->width;
334 for (x = 0; x < dw; x++) {
335 *(yld + x) = ALPHABLEND24(*(yls+ *(row+x)), *(yld+x), *(yla+*(row+x)));
336 }
337 y++;
338 }
339 }
340 break;
341 }
342 }
343
344 g_free(row);
345 g_free(col);
346 }
347
348 #include "graph2.c"
349