diff options
author | Jason Sams <jsams@google.com> | 2013-11-14 17:34:51 -0800 |
---|---|---|
committer | Jason Sams <jsams@google.com> | 2013-11-25 16:37:55 -0800 |
commit | 23e1074f29f431f68c6b3230c1315ea0f7c7bc86 (patch) | |
tree | ff326acd743b75edf10b90095e9ab6caf9007421 | |
parent | ab84c3968abce348c212bc9d466c534bc2a03cd6 (diff) | |
download | rs-23e1074f29f431f68c6b3230c1315ea0f7c7bc86.tar.gz |
Sync changes between IP and IP_JB.
Change-Id: Ib4e1b3d4c2e3b57250f73fd926bb840cbfe60e5b
31 files changed, 390 insertions, 209 deletions
diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/java/tests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java index c3b21e2a..1a36417a 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java +++ b/java/tests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java @@ -140,7 +140,7 @@ public class ImageProcessingActivity extends Activity CROSS_PROCESS_USING_LUT ("CrossProcess (using LUT)"), CONVOLVE_5X5 ("Convolve 5x5"), INTRINSICS_CONVOLVE_5X5 ("Intrinsics Convolve 5x5"), - MANDELBROT ("Mandelbrot"), + MANDELBROT_FLOAT ("Mandelbrot fp32"), INTRINSICS_BLEND ("Intrinsics Blend"), INTRINSICS_BLUR_25G ("Intrinsics Blur 25 uchar"), VIBRANCE ("Vibrance"), @@ -153,7 +153,8 @@ public class ImageProcessingActivity extends Activity COLOR_CUBE_3D_INTRINSIC ("Color Cube (3D LUT intrinsic)"), USAGE_IO ("Usage io"), ARTISTIC_1("Artistic 1"), - HISTOGRAM ("Histogram"); + HISTOGRAM ("Histogram"), + MANDELBROT_DOUBLE ("Mandelbrot fp64"); private final String name; @@ -375,8 +376,8 @@ public class ImageProcessingActivity extends Activity case INTRINSICS_CONVOLVE_5X5: mTest = new Convolve5x5(true); break; - case MANDELBROT: - mTest = new Mandelbrot(); + case MANDELBROT_FLOAT: + mTest = new Mandelbrot(false); break; case INTRINSICS_BLEND: mTest = new Blend(); @@ -417,6 +418,9 @@ public class ImageProcessingActivity extends Activity case HISTOGRAM: mTest = new Histogram(); break; + case MANDELBROT_DOUBLE: + mTest = new Mandelbrot(true); + break; } mTest.createBaseTest(this, mBitmapIn, mBitmapIn2, mBitmapOut); diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/ImageProcessingTest.java b/java/tests/ImageProcessing/src/com/android/rs/image/ImageProcessingTest.java index 5263c615..8b3984a4 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/ImageProcessingTest.java +++ b/java/tests/ImageProcessing/src/com/android/rs/image/ImageProcessingTest.java @@ -303,8 +303,8 @@ public class ImageProcessingTest extends ActivityInstrumentationTestCase2<ImageP // Test case 27: Mandelbrot @LargeTest public void testMandelbrot() { - TestAction ta = new TestAction(TestName.MANDELBROT); - runTest(ta, TestName.MANDELBROT.name()); + TestAction ta = new TestAction(TestName.MANDELBROT_FLOAT); + runTest(ta, TestName.MANDELBROT_FLOAT.name()); } // Test case 28: Intrinsics Blend diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/Mandelbrot.java b/java/tests/ImageProcessing/src/com/android/rs/image/Mandelbrot.java index 20036e6c..f84dcb9d 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/Mandelbrot.java +++ b/java/tests/ImageProcessing/src/com/android/rs/image/Mandelbrot.java @@ -30,6 +30,11 @@ import android.widget.TextView; public class Mandelbrot extends TestBase { private ScriptC_mandelbrot mScript; + private boolean mUseDouble = false; + + public Mandelbrot(boolean useDouble) { + mUseDouble = useDouble; + } public boolean onBar1Setup(SeekBar b, TextView t) { t.setText("Iterations"); @@ -90,7 +95,11 @@ public class Mandelbrot extends TestBase { } public void runTest() { - mScript.forEach_root(mOutPixelsAllocation); + if (mUseDouble) { + mScript.forEach_rootD(mOutPixelsAllocation); + } else { + mScript.forEach_root(mOutPixelsAllocation); + } mRS.finish(); } diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/colorcube.rs b/java/tests/ImageProcessing/src/com/android/rs/image/colorcube.rs index c0d6ace0..a501ee63 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/colorcube.rs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/colorcube.rs @@ -32,15 +32,10 @@ void setCube(rs_allocation c) { float4 m = (float4)(1.f / 255.f) * convert_float4(gDims - 1); gCoordMul = convert_int4(m * (float4)0x10000); - - rsDebug("dims", gDims); - rsDebug("gCoordMul", gCoordMul); } -void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) { - //rsDebug("root", in); - - int4 baseCoord = convert_int4(*in) * gCoordMul; +uchar4 __attribute__((kernel)) root(uchar4 in) { + int4 baseCoord = convert_int4(in) * gCoordMul; int4 coord1 = baseCoord >> (int4)16; int4 coord2 = min(coord1 + 1, gDims - 1); @@ -67,23 +62,8 @@ void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) { uint4 v = ((z0 * weight1.z) + (z1 * weight2.z)) >> (uint4)16; uint4 v2 = (v + 0x7f) >> (uint4)8; - *out = convert_uchar4(v2); - out->a = 0xff; - - #if 0 - if (in->r != out->r) { - rsDebug("dr", in->r - out->r); - //rsDebug("in", convert_int4(*in)); - //rsDebug("coord1", coord1); - //rsDebug("coord2", coord2); - //rsDebug("weight1", weight1); - //rsDebug("weight2", weight2); - //rsDebug("yz00", yz00); - //rsDebug("z0", z0); - //rsDebug("v", v); - //rsDebug("v2", v2); - //rsDebug("out", convert_int4(*out)); - } - #endif + uchar4 o = convert_uchar4(v2); + o.a = 0xff; + return o; } diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/colormatrix.fs b/java/tests/ImageProcessing/src/com/android/rs/image/colormatrix.rs index 86fb2482..fa083eac 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/colormatrix.fs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/colormatrix.rs @@ -15,6 +15,7 @@ */ #include "ip.rsh" +#pragma rs_fp_relaxed static rs_matrix4x4 Mat; diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/contrast.rs b/java/tests/ImageProcessing/src/com/android/rs/image/contrast.rs index ef6fd635..06c18023 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/contrast.rs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/contrast.rs @@ -25,8 +25,10 @@ void setBright(float v) { brightC = 127.f - brightM * 127.f; } -void contrast(const uchar4 *in, uchar4 *out) -{ - float3 v = convert_float3(in->rgb) * brightM + brightC; - out->rgb = convert_uchar3(clamp(v, 0.f, 255.f)); +uchar4 __attribute__((kernel)) contrast(uchar4 in) { + float3 v = convert_float3(in.rgb) * brightM + brightC; + uchar4 o; + o.rgb = convert_uchar3(clamp(v, 0.f, 255.f)); + o.a = 0xff; + return o; } diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/convolve3x3.fs b/java/tests/ImageProcessing/src/com/android/rs/image/convolve3x3.fs deleted file mode 100644 index 4f8b4d80..00000000 --- a/java/tests/ImageProcessing/src/com/android/rs/image/convolve3x3.fs +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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. - */ - -#include "ip.rsh" - -int32_t gWidth; -int32_t gHeight; -rs_allocation gIn; - -float gCoeffs[9]; - -uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) { - uint32_t x1 = min((int32_t)x+1, gWidth-1); - uint32_t x2 = max((int32_t)x-1, 0); - uint32_t y1 = min((int32_t)y+1, gHeight-1); - uint32_t y2 = max((int32_t)y-1, 0); - - float4 result; - - float4 p00 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y1)); - float4 p01 = convert_float4(rsGetElementAt_uchar4(gIn, x, y1)); - float4 p02 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y1)); - float4 p10 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y)); - float4 p11 = convert_float4(rsGetElementAt_uchar4(gIn, x, y)); - float4 p12 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y)); - float4 p20 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y2)); - float4 p21 = convert_float4(rsGetElementAt_uchar4(gIn, x, y2)); - float4 p22 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y2)); - - result = p00 * gCoeffs[0]; - result += p01 * gCoeffs[1]; - result += p02 * gCoeffs[2]; - result += p10 * gCoeffs[3]; - result += p11 * gCoeffs[4]; - result += p12 * gCoeffs[5]; - result += p20 * gCoeffs[6]; - result += p21 * gCoeffs[7]; - result += p22 * gCoeffs[8]; - - result = clamp(result, 0.f, 255.f); - return convert_uchar4(result); -} - - diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/convolve3x3.rs b/java/tests/ImageProcessing/src/com/android/rs/image/convolve3x3.rs new file mode 100644 index 00000000..1b1cf3fb --- /dev/null +++ b/java/tests/ImageProcessing/src/com/android/rs/image/convolve3x3.rs @@ -0,0 +1,46 @@ +/* + * 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. + */ + +#include "ip.rsh" +#pragma rs_fp_relaxed + +int32_t gWidth; +int32_t gHeight; +rs_allocation gIn; + +float gCoeffs[9]; + +uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) { + uint32_t x1 = min((int32_t)x+1, gWidth-1); + uint32_t x2 = max((int32_t)x-1, 0); + uint32_t y1 = min((int32_t)y+1, gHeight-1); + uint32_t y2 = max((int32_t)y-1, 0); + + float4 sum = convert_float4(rsGetElementAt_uchar4(gIn, x1, y1)) * gCoeffs[0]; + sum += convert_float4(rsGetElementAt_uchar4(gIn, x, y1)) * gCoeffs[1]; + sum += convert_float4(rsGetElementAt_uchar4(gIn, x2, y1)) * gCoeffs[2]; + sum += convert_float4(rsGetElementAt_uchar4(gIn, x1, y)) * gCoeffs[3]; + sum += convert_float4(rsGetElementAt_uchar4(gIn, x, y)) * gCoeffs[4]; + sum += convert_float4(rsGetElementAt_uchar4(gIn, x2, y)) * gCoeffs[5]; + sum += convert_float4(rsGetElementAt_uchar4(gIn, x1, y2)) * gCoeffs[6]; + sum += convert_float4(rsGetElementAt_uchar4(gIn, x, y2)) * gCoeffs[7]; + sum += convert_float4(rsGetElementAt_uchar4(gIn, x2, y2)) * gCoeffs[8]; + + sum = clamp(sum, 0.f, 255.f); + return convert_uchar4(sum); +} + + diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/convolve5x5.fs b/java/tests/ImageProcessing/src/com/android/rs/image/convolve5x5.fs deleted file mode 100644 index 922a5930..00000000 --- a/java/tests/ImageProcessing/src/com/android/rs/image/convolve5x5.fs +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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. - */ - -#include "ip.rsh" - -int32_t gWidth; -int32_t gHeight; -rs_allocation gIn; - -float gCoeffs[25]; - -uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) { - uint32_t x0 = max((int32_t)x-2, 0); - uint32_t x1 = max((int32_t)x-1, 0); - uint32_t x2 = x; - uint32_t x3 = min((int32_t)x+1, gWidth-1); - uint32_t x4 = min((int32_t)x+2, gWidth-1); - - uint32_t y0 = max((int32_t)y-2, 0); - uint32_t y1 = max((int32_t)y-1, 0); - uint32_t y2 = y; - uint32_t y3 = min((int32_t)y+1, gHeight-1); - uint32_t y4 = min((int32_t)y+2, gHeight-1); - - float4 p0 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y0)) * gCoeffs[0] - + convert_float4(rsGetElementAt_uchar4(gIn, x1, y0)) * gCoeffs[1] - + convert_float4(rsGetElementAt_uchar4(gIn, x2, y0)) * gCoeffs[2] - + convert_float4(rsGetElementAt_uchar4(gIn, x3, y0)) * gCoeffs[3] - + convert_float4(rsGetElementAt_uchar4(gIn, x4, y0)) * gCoeffs[4]; - - float4 p1 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y1)) * gCoeffs[5] - + convert_float4(rsGetElementAt_uchar4(gIn, x1, y1)) * gCoeffs[6] - + convert_float4(rsGetElementAt_uchar4(gIn, x2, y1)) * gCoeffs[7] - + convert_float4(rsGetElementAt_uchar4(gIn, x3, y1)) * gCoeffs[8] - + convert_float4(rsGetElementAt_uchar4(gIn, x4, y1)) * gCoeffs[9]; - - float4 p2 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y2)) * gCoeffs[10] - + convert_float4(rsGetElementAt_uchar4(gIn, x1, y2)) * gCoeffs[11] - + convert_float4(rsGetElementAt_uchar4(gIn, x2, y2)) * gCoeffs[12] - + convert_float4(rsGetElementAt_uchar4(gIn, x3, y2)) * gCoeffs[13] - + convert_float4(rsGetElementAt_uchar4(gIn, x4, y2)) * gCoeffs[14]; - - float4 p3 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y3)) * gCoeffs[15] - + convert_float4(rsGetElementAt_uchar4(gIn, x1, y3)) * gCoeffs[16] - + convert_float4(rsGetElementAt_uchar4(gIn, x2, y3)) * gCoeffs[17] - + convert_float4(rsGetElementAt_uchar4(gIn, x3, y3)) * gCoeffs[18] - + convert_float4(rsGetElementAt_uchar4(gIn, x4, y3)) * gCoeffs[19]; - - float4 p4 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y4)) * gCoeffs[20] - + convert_float4(rsGetElementAt_uchar4(gIn, x1, y4)) * gCoeffs[21] - + convert_float4(rsGetElementAt_uchar4(gIn, x2, y4)) * gCoeffs[22] - + convert_float4(rsGetElementAt_uchar4(gIn, x3, y4)) * gCoeffs[23] - + convert_float4(rsGetElementAt_uchar4(gIn, x4, y4)) * gCoeffs[24]; - - p0 = clamp(p0 + p1 + p2 + p3 + p4, 0.f, 255.f); - return convert_uchar4(p0); -} - - diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/convolve5x5.rs b/java/tests/ImageProcessing/src/com/android/rs/image/convolve5x5.rs new file mode 100644 index 00000000..ed8461bd --- /dev/null +++ b/java/tests/ImageProcessing/src/com/android/rs/image/convolve5x5.rs @@ -0,0 +1,72 @@ +/* + * 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. + */ + +#include "ip.rsh" +#pragma rs_fp_relaxed + +int32_t gWidth; +int32_t gHeight; +rs_allocation gIn; + +float gCoeffs[25]; + +uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) { + uint32_t x0 = max((int32_t)x-2, 0); + uint32_t x1 = max((int32_t)x-1, 0); + uint32_t x2 = x; + uint32_t x3 = min((int32_t)x+1, gWidth-1); + uint32_t x4 = min((int32_t)x+2, gWidth-1); + + uint32_t y0 = max((int32_t)y-2, 0); + uint32_t y1 = max((int32_t)y-1, 0); + uint32_t y2 = y; + uint32_t y3 = min((int32_t)y+1, gHeight-1); + uint32_t y4 = min((int32_t)y+2, gHeight-1); + + float4 sum = convert_float4(rsGetElementAt_uchar4(gIn, x0, y0)) * gCoeffs[0] + + convert_float4(rsGetElementAt_uchar4(gIn, x1, y0)) * gCoeffs[1] + + convert_float4(rsGetElementAt_uchar4(gIn, x2, y0)) * gCoeffs[2] + + convert_float4(rsGetElementAt_uchar4(gIn, x3, y0)) * gCoeffs[3] + + convert_float4(rsGetElementAt_uchar4(gIn, x4, y0)) * gCoeffs[4] + + + convert_float4(rsGetElementAt_uchar4(gIn, x0, y1)) * gCoeffs[5] + + convert_float4(rsGetElementAt_uchar4(gIn, x1, y1)) * gCoeffs[6] + + convert_float4(rsGetElementAt_uchar4(gIn, x2, y1)) * gCoeffs[7] + + convert_float4(rsGetElementAt_uchar4(gIn, x3, y1)) * gCoeffs[8] + + convert_float4(rsGetElementAt_uchar4(gIn, x4, y1)) * gCoeffs[9] + + + convert_float4(rsGetElementAt_uchar4(gIn, x0, y2)) * gCoeffs[10] + + convert_float4(rsGetElementAt_uchar4(gIn, x1, y2)) * gCoeffs[11] + + convert_float4(rsGetElementAt_uchar4(gIn, x2, y2)) * gCoeffs[12] + + convert_float4(rsGetElementAt_uchar4(gIn, x3, y2)) * gCoeffs[13] + + convert_float4(rsGetElementAt_uchar4(gIn, x4, y2)) * gCoeffs[14] + + + convert_float4(rsGetElementAt_uchar4(gIn, x0, y3)) * gCoeffs[15] + + convert_float4(rsGetElementAt_uchar4(gIn, x1, y3)) * gCoeffs[16] + + convert_float4(rsGetElementAt_uchar4(gIn, x2, y3)) * gCoeffs[17] + + convert_float4(rsGetElementAt_uchar4(gIn, x3, y3)) * gCoeffs[18] + + convert_float4(rsGetElementAt_uchar4(gIn, x4, y3)) * gCoeffs[19] + + + convert_float4(rsGetElementAt_uchar4(gIn, x0, y4)) * gCoeffs[20] + + convert_float4(rsGetElementAt_uchar4(gIn, x1, y4)) * gCoeffs[21] + + convert_float4(rsGetElementAt_uchar4(gIn, x2, y4)) * gCoeffs[22] + + convert_float4(rsGetElementAt_uchar4(gIn, x3, y4)) * gCoeffs[23] + + convert_float4(rsGetElementAt_uchar4(gIn, x4, y4)) * gCoeffs[24]; + + return convert_uchar4(clamp(sum, 0.f, 255.f)); +} + + diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/copy.fs b/java/tests/ImageProcessing/src/com/android/rs/image/copy.rs index 65958748..b69f2dfe 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/copy.fs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/copy.rs @@ -15,6 +15,7 @@ */ #include "ip.rsh" +#pragma rs_fp_relaxed uchar4 __attribute__((kernel)) root(uchar4 v_in) { return v_in; diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/fisheye.rsh b/java/tests/ImageProcessing/src/com/android/rs/image/fisheye.rsh index 2eacb7d4..fb95005a 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/fisheye.rsh +++ b/java/tests/ImageProcessing/src/com/android/rs/image/fisheye.rsh @@ -33,7 +33,7 @@ void init_filter(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y, axis_scale.y = (float)dim_y / (float)dim_x; else axis_scale.x = (float)dim_x / (float)dim_y; - + const float bound2 = 0.25f * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y); const float bound = sqrt(bound2); const float radius = 1.15f * bound; diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.fs b/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs index ed69ff46..ed69ff46 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.fs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.fs b/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.rs index f986b5df..31646c40 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.fs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.rs @@ -15,6 +15,7 @@ */ #include "ip.rsh" +#pragma rs_fp_relaxed #include "fisheye.rsh" diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/grain.fs b/java/tests/ImageProcessing/src/com/android/rs/image/grain.rs index 2e62cd7f..2e62cd7f 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/grain.fs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/grain.rs diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/greyscale.fs b/java/tests/ImageProcessing/src/com/android/rs/image/greyscale.rs index 4e13072c..4e13072c 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/greyscale.fs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/greyscale.rs diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/levels.rsh b/java/tests/ImageProcessing/src/com/android/rs/image/levels.rsh index e289906b..b864493f 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/levels.rsh +++ b/java/tests/ImageProcessing/src/com/android/rs/image/levels.rsh @@ -21,7 +21,7 @@ float outWMinOutB; float overInWMinInB; rs_matrix3x3 colorMat; -uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) { +uchar4 __attribute__((kernel)) root(uchar4 in) { uchar4 out; float3 pixel = convert_float4(in).rgb; pixel = rsMatrixMultiply(&colorMat, pixel); @@ -34,7 +34,7 @@ uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) { return out; } -uchar4 __attribute__((kernel)) root4(uchar4 in, uint32_t x, uint32_t y) { +uchar4 __attribute__((kernel)) root4(uchar4 in) { float4 pixel = convert_float4(in); pixel.rgb = rsMatrixMultiply(&colorMat, pixel.rgb); pixel = clamp(pixel, 0.f, 255.f); diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/levels_relaxed.fs b/java/tests/ImageProcessing/src/com/android/rs/image/levels_relaxed.rs index 28596ba4..c0bc4b7c 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/levels_relaxed.fs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/levels_relaxed.rs @@ -15,6 +15,7 @@ */ #include "ip.rsh" +#pragma rs_fp_relaxed #include "levels.rsh" diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/mandelbrot.rs b/java/tests/ImageProcessing/src/com/android/rs/image/mandelbrot.rs index de0bd002..5429acdd 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/mandelbrot.rs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/mandelbrot.rs @@ -53,3 +53,36 @@ uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) { (0xff * ((iter - (mi3 * 2)) / mi3)), 0xff}; } } + +uchar4 __attribute__((kernel)) rootD(uint32_t x, uint32_t y) { + double2 p; + p.x = lowerBoundX + ((float)x / gDimX) * scaleFactor; + p.y = lowerBoundY + ((float)y / gDimY) * scaleFactor; + + double2 t = 0; + double2 t2 = t * t; + int iter = 0; + while((t2.x + t2.y < 4.f) && (iter < gMaxIteration)) { + double xtemp = t2.x - t2.y + p.x; + t.y = 2 * t.x * t.y + p.y; + t.x = xtemp; + iter++; + t2 = t * t; + } + + if(iter >= gMaxIteration) { + // write a non-transparent black pixel + return (uchar4){0, 0, 0, 0xff}; + } else { + double mi3 = gMaxIteration / 3.f; + if (iter <= (gMaxIteration / 3)) + return (uchar4){0xff * (iter / mi3), 0, 0, 0xff}; + else if (iter <= (((gMaxIteration / 3) * 2))) + return (uchar4){0xff - (0xff * ((iter - mi3) / mi3)), + (0xff * ((iter - mi3) / mi3)), 0, 0xff}; + else + return (uchar4){0, 0xff - (0xff * ((iter - (mi3 * 2)) / mi3)), + (0xff * ((iter - (mi3 * 2)) / mi3)), 0xff}; + } +} + diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/shadows.rs b/java/tests/ImageProcessing/src/com/android/rs/image/shadows.rs index 90757a37..2f061047 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/shadows.rs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/shadows.rs @@ -17,18 +17,18 @@ #include "ip.rsh" #pragma rs_fp_relaxed -static double shadowFilterMap[] = { - -0.00591, 0.0001, - 1.16488, 0.01668, - -0.18027, -0.06791, - -0.12625, 0.09001, - 0.15065, -0.03897 +static float shadowFilterMap[] = { + -0.00591f, 0.0001f, + 1.16488f, 0.01668f, + -0.18027f, -0.06791f, + -0.12625f, 0.09001f, + 0.15065f, -0.03897f }; -static double poly[] = { - 0., 0., - 0., 0., - 0. +static float poly[] = { + 0.f, 0.f, + 0.f, 0.f, + 0.f }; static const int ABITS = 4; @@ -36,10 +36,10 @@ static const int HSCALE = 256; static const int k1=255 << ABITS; static const int k2=HSCALE << ABITS; -static double fastevalPoly(double *poly,int n, double x){ +static float fastevalPoly(float *poly,int n, float x){ - double f =x; - double sum = poly[0]+poly[1]*f; + float f =x; + float sum = poly[0]+poly[1]*f; int i; for (i = 2; i < n; i++) { f*=x; @@ -177,16 +177,15 @@ static uchar4 hsv2rgb(ushort3 hsv) } void prepareShadows(float scale) { - double s = (scale>=0)?scale:scale/5; + float s = (scale>=0) ? scale : scale / 5.f; for (int i = 0; i < 5; i++) { poly[i] = fastevalPoly(shadowFilterMap+i*2,2 , s); } } -void shadowsKernel(const uchar4 *in, uchar4 *out) { - ushort3 hsv = rgb2hsv(*in); - double v = (fastevalPoly(poly,5,hsv.x/4080.)*4080); - if (v>4080) v = 4080; - hsv.x = (unsigned short) ((v>0)?v:0); - *out = hsv2rgb(hsv); +uchar4 __attribute__((kernel)) shadowsKernel(uchar4 in) { + ushort3 hsv = rgb2hsv(in); + float v = (fastevalPoly(poly, 5, hsv.x * (1.f / 4080.f)) * 4080.f); + hsv.x = (unsigned short) clamp(v, 0.f, 4080.f); + return hsv2rgb(hsv); } diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/threshold.fs b/java/tests/ImageProcessing/src/com/android/rs/image/threshold.rs index 0b2c2e86..d30a87b5 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/threshold.fs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/threshold.rs @@ -15,7 +15,7 @@ */ #include "ip.rsh" - +#pragma rs_fp_relaxed int height; int width; diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/vibrance.rs b/java/tests/ImageProcessing/src/com/android/rs/image/vibrance.rs index b82e1d34..7fa295e8 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/vibrance.rs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/vibrance.rs @@ -25,13 +25,10 @@ static const float Bf = 0.114f; static float Vib = 0.f; -void vibranceKernel(const uchar4 *in, uchar4 *out) { - - float R, G, B; - - int r = in->r; - int g = in->g; - int b = in->b; +uchar4 __attribute__((kernel)) vibranceKernel(uchar4 in) { + int r = in.r; + int g = in.g; + int b = in.b; float red = (r-max(g, b)) * (1.f / 256.f); float S = (float)(Vib/(1+native_exp(-red*3)))+1; float MS = 1.0f - S; @@ -39,18 +36,21 @@ void vibranceKernel(const uchar4 *in, uchar4 *out) { float Gt = Gf * MS; float Bt = Bf * MS; int t = (r + g) >> 1; - R = r; - G = g; - B = b; + + float R = r; + float G = g; + float B = b; float Rc = R * (Rt + S) + G * Gt + B * Bt; float Gc = R * Rt + G * (Gt + S) + B * Bt; float Bc = R * Rt + G * Gt + B * (Bt + S); - out->r = rsClamp(Rc, 0, 255); - out->g = rsClamp(Gc, 0, 255); - out->b = rsClamp(Bc, 0, 255); - + uchar4 o; + o.r = rsClamp(Rc, 0, 255); + o.g = rsClamp(Gc, 0, 255); + o.b = rsClamp(Bc, 0, 255); + o.a = 0xff; + return o; } void prepareVibrance() { diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.fs b/java/tests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.rs index 00cbbc4d..00cbbc4d 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.fs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.rs diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.fs b/java/tests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.rs index 8202c5c1..262d516b 100644 --- a/java/tests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.fs +++ b/java/tests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.rs @@ -15,6 +15,7 @@ */ #include "ip.rsh" +#pragma rs_fp_relaxed #include "vignette.rsh" diff --git a/java/tests/ImageProcessing2/src/com/android/rs/image/fisheye.rsh b/java/tests/ImageProcessing2/src/com/android/rs/image/fisheye.rsh index 2eacb7d4..fb95005a 100644 --- a/java/tests/ImageProcessing2/src/com/android/rs/image/fisheye.rsh +++ b/java/tests/ImageProcessing2/src/com/android/rs/image/fisheye.rsh @@ -33,7 +33,7 @@ void init_filter(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y, axis_scale.y = (float)dim_y / (float)dim_x; else axis_scale.x = (float)dim_x / (float)dim_y; - + const float bound2 = 0.25f * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y); const float bound = sqrt(bound2); const float radius = 1.15f * bound; diff --git a/java/tests/ImageProcessing_jb/src/com/android/rs/image/Artistic1.java b/java/tests/ImageProcessing_jb/src/com/android/rs/image/Artistic1.java new file mode 100644 index 00000000..181493d6 --- /dev/null +++ b/java/tests/ImageProcessing_jb/src/com/android/rs/image/Artistic1.java @@ -0,0 +1,44 @@ +/* + * 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.imagejb; + +import java.lang.Math; + +import android.renderscript.*; +import android.util.Log; + +public class Artistic1 extends TestBase { + private ScriptC_artistic1 mScript; + private Allocation mBlured; + + public void createTest(android.content.res.Resources res) { + mScript = new ScriptC_artistic1(mRS); + mBlured = Allocation.createTyped(mRS, mInPixelsAllocation.getType()); + mScript.set_gBlur(mBlured); + + ScriptIntrinsicBlur blur = ScriptIntrinsicBlur.create(mRS, Element.U8_4(mRS)); + blur.setRadius(20); + blur.setInput(mInPixelsAllocation); + blur.forEach(mBlured); + } + + public void runTest() { + mScript.invoke_setup(); + mScript.forEach_process(mInPixelsAllocation, mOutPixelsAllocation); + } + +} diff --git a/java/tests/ImageProcessing_jb/src/com/android/rs/image/IPTestListJB.java b/java/tests/ImageProcessing_jb/src/com/android/rs/image/IPTestListJB.java index 9ad827d7..4bf99e3d 100644 --- a/java/tests/ImageProcessing_jb/src/com/android/rs/image/IPTestListJB.java +++ b/java/tests/ImageProcessing_jb/src/com/android/rs/image/IPTestListJB.java @@ -59,7 +59,8 @@ public class IPTestListJB { CROSS_PROCESS_USING_LUT ("CrossProcess (using LUT)", INTRINSIC, 18.6f), CONVOLVE_5X5 ("Convolve 5x5", RELAXED_FP, 215.8f), INTRINSICS_CONVOLVE_5X5 ("Intrinsics Convolve 5x5", INTRINSIC, 29.8f), - MANDELBROT ("Mandelbrot", FULL_FP, 108.1f), + MANDELBROT_FLOAT ("Mandelbrot (fp32)", FULL_FP, 108.1f), + MANDELBROT_DOUBLE ("Mandelbrot (fp64)", FULL_FP, 108.1f), INTRINSICS_BLEND ("Intrinsics Blend", INTRINSIC, 94.2f), INTRINSICS_BLUR_25G ("Intrinsics Blur 25 uchar", INTRINSIC, 173.3f), VIBRANCE ("Vibrance", RELAXED_FP, 88.3f), @@ -69,7 +70,8 @@ public class IPTestListJB { EXPOSURE ("Exposure", RELAXED_FP, 64.7f), WHITE_BALANCE ("White Balance", RELAXED_FP, 160.1f), COLOR_CUBE ("Color Cube", RELAXED_FP, 85.3f), - COLOR_CUBE_3D_INTRINSIC ("Color Cube (3D LUT intrinsic)", INTRINSIC, 49.5f); + COLOR_CUBE_3D_INTRINSIC ("Color Cube (3D LUT intrinsic)", INTRINSIC, 49.5f), + ARTISTIC1 ("Artistic 1", RELAXED_FP, 120.f); private final String name; @@ -149,8 +151,10 @@ public class IPTestListJB { return new Convolve5x5(false); case INTRINSICS_CONVOLVE_5X5: return new Convolve5x5(true); - case MANDELBROT: - return new Mandelbrot(); + case MANDELBROT_FLOAT: + return new Mandelbrot(false); + case MANDELBROT_DOUBLE: + return new Mandelbrot(true); case INTRINSICS_BLEND: return new Blend(); case INTRINSICS_BLUR_25G: @@ -171,6 +175,8 @@ public class IPTestListJB { return new ColorCube(false); case COLOR_CUBE_3D_INTRINSIC: return new ColorCube(true); + case ARTISTIC1: + return new Artistic1(); } return null; } diff --git a/java/tests/ImageProcessing_jb/src/com/android/rs/image/Mandelbrot.java b/java/tests/ImageProcessing_jb/src/com/android/rs/image/Mandelbrot.java index ca348486..26134b11 100644 --- a/java/tests/ImageProcessing_jb/src/com/android/rs/image/Mandelbrot.java +++ b/java/tests/ImageProcessing_jb/src/com/android/rs/image/Mandelbrot.java @@ -30,6 +30,11 @@ import android.widget.TextView; public class Mandelbrot extends TestBase { private ScriptC_mandelbrot mScript; + private boolean mUseDouble = false; + + public Mandelbrot(boolean useDouble) { + mUseDouble = useDouble; + } public boolean onBar1Setup(SeekBar b, TextView t) { t.setText("Iterations"); @@ -90,7 +95,11 @@ public class Mandelbrot extends TestBase { } public void runTest() { - mScript.forEach_root(mOutPixelsAllocation); + if (mUseDouble) { + mScript.forEach_rootD(mOutPixelsAllocation); + } else { + mScript.forEach_root(mOutPixelsAllocation); + } mRS.finish(); } diff --git a/java/tests/ImageProcessing_jb/src/com/android/rs/image/artistic1.rs b/java/tests/ImageProcessing_jb/src/com/android/rs/image/artistic1.rs new file mode 100644 index 00000000..8051f29d --- /dev/null +++ b/java/tests/ImageProcessing_jb/src/com/android/rs/image/artistic1.rs @@ -0,0 +1,67 @@ +/* + * 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. + */ + +#include "ip.rsh" +#pragma rs_fp_relaxed + +rs_allocation gBlur; + +static float gOverWm1; +static float gOverHm1; +static uchar gLutR[256]; +static uchar gLutG[256]; +static uchar gLutB[256]; + +void setup() { + int w = rsAllocationGetDimX(gBlur); + int h = rsAllocationGetDimY(gBlur); + gOverWm1 = 1.f / w; + gOverHm1 = 1.f / h; + + for (int x=0; x < 256; x++) { + gLutR[x] = x;//255-x; + gLutG[x] = x;//255-x; + gLutB[x] = x;//255-x; + } +} + +uchar4 __attribute__((kernel)) process(uchar4 in, uint32_t x, uint32_t y) { + float2 xyDist; + xyDist.x = (x * gOverWm1 - 0.5f); + xyDist.y = (y * gOverHm1 - 0.5f); + + // color + float4 v1 = rsUnpackColor8888(in); + float4 v2 = rsUnpackColor8888(rsGetElementAt_uchar4(gBlur, x, y)); + + float dist = dot(xyDist, xyDist) * 1.4f; + float pdist = native_powr(dist, 2.7f * 0.5f); + //float pdist = powr(dist, 2.7f * 0.5f); + + pdist = clamp(pdist, 0.f, 1.f); + v1 = mix(v1, v2, dist * 2.f); + v1 *= 1.f - pdist; + + // apply curve + uchar4 out = rsPackColorTo8888(v1); + + out.r = gLutR[out.r]; + out.g = gLutG[out.g]; + out.b = gLutB[out.b]; + return out; +} + + diff --git a/java/tests/ImageProcessing_jb/src/com/android/rs/image/colormatrix.rs b/java/tests/ImageProcessing_jb/src/com/android/rs/image/colormatrix.rs index 86fb2482..fa083eac 100644 --- a/java/tests/ImageProcessing_jb/src/com/android/rs/image/colormatrix.rs +++ b/java/tests/ImageProcessing_jb/src/com/android/rs/image/colormatrix.rs @@ -15,6 +15,7 @@ */ #include "ip.rsh" +#pragma rs_fp_relaxed static rs_matrix4x4 Mat; diff --git a/java/tests/ImageProcessing_jb/src/com/android/rs/image/mandelbrot.rs b/java/tests/ImageProcessing_jb/src/com/android/rs/image/mandelbrot.rs index de0bd002..5429acdd 100644 --- a/java/tests/ImageProcessing_jb/src/com/android/rs/image/mandelbrot.rs +++ b/java/tests/ImageProcessing_jb/src/com/android/rs/image/mandelbrot.rs @@ -53,3 +53,36 @@ uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) { (0xff * ((iter - (mi3 * 2)) / mi3)), 0xff}; } } + +uchar4 __attribute__((kernel)) rootD(uint32_t x, uint32_t y) { + double2 p; + p.x = lowerBoundX + ((float)x / gDimX) * scaleFactor; + p.y = lowerBoundY + ((float)y / gDimY) * scaleFactor; + + double2 t = 0; + double2 t2 = t * t; + int iter = 0; + while((t2.x + t2.y < 4.f) && (iter < gMaxIteration)) { + double xtemp = t2.x - t2.y + p.x; + t.y = 2 * t.x * t.y + p.y; + t.x = xtemp; + iter++; + t2 = t * t; + } + + if(iter >= gMaxIteration) { + // write a non-transparent black pixel + return (uchar4){0, 0, 0, 0xff}; + } else { + double mi3 = gMaxIteration / 3.f; + if (iter <= (gMaxIteration / 3)) + return (uchar4){0xff * (iter / mi3), 0, 0, 0xff}; + else if (iter <= (((gMaxIteration / 3) * 2))) + return (uchar4){0xff - (0xff * ((iter - mi3) / mi3)), + (0xff * ((iter - mi3) / mi3)), 0, 0xff}; + else + return (uchar4){0, 0xff - (0xff * ((iter - (mi3 * 2)) / mi3)), + (0xff * ((iter - (mi3 * 2)) / mi3)), 0xff}; + } +} + |