File: graph_copy.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 (80 lines) | stat: -rw-r--r-- 2,323 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
/*
 * graph_copy.c  pixel ǡΥԡ
 *
 * 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_copy.c,v 1.2 2003/04/25 17:23:55 chikama Exp $ */

#include <string.h>

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

/**
 *  surface ΰ ̤ surface λ֤إԡ
 * pixelǡΤߥԡ
 * 
 * @param dst: ž surface
 * @param dx: žغɸ
 * @param dy: žٺɸ
 * @param src: žsurface
 * @param sx: žغɸ
 * @param sy: žٺɸ
 * @param sw: ž
 * @param sh: ž⤵
 */
int gr_copy(surface_t *dst, int dx, int dy, surface_t *src, int sx, int sy, int sw, int sh) {
	BYTE *sp, *dp;
	
	if (src == NULL || dst == NULL) return NG;
	if (!gr_clip(src, &sx, &sy, &sw, &sh, dst, &dx, &dy)) return NG;
	
	sp = GETOFFSET_PIXEL(src, sx, sy);
	dp = GETOFFSET_PIXEL(dst, dx, dy);
	
	if (sp == NULL || dp == NULL) return NG;

	if (src == dst) {
		if (sy <= dy && dy < (sy + sh)) {
			sp += (sh -1) * src->bytes_per_line;
			dp += (sh -1) * dst->bytes_per_line;
			while(sh--) {
				memmove(dp, sp, sw * src->bytes_per_pixel);
				sp -= src->bytes_per_line;
				dp -= dst->bytes_per_line;
			}
		} else {
			while(sh--) {
				memmove(dp, sp, sw * src->bytes_per_pixel);
				sp += src->bytes_per_line;
				dp += dst->bytes_per_line;
			}
		}
	} else {
		while(sh--) {
			memcpy(dp, sp, sw * src->bytes_per_pixel);
			sp += src->bytes_per_line;
			dp += dst->bytes_per_line;
		}	
	}
	
	return OK;
}