Skip to content

Commit 3e777c7

Browse files
Jason SamsAndroid (Google) Code Review
authored andcommitted
Merge "Add ColorMatrix Intrinsic." into jb-mr1-dev
2 parents 27230f0 + 5729fcd commit 3e777c7

File tree

6 files changed

+254
-31
lines changed

6 files changed

+254
-31
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright (C) 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+
package android.renderscript;
18+
19+
import android.content.Context;
20+
import android.content.res.Resources;
21+
import android.util.Log;
22+
23+
import java.io.File;
24+
import java.io.IOException;
25+
import java.io.InputStream;
26+
import java.util.Map.Entry;
27+
import java.util.HashMap;
28+
29+
30+
/**
31+
* @hide
32+
**/
33+
public class ScriptIntrinsicColorMatrix extends ScriptIntrinsic {
34+
private Matrix4f mMatrix = new Matrix4f();
35+
private Allocation mInput;
36+
37+
ScriptIntrinsicColorMatrix(int id, RenderScript rs) {
38+
super(id, rs);
39+
}
40+
41+
/**
42+
* Supported elements types are float, float4, uchar, uchar4
43+
*
44+
*
45+
* @param rs
46+
* @param e
47+
*
48+
* @return ScriptIntrinsicColorMatrix
49+
*/
50+
public static ScriptIntrinsicColorMatrix create(RenderScript rs, Element e) {
51+
int id = rs.nScriptIntrinsicCreate(2, e.getID(rs));
52+
return new ScriptIntrinsicColorMatrix(id, rs);
53+
54+
}
55+
56+
public void setColorMatrix(Matrix4f m) {
57+
mMatrix.load(m);
58+
FieldPacker fp = new FieldPacker(16*4);
59+
fp.addMatrix(m);
60+
setVar(0, fp);
61+
}
62+
63+
public void forEach(Allocation ain, Allocation aout) {
64+
forEach(0, ain, aout, null);
65+
}
66+
67+
}
68+
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (C) 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+
package com.android.rs.image;
18+
19+
import java.lang.Math;
20+
21+
import android.renderscript.Allocation;
22+
import android.renderscript.Element;
23+
import android.renderscript.Matrix4f;
24+
import android.renderscript.RenderScript;
25+
import android.renderscript.Script;
26+
import android.renderscript.ScriptC;
27+
import android.renderscript.ScriptGroup;
28+
import android.renderscript.ScriptIntrinsicColorMatrix;
29+
import android.renderscript.Type;
30+
import android.util.Log;
31+
32+
public class ColorMatrix extends TestBase {
33+
private ScriptC_colormatrix mScript;
34+
private ScriptIntrinsicColorMatrix mIntrinsic;
35+
private boolean mUseIntrinsic;
36+
37+
public ColorMatrix(boolean useIntrinsic) {
38+
mUseIntrinsic = useIntrinsic;
39+
}
40+
41+
public void createTest(android.content.res.Resources res) {
42+
Matrix4f m = new Matrix4f();
43+
m.set(1, 0, 0.2f);
44+
m.set(1, 1, 0.9f);
45+
m.set(1, 2, 0.2f);
46+
47+
if (mUseIntrinsic) {
48+
mIntrinsic = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS));
49+
mIntrinsic.setColorMatrix(m);
50+
} else {
51+
mScript = new ScriptC_colormatrix(mRS, res, R.raw.colormatrix);
52+
mScript.invoke_setMatrix(m);
53+
}
54+
}
55+
56+
public void runTest() {
57+
if (mUseIntrinsic) {
58+
mIntrinsic.forEach(mInPixelsAllocation, mOutPixelsAllocation);
59+
} else {
60+
mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
61+
}
62+
}
63+
64+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (C) 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+
package com.android.rs.image;
18+
19+
import java.lang.Math;
20+
21+
import android.renderscript.Allocation;
22+
import android.renderscript.Element;
23+
import android.renderscript.Matrix4f;
24+
import android.renderscript.RenderScript;
25+
import android.renderscript.Script;
26+
import android.renderscript.ScriptC;
27+
import android.renderscript.ScriptGroup;
28+
import android.renderscript.ScriptIntrinsicConvolve3x3;
29+
import android.renderscript.Type;
30+
import android.util.Log;
31+
32+
public class Convolve3x3 extends TestBase {
33+
private ScriptC_convolve3x3 mScript;
34+
private ScriptIntrinsicConvolve3x3 mIntrinsic;
35+
36+
private int mWidth;
37+
private int mHeight;
38+
private boolean mUseIntrinsic;
39+
40+
public Convolve3x3(boolean useIntrinsic) {
41+
mUseIntrinsic = useIntrinsic;
42+
}
43+
44+
public void createTest(android.content.res.Resources res) {
45+
mWidth = mInPixelsAllocation.getType().getX();
46+
mHeight = mInPixelsAllocation.getType().getY();
47+
48+
float f[] = new float[9];
49+
f[0] = 0.f; f[1] = -1.f; f[2] = 0.f;
50+
f[3] = -1.f; f[4] = 5.f; f[5] = -1.f;
51+
f[6] = 0.f; f[7] = -1.f; f[8] = 0.f;
52+
53+
if (mUseIntrinsic) {
54+
mIntrinsic = ScriptIntrinsicConvolve3x3.create(mRS, Element.U8_4(mRS));
55+
mIntrinsic.setColorMatrix(f);
56+
mIntrinsic.setInput(mInPixelsAllocation);
57+
} else {
58+
mScript = new ScriptC_convolve3x3(mRS, res, R.raw.convolve3x3);
59+
mScript.set_gCoeffs(f);
60+
mScript.set_gIn(mInPixelsAllocation);
61+
mScript.set_gWidth(mWidth);
62+
mScript.set_gHeight(mHeight);
63+
}
64+
}
65+
66+
public void runTest() {
67+
if (mUseIntrinsic) {
68+
mIntrinsic.forEach(mOutPixelsAllocation);
69+
} else {
70+
mScript.forEach_root(mOutPixelsAllocation);
71+
}
72+
}
73+
74+
}

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Intrinsics.java renamed to tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Copy.java

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,19 @@
2222
import android.renderscript.Element;
2323
import android.renderscript.RenderScript;
2424
import android.renderscript.Script;
25-
import android.renderscript.ScriptIntrinsicConvolve3x3;
25+
import android.renderscript.ScriptC;
2626
import android.renderscript.Type;
2727
import android.util.Log;
28-
import android.widget.SeekBar;
29-
import android.widget.TextView;
30-
31-
public class Intrinsics extends TestBase {
32-
private ScriptIntrinsicConvolve3x3 mScript;
33-
34-
Intrinsics(int id) {
35-
}
36-
37-
public boolean onBar1Setup(SeekBar b, TextView t) {
38-
t.setText("Strength");
39-
b.setProgress(50);
40-
return true;
41-
}
42-
43-
public void onBar1Changed(int progress) {
44-
float s = progress / 100.0f;
45-
float v[] = new float[9];
46-
v[0] = 0.f; v[1] = -s; v[2] = 0.f;
47-
v[3] = -s; v[4] = s*4+1; v[5] = -s;
48-
v[6] = 0.f; v[7] = -s; v[8] = 0.f;
49-
mScript.setColorMatrix(v);
50-
}
5128

29+
public class Copy extends TestBase {
30+
private ScriptC_copy mScript;
5231

5332
public void createTest(android.content.res.Resources res) {
54-
mScript = ScriptIntrinsicConvolve3x3.create(mRS, Element.RGBA_8888(mRS));
33+
mScript = new ScriptC_copy(mRS, res, R.raw.copy);
5534
}
5635

5736
public void runTest() {
58-
mScript.setInput(mInPixelsAllocation);
59-
mScript.forEach(mOutPixelsAllocation);
37+
mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation);
6038
}
6139

6240
}
63-

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,19 @@ void changeTest(int testID) {
174174
mTest = new GroupTest(true);
175175
break;
176176
case 17:
177-
mTest = new Intrinsics(0);
177+
mTest = new Convolve3x3(false);
178+
break;
179+
case 18:
180+
mTest = new Convolve3x3(true);
181+
break;
182+
case 19:
183+
mTest = new ColorMatrix(false);
184+
break;
185+
case 20:
186+
mTest = new ColorMatrix(true);
187+
break;
188+
case 21:
189+
mTest = new Copy();
178190
break;
179191
}
180192

@@ -188,7 +200,7 @@ void changeTest(int testID) {
188200
}
189201

190202
void setupTests() {
191-
mTestNames = new String[18];
203+
mTestNames = new String[22];
192204
mTestNames[0] = "Levels Vec3 Relaxed";
193205
mTestNames[1] = "Levels Vec4 Relaxed";
194206
mTestNames[2] = "Levels Vec3 Full";
@@ -206,7 +218,11 @@ void setupTests() {
206218
mTestNames[14] = "Vignette Approximate Relaxed";
207219
mTestNames[15] = "Group Test (emulated)";
208220
mTestNames[16] = "Group Test (native)";
209-
mTestNames[17] = "Intrinsics Convolve 3x3";
221+
mTestNames[17] = "Convolve 3x3";
222+
mTestNames[18] = "Intrinsics Convolve 3x3";
223+
mTestNames[19] = "ColorMatrix";
224+
mTestNames[20] = "Intrinsics ColorMatrix";
225+
mTestNames[21] = "Copy";
210226
mTestSpinner.setAdapter(new ArrayAdapter<String>(
211227
this, R.layout.spinner_layout, mTestNames));
212228
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (C) 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+
#pragma version(1)
18+
#pragma rs java_package_name(com.android.rs.image)
19+
20+
void root(const uchar4 *v_in, uchar4 *v_out) {
21+
*v_out = *v_in;
22+
}
23+
24+

0 commit comments

Comments
 (0)