Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
2511 lines (2341 loc) · 85.1 KB

SDL_blit_N.c

File metadata and controls

2511 lines (2341 loc) · 85.1 KB
 
Apr 26, 2001
Apr 26, 2001
1
2
/*
SDL - Simple DirectMedia Layer
Jan 24, 2010
Jan 24, 2010
3
Copyright (C) 1997-2010 Sam Lantinga
Apr 26, 2001
Apr 26, 2001
4
5
This library is free software; you can redistribute it and/or
Feb 1, 2006
Feb 1, 2006
6
modify it under the terms of the GNU Lesser General Public
Apr 26, 2001
Apr 26, 2001
7
License as published by the Free Software Foundation; either
Feb 1, 2006
Feb 1, 2006
8
version 2.1 of the License, or (at your option) any later version.
Apr 26, 2001
Apr 26, 2001
9
10
11
12
This library 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
Feb 1, 2006
Feb 1, 2006
13
Lesser General Public License for more details.
Apr 26, 2001
Apr 26, 2001
14
Feb 1, 2006
Feb 1, 2006
15
16
17
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Apr 26, 2001
Apr 26, 2001
18
19
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
20
slouken@libsdl.org
Apr 26, 2001
Apr 26, 2001
21
*/
Feb 21, 2006
Feb 21, 2006
22
#include "SDL_config.h"
Apr 26, 2001
Apr 26, 2001
23
24
#include "SDL_video.h"
Feb 10, 2006
Feb 10, 2006
25
#include "SDL_endian.h"
Nov 18, 2003
Nov 18, 2003
26
#include "SDL_cpuinfo.h"
Feb 10, 2006
Feb 10, 2006
27
#include "SDL_blit.h"
Apr 26, 2001
Apr 26, 2001
28
29
30
/* Functions to blit from N-bit surfaces to other surfaces */
Feb 16, 2006
Feb 16, 2006
31
#if SDL_ALTIVEC_BLITTERS
May 9, 2006
May 9, 2006
32
33
34
#if __MWERKS__
#pragma altivec_model on
#endif
Nov 17, 2005
Nov 17, 2005
35
#ifdef HAVE_ALTIVEC_H
Oct 20, 2005
Oct 20, 2005
36
#include <altivec.h>
Nov 17, 2005
Nov 17, 2005
37
#endif
Feb 7, 2006
Feb 7, 2006
38
#define assert(X)
Feb 21, 2006
Feb 21, 2006
39
#ifdef __MACOSX__
Apr 17, 2005
Apr 17, 2005
40
#include <sys/sysctl.h>
Jul 10, 2006
Jul 10, 2006
41
42
static size_t
GetL3CacheSize(void)
Apr 17, 2005
Apr 17, 2005
43
44
45
{
const char key[] = "hw.l3cachesize";
u_int64_t result = 0;
Jul 10, 2006
Jul 10, 2006
46
size_t typeSize = sizeof(result);
Apr 17, 2005
Apr 17, 2005
47
48
Jul 10, 2006
Jul 10, 2006
49
50
51
int err = sysctlbyname(key, &result, &typeSize, NULL, 0);
if (0 != err)
return 0;
Apr 17, 2005
Apr 17, 2005
52
53
54
55
return result;
}
#else
Jul 10, 2006
Jul 10, 2006
56
57
static size_t
GetL3CacheSize(void)
Apr 17, 2005
Apr 17, 2005
58
59
60
61
{
/* XXX: Just guess G4 */
return 2097152;
}
Feb 21, 2006
Feb 21, 2006
62
#endif /* __MACOSX__ */
Apr 17, 2005
Apr 17, 2005
63
Feb 21, 2006
Feb 21, 2006
64
#if (defined(__MACOSX__) && (__GNUC__ < 4))
Jul 10, 2006
Jul 10, 2006
65
#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
Oct 20, 2005
Oct 20, 2005
66
(vector unsigned char) ( a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p )
Jul 10, 2006
Jul 10, 2006
67
#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
Oct 20, 2005
Oct 20, 2005
68
69
(vector unsigned short) ( a,b,c,d,e,f,g,h )
#else
Jul 10, 2006
Jul 10, 2006
70
#define VECUINT8_LITERAL(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \
Oct 20, 2005
Oct 20, 2005
71
(vector unsigned char) { a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p }
Jul 10, 2006
Jul 10, 2006
72
#define VECUINT16_LITERAL(a,b,c,d,e,f,g,h) \
Oct 20, 2005
Oct 20, 2005
73
74
75
(vector unsigned short) { a,b,c,d,e,f,g,h }
#endif
Apr 17, 2005
Apr 17, 2005
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
#define UNALIGNED_PTR(x) (((size_t) x) & 0x0000000F)
#define VSWIZZLE32(a,b,c,d) (vector unsigned char) \
( 0x00+a, 0x00+b, 0x00+c, 0x00+d, \
0x04+a, 0x04+b, 0x04+c, 0x04+d, \
0x08+a, 0x08+b, 0x08+c, 0x08+d, \
0x0C+a, 0x0C+b, 0x0C+c, 0x0C+d )
#define MAKE8888(dstfmt, r, g, b, a) \
( ((r<<dstfmt->Rshift)&dstfmt->Rmask) | \
((g<<dstfmt->Gshift)&dstfmt->Gmask) | \
((b<<dstfmt->Bshift)&dstfmt->Bmask) | \
((a<<dstfmt->Ashift)&dstfmt->Amask) )
/*
* Data Stream Touch...Altivec cache prefetching.
*
* Don't use this on a G5...however, the speed boost is very significant
* on a G4.
*/
#define DST_CHAN_SRC 1
#define DST_CHAN_DEST 2
/* macro to set DST control word value... */
#define DST_CTRL(size, count, stride) \
(((size) << 24) | ((count) << 16) | (stride))
#define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \
? vec_lvsl(0, src) \
: vec_add(vec_lvsl(8, src), vec_splat_u8(8)))
/* Calculate the permute vector used for 32->32 swizzling */
Jul 10, 2006
Jul 10, 2006
107
108
static vector unsigned char
calc_swizzle32(const SDL_PixelFormat * srcfmt, const SDL_PixelFormat * dstfmt)
Apr 17, 2005
Apr 17, 2005
109
110
{
/*
Jul 10, 2006
Jul 10, 2006
111
* We have to assume that the bits that aren't used by other
Apr 17, 2005
Apr 17, 2005
112
113
114
115
* colors is alpha, and it's one complete byte, since some formats
* leave alpha with a zero mask, but we should still swizzle the bits.
*/
/* ARGB */
Jun 3, 2009
Jun 3, 2009
116
const static const struct SDL_PixelFormat default_pixel_format = {
Jan 25, 2009
Jan 25, 2009
117
NULL, 32, 4,
Apr 17, 2005
Apr 17, 2005
118
119
0, 0, 0, 0,
16, 8, 0, 24,
Jan 25, 2009
Jan 25, 2009
120
0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000
Jul 10, 2006
Jul 10, 2006
121
};
Apr 17, 2005
Apr 17, 2005
122
123
124
125
126
127
if (!srcfmt) {
srcfmt = &default_pixel_format;
}
if (!dstfmt) {
dstfmt = &default_pixel_format;
}
Jul 10, 2006
Jul 10, 2006
128
129
130
131
132
const vector unsigned char plus = VECUINT8_LITERAL(0x00, 0x00, 0x00, 0x00,
0x04, 0x04, 0x04, 0x04,
0x08, 0x08, 0x08, 0x08,
0x0C, 0x0C, 0x0C,
0x0C);
Apr 17, 2005
Apr 17, 2005
133
134
135
136
137
138
139
140
141
vector unsigned char vswiz;
vector unsigned int srcvec;
#define RESHIFT(X) (3 - ((X) >> 3))
Uint32 rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift);
Uint32 gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift);
Uint32 bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift);
Uint32 amask;
/* Use zero for alpha if either surface doesn't have alpha */
if (dstfmt->Amask) {
Jul 10, 2006
Jul 10, 2006
142
amask =
Jan 10, 2009
Jan 10, 2009
143
144
((srcfmt->Amask) ? RESHIFT(srcfmt->
Ashift) : 0x10) << (dstfmt->Ashift);
Jul 10, 2006
Jul 10, 2006
145
146
147
148
149
150
151
152
153
} else {
amask =
0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^
0xFFFFFFFF);
}
#undef RESHIFT
((unsigned int *) (char *) &srcvec)[0] = (rmask | gmask | bmask | amask);
vswiz = vec_add(plus, (vector unsigned char) vec_splat(srcvec, 0));
return (vswiz);
Apr 17, 2005
Apr 17, 2005
154
155
}
Jul 10, 2006
Jul 10, 2006
156
157
158
159
static void Blit_RGB888_RGB565(SDL_BlitInfo * info);
static void
Blit_RGB888_RGB565Altivec(SDL_BlitInfo * info)
{
Aug 17, 2007
Aug 17, 2007
160
161
int height = info->dst_h;
Uint8 *src = (Uint8 *) info->src;
Aug 18, 2007
Aug 18, 2007
162
int srcskip = info->src_skip;
Aug 17, 2007
Aug 17, 2007
163
Uint8 *dst = (Uint8 *) info->dst;
Aug 18, 2007
Aug 18, 2007
164
int dstskip = info->dst_skip;
Jan 25, 2009
Jan 25, 2009
165
SDL_PixelFormat *srcfmt = info->src_fmt;
Apr 17, 2005
Apr 17, 2005
166
167
vector unsigned char valpha = vec_splat_u8(0);
vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
Jul 10, 2006
Jul 10, 2006
168
169
170
171
vector unsigned char vgmerge = VECUINT8_LITERAL(0x00, 0x02, 0x00, 0x06,
0x00, 0x0a, 0x00, 0x0e,
0x00, 0x12, 0x00, 0x16,
0x00, 0x1a, 0x00, 0x1e);
Apr 17, 2005
Apr 17, 2005
172
173
vector unsigned short v1 = vec_splat_u16(1);
vector unsigned short v3 = vec_splat_u16(3);
Jul 10, 2006
Jul 10, 2006
174
175
176
177
178
179
180
vector unsigned short v3f =
VECUINT16_LITERAL(0x003f, 0x003f, 0x003f, 0x003f,
0x003f, 0x003f, 0x003f, 0x003f);
vector unsigned short vfc =
VECUINT16_LITERAL(0x00fc, 0x00fc, 0x00fc, 0x00fc,
0x00fc, 0x00fc, 0x00fc, 0x00fc);
vector unsigned short vf800 = (vector unsigned short) vec_splat_u8(-7);
Apr 17, 2005
Apr 17, 2005
181
182
183
184
185
186
187
vf800 = vec_sl(vf800, vec_splat_u16(8));
while (height--) {
vector unsigned char valigner;
vector unsigned char voverflow;
vector unsigned char vsrc;
Aug 17, 2007
Aug 17, 2007
188
int width = info->dst_w;
Apr 17, 2005
Apr 17, 2005
189
190
191
192
193
int extrawidth;
/* do scalar until we can align... */
#define ONE_PIXEL_BLEND(condition, widthvar) \
while (condition) { \
Oct 20, 2005
Oct 20, 2005
194
Uint32 Pixel; \
Apr 17, 2005
Apr 17, 2005
195
unsigned sR, sG, sB, sA; \
Oct 20, 2005
Oct 20, 2005
196
DISEMBLE_RGBA((Uint8 *)src, 4, srcfmt, Pixel, \
Apr 17, 2005
Apr 17, 2005
197
198
199
200
201
202
203
204
205
206
207
208
sR, sG, sB, sA); \
*(Uint16 *)(dst) = (((sR << 8) & 0x0000F800) | \
((sG << 3) & 0x000007E0) | \
((sB >> 3) & 0x0000001F)); \
dst += 2; \
src += 4; \
widthvar--; \
}
ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
/* After all that work, here's the vector part! */
Jul 10, 2006
Jul 10, 2006
209
extrawidth = (width % 8); /* trailing unaligned stores */
Apr 17, 2005
Apr 17, 2005
210
211
212
213
214
215
216
217
218
219
220
width -= extrawidth;
vsrc = vec_ld(0, src);
valigner = VEC_ALIGNER(src);
while (width) {
vector unsigned short vpixel, vrpixel, vgpixel, vbpixel;
vector unsigned int vsrc1, vsrc2;
vector unsigned char vdst;
voverflow = vec_ld(15, src);
vsrc = vec_perm(vsrc, voverflow, valigner);
Jul 10, 2006
Jul 10, 2006
221
vsrc1 = (vector unsigned int) vec_perm(vsrc, valpha, vpermute);
Apr 17, 2005
Apr 17, 2005
222
223
224
225
src += 16;
vsrc = voverflow;
voverflow = vec_ld(15, src);
vsrc = vec_perm(vsrc, voverflow, valigner);
Jul 10, 2006
Jul 10, 2006
226
vsrc2 = (vector unsigned int) vec_perm(vsrc, valpha, vpermute);
Apr 17, 2005
Apr 17, 2005
227
/* 1555 */
Jul 10, 2006
Jul 10, 2006
228
229
vpixel = (vector unsigned short) vec_packpx(vsrc1, vsrc2);
vgpixel = (vector unsigned short) vec_perm(vsrc1, vsrc2, vgmerge);
Apr 17, 2005
Apr 17, 2005
230
231
232
233
234
vgpixel = vec_and(vgpixel, vfc);
vgpixel = vec_sl(vgpixel, v3);
vrpixel = vec_sl(vpixel, v1);
vrpixel = vec_and(vrpixel, vf800);
vbpixel = vec_and(vpixel, v3f);
Jul 10, 2006
Jul 10, 2006
235
236
237
vdst =
vec_or((vector unsigned char) vrpixel,
(vector unsigned char) vgpixel);
Apr 17, 2005
Apr 17, 2005
238
/* 565 */
Jul 10, 2006
Jul 10, 2006
239
vdst = vec_or(vdst, (vector unsigned char) vbpixel);
Apr 17, 2005
Apr 17, 2005
240
241
242
243
244
245
246
247
248
249
250
251
252
253
vec_st(vdst, 0, dst);
width -= 8;
src += 16;
dst += 16;
vsrc = voverflow;
}
assert(width == 0);
/* do scalar until we can align... */
ONE_PIXEL_BLEND((extrawidth), extrawidth);
#undef ONE_PIXEL_BLEND
Jul 10, 2006
Jul 10, 2006
254
src += srcskip; /* move to next row, accounting for pitch. */
Apr 17, 2005
Apr 17, 2005
255
256
257
258
259
260
dst += dstskip;
}
}
Jul 10, 2006
Jul 10, 2006
261
262
263
static void
Blit_RGB565_32Altivec(SDL_BlitInfo * info)
{
Aug 17, 2007
Aug 17, 2007
264
265
int height = info->dst_h;
Uint8 *src = (Uint8 *) info->src;
Aug 18, 2007
Aug 18, 2007
266
int srcskip = info->src_skip;
Aug 17, 2007
Aug 17, 2007
267
Uint8 *dst = (Uint8 *) info->dst;
Aug 18, 2007
Aug 18, 2007
268
int dstskip = info->dst_skip;
Jan 25, 2009
Jan 25, 2009
269
270
SDL_PixelFormat *srcfmt = info->src_fmt;
SDL_PixelFormat *dstfmt = info->dst_fmt;
Apr 17, 2005
Apr 17, 2005
271
272
273
274
275
276
277
278
279
unsigned alpha;
vector unsigned char valpha;
vector unsigned char vpermute;
vector unsigned short vf800;
vector unsigned int v8 = vec_splat_u32(8);
vector unsigned int v16 = vec_add(v8, v8);
vector unsigned short v2 = vec_splat_u16(2);
vector unsigned short v3 = vec_splat_u16(3);
/*
Jul 10, 2006
Jul 10, 2006
280
281
282
283
284
285
286
287
288
289
290
291
292
0x10 - 0x1f is the alpha
0x00 - 0x0e evens are the red
0x01 - 0x0f odds are zero
*/
vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01,
0x10, 0x02, 0x01, 0x01,
0x10, 0x04, 0x01, 0x01,
0x10, 0x06, 0x01,
0x01);
vector unsigned char vredalpha2 =
(vector unsigned
char) (vec_add((vector unsigned int) vredalpha1, vec_sl(v8, v16))
);
Apr 17, 2005
Apr 17, 2005
293
/*
Jul 10, 2006
Jul 10, 2006
294
295
296
297
298
299
300
301
302
303
0x00 - 0x0f is ARxx ARxx ARxx ARxx
0x11 - 0x0f odds are blue
*/
vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11,
0x04, 0x05, 0x06, 0x13,
0x08, 0x09, 0x0a, 0x15,
0x0c, 0x0d, 0x0e, 0x17);
vector unsigned char vblue2 =
(vector unsigned char) (vec_add((vector unsigned int) vblue1, v8)
);
Apr 17, 2005
Apr 17, 2005
304
/*
Jul 10, 2006
Jul 10, 2006
305
306
307
308
309
310
311
312
313
314
315
316
0x00 - 0x0f is ARxB ARxB ARxB ARxB
0x10 - 0x0e evens are green
*/
vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03,
0x04, 0x05, 0x12, 0x07,
0x08, 0x09, 0x14, 0x0b,
0x0c, 0x0d, 0x16, 0x0f);
vector unsigned char vgreen2 =
(vector unsigned
char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8, v8))
);
Apr 17, 2005
Apr 17, 2005
317
318
319
320
assert(srcfmt->BytesPerPixel == 2);
assert(dstfmt->BytesPerPixel == 4);
Jul 10, 2006
Jul 10, 2006
321
vf800 = (vector unsigned short) vec_splat_u8(-7);
Apr 17, 2005
Apr 17, 2005
322
323
vf800 = vec_sl(vf800, vec_splat_u16(8));
Aug 18, 2007
Aug 18, 2007
324
325
if (dstfmt->Amask && info->a) {
((unsigned char *) &valpha)[0] = alpha = info->a;
Apr 17, 2005
Apr 17, 2005
326
327
328
329
330
331
332
333
334
335
336
337
valpha = vec_splat(valpha, 0);
} else {
alpha = 0;
valpha = vec_splat_u8(0);
}
vpermute = calc_swizzle32(NULL, dstfmt);
while (height--) {
vector unsigned char valigner;
vector unsigned char voverflow;
vector unsigned char vsrc;
Aug 17, 2007
Aug 17, 2007
338
int width = info->dst_w;
Apr 17, 2005
Apr 17, 2005
339
340
341
342
343
344
int extrawidth;
/* do scalar until we can align... */
#define ONE_PIXEL_BLEND(condition, widthvar) \
while (condition) { \
unsigned sR, sG, sB; \
Oct 20, 2005
Oct 20, 2005
345
346
347
348
unsigned short Pixel = *((unsigned short *)src); \
sR = (Pixel >> 8) & 0xf8; \
sG = (Pixel >> 3) & 0xfc; \
sB = (Pixel << 3) & 0xf8; \
Apr 17, 2005
Apr 17, 2005
349
350
351
352
353
354
355
356
ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
src += 2; \
dst += 4; \
widthvar--; \
}
ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
/* After all that work, here's the vector part! */
Jul 10, 2006
Jul 10, 2006
357
extrawidth = (width % 8); /* trailing unaligned stores */
Apr 17, 2005
Apr 17, 2005
358
359
360
361
362
363
364
365
366
367
368
width -= extrawidth;
vsrc = vec_ld(0, src);
valigner = VEC_ALIGNER(src);
while (width) {
vector unsigned short vR, vG, vB;
vector unsigned char vdst1, vdst2;
voverflow = vec_ld(15, src);
vsrc = vec_perm(vsrc, voverflow, valigner);
Jul 10, 2006
Jul 10, 2006
369
370
vR = vec_and((vector unsigned short) vsrc, vf800);
vB = vec_sl((vector unsigned short) vsrc, v3);
Apr 17, 2005
Apr 17, 2005
371
372
vG = vec_sl(vB, v2);
Jul 10, 2006
Jul 10, 2006
373
374
375
376
377
vdst1 =
(vector unsigned char) vec_perm((vector unsigned char) vR,
valpha, vredalpha1);
vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1);
vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1);
Apr 17, 2005
Apr 17, 2005
378
379
380
vdst1 = vec_perm(vdst1, valpha, vpermute);
vec_st(vdst1, 0, dst);
Jul 10, 2006
Jul 10, 2006
381
382
383
384
385
vdst2 =
(vector unsigned char) vec_perm((vector unsigned char) vR,
valpha, vredalpha2);
vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2);
vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2);
Apr 17, 2005
Apr 17, 2005
386
387
vdst2 = vec_perm(vdst2, valpha, vpermute);
vec_st(vdst2, 16, dst);
Jul 10, 2006
Jul 10, 2006
388
Apr 17, 2005
Apr 17, 2005
389
390
391
392
393
394
395
396
397
398
399
400
401
width -= 8;
dst += 32;
src += 16;
vsrc = voverflow;
}
assert(width == 0);
/* do scalar until we can align... */
ONE_PIXEL_BLEND((extrawidth), extrawidth);
#undef ONE_PIXEL_BLEND
Jul 10, 2006
Jul 10, 2006
402
src += srcskip; /* move to next row, accounting for pitch. */
Apr 17, 2005
Apr 17, 2005
403
404
405
406
407
dst += dstskip;
}
}
Sep 8, 2005
Sep 8, 2005
408
Jul 10, 2006
Jul 10, 2006
409
410
411
static void
Blit_RGB555_32Altivec(SDL_BlitInfo * info)
{
Aug 17, 2007
Aug 17, 2007
412
413
int height = info->dst_h;
Uint8 *src = (Uint8 *) info->src;
Aug 18, 2007
Aug 18, 2007
414
int srcskip = info->src_skip;
Aug 17, 2007
Aug 17, 2007
415
Uint8 *dst = (Uint8 *) info->dst;
Aug 18, 2007
Aug 18, 2007
416
int dstskip = info->dst_skip;
Jan 25, 2009
Jan 25, 2009
417
418
SDL_PixelFormat *srcfmt = info->src_fmt;
SDL_PixelFormat *dstfmt = info->dst_fmt;
Sep 8, 2005
Sep 8, 2005
419
420
421
422
423
424
425
426
427
unsigned alpha;
vector unsigned char valpha;
vector unsigned char vpermute;
vector unsigned short vf800;
vector unsigned int v8 = vec_splat_u32(8);
vector unsigned int v16 = vec_add(v8, v8);
vector unsigned short v1 = vec_splat_u16(1);
vector unsigned short v3 = vec_splat_u16(3);
/*
Jul 10, 2006
Jul 10, 2006
428
429
430
431
432
433
434
435
436
437
438
439
440
0x10 - 0x1f is the alpha
0x00 - 0x0e evens are the red
0x01 - 0x0f odds are zero
*/
vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01,
0x10, 0x02, 0x01, 0x01,
0x10, 0x04, 0x01, 0x01,
0x10, 0x06, 0x01,
0x01);
vector unsigned char vredalpha2 =
(vector unsigned
char) (vec_add((vector unsigned int) vredalpha1, vec_sl(v8, v16))
);
Sep 8, 2005
Sep 8, 2005
441
/*
Jul 10, 2006
Jul 10, 2006
442
443
444
445
446
447
448
449
450
451
0x00 - 0x0f is ARxx ARxx ARxx ARxx
0x11 - 0x0f odds are blue
*/
vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11,
0x04, 0x05, 0x06, 0x13,
0x08, 0x09, 0x0a, 0x15,
0x0c, 0x0d, 0x0e, 0x17);
vector unsigned char vblue2 =
(vector unsigned char) (vec_add((vector unsigned int) vblue1, v8)
);
Sep 8, 2005
Sep 8, 2005
452
/*
Jul 10, 2006
Jul 10, 2006
453
454
455
456
457
458
459
460
461
462
463
464
0x00 - 0x0f is ARxB ARxB ARxB ARxB
0x10 - 0x0e evens are green
*/
vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03,
0x04, 0x05, 0x12, 0x07,
0x08, 0x09, 0x14, 0x0b,
0x0c, 0x0d, 0x16, 0x0f);
vector unsigned char vgreen2 =
(vector unsigned
char) (vec_add((vector unsigned int) vgreen1, vec_sl(v8, v8))
);
Sep 8, 2005
Sep 8, 2005
465
466
467
468
assert(srcfmt->BytesPerPixel == 2);
assert(dstfmt->BytesPerPixel == 4);
Jul 10, 2006
Jul 10, 2006
469
vf800 = (vector unsigned short) vec_splat_u8(-7);
Sep 8, 2005
Sep 8, 2005
470
471
vf800 = vec_sl(vf800, vec_splat_u16(8));
Aug 18, 2007
Aug 18, 2007
472
473
if (dstfmt->Amask && info->a) {
((unsigned char *) &valpha)[0] = alpha = info->a;
Sep 8, 2005
Sep 8, 2005
474
475
476
477
478
479
480
481
482
483
484
485
valpha = vec_splat(valpha, 0);
} else {
alpha = 0;
valpha = vec_splat_u8(0);
}
vpermute = calc_swizzle32(NULL, dstfmt);
while (height--) {
vector unsigned char valigner;
vector unsigned char voverflow;
vector unsigned char vsrc;
Aug 17, 2007
Aug 17, 2007
486
int width = info->dst_w;
Sep 8, 2005
Sep 8, 2005
487
488
489
490
491
492
int extrawidth;
/* do scalar until we can align... */
#define ONE_PIXEL_BLEND(condition, widthvar) \
while (condition) { \
unsigned sR, sG, sB; \
Oct 20, 2005
Oct 20, 2005
493
494
495
496
unsigned short Pixel = *((unsigned short *)src); \
sR = (Pixel >> 7) & 0xf8; \
sG = (Pixel >> 2) & 0xf8; \
sB = (Pixel << 3) & 0xf8; \
Sep 8, 2005
Sep 8, 2005
497
498
499
500
501
502
503
504
ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
src += 2; \
dst += 4; \
widthvar--; \
}
ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
/* After all that work, here's the vector part! */
Jul 10, 2006
Jul 10, 2006
505
extrawidth = (width % 8); /* trailing unaligned stores */
Sep 8, 2005
Sep 8, 2005
506
507
508
509
510
511
512
513
514
515
516
width -= extrawidth;
vsrc = vec_ld(0, src);
valigner = VEC_ALIGNER(src);
while (width) {
vector unsigned short vR, vG, vB;
vector unsigned char vdst1, vdst2;
voverflow = vec_ld(15, src);
vsrc = vec_perm(vsrc, voverflow, valigner);
Jul 10, 2006
Jul 10, 2006
517
518
vR = vec_and(vec_sl((vector unsigned short) vsrc, v1), vf800);
vB = vec_sl((vector unsigned short) vsrc, v3);
Sep 8, 2005
Sep 8, 2005
519
520
vG = vec_sl(vB, v3);
Jul 10, 2006
Jul 10, 2006
521
522
523
524
525
vdst1 =
(vector unsigned char) vec_perm((vector unsigned char) vR,
valpha, vredalpha1);
vdst1 = vec_perm(vdst1, (vector unsigned char) vB, vblue1);
vdst1 = vec_perm(vdst1, (vector unsigned char) vG, vgreen1);
Sep 8, 2005
Sep 8, 2005
526
527
528
vdst1 = vec_perm(vdst1, valpha, vpermute);
vec_st(vdst1, 0, dst);
Jul 10, 2006
Jul 10, 2006
529
530
531
532
533
vdst2 =
(vector unsigned char) vec_perm((vector unsigned char) vR,
valpha, vredalpha2);
vdst2 = vec_perm(vdst2, (vector unsigned char) vB, vblue2);
vdst2 = vec_perm(vdst2, (vector unsigned char) vG, vgreen2);
Sep 8, 2005
Sep 8, 2005
534
535
vdst2 = vec_perm(vdst2, valpha, vpermute);
vec_st(vdst2, 16, dst);
Jul 10, 2006
Jul 10, 2006
536
Sep 8, 2005
Sep 8, 2005
537
538
539
540
541
542
543
544
545
546
547
548
549
width -= 8;
dst += 32;
src += 16;
vsrc = voverflow;
}
assert(width == 0);
/* do scalar until we can align... */
ONE_PIXEL_BLEND((extrawidth), extrawidth);
#undef ONE_PIXEL_BLEND
Jul 10, 2006
Jul 10, 2006
550
src += srcskip; /* move to next row, accounting for pitch. */
Sep 8, 2005
Sep 8, 2005
551
552
553
554
555
dst += dstskip;
}
}
Jul 10, 2006
Jul 10, 2006
556
557
558
559
static void BlitNtoNKey(SDL_BlitInfo * info);
static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo * info);
static void
Blit32to32KeyAltivec(SDL_BlitInfo * info)
Apr 17, 2005
Apr 17, 2005
560
{
Aug 17, 2007
Aug 17, 2007
561
562
int height = info->dst_h;
Uint32 *srcp = (Uint32 *) info->src;
Jan 25, 2009
Jan 25, 2009
563
int srcskip = info->src_skip / 4;
Aug 17, 2007
Aug 17, 2007
564
Uint32 *dstp = (Uint32 *) info->dst;
Jan 25, 2009
Jan 25, 2009
565
566
int dstskip = info->dst_skip / 4;
SDL_PixelFormat *srcfmt = info->src_fmt;
Apr 17, 2005
Apr 17, 2005
567
int srcbpp = srcfmt->BytesPerPixel;
Jan 25, 2009
Jan 25, 2009
568
SDL_PixelFormat *dstfmt = info->dst_fmt;
Apr 17, 2005
Apr 17, 2005
569
570
int dstbpp = dstfmt->BytesPerPixel;
int copy_alpha = (srcfmt->Amask && dstfmt->Amask);
Aug 18, 2007
Aug 18, 2007
571
unsigned alpha = dstfmt->Amask ? info->a : 0;
Apr 17, 2005
Apr 17, 2005
572
Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
Aug 18, 2007
Aug 18, 2007
573
Uint32 ckey = info->colorkey;
Apr 17, 2005
Apr 17, 2005
574
575
576
577
578
579
vector unsigned int valpha;
vector unsigned char vpermute;
vector unsigned char vzero;
vector unsigned int vckey;
vector unsigned int vrgbmask;
vpermute = calc_swizzle32(srcfmt, dstfmt);
Aug 17, 2007
Aug 17, 2007
580
if (info->dst_w < 16) {
Jul 10, 2006
Jul 10, 2006
581
if (copy_alpha) {
Mar 9, 2006
Mar 9, 2006
582
BlitNtoNKeyCopyAlpha(info);
Apr 17, 2005
Apr 17, 2005
583
} else {
Mar 9, 2006
Mar 9, 2006
584
BlitNtoNKey(info);
Apr 17, 2005
Apr 17, 2005
585
}
Mar 9, 2006
Mar 9, 2006
586
return;
Apr 17, 2005
Apr 17, 2005
587
588
589
}
vzero = vec_splat_u8(0);
if (alpha) {
Jul 10, 2006
Jul 10, 2006
590
591
592
((unsigned char *) &valpha)[0] = (unsigned char) alpha;
valpha =
(vector unsigned int) vec_splat((vector unsigned char) valpha, 0);
Apr 17, 2005
Apr 17, 2005
593
} else {
Jul 10, 2006
Jul 10, 2006
594
valpha = (vector unsigned int) vzero;
Apr 17, 2005
Apr 17, 2005
595
596
}
ckey &= rgbmask;
Jul 10, 2006
Jul 10, 2006
597
((unsigned int *) (char *) &vckey)[0] = ckey;
Apr 17, 2005
Apr 17, 2005
598
vckey = vec_splat(vckey, 0);
Jul 10, 2006
Jul 10, 2006
599
((unsigned int *) (char *) &vrgbmask)[0] = rgbmask;
Apr 17, 2005
Apr 17, 2005
600
601
602
603
604
605
vrgbmask = vec_splat(vrgbmask, 0);
while (height--) {
#define ONE_PIXEL_BLEND(condition, widthvar) \
if (copy_alpha) { \
while (condition) { \
Oct 20, 2005
Oct 20, 2005
606
Uint32 Pixel; \
Apr 17, 2005
Apr 17, 2005
607
unsigned sR, sG, sB, sA; \
Oct 20, 2005
Oct 20, 2005
608
DISEMBLE_RGBA((Uint8 *)srcp, srcbpp, srcfmt, Pixel, \
Apr 17, 2005
Apr 17, 2005
609
sR, sG, sB, sA); \
Oct 20, 2005
Oct 20, 2005
610
if ( (Pixel & rgbmask) != ckey ) { \
Apr 17, 2005
Apr 17, 2005
611
612
613
ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
sR, sG, sB, sA); \
} \
Oct 20, 2005
Oct 20, 2005
614
615
dstp = (Uint32 *) (((Uint8 *) dstp) + dstbpp); \
srcp = (Uint32 *) (((Uint8 *) srcp) + srcbpp); \
Apr 17, 2005
Apr 17, 2005
616
617
618
619
widthvar--; \
} \
} else { \
while (condition) { \
Oct 20, 2005
Oct 20, 2005
620
Uint32 Pixel; \
Apr 17, 2005
Apr 17, 2005
621
unsigned sR, sG, sB; \
Oct 20, 2005
Oct 20, 2005
622
623
624
RETRIEVE_RGB_PIXEL((Uint8 *)srcp, srcbpp, Pixel); \
if ( Pixel != ckey ) { \
RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
Apr 17, 2005
Apr 17, 2005
625
626
627
ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
sR, sG, sB, alpha); \
} \
Oct 20, 2005
Oct 20, 2005
628
629
dstp = (Uint32 *) (((Uint8 *)dstp) + dstbpp); \
srcp = (Uint32 *) (((Uint8 *)srcp) + srcbpp); \
Apr 17, 2005
Apr 17, 2005
630
631
632
widthvar--; \
} \
}
Aug 17, 2007
Aug 17, 2007
633
int width = info->dst_w;
Apr 17, 2005
Apr 17, 2005
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
assert(width > 0);
if (width > 0) {
int extrawidth = (width % 4);
vector unsigned char valigner = VEC_ALIGNER(srcp);
vector unsigned int vs = vec_ld(0, srcp);
width -= extrawidth;
assert(width >= 4);
while (width) {
vector unsigned char vsel;
vector unsigned int vd;
vector unsigned int voverflow = vec_ld(15, srcp);
/* load the source vec */
vs = vec_perm(vs, voverflow, valigner);
/* vsel is set for items that match the key */
Jul 10, 2006
Jul 10, 2006
649
650
vsel = (vector unsigned char) vec_and(vs, vrgbmask);
vsel = (vector unsigned char) vec_cmpeq(vs, vckey);
Apr 17, 2005
Apr 17, 2005
651
652
653
654
655
/* permute the src vec to the dest format */
vs = vec_perm(vs, valpha, vpermute);
/* load the destination vec */
vd = vec_ld(0, dstp);
/* select the source and dest into vs */
Jul 10, 2006
Jul 10, 2006
656
657
658
659
vd = (vector unsigned int) vec_sel((vector unsigned char) vs,
(vector unsigned char) vd,
vsel);
Apr 17, 2005
Apr 17, 2005
660
661
662
663
664
665
666
667
vec_st(vd, 0, dstp);
srcp += 4;
width -= 4;
dstp += 4;
vs = voverflow;
}
ONE_PIXEL_BLEND((extrawidth), extrawidth);
#undef ONE_PIXEL_BLEND
Jan 25, 2009
Jan 25, 2009
668
669
srcp += srcskip;
dstp += dstskip;
Apr 17, 2005
Apr 17, 2005
670
671
672
673
674
675
}
}
}
/* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */
/* Use this on a G5 */
Jul 10, 2006
Jul 10, 2006
676
677
static void
ConvertAltivec32to32_noprefetch(SDL_BlitInfo * info)
Apr 17, 2005
Apr 17, 2005
678
{
Aug 17, 2007
Aug 17, 2007
679
680
int height = info->dst_h;
Uint32 *src = (Uint32 *) info->src;
Jan 25, 2009
Jan 25, 2009
681
int srcskip = info->src_skip / 4;
Aug 17, 2007
Aug 17, 2007
682
Uint32 *dst = (Uint32 *) info->dst;
Jan 25, 2009
Jan 25, 2009
683
684
685
int dstskip = info->dst_skip / 4;
SDL_PixelFormat *srcfmt = info->src_fmt;
SDL_PixelFormat *dstfmt = info->dst_fmt;
Apr 17, 2005
Apr 17, 2005
686
687
688
vector unsigned int vzero = vec_splat_u32(0);
vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
if (dstfmt->Amask && !srcfmt->Amask) {
Aug 18, 2007
Aug 18, 2007
689
if (info->a) {
Apr 17, 2005
Apr 17, 2005
690
vector unsigned char valpha;
Aug 18, 2007
Aug 18, 2007
691
((unsigned char *) &valpha)[0] = info->a;
Jul 10, 2006
Jul 10, 2006
692
vzero = (vector unsigned int) vec_splat(valpha, 0);
Apr 17, 2005
Apr 17, 2005
693
694
695
}
}
Feb 7, 2006
Feb 7, 2006
696
697
assert(srcfmt->BytesPerPixel == 4);
assert(dstfmt->BytesPerPixel == 4);
Apr 17, 2005
Apr 17, 2005
698
699
700
701
702
703
704
705
while (height--) {
vector unsigned char valigner;
vector unsigned int vbits;
vector unsigned int voverflow;
Uint32 bits;
Uint8 r, g, b, a;
Aug 17, 2007
Aug 17, 2007
706
int width = info->dst_w;
Apr 17, 2005
Apr 17, 2005
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
int extrawidth;
/* do scalar until we can align... */
while ((UNALIGNED_PTR(dst)) && (width)) {
bits = *(src++);
RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
*(dst++) = MAKE8888(dstfmt, r, g, b, a);
width--;
}
/* After all that work, here's the vector part! */
extrawidth = (width % 4);
width -= extrawidth;
valigner = VEC_ALIGNER(src);
vbits = vec_ld(0, src);
Jul 10, 2006
Jul 10, 2006
723
while (width) {
Apr 17, 2005
Apr 17, 2005
724
725
726
voverflow = vec_ld(15, src);
src += 4;
width -= 4;
Jul 10, 2006
Jul 10, 2006
727
728
729
vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */
vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */
vec_st(vbits, 0, dst); /* store it back out. */
Apr 17, 2005
Apr 17, 2005
730
731
732
733
734
735
736
737
dst += 4;
vbits = voverflow;
}
assert(width == 0);
/* cover pixels at the end of the row that didn't fit in 16 bytes. */
while (extrawidth) {
Jul 10, 2006
Jul 10, 2006
738
bits = *(src++); /* max 7 pixels, don't bother with prefetch. */
Apr 17, 2005
Apr 17, 2005
739
740
741
742
743
RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
*(dst++) = MAKE8888(dstfmt, r, g, b, a);
extrawidth--;
}
Jan 25, 2009
Jan 25, 2009
744
745
src += srcskip;
dst += dstskip;
Apr 17, 2005
Apr 17, 2005
746
747
748
749
750
751
}
}
/* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */
/* Use this on a G4 */
Jul 10, 2006
Jul 10, 2006
752
753
static void
ConvertAltivec32to32_prefetch(SDL_BlitInfo * info)
Apr 17, 2005
Apr 17, 2005
754
{
Jul 10, 2006
Jul 10, 2006
755
756
const int scalar_dst_lead = sizeof(Uint32) * 4;
const int vector_dst_lead = sizeof(Uint32) * 16;
Apr 17, 2005
Apr 17, 2005
757
Aug 17, 2007
Aug 17, 2007
758
759
int height = info->dst_h;
Uint32 *src = (Uint32 *) info->src;
Jan 25, 2009
Jan 25, 2009
760
int srcskip = info->src_skip / 4;
Aug 17, 2007
Aug 17, 2007
761
Uint32 *dst = (Uint32 *) info->dst;
Jan 25, 2009
Jan 25, 2009
762
763
764
int dstskip = info->dst_skip / 4;
SDL_PixelFormat *srcfmt = info->src_fmt;
SDL_PixelFormat *dstfmt = info->dst_fmt;
Apr 17, 2005
Apr 17, 2005
765
766
767
vector unsigned int vzero = vec_splat_u32(0);
vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
if (dstfmt->Amask && !srcfmt->Amask) {
Aug 18, 2007
Aug 18, 2007
768
if (info->a) {
Apr 17, 2005
Apr 17, 2005
769
vector unsigned char valpha;
Aug 18, 2007
Aug 18, 2007
770
((unsigned char *) &valpha)[0] = info->a;
Jul 10, 2006
Jul 10, 2006
771
vzero = (vector unsigned int) vec_splat(valpha, 0);
Apr 17, 2005
Apr 17, 2005
772
773
774
}
}
Feb 7, 2006
Feb 7, 2006
775
776
assert(srcfmt->BytesPerPixel == 4);
assert(dstfmt->BytesPerPixel == 4);
Apr 17, 2005
Apr 17, 2005
777
778
779
780
781
782
783
784
while (height--) {
vector unsigned char valigner;
vector unsigned int vbits;
vector unsigned int voverflow;
Uint32 bits;
Uint8 r, g, b, a;
Aug 17, 2007
Aug 17, 2007
785
int width = info->dst_w;
Apr 17, 2005
Apr 17, 2005
786
787
788
789
int extrawidth;
/* do scalar until we can align... */
while ((UNALIGNED_PTR(dst)) && (width)) {
Jul 10, 2006
Jul 10, 2006
790
791
792
793
vec_dstt(src + scalar_dst_lead, DST_CTRL(2, 32, 1024),
DST_CHAN_SRC);
vec_dstst(dst + scalar_dst_lead, DST_CTRL(2, 32, 1024),
DST_CHAN_DEST);
Apr 17, 2005
Apr 17, 2005
794
795
796
797
798
799
800
801
802
803
804
805
806
bits = *(src++);
RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
*(dst++) = MAKE8888(dstfmt, r, g, b, a);
width--;
}
/* After all that work, here's the vector part! */
extrawidth = (width % 4);
width -= extrawidth;
valigner = VEC_ALIGNER(src);
vbits = vec_ld(0, src);
while (width) {
Jul 10, 2006
Jul 10, 2006
807
808
809
810
vec_dstt(src + vector_dst_lead, DST_CTRL(2, 32, 1024),
DST_CHAN_SRC);
vec_dstst(dst + vector_dst_lead, DST_CTRL(2, 32, 1024),
DST_CHAN_DEST);
Apr 17, 2005
Apr 17, 2005
811
812
813
voverflow = vec_ld(15, src);
src += 4;
width -= 4;
Jul 10, 2006
Jul 10, 2006
814
815
816
vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */
vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */
vec_st(vbits, 0, dst); /* store it back out. */
Apr 17, 2005
Apr 17, 2005
817
818
819
dst += 4;
vbits = voverflow;
}
Jul 10, 2006
Jul 10, 2006
820
Apr 17, 2005
Apr 17, 2005
821
822
823
824
assert(width == 0);
/* cover pixels at the end of the row that didn't fit in 16 bytes. */
while (extrawidth) {
Jul 10, 2006
Jul 10, 2006
825
bits = *(src++); /* max 7 pixels, don't bother with prefetch. */
Apr 17, 2005
Apr 17, 2005
826
827
828
829
830
RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
*(dst++) = MAKE8888(dstfmt, r, g, b, a);
extrawidth--;
}
Jan 25, 2009
Jan 25, 2009
831
832
src += srcskip;
dst += dstskip;
Apr 17, 2005
Apr 17, 2005
833
834
835
836
837
838
}
vec_dss(DST_CHAN_SRC);
vec_dss(DST_CHAN_DEST);
}
Jul 10, 2006
Jul 10, 2006
839
840
static Uint32
GetBlitFeatures(void)
Apr 17, 2005
Apr 17, 2005
841
842
843
844
{
static Uint32 features = 0xffffffff;
if (features == 0xffffffff) {
/* Provide an override for testing .. */
Feb 7, 2006
Feb 7, 2006
845
char *override = SDL_getenv("SDL_ALTIVEC_BLIT_FEATURES");
Apr 17, 2005
Apr 17, 2005
846
847
if (override) {
features = 0;
Feb 7, 2006
Feb 7, 2006
848
SDL_sscanf(override, "%u", &features);
Apr 17, 2005
Apr 17, 2005
849
} else {
Jul 10, 2006
Jul 10, 2006
850
851
852
853
854
855
856
857
858
features = (0
/* Feature 1 is has-MMX */
| ((SDL_HasMMX())? 1 : 0)
/* Feature 2 is has-AltiVec */
| ((SDL_HasAltiVec())? 2 : 0)
/* Feature 4 is dont-use-prefetch */
/* !!!! FIXME: Check for G5 or later, not the cache size! Always prefetch on a G4. */
| ((GetL3CacheSize() == 0) ? 4 : 0)
);
Apr 17, 2005
Apr 17, 2005
859
860
861
862
}
}
return features;
}
Jul 10, 2006
Jul 10, 2006
863
May 9, 2006
May 9, 2006
864
865
866
#if __MWERKS__
#pragma altivec_model off
#endif
Apr 17, 2005
Apr 17, 2005
867
868
869
870
871
#else
/* Feature 1 is has-MMX */
#define GetBlitFeatures() ((Uint32)(SDL_HasMMX() ? 1 : 0))
#endif
Apr 20, 2005
Apr 20, 2005
872
/* This is now endian dependent */
Feb 26, 2006
Feb 26, 2006
873
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
Apr 20, 2005
Apr 20, 2005
874
875
#define HI 1
#define LO 0
Feb 26, 2006
Feb 26, 2006
876
#else /* SDL_BYTEORDER == SDL_BIG_ENDIAN */
Apr 20, 2005
Apr 20, 2005
877
878
879
880
#define HI 0
#define LO 1
#endif
Apr 26, 2001
Apr 26, 2001
881
882
/* Special optimized blit for RGB 8-8-8 --> RGB 3-3-2 */
#define RGB888_RGB332(dst, src) { \
Feb 24, 2006
Feb 24, 2006
883
884
885
dst = (Uint8)((((src)&0x00E00000)>>16)| \
(((src)&0x0000E000)>>11)| \
(((src)&0x000000C0)>>6)); \
Apr 26, 2001
Apr 26, 2001
886
}
Jul 10, 2006
Jul 10, 2006
887
888
static void
Blit_RGB888_index8(SDL_BlitInfo * info)
Apr 26, 2001
Apr 26, 2001
889
890
{
#ifndef USE_DUFFS_LOOP
Jul 10, 2006
Jul 10, 2006
891
int c;
Apr 26, 2001
Apr 26, 2001
892
#endif
Jul 10, 2006
Jul 10, 2006
893
894
895
896
897
898
899
int width, height;
Uint32 *src;
const Uint8 *map;
Uint8 *dst;
int srcskip, dstskip;
/* Set up some basic variables */
Aug 17, 2007
Aug 17, 2007
900
901
902
width = info->dst_w;
height = info->dst_h;
src = (Uint32 *) info->src;
Aug 18, 2007
Aug 18, 2007
903
srcskip = info->src_skip / 4;
Aug 17, 2007
Aug 17, 2007
904
dst = info->dst;
Aug 18, 2007
Aug 18, 2007
905
dstskip = info->dst_skip;
Jul 10, 2006
Jul 10, 2006
906
907
908
909
map = info->table;
if (map == NULL) {
while (height--) {
Apr 26, 2001
Apr 26, 2001
910
#ifdef USE_DUFFS_LOOP
Jul 10, 2006
Jul 10, 2006
911
/* *INDENT-OFF* */
Apr 26, 2001
Apr 26, 2001
912
913
914
DUFFS_LOOP(
RGB888_RGB332(*dst++, *src);
, width);
Jul 10, 2006
Jul 10, 2006
915
/* *INDENT-ON* */
Apr 26, 2001
Apr 26, 2001
916
#else
Jul 10, 2006
Jul 10, 2006
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
for (c = width / 4; c; --c) {
/* Pack RGB into 8bit pixel */
++src;
RGB888_RGB332(*dst++, *src);
++src;
RGB888_RGB332(*dst++, *src);
++src;
RGB888_RGB332(*dst++, *src);
++src;
}
switch (width & 3) {
case 3:
RGB888_RGB332(*dst++, *src);
++src;
case 2:
RGB888_RGB332(*dst++, *src);
++src;
case 1:
RGB888_RGB332(*dst++, *src);
++src;
}
Apr 26, 2001
Apr 26, 2001
938
#endif /* USE_DUFFS_LOOP */
Jul 10, 2006
Jul 10, 2006
939
940
941
942
943
src += srcskip;
dst += dstskip;
}
} else {
int Pixel;
Apr 26, 2001
Apr 26, 2001
944
Jul 10, 2006
Jul 10, 2006
945
while (height--) {
Apr 26, 2001
Apr 26, 2001
946
#ifdef USE_DUFFS_LOOP
Jul 10, 2006
Jul 10, 2006
947
/* *INDENT-OFF* */
Apr 26, 2001
Apr 26, 2001
948
DUFFS_LOOP(
Oct 20, 2005
Oct 20, 2005
949
950
RGB888_RGB332(Pixel, *src);
*dst++ = map[Pixel];
Apr 26, 2001
Apr 26, 2001
951
952
++src;
, width);
Jul 10, 2006
Jul 10, 2006
953
/* *INDENT-ON* */
Apr 26, 2001
Apr 26, 2001
954
#else
Jul 10, 2006
Jul 10, 2006
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
for (c = width / 4; c; --c) {
/* Pack RGB into 8bit pixel */
RGB888_RGB332(Pixel, *src);
*dst++ = map[Pixel];
++src;
RGB888_RGB332(Pixel, *src);
*dst++ = map[Pixel];
++src;
RGB888_RGB332(Pixel, *src);
*dst++ = map[Pixel];
++src;
RGB888_RGB332(Pixel, *src);
*dst++ = map[Pixel];
++src;
}
switch (width & 3) {
case 3:
RGB888_RGB332(Pixel, *src);
*dst++ = map[Pixel];
++src;
case 2:
RGB888_RGB332(Pixel, *src);
*dst++ = map[Pixel];
++src;
case 1:
RGB888_RGB332(Pixel, *src);
*dst++ = map[Pixel];
++src;
}
Apr 26, 2001
Apr 26, 2001
984
#endif /* USE_DUFFS_LOOP */
Jul 10, 2006
Jul 10, 2006
985
986
987
988
src += srcskip;
dst += dstskip;
}
}
Apr 26, 2001
Apr 26, 2001
989
}
Jul 10, 2006
Jul 10, 2006
990
Apr 26, 2001
Apr 26, 2001
991
992
/* Special optimized blit for RGB 8-8-8 --> RGB 5-5-5 */
#define RGB888_RGB555(dst, src) { \
Feb 24, 2006
Feb 24, 2006
993
994
995
*(Uint16 *)(dst) = (Uint16)((((*src)&0x00F80000)>>9)| \
(((*src)&0x0000F800)>>6)| \
(((*src)&0x000000F8)>>3)); \
Apr 26, 2001
Apr 26, 2001
996
997
998
999
1000
}
#define RGB888_RGB555_TWO(dst, src) { \
*(Uint32 *)(dst) = (((((src[HI])&0x00F80000)>>9)| \
(((src[HI])&0x0000F800)>>6)| \
(((src[HI])&0x000000F8)>>3))<<16)| \