0
|
1 /*
|
|
2 * DMLib
|
|
3 * -- Sprite / surface blitting function template
|
|
4 * Programmed and designed by Matti 'ccr' Hamalainen
|
|
5 * (C) Copyright 2011-2012 Tecnic Software productions (TNSP)
|
|
6 */
|
|
7
|
|
8 int DM_SCALED_NAME (SDL_Surface *src,
|
|
9 const int x0, const int y0,
|
|
10 const int dwidth, const int dheight,
|
|
11 SDL_Surface *dst)
|
|
12 {
|
|
13 int yc;
|
|
14 DMFixedPoint32 xv, yv, dx, dy;
|
|
15 DMQValue xr, yr;
|
|
16
|
|
17 #ifdef DM_SCALED_VARS
|
|
18 DM_SCALED_VARS
|
|
19 #endif
|
|
20
|
|
21 // Clip coordinates
|
|
22 if (dmClipCoord(&xr, x0, src->w, dwidth,
|
|
23 dst->clip_rect.x, dst->clip_rect.x + dst->clip_rect.w)
|
|
24 ||
|
|
25 dmClipCoord(&yr, y0, src->h, dheight,
|
|
26 dst->clip_rect.y, dst->clip_rect.y + dst->clip_rect.h))
|
|
27 return -1;
|
|
28
|
|
29 #ifdef DM_SCALED_INIT
|
|
30 DM_SCALED_INIT
|
|
31 #endif
|
|
32
|
|
33 // Calculate "final" initial source bitmap offsets
|
|
34 FP_CONV(dy, yr.voffs);
|
|
35 FP_MUL_R(yv, dy, yr.vdelta);
|
|
36
|
|
37 FP_CONV(dx, xr.voffs);
|
|
38 FP_MUL_R(dx, dx, xr.vdelta);
|
|
39
|
|
40 // Take pitch into account
|
|
41 const int xadd = xr.vadd - dst->clip_rect.w + dst->clip_rect.x + (dst->pitch / DM_SCALED_DST_BYTES);
|
|
42
|
|
43 // Blit scaled
|
|
44 DM_SCALED_DST_TYPE * dp = ((DM_SCALED_DST_TYPE *) dst->pixels) + (yr.v0 * dst->pitch) / DM_SCALED_DST_BYTES + xr.v0;
|
|
45 for (yc = yr.v0; yc < yr.v1; yc++)
|
|
46 {
|
|
47 const DM_SCALED_SRC_TYPE * sp = ((DM_SCALED_SRC_TYPE *) src->pixels) + (FP_GETH(yv) * src->pitch) / DM_SCALED_SRC_BYTES;
|
|
48 int xc;
|
|
49
|
|
50 #ifdef DM_SCALED_INNER_INIT
|
|
51 DM_SCALED_INNER_INIT
|
|
52 #endif
|
|
53
|
|
54 for (xv.dw = dx.dw, xc = xr.v0; xc < xr.v1; xc++)
|
|
55 {
|
|
56 DM_SCALED_INNER
|
|
57 FP_ADD(xv, xr.vdelta);
|
|
58 }
|
|
59 FP_ADD(yv, yr.vdelta);
|
|
60 dp += xadd;
|
|
61 }
|
|
62
|
|
63 #ifdef DM_SCALED_FINISH
|
|
64 DM_SCALED_FINISH
|
|
65 #endif
|
|
66
|
|
67 return 0;
|
|
68 }
|
|
69
|
|
70
|
|
71 #undef DM_SCALED_NAME
|
|
72 #undef DM_SCALED_SRC_BYTES
|
|
73 #undef DM_SCALED_DST_BYTES
|
|
74 #undef DM_SCALED_SRC_TYPE
|
|
75 #undef DM_SCALED_DST_TYPE
|
|
76 #undef DM_SCALED_VARS
|
|
77 #undef DM_SCALED_INIT
|
|
78 #undef DM_SCALED_INNER_INIT
|
|
79 #undef DM_SCALED_INNER
|
|
80 #undef DM_SCALED_FINISH
|