From d1c306a9e66f8e541f866a6f3740959ed8cc70a6 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Thu, 27 Dec 2012 20:26:41 -0800 Subject: Add API support for 3D allocations. Change-Id: I19c525f90135d83caec545e77e8f61a957d220ee --- .../src/com/android/rs/image/ColorCube.java | 83 ++++++++++++++++++++++ .../android/rs/image/ImageProcessingActivity.java | 6 +- .../src/com/android/rs/image/colorcube.rs | 55 ++++++++++++++ 3 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ColorCube.java create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/colorcube.rs (limited to 'tests/RenderScriptTests') diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ColorCube.java b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ColorCube.java new file mode 100644 index 000000000000..d03466d1ff7b --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ColorCube.java @@ -0,0 +1,83 @@ +/* + * 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 ColorCube extends TestBase { + private Allocation mCube; + private ScriptC_colorcube mScript; + + public ColorCube() { + } + + private void initCube() { + final int sx = 32; + final int sy = 32; + final int sz = 16; + + Type.Builder tb = new Type.Builder(mRS, Element.U8_4(mRS)); + tb.setX(sx); + tb.setY(sy); + tb.setZ(sz); + Type t = tb.create(); + mCube = Allocation.createTyped(mRS, t); + + int dat[] = new int[sx * sy * sz]; + for (int z = 0; z < sz; z++) { + for (int y = 0; y < sy; y++) { + for (int x = 0; x < sx; x++ ) { + + dat[z*sy*sx + y*sx + x] = 0xff000000 | + ((x | (x<<2)) << 16) | + ((y | (y<<2)) << 8) | + ((z | (z<<2)) << 0); + + + } + } + } + + mCube.copyFromUnchecked(dat); + } + + public void createTest(android.content.res.Resources res) { + mScript = new ScriptC_colorcube(mRS, res, R.raw.colorcube); + + initCube(); + mScript.invoke_setCube(mCube); + + + //mScript.invoke_setMatrix(m); + } + + public void runTest() { + mScript.forEach_root(mInPixelsAllocation, mOutPixelsAllocation); + } + +} diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java index ac7268864dd0..18f438ab3122 100644 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java @@ -291,6 +291,9 @@ public class ImageProcessingActivity extends Activity case 35: mTest = new WhiteBalance(); break; + case 36: + mTest = new ColorCube(); + break; } mTest.createBaseTest(this, mBitmapIn, mBitmapIn2, mBitmapOut); @@ -302,7 +305,7 @@ public class ImageProcessingActivity extends Activity } void setupTests() { - mTestNames = new String[36]; + mTestNames = new String[37]; mTestNames[0] = "Levels Vec3 Relaxed"; mTestNames[1] = "Levels Vec4 Relaxed"; mTestNames[2] = "Levels Vec3 Full"; @@ -339,6 +342,7 @@ public class ImageProcessingActivity extends Activity mTestNames[33] = "Contrast"; mTestNames[34] = "Exposure"; mTestNames[35] = "White Balance"; + mTestNames[36] = "Color Cube"; mTestSpinner.setAdapter(new ArrayAdapter( this, R.layout.spinner_layout, mTestNames)); diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/colorcube.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/colorcube.rs new file mode 100644 index 000000000000..97bb4293f9f1 --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/colorcube.rs @@ -0,0 +1,55 @@ +/* + * 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.image) +#pragma rs_fp_relaxed + + +static rs_allocation gCube; +static int4 gDims; +static int4 gFracMask; +static int4 gFracBits; + +void setCube(rs_allocation c) { + gCube = c; + gDims.x = rsAllocationGetDimX(gCube); + gDims.y = rsAllocationGetDimY(gCube); + gDims.z = rsAllocationGetDimZ(gCube); + gDims.w = 0; + + gFracMask = gDims - 1; + gFracBits = (int4)32 - clz(gFracMask); + + rsDebug("dims", gDims); + rsDebug("gFracMask", gFracMask); + rsDebug("gFracBits", gFracBits); +} + +void root(const uchar4 *in, uchar4 *out) { + //rsDebug("root", in); + + int4 coord1 = convert_int4(*in); + int4 coord2 = min(coord1 + 1, gDims); + + uchar4 v1 = rsGetElementAt_uchar4(gCube, coord1.x >> 3, coord1.y >> 3, coord1.z >> 4); + + //rsDebug("coord1", coord1); + //rsDebug("coord2", coord2); + + *out = v1; +} + -- cgit v1.2.3-59-g8ed1b