1 /*
2  * graph_copy_amap.c  alpha map �Υ��ԡ�
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_copy_amap.c,v 1.2 2003/04/25 17:23:55 chikama Exp $ */
23 
24 #include <string.h>
25 
26 #include "portab.h"
27 #include "system.h"
28 #include "surface.h"
29 #include "ngraph.h"
30 #include "ags.h"
31 
32 /**
33  * ����� surface �� alphamap ���̤� surface �λ����ΰ�˥��ԡ�����
34  *
35  * @param dst: ž���� surface
36  * @param dx:  ž����غ�ɸ
37  * @param dy:  ž����ٺ�ɸ
38  * @param src: ž����surface
39  * @param sx:  ž�����غ�ɸ
40  * @param sy:  ž�����ٺ�ɸ
41  * @param sw:  ž����
42  * @param sh:  ž���⤵
43  */
gr_copy_alpha_map(surface_t * dst,int dx,int dy,surface_t * src,int sx,int sy,int sw,int sh)44 int gr_copy_alpha_map(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int sw, int sh) {
45 	BYTE *sp, *dp;
46 
47 	if (!gr_clip(src, &sx, &sy, &sw, &sh, dst, &dx, &dy)) return NG;
48 
49 	sp = GETOFFSET_ALPHA(src, sx, sy);
50 	dp = GETOFFSET_ALPHA(dst, dx, dy);
51 
52 	if (sp == NULL) {
53 		WARNING("src alpha NULL\n");
54 		return NG;
55 	}
56 
57 	if (dp == NULL) {
58 		WARNING("dst alpha NULL\n");
59 		return NG;
60 	}
61 
62 	if (src == dst) {
63 		if (sy <= dy && dy < (sy + sh)) {
64 			sp += (sh -1) * src->width;
65 			dp += (sh -1) * dst->width;
66 			while(sh--) {
67 				memmove(dp, sp, sw);
68 				sp -= src->width;
69 				dp -= dst->width;
70 			}
71 		} else {
72 			while(sh--) {
73 				memmove(dp, sp, sw);
74 				sp += src->width;
75 				dp += dst->width;
76 			}
77 		}
78 	} else {
79 		while(sh--) {
80 			memcpy(dp, sp, sw);
81 			sp += src->width;
82 			dp += dst->width;
83 		}
84 	}
85 
86 	return OK;
87 }
88