Loading graphics/java/android/renderscript/ScriptIntrinsicColorMatrix.java 0 → 100644 +68 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.renderscript; import android.content.Context; import android.content.res.Resources; import android.util.Log; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.Map.Entry; import java.util.HashMap; /** * @hide **/ public class ScriptIntrinsicColorMatrix extends ScriptIntrinsic { private Matrix4f mMatrix = new Matrix4f(); private Allocation mInput; ScriptIntrinsicColorMatrix(int id, RenderScript rs) { super(id, rs); } /** * Supported elements types are float, float4, uchar, uchar4 * * * @param rs * @param e * * @return ScriptIntrinsicColorMatrix */ public static ScriptIntrinsicColorMatrix create(RenderScript rs, Element e) { int id = rs.nScriptIntrinsicCreate(2, e.getID(rs)); return new ScriptIntrinsicColorMatrix(id, rs); } public void setColorMatrix(Matrix4f m) { mMatrix.load(m); FieldPacker fp = new FieldPacker(16*4); fp.addMatrix(m); setVar(0, fp); } public void forEach(Allocation ain, Allocation aout) { forEach(0, ain, aout, null); } } tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ColorMatrix.java 0 → 100644 +64 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.rs.image; import java.lang.Math; import android.renderscript.Allocation; import android.renderscript.Element; import android.renderscript.Matrix4f; import android.renderscript.RenderScript; import android.renderscript.Script; import android.renderscript.ScriptC; import android.renderscript.ScriptGroup; import android.renderscript.ScriptIntrinsicColorMatrix; import android.renderscript.Type; import android.util.Log; public class ColorMatrix extends TestBase { private ScriptC_colormatrix mScript; private ScriptIntrinsicColorMatrix mIntrinsic; private boolean mUseIntrinsic; public ColorMatrix(boolean useIntrinsic) { mUseIntrinsic = useIntrinsic; } public void createTest(android.content.res.Resources res) { Matrix4f m = new Matrix4f(); m.set(1, 0, 0.2f); m.set(1, 1, 0.9f); m.set(1, 2, 0.2f); if (mUseIntrinsic) { mIntrinsic = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS)); mIntrinsic.setColorMatrix(m); } else { mScript = new ScriptC_colormatrix(mRS, res, R.raw.colormatrix); mScript.invoke_setMatrix(m); } } public void runTest() { if (mUseIntrinsic) { mIntrinsic.forEach(mInPixelsAllocation, mOutPixelsAllocation); } else { mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation); } } } tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Convolve3x3.java 0 → 100644 +74 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.rs.image; import java.lang.Math; import android.renderscript.Allocation; import android.renderscript.Element; import android.renderscript.Matrix4f; import android.renderscript.RenderScript; import android.renderscript.Script; import android.renderscript.ScriptC; import android.renderscript.ScriptGroup; import android.renderscript.ScriptIntrinsicConvolve3x3; import android.renderscript.Type; import android.util.Log; public class Convolve3x3 extends TestBase { private ScriptC_convolve3x3 mScript; private ScriptIntrinsicConvolve3x3 mIntrinsic; private int mWidth; private int mHeight; private boolean mUseIntrinsic; public Convolve3x3(boolean useIntrinsic) { mUseIntrinsic = useIntrinsic; } public void createTest(android.content.res.Resources res) { mWidth = mInPixelsAllocation.getType().getX(); mHeight = mInPixelsAllocation.getType().getY(); float f[] = new float[9]; f[0] = 0.f; f[1] = -1.f; f[2] = 0.f; f[3] = -1.f; f[4] = 5.f; f[5] = -1.f; f[6] = 0.f; f[7] = -1.f; f[8] = 0.f; if (mUseIntrinsic) { mIntrinsic = ScriptIntrinsicConvolve3x3.create(mRS, Element.U8_4(mRS)); mIntrinsic.setColorMatrix(f); mIntrinsic.setInput(mInPixelsAllocation); } else { mScript = new ScriptC_convolve3x3(mRS, res, R.raw.convolve3x3); mScript.set_gCoeffs(f); mScript.set_gIn(mInPixelsAllocation); mScript.set_gWidth(mWidth); mScript.set_gHeight(mHeight); } } public void runTest() { if (mUseIntrinsic) { mIntrinsic.forEach(mOutPixelsAllocation); } else { mScript.forEach_root(mOutPixelsAllocation); } } } tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Intrinsics.java→tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Copy.java +5 −28 Original line number Diff line number Diff line Loading @@ -22,42 +22,19 @@ import android.renderscript.Allocation; import android.renderscript.Element; import android.renderscript.RenderScript; import android.renderscript.Script; import android.renderscript.ScriptIntrinsicConvolve3x3; import android.renderscript.ScriptC; import android.renderscript.Type; import android.util.Log; import android.widget.SeekBar; import android.widget.TextView; public class Intrinsics extends TestBase { private ScriptIntrinsicConvolve3x3 mScript; Intrinsics(int id) { } public boolean onBar1Setup(SeekBar b, TextView t) { t.setText("Strength"); b.setProgress(50); return true; } public void onBar1Changed(int progress) { float s = progress / 100.0f; float v[] = new float[9]; v[0] = 0.f; v[1] = -s; v[2] = 0.f; v[3] = -s; v[4] = s*4+1; v[5] = -s; v[6] = 0.f; v[7] = -s; v[8] = 0.f; mScript.setColorMatrix(v); } public class Copy extends TestBase { private ScriptC_copy mScript; public void createTest(android.content.res.Resources res) { mScript = ScriptIntrinsicConvolve3x3.create(mRS, Element.RGBA_8888(mRS)); mScript = new ScriptC_copy(mRS, res, R.raw.copy); } public void runTest() { mScript.setInput(mInPixelsAllocation); mScript.forEach(mOutPixelsAllocation); mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation); } } tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java +19 −3 Original line number Diff line number Diff line Loading @@ -174,7 +174,19 @@ public class ImageProcessingActivity extends Activity mTest = new GroupTest(true); break; case 17: mTest = new Intrinsics(0); mTest = new Convolve3x3(false); break; case 18: mTest = new Convolve3x3(true); break; case 19: mTest = new ColorMatrix(false); break; case 20: mTest = new ColorMatrix(true); break; case 21: mTest = new Copy(); break; } Loading @@ -188,7 +200,7 @@ public class ImageProcessingActivity extends Activity } void setupTests() { mTestNames = new String[18]; mTestNames = new String[22]; mTestNames[0] = "Levels Vec3 Relaxed"; mTestNames[1] = "Levels Vec4 Relaxed"; mTestNames[2] = "Levels Vec3 Full"; Loading @@ -206,7 +218,11 @@ public class ImageProcessingActivity extends Activity mTestNames[14] = "Vignette Approximate Relaxed"; mTestNames[15] = "Group Test (emulated)"; mTestNames[16] = "Group Test (native)"; mTestNames[17] = "Intrinsics Convolve 3x3"; mTestNames[17] = "Convolve 3x3"; mTestNames[18] = "Intrinsics Convolve 3x3"; mTestNames[19] = "ColorMatrix"; mTestNames[20] = "Intrinsics ColorMatrix"; mTestNames[21] = "Copy"; mTestSpinner.setAdapter(new ArrayAdapter<String>( this, R.layout.spinner_layout, mTestNames)); } Loading Loading
graphics/java/android/renderscript/ScriptIntrinsicColorMatrix.java 0 → 100644 +68 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.renderscript; import android.content.Context; import android.content.res.Resources; import android.util.Log; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.Map.Entry; import java.util.HashMap; /** * @hide **/ public class ScriptIntrinsicColorMatrix extends ScriptIntrinsic { private Matrix4f mMatrix = new Matrix4f(); private Allocation mInput; ScriptIntrinsicColorMatrix(int id, RenderScript rs) { super(id, rs); } /** * Supported elements types are float, float4, uchar, uchar4 * * * @param rs * @param e * * @return ScriptIntrinsicColorMatrix */ public static ScriptIntrinsicColorMatrix create(RenderScript rs, Element e) { int id = rs.nScriptIntrinsicCreate(2, e.getID(rs)); return new ScriptIntrinsicColorMatrix(id, rs); } public void setColorMatrix(Matrix4f m) { mMatrix.load(m); FieldPacker fp = new FieldPacker(16*4); fp.addMatrix(m); setVar(0, fp); } public void forEach(Allocation ain, Allocation aout) { forEach(0, ain, aout, null); } }
tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ColorMatrix.java 0 → 100644 +64 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.rs.image; import java.lang.Math; import android.renderscript.Allocation; import android.renderscript.Element; import android.renderscript.Matrix4f; import android.renderscript.RenderScript; import android.renderscript.Script; import android.renderscript.ScriptC; import android.renderscript.ScriptGroup; import android.renderscript.ScriptIntrinsicColorMatrix; import android.renderscript.Type; import android.util.Log; public class ColorMatrix extends TestBase { private ScriptC_colormatrix mScript; private ScriptIntrinsicColorMatrix mIntrinsic; private boolean mUseIntrinsic; public ColorMatrix(boolean useIntrinsic) { mUseIntrinsic = useIntrinsic; } public void createTest(android.content.res.Resources res) { Matrix4f m = new Matrix4f(); m.set(1, 0, 0.2f); m.set(1, 1, 0.9f); m.set(1, 2, 0.2f); if (mUseIntrinsic) { mIntrinsic = ScriptIntrinsicColorMatrix.create(mRS, Element.U8_4(mRS)); mIntrinsic.setColorMatrix(m); } else { mScript = new ScriptC_colormatrix(mRS, res, R.raw.colormatrix); mScript.invoke_setMatrix(m); } } public void runTest() { if (mUseIntrinsic) { mIntrinsic.forEach(mInPixelsAllocation, mOutPixelsAllocation); } else { mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation); } } }
tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Convolve3x3.java 0 → 100644 +74 −0 Original line number Diff line number Diff line /* * Copyright (C) 2012 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.rs.image; import java.lang.Math; import android.renderscript.Allocation; import android.renderscript.Element; import android.renderscript.Matrix4f; import android.renderscript.RenderScript; import android.renderscript.Script; import android.renderscript.ScriptC; import android.renderscript.ScriptGroup; import android.renderscript.ScriptIntrinsicConvolve3x3; import android.renderscript.Type; import android.util.Log; public class Convolve3x3 extends TestBase { private ScriptC_convolve3x3 mScript; private ScriptIntrinsicConvolve3x3 mIntrinsic; private int mWidth; private int mHeight; private boolean mUseIntrinsic; public Convolve3x3(boolean useIntrinsic) { mUseIntrinsic = useIntrinsic; } public void createTest(android.content.res.Resources res) { mWidth = mInPixelsAllocation.getType().getX(); mHeight = mInPixelsAllocation.getType().getY(); float f[] = new float[9]; f[0] = 0.f; f[1] = -1.f; f[2] = 0.f; f[3] = -1.f; f[4] = 5.f; f[5] = -1.f; f[6] = 0.f; f[7] = -1.f; f[8] = 0.f; if (mUseIntrinsic) { mIntrinsic = ScriptIntrinsicConvolve3x3.create(mRS, Element.U8_4(mRS)); mIntrinsic.setColorMatrix(f); mIntrinsic.setInput(mInPixelsAllocation); } else { mScript = new ScriptC_convolve3x3(mRS, res, R.raw.convolve3x3); mScript.set_gCoeffs(f); mScript.set_gIn(mInPixelsAllocation); mScript.set_gWidth(mWidth); mScript.set_gHeight(mHeight); } } public void runTest() { if (mUseIntrinsic) { mIntrinsic.forEach(mOutPixelsAllocation); } else { mScript.forEach_root(mOutPixelsAllocation); } } }
tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Intrinsics.java→tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/Copy.java +5 −28 Original line number Diff line number Diff line Loading @@ -22,42 +22,19 @@ import android.renderscript.Allocation; import android.renderscript.Element; import android.renderscript.RenderScript; import android.renderscript.Script; import android.renderscript.ScriptIntrinsicConvolve3x3; import android.renderscript.ScriptC; import android.renderscript.Type; import android.util.Log; import android.widget.SeekBar; import android.widget.TextView; public class Intrinsics extends TestBase { private ScriptIntrinsicConvolve3x3 mScript; Intrinsics(int id) { } public boolean onBar1Setup(SeekBar b, TextView t) { t.setText("Strength"); b.setProgress(50); return true; } public void onBar1Changed(int progress) { float s = progress / 100.0f; float v[] = new float[9]; v[0] = 0.f; v[1] = -s; v[2] = 0.f; v[3] = -s; v[4] = s*4+1; v[5] = -s; v[6] = 0.f; v[7] = -s; v[8] = 0.f; mScript.setColorMatrix(v); } public class Copy extends TestBase { private ScriptC_copy mScript; public void createTest(android.content.res.Resources res) { mScript = ScriptIntrinsicConvolve3x3.create(mRS, Element.RGBA_8888(mRS)); mScript = new ScriptC_copy(mRS, res, R.raw.copy); } public void runTest() { mScript.setInput(mInPixelsAllocation); mScript.forEach(mOutPixelsAllocation); mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation); } }
tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java +19 −3 Original line number Diff line number Diff line Loading @@ -174,7 +174,19 @@ public class ImageProcessingActivity extends Activity mTest = new GroupTest(true); break; case 17: mTest = new Intrinsics(0); mTest = new Convolve3x3(false); break; case 18: mTest = new Convolve3x3(true); break; case 19: mTest = new ColorMatrix(false); break; case 20: mTest = new ColorMatrix(true); break; case 21: mTest = new Copy(); break; } Loading @@ -188,7 +200,7 @@ public class ImageProcessingActivity extends Activity } void setupTests() { mTestNames = new String[18]; mTestNames = new String[22]; mTestNames[0] = "Levels Vec3 Relaxed"; mTestNames[1] = "Levels Vec4 Relaxed"; mTestNames[2] = "Levels Vec3 Full"; Loading @@ -206,7 +218,11 @@ public class ImageProcessingActivity extends Activity mTestNames[14] = "Vignette Approximate Relaxed"; mTestNames[15] = "Group Test (emulated)"; mTestNames[16] = "Group Test (native)"; mTestNames[17] = "Intrinsics Convolve 3x3"; mTestNames[17] = "Convolve 3x3"; mTestNames[18] = "Intrinsics Convolve 3x3"; mTestNames[19] = "ColorMatrix"; mTestNames[20] = "Intrinsics ColorMatrix"; mTestNames[21] = "Copy"; mTestSpinner.setAdapter(new ArrayAdapter<String>( this, R.layout.spinner_layout, mTestNames)); } Loading