diff options
5 files changed, 152 insertions, 1 deletions
diff --git a/api/current.txt b/api/current.txt index 98eeaeb..1eec50e 100644 --- a/api/current.txt +++ b/api/current.txt @@ -20248,6 +20248,7 @@ package android.renderscript { method public android.renderscript.Type.Builder setMipmaps(boolean); method public android.renderscript.Type.Builder setX(int); method public android.renderscript.Type.Builder setY(int); + method public android.renderscript.Type.Builder setZ(int); } public static final class Type.CubemapFace extends java.lang.Enum { diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java index a707df2..b36aee2 100644 --- a/graphics/java/android/renderscript/Type.java +++ b/graphics/java/android/renderscript/Type.java @@ -244,6 +244,14 @@ public class Type extends BaseObj { return this; } + public Builder setZ(int value) { + if(value < 1) { + throw new RSIllegalArgumentException("Values of less than 1 for Dimension Z are not valid."); + } + mDimZ = value; + return this; + } + public Builder setMipmaps(boolean value) { mDimMipmaps = value; return this; 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 0000000..d03466d --- /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 ac72688..18f438a 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<String>( 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 0000000..97bb429 --- /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; +} + |