ScriptIntrinsics.cpp revision 89daad6bae798779e57f252e9da4fe4e62337124
1/*
2 * Copyright (C) 2008-2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <malloc.h>
18
19#include "RenderScript.h"
20
21using namespace android;
22using namespace RSC;
23
24ScriptIntrinsic::ScriptIntrinsic(sp<RS> rs, int id, sp<const Element> e)
25    : Script(NULL, rs) {
26    mID = RS::dispatch->ScriptIntrinsicCreate(rs->getContext(), id, e->getID());
27}
28
29ScriptIntrinsic3DLUT::ScriptIntrinsic3DLUT(sp<RS> rs, sp<const Element> e)
30    : ScriptIntrinsic(rs, RS_SCRIPT_INTRINSIC_ID_3DLUT, e) {
31
32}
33void ScriptIntrinsic3DLUT::forEach(sp<Allocation> ain, sp<Allocation> aout) {
34    Script::forEach(0, ain, aout, NULL, 0);
35}
36void ScriptIntrinsic3DLUT::setLUT(sp<Allocation> lut) {
37    Script::setVar(0, lut);
38}
39
40ScriptIntrinsicBlend::ScriptIntrinsicBlend(sp<RS> rs, sp<const Element> e)
41    : ScriptIntrinsic(rs, RS_SCRIPT_INTRINSIC_ID_BLEND, e) {
42}
43
44void ScriptIntrinsicBlend::blendClear(sp<Allocation> in, sp<Allocation> out) {
45    Script::forEach(0, in, out, NULL, 0);
46}
47
48void ScriptIntrinsicBlend::blendSrc(sp<Allocation> in, sp<Allocation> out) {
49    Script::forEach(1, in, out, NULL, 0);
50}
51
52void ScriptIntrinsicBlend::blendDst(sp<Allocation> in, sp<Allocation> out) {
53    Script::forEach(2, in, out, NULL, 0);
54}
55
56void ScriptIntrinsicBlend::blendSrcOver(sp<Allocation> in, sp<Allocation> out) {
57    Script::forEach(3, in, out, NULL, 0);
58}
59
60void ScriptIntrinsicBlend::blendDstOver(sp<Allocation> in, sp<Allocation> out) {
61    Script::forEach(4, in, out, NULL, 0);
62}
63
64void ScriptIntrinsicBlend::blendSrcIn(sp<Allocation> in, sp<Allocation> out) {
65    Script::forEach(5, in, out, NULL, 0);
66}
67
68void ScriptIntrinsicBlend::blendDstIn(sp<Allocation> in, sp<Allocation> out) {
69    Script::forEach(6, in, out, NULL, 0);
70}
71
72void ScriptIntrinsicBlend::blendSrcOut(sp<Allocation> in, sp<Allocation> out) {
73    Script::forEach(7, in, out, NULL, 0);
74}
75
76void ScriptIntrinsicBlend::blendDstOut(sp<Allocation> in, sp<Allocation> out) {
77    Script::forEach(8, in, out, NULL, 0);
78}
79
80void ScriptIntrinsicBlend::blendSrcAtop(sp<Allocation> in, sp<Allocation> out) {
81    Script::forEach(9, in, out, NULL, 0);
82}
83
84void ScriptIntrinsicBlend::blendDstAtop(sp<Allocation> in, sp<Allocation> out) {
85    Script::forEach(10, in, out, NULL, 0);
86}
87
88void ScriptIntrinsicBlend::blendXor(sp<Allocation> in, sp<Allocation> out) {
89    Script::forEach(11, in, out, NULL, 0);
90}
91
92// Numbering jumps here
93void ScriptIntrinsicBlend::blendMultiply(sp<Allocation> in, sp<Allocation> out) {
94    Script::forEach(14, in, out, NULL, 0);
95}
96
97// Numbering jumps here
98void ScriptIntrinsicBlend::blendAdd(sp<Allocation> in, sp<Allocation> out) {
99    Script::forEach(34, in, out, NULL, 0);
100}
101
102void ScriptIntrinsicBlend::blendSubtract(sp<Allocation> in, sp<Allocation> out) {
103    Script::forEach(35, in, out, NULL, 0);
104}
105
106
107
108
109ScriptIntrinsicBlur::ScriptIntrinsicBlur(sp<RS> rs, sp<const Element> e)
110    : ScriptIntrinsic(rs, RS_SCRIPT_INTRINSIC_ID_BLUR, e) {
111
112}
113
114void ScriptIntrinsicBlur::blur(sp<Allocation> in, sp<Allocation> out) {
115    Script::setVar(1, in);
116    Script::forEach(0, NULL, out, NULL, 0);
117}
118
119void ScriptIntrinsicBlur::setRadius(float radius) {
120    Script::setVar(0, &radius, sizeof(float));
121}
122
123
124
125ScriptIntrinsicColorMatrix::ScriptIntrinsicColorMatrix(sp<RS> rs, sp<const Element> e)
126    : ScriptIntrinsic(rs, RS_SCRIPT_INTRINSIC_ID_COLOR_MATRIX, e) {
127
128}
129
130void ScriptIntrinsicColorMatrix::forEach(sp<Allocation> in, sp<Allocation> out) {
131    Script::forEach(0, in, out, NULL, 0);
132}
133
134
135void ScriptIntrinsicColorMatrix::setColorMatrix3(float* m) {
136    Script::setVar(0, (void*)m, sizeof(float) * 9);
137}
138
139
140void ScriptIntrinsicColorMatrix::setColorMatrix4(float* m) {
141    Script::setVar(0, (void*)m, sizeof(float) * 16);
142}
143
144
145void ScriptIntrinsicColorMatrix::setGreyscale() {
146    float matrix[] = {0.299f, 0.587f,  0.114f, 0.299f, 0.587f, 0.114f, 0.299f, 0.587f, 0.114f};
147    setColorMatrix3(matrix);
148}
149
150
151void ScriptIntrinsicColorMatrix::setRGBtoYUV() {
152    float matrix[] = {0.299f,0.587f,0.114f,-0.14713f,-0.28886f,0.436f,0.615f,-0.51499f,-0.10001f};
153    setColorMatrix3(matrix);
154}
155
156
157void ScriptIntrinsicColorMatrix::setYUVtoRGB() {
158    float matrix[] = {1.f,0.f,1.13983f,1.f,-0.39465f,-0.5806f,1.f,2.03211f,0.f};
159    setColorMatrix3(matrix);
160}
161
162ScriptIntrinsicConvolve3x3::ScriptIntrinsicConvolve3x3(sp<RS> rs, sp<const Element> e)
163    : ScriptIntrinsic(rs, RS_SCRIPT_INTRINSIC_ID_CONVOLVE_3x3, e) {
164
165}
166
167void ScriptIntrinsicConvolve3x3::setInput(sp<Allocation> in) {
168    Script::setVar(1, in);
169}
170
171void ScriptIntrinsicConvolve3x3::forEach(sp<Allocation> out) {
172    Script::forEach(0, NULL, out, NULL, 0);
173}
174
175void ScriptIntrinsicConvolve3x3::setCoefficients(float* v) {
176    Script::setVar(0, (void*)v, sizeof(float) * 9);
177}
178
179ScriptIntrinsicConvolve5x5::ScriptIntrinsicConvolve5x5(sp<RS> rs, sp<const Element> e)
180    : ScriptIntrinsic(rs, RS_SCRIPT_INTRINSIC_ID_CONVOLVE_5x5, e) {
181
182}
183
184void ScriptIntrinsicConvolve5x5::setInput(sp<Allocation> in) {
185    Script::setVar(1, in);
186}
187
188void ScriptIntrinsicConvolve5x5::forEach(sp<Allocation> out) {
189    Script::forEach(0, NULL, out, NULL, 0);
190}
191
192void ScriptIntrinsicConvolve5x5::setCoefficients(float* v) {
193    Script::setVar(0, (void*)v, sizeof(float) * 25);
194}
195
196/*ScriptIntrinsicLUT::ScriptIntrinsicLUT(sp<RS> rs, sp<const Element> e)
197    : ScriptIntrinsic(rs, RS_SCRIPT_INTRINSIC_ID_LUT, e) {
198
199}
200
201void ScriptIntrinsicLUT::forEach(sp<Allocation> ain, sp<Allocation> aout) {
202
203}
204
205void ScriptIntrinsicLUT::setLUT(sp<Allocation> lut) {
206
207}*/
208
209