-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphics_routines.cpp
284 lines (233 loc) · 6.91 KB
/
graphics_routines.cpp
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
/* -*- C++ -*-
*
* graphics_routines.cpp - ons_gfx namespace interface functions for
* image blends and resizing
*
* Copyright (c) 2009-2011 "Uncle" Mion Sonozaki
*
* UncleMion@gmail.com
*
* 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, see <http://www.gnu.org/licenses/>
* or write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "graphics_cpu.h"
#include "graphics_sum.h"
#include "graphics_blend.h"
#include "graphics_resize.h"
#if defined(USE_X86_GFX)
#include "graphics_mmx.h"
#include "graphics_sse2.h"
#endif
#if defined(USE_PPC_GFX)
#include "graphics_altivec.h"
#endif
#include "resize_image.h"
namespace ons_gfx {
//Mion: for special graphics routine handling
static unsigned int cpufuncs;
void setCpufuncs(unsigned int func)
{
cpufuncs = func;
}
unsigned int getCpufuncs()
{
return cpufuncs;
}
#ifndef BPP16 // currently none of the fast CPU routines support 16bpp
void imageFilterMean(unsigned char *src1, unsigned char *src2, unsigned char *dst, int length)
{
#if defined(USE_PPC_GFX)
if(cpufuncs & CPUF_PPC_ALTIVEC) {
imageFilterMean_Altivec(src1, src2, dst, length);
} else {
int n = length + 1;
BASIC_MEAN();
}
#elif defined(USE_X86_GFX)
#ifndef MACOSX
if (cpufuncs & CPUF_X86_SSE2) {
#endif // !MACOSX
imageFilterMean_SSE2(src1, src2, dst, length);
#ifndef MACOSX
} else if (cpufuncs & CPUF_X86_MMX) {
imageFilterMean_MMX(src1, src2, dst, length);
} else {
int n = length + 1;
BASIC_MEAN();
}
#endif // !MACOSX
#else // no special gfx handling
int n = length + 1;
BASIC_MEAN();
#endif
}
void imageFilterAddTo(unsigned char *dst, unsigned char *src, int length)
{
#if defined(USE_PPC_GFX)
if(cpufuncs & CPUF_PPC_ALTIVEC) {
imageFilterAddTo_Altivec(dst, src, length);
} else {
int n = length + 1;
BASIC_ADDTO();
}
#elif defined(USE_X86_GFX)
#ifndef MACOSX
if (cpufuncs & CPUF_X86_SSE2) {
#endif // !MACOSX
imageFilterAddTo_SSE2(dst, src, length);
#ifndef MACOSX
} else if (cpufuncs & CPUF_X86_MMX) {
imageFilterAddTo_MMX(dst, src, length);
} else {
int n = length + 1;
BASIC_ADDTO();
}
#endif // !MACOSX
#else // no special gfx handling
int n = length + 1;
BASIC_ADDTO();
#endif
}
void imageFilterSubFrom(unsigned char *dst, unsigned char *src, int length)
{
#if defined(USE_PPC_GFX)
if(cpufuncs & CPUF_PPC_ALTIVEC) {
imageFilterSubFrom_Altivec(dst, src, length);
} else {
int n = length + 1;
BASIC_SUBFROM();
}
#elif defined(USE_X86_GFX)
#ifndef MACOSX
if (cpufuncs & CPUF_X86_SSE2) {
#endif // !MACOSX
imageFilterSubFrom_SSE2(dst, src, length);
#ifndef MACOSX
} else if (cpufuncs & CPUF_X86_MMX) {
imageFilterSubFrom_MMX(dst, src, length);
} else {
int n = length + 1;
BASIC_SUBFROM();
}
#endif // !MACOSX
#else // no special gfx handling
int n = length + 1;
BASIC_SUBFROM();
#endif
}
void imageFilterBlend(Uint32 *dst_buffer, Uint32 *src_buffer,
Uint8 *alphap, int alpha, int length)
{
#if defined(USE_X86_GFX)
#ifndef MACOSX
if (cpufuncs & CPUF_X86_SSE2) {
#endif // !MACOSX
imageFilterBlend_SSE2(dst_buffer, src_buffer, alphap, alpha, length);
#ifndef MACOSX
} else {
int n = length + 1;
BASIC_BLEND();
}
#endif // !MACOSX
#else // no special gfx handling
int n = length + 1;
BASIC_BLEND();
#endif
}
void imageFilterEffectBlend(Uint32 *dst_buffer, Uint32 *src1_buffer,
Uint32 *src2_buffer, Uint32 mask2, int length)
{
#if defined(USE_X86_GFX)
#ifndef MACOSX
if (cpufuncs & CPUF_X86_SSE2) {
#endif // !MACOSX
imageFilterEffectBlend_SSE2(dst_buffer, src1_buffer, src2_buffer, mask2, length);
#ifndef MACOSX
} else {
int n = length + 1;
while(--n > 0) {
BLEND_EFFECT_PIXEL();
++dst_buffer, ++src1_buffer, ++src2_buffer;
}
}
#endif // !MACOSX
#else // no special gfx handling
int n = length + 1;
while(--n > 0) {
BLEND_EFFECT_PIXEL();
++dst_buffer, ++src1_buffer, ++src2_buffer;
}
#endif
}
void imageFilterEffectMaskBlend(Uint32 *dst_buffer, Uint32 *src1_buffer,
Uint32 *src2_buffer, Uint32 *mask_buffer,
Uint32 overflow_mask, Uint32 mask_value,
int length)
{
#if defined(USE_X86_GFX)
#ifndef MACOSX
if (cpufuncs & CPUF_X86_SSE2) {
#endif // !MACOSX
imageFilterEffectMaskBlend_SSE2(dst_buffer, src1_buffer, src2_buffer,
mask_buffer, overflow_mask, mask_value, length);
#ifndef MACOSX
} else {
int n = length + 1;
while(--n > 0) {
BLEND_EFFECT_MASK_PIXEL();
++dst_buffer, ++src1_buffer, ++src2_buffer, ++mask_buffer;
}
}
#endif // !MACOSX
#else // no special gfx handling
int n = length + 1;
while(--n > 0) {
BLEND_EFFECT_MASK_PIXEL();
++dst_buffer, ++src1_buffer, ++src2_buffer, ++mask_buffer;
}
#endif
}
#endif //!BPP16
static unsigned char *resize_buffer = NULL;
static size_t resize_buffer_size = 0;
void resetResizeBuffer() {
if (resize_buffer_size != 16){
if (resize_buffer) delete[] resize_buffer;
resize_buffer = new unsigned char[16];
resize_buffer_size = 16;
}
}
// resize 32bit surface to 32bit surface
int resizeSurface( SDL_Surface *src, SDL_Surface *dst, int num_cells )
{
SDL_LockSurface( dst );
SDL_LockSurface( src );
Uint32 *src_buffer = (Uint32 *)src->pixels;
Uint32 *dst_buffer = (Uint32 *)dst->pixels;
/* size of tmp_buffer must be larger than 16 bytes */
size_t len = src->w * (src->h+1) * 4 + 4;
if (resize_buffer_size < len){
if (resize_buffer) delete[] resize_buffer;
resize_buffer = new unsigned char[len];
resize_buffer_size = len;
}
resizeImage( (unsigned char*)dst_buffer, dst->w, dst->h, dst->w * 4,
(unsigned char*)src_buffer, src->w, src->h, src->w * 4,
4, resize_buffer, src->w * 4, num_cells );
SDL_UnlockSurface( src );
SDL_UnlockSurface( dst );
return 0;
}
} //namespace ons_gfx