-
Notifications
You must be signed in to change notification settings - Fork 5
/
dsprite.c
176 lines (143 loc) · 3.88 KB
/
dsprite.c
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#include "32x.h"
#include "types.h"
#include "draw.h"
drawsprcmd_t slave_drawsprcmd ATTR_CACHE_ALIGNED;
static int draw_clipsprite(int x, int y, int w, int h, int sw, int sh,
rect_t* cliprect, const uint8_t* data, int flags, fixed_t scale,
int stide)
ATTR_DATA_ALIGNED;
static int draw_clipsprite(int x, int y, int w, int h, int sw, int sh,
rect_t* cliprect, const uint8_t* data, int flags, fixed_t scale,
int stride)
{
drawsprcmd_t cmd, * scmd;
int hh;
int cl = cliprect->x1;
int cr = cliprect->x2;
int ct = cliprect->y1;
int cb = cliprect->y2;
int sx = 0, sy = 0, sy2;
x += window_canvas_x;
y += window_canvas_y;
x += cl;
y += ct;
w -= cr + cl;
h -= cb + ct;
if (flags & DRAWSPR_MULTICORE)
hh = h >> 1;
else
hh = h;
if (flags & DRAWSPR_PRECISE) {
if (!(x & 1) && !(w & 1) && !(flags & DRAWSPR_SCALE)) {
flags &= ~DRAWSPR_PRECISE;
}
}
else {
// snap to even coordinate
x &= ~1;
w &= ~1;
}
switch (flags & (DRAWSPR_HFLIP | DRAWSPR_VFLIP)) {
case 0:
default:
sx = cl;
sy = ct;
sy2 = ct + hh;
break;
case DRAWSPR_HFLIP:
sx = w + cl;
sy = ct;
sy2 = ct + hh;
break;
case DRAWSPR_VFLIP:
sx = w + cl;
sy = cb + h - hh;
sy2 = cb;
break;
case DRAWSPR_HFLIP | DRAWSPR_VFLIP:
sx = cl;
sy = cb + h - hh;
sy2 = cb;
break;
}
if (flags & DRAWSPR_SCALE) {
int nudge = scale > 0x10000 ? 1 : 0;
sx = IDiv((sx + nudge) << 16, scale);
if (sx > sw) sx = sw;
if (sx < 0) sx = 0;
sy = IDiv((sy + nudge) << 16, scale);
if (sy > sh) sy = sh;
if (sy < 0) sy = 0;
sy2 = IDiv((sy2 + nudge) << 16, scale);
if (sy2 > sh) sy2 = sh;
if (sy2 < 0) sy2 = 0;
}
switch (flags & (DRAWSPR_HFLIP | DRAWSPR_VFLIP)) {
case DRAWSPR_HFLIP:
case DRAWSPR_VFLIP:
sx = sw - sx;
break;
}
cmd.flags = flags;
cmd.x = x, cmd.y = y;
cmd.w = w, cmd.h = hh;
cmd.sx = sx, cmd.sy = sy;
cmd.sw = sw, cmd.sh = sh;
cmd.sdata = (void*)data;
cmd.scale = scale;
cmd.stride = stride;
if (h > hh)
{
while (MARS_SYS_COMM4 != 0) {}
scmd = &slave_drawsprcmd;
scmd->flags = flags;
scmd->x = x, scmd->y = y + hh;
scmd->w = w, scmd->h = h - hh;
scmd->sx = sx, scmd->sy = sy2;
scmd->sw = sw, scmd->sh = sh;
scmd->sdata = (void*)data;
scmd->scale = scale;
scmd->stride = stride;
MARS_SYS_COMM4 = 2;
}
draw_handle_drawspritecmd(&cmd);
draw_dirtyrect(&tm, x, y, w, h);
return 1;
}
int draw_sprite(int x, int y, int w, int h, int stride, const uint8_t* data, int flags)
{
int clip;
rect_t cliprect;
flags &= ~DRAWSPR_SCALE;
clip = draw_clip(x, y, w, h, &cliprect);
if (clip == 2)
return 0;
draw_clipsprite(x, y, w, h, w, h, &cliprect, data, flags, 0, stride);
return 1;
}
void draw_stretch_sprite(int x, int y, int sw, int sh, int stride, const uint8_t* data, int flags, fixed_t scale)
{
int w, h;
rect_t cliprect;
w = FixedMul(sw, scale);
h = FixedMul(sh, scale);
//w &= ~1;
//h &= ~1;
int clip = draw_clip(x, y, w, h, &cliprect);
if (clip == 2)
return;
draw_clipsprite(x, y, w, h, sw, sh, &cliprect, data, flags, scale, stride);
}
void draw_pivot_stretch_sprite(int x, int y, int sw, int sh, int stride, const uint8_t* data, int flags, fixed_t scale)
{
int w, h;
rect_t cliprect;
w = FixedMul(sw, scale);
h = FixedMul(sh, scale);
x -= (w >> 1);
y -= (h >> 1);
int clip = draw_clip(x, y, w, h, &cliprect);
if (clip == 2)
return;
draw_clipsprite(x, y, w, h, sw, sh, &cliprect, data, flags, scale, stride);
}