-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphics_altivec.cpp
123 lines (97 loc) · 3.46 KB
/
graphics_altivec.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
/* -*- C++ -*-
*
* graphics_altivec.cpp - graphics routines using PPC Altivec cpu functionality
*
* 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
*/
// Based upon routines provided by Roto
#ifdef USE_PPC_GFX
#include <altivec.h>
#include <math.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "graphics_sum.h"
namespace ons_gfx {
void imageFilterMean_Altivec(unsigned char *src1, unsigned char *src2, unsigned char *dst, int length)
{
int n = length;
// Compute first few values so we're on a 16-byte boundary in dst
while( (((long)dst & 0xF) > 0) && (n > 0) ) {
MEAN_PIXEL();
--n; ++dst; ++src1; ++src2;
}
// Do bulk of processing using Altivec (find the mean of 16 8-bit unsigned integers, with saturation)
vector unsigned char rshft = vec_splat_u8(0x1);
while(n >= 16) {
vector unsigned char s1 = vec_ld(0,src1);
s1 = vec_sr(s1, rshft); // shift right 1
vector unsigned char s2 = vec_ld(0,src2);
s2 = vec_sr(s2, rshft); // shift right 1
vector unsigned char r = vec_adds(s1, s2);
vec_st(r,0,dst);
n -= 16; src1 += 16; src2 += 16; dst += 16;
}
// If any bytes are left over, deal with them individually
++n;
BASIC_MEAN();
}
void imageFilterAddTo_Altivec(unsigned char *dst, unsigned char *src, int length)
{
int n = length;
// Compute first few values so we're on a 16-byte boundary in dst
while( (((long)dst & 0xF) > 0) && (n > 0) ) {
ADDTO_PIXEL();
--n; ++dst; ++src;
}
// Do bulk of processing using Altivec (add 16 8-bit unsigned integers, with saturation)
while(n >= 16) {
vector unsigned char s = vec_ld(0,src);
vector unsigned char d = vec_ld(0,dst);
vector unsigned char r = vec_adds(d, s);
vec_st(r,0,dst);
n -= 16; src += 16; dst += 16;
}
// If any bytes are left over, deal with them individually
++n;
BASIC_ADDTO();
}
void imageFilterSubFrom_Altivec(unsigned char *dst, unsigned char *src, int length)
{
int n = length;
// Compute first few values so we're on a 16-byte boundary in dst
while( (((long)dst & 0xF) > 0) && (n > 0) ) {
SUBFROM_PIXEL();
--n; ++dst; ++src;
}
// Do bulk of processing using Altivec (sub 16 8-bit unsigned integers, with saturation)
while(n >= 16) {
vector unsigned char s = vec_ld(0,src);
vector unsigned char d = vec_ld(0,dst);
vector unsigned char r = vec_subs(d, s);
vec_st(r,0,dst);
n -= 16; src += 16; dst += 16;
}
// If any bytes are left over, deal with them individually
++n;
BASIC_SUBFROM();
}
}//namespace ons_gfx
#endif //USE_PPC_GFX