From 23e1074f29f431f68c6b3230c1315ea0f7c7bc86 Mon Sep 17 00:00:00 2001 From: Jason Sams Date: Thu, 14 Nov 2013 17:34:51 -0800 Subject: Sync changes between IP and IP_JB. Change-Id: Ib4e1b3d4c2e3b57250f73fd926bb840cbfe60e5b --- .../android/rs/image/ImageProcessingActivity.java | 12 ++- .../com/android/rs/image/ImageProcessingTest.java | 4 +- .../src/com/android/rs/image/Mandelbrot.java | 11 +- .../src/com/android/rs/image/colorcube.rs | 30 +----- .../src/com/android/rs/image/colormatrix.fs | 35 ------ .../src/com/android/rs/image/colormatrix.rs | 36 +++++++ .../src/com/android/rs/image/contrast.rs | 10 +- .../src/com/android/rs/image/convolve3x3.fs | 57 ---------- .../src/com/android/rs/image/convolve3x3.rs | 46 ++++++++ .../src/com/android/rs/image/convolve5x5.fs | 72 ------------- .../src/com/android/rs/image/convolve5x5.rs | 72 +++++++++++++ .../src/com/android/rs/image/copy.fs | 23 ---- .../src/com/android/rs/image/copy.rs | 24 +++++ .../src/com/android/rs/image/fisheye.rsh | 2 +- .../com/android/rs/image/fisheye_approx_relaxed.fs | 20 ---- .../com/android/rs/image/fisheye_approx_relaxed.rs | 20 ++++ .../src/com/android/rs/image/fisheye_relaxed.fs | 20 ---- .../src/com/android/rs/image/fisheye_relaxed.rs | 21 ++++ .../src/com/android/rs/image/grain.fs | 91 ---------------- .../src/com/android/rs/image/grain.rs | 91 ++++++++++++++++ .../src/com/android/rs/image/greyscale.fs | 36 ------- .../src/com/android/rs/image/greyscale.rs | 36 +++++++ .../src/com/android/rs/image/levels.rsh | 4 +- .../src/com/android/rs/image/levels_relaxed.fs | 20 ---- .../src/com/android/rs/image/levels_relaxed.rs | 21 ++++ .../src/com/android/rs/image/mandelbrot.rs | 33 ++++++ .../src/com/android/rs/image/shadows.rs | 39 ++++--- .../src/com/android/rs/image/threshold.fs | 118 --------------------- .../src/com/android/rs/image/threshold.rs | 118 +++++++++++++++++++++ .../src/com/android/rs/image/vibrance.rs | 28 ++--- .../android/rs/image/vignette_approx_relaxed.fs | 20 ---- .../android/rs/image/vignette_approx_relaxed.rs | 20 ++++ .../src/com/android/rs/image/vignette_relaxed.fs | 20 ---- .../src/com/android/rs/image/vignette_relaxed.rs | 21 ++++ .../src/com/android/rs/image/fisheye.rsh | 2 +- .../src/com/android/rs/image/Artistic1.java | 44 ++++++++ .../src/com/android/rs/image/IPTestListJB.java | 14 ++- .../src/com/android/rs/image/Mandelbrot.java | 11 +- .../src/com/android/rs/image/artistic1.rs | 67 ++++++++++++ .../src/com/android/rs/image/colormatrix.rs | 1 + .../src/com/android/rs/image/mandelbrot.rs | 33 ++++++ 41 files changed, 792 insertions(+), 611 deletions(-) delete mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/colormatrix.fs create mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/colormatrix.rs delete mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/convolve3x3.fs create mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/convolve3x3.rs delete mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/convolve5x5.fs create mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/convolve5x5.rs delete mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/copy.fs create mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/copy.rs delete mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.fs create mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs delete mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.fs create mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.rs delete mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/grain.fs create mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/grain.rs delete mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/greyscale.fs create mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/greyscale.rs delete mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/levels_relaxed.fs create mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/levels_relaxed.rs delete mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/threshold.fs create mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/threshold.rs delete mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.fs create mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.rs delete mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.fs create mode 100644 java/tests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.rs create mode 100644 java/tests/ImageProcessing_jb/src/com/android/rs/image/Artistic1.java create mode 100644 java/tests/ImageProcessing_jb/src/com/android/rs/image/artistic1.rs 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> (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.fs deleted file mode 100644 index 86fb2482..00000000 --- a/java/tests/ImageProcessing/src/com/android/rs/image/colormatrix.fs +++ /dev/null @@ -1,35 +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" - -static rs_matrix4x4 Mat; - -void init() { - rsMatrixLoadIdentity(&Mat); -} - -void setMatrix(rs_matrix4x4 m) { - Mat = m; -} - -uchar4 __attribute__((kernel)) root(uchar4 in) { - float4 f = convert_float4(in); - f = rsMatrixMultiply(&Mat, f); - f = clamp(f, 0.f, 255.f); - return convert_uchar4(f); -} - diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/colormatrix.rs b/java/tests/ImageProcessing/src/com/android/rs/image/colormatrix.rs new file mode 100644 index 00000000..fa083eac --- /dev/null +++ b/java/tests/ImageProcessing/src/com/android/rs/image/colormatrix.rs @@ -0,0 +1,36 @@ +/* + * 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 + +static rs_matrix4x4 Mat; + +void init() { + rsMatrixLoadIdentity(&Mat); +} + +void setMatrix(rs_matrix4x4 m) { + Mat = m; +} + +uchar4 __attribute__((kernel)) root(uchar4 in) { + float4 f = convert_float4(in); + f = rsMatrixMultiply(&Mat, f); + f = clamp(f, 0.f, 255.f); + return convert_uchar4(f); +} + 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.fs deleted file mode 100644 index 65958748..00000000 --- a/java/tests/ImageProcessing/src/com/android/rs/image/copy.fs +++ /dev/null @@ -1,23 +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" - -uchar4 __attribute__((kernel)) root(uchar4 v_in) { - return v_in; -} - - diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/copy.rs b/java/tests/ImageProcessing/src/com/android/rs/image/copy.rs new file mode 100644 index 00000000..b69f2dfe --- /dev/null +++ b/java/tests/ImageProcessing/src/com/android/rs/image/copy.rs @@ -0,0 +1,24 @@ +/* + * 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 + +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.fs deleted file mode 100644 index ed69ff46..00000000 --- a/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.fs +++ /dev/null @@ -1,20 +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" - -#include "fisheye_approx.rsh" - diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs b/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs new file mode 100644 index 00000000..ed69ff46 --- /dev/null +++ b/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs @@ -0,0 +1,20 @@ +/* + * 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" + +#include "fisheye_approx.rsh" + 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.fs deleted file mode 100644 index f986b5df..00000000 --- a/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.fs +++ /dev/null @@ -1,20 +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" - -#include "fisheye.rsh" - diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.rs b/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.rs new file mode 100644 index 00000000..31646c40 --- /dev/null +++ b/java/tests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.rs @@ -0,0 +1,21 @@ +/* + * 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 + +#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.fs deleted file mode 100644 index 2e62cd7f..00000000 --- a/java/tests/ImageProcessing/src/com/android/rs/image/grain.fs +++ /dev/null @@ -1,91 +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" - -uchar __attribute__((kernel)) genRand() { - return (uchar)rsRand(0xff); -} - -/* - * Convolution matrix of distance 2 with fixed point of 'kShiftBits' bits - * shifted. Thus the sum of this matrix should be 'kShiftValue'. Entries of - * small values are not calculated to gain efficiency. - * The order ot pixels represented in this matrix is: - * 1 2 3 - * 4 0 5 - * 6 7 8 - * and the matrix should be: {230, 56, 114, 56, 114, 114, 56, 114, 56}. - * However, since most of the valus are identical, we only use the first three - * entries and the entries corresponding to the pixels is: - * 1 2 1 - * 2 0 2 - * 1 2 1 - */ - -int32_t gWMask; -int32_t gHMask; - -rs_allocation gBlendSource; -uchar __attribute__((kernel)) blend9(uint32_t x, uint32_t y) { - uint32_t x1 = (x-1) & gWMask; - uint32_t x2 = (x+1) & gWMask; - uint32_t y1 = (y-1) & gHMask; - uint32_t y2 = (y+1) & gHMask; - - uint p00 = 56 * rsGetElementAt_uchar(gBlendSource, x1, y1); - uint p01 = 114 * rsGetElementAt_uchar(gBlendSource, x, y1); - uint p02 = 56 * rsGetElementAt_uchar(gBlendSource, x2, y1); - uint p10 = 114 * rsGetElementAt_uchar(gBlendSource, x1, y); - uint p11 = 230 * rsGetElementAt_uchar(gBlendSource, x, y); - uint p12 = 114 * rsGetElementAt_uchar(gBlendSource, x2, y); - uint p20 = 56 * rsGetElementAt_uchar(gBlendSource, x1, y2); - uint p21 = 114 * rsGetElementAt_uchar(gBlendSource, x, y2); - uint p22 = 56 * rsGetElementAt_uchar(gBlendSource, x2, y2); - - p00 += p01; - p02 += p10; - p11 += p12; - p20 += p21; - - p22 += p00; - p02 += p11; - - p20 += p22; - p20 += p02; - - p20 = min(p20 >> 10, (uint)255); - return (uchar)p20; -} - -float gNoiseStrength; - -rs_allocation gNoise; -uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) { - float4 ip = convert_float4(in); - float pnoise = (float) rsGetElementAt_uchar(gNoise, x & gWMask, y & gHMask); - - float energy_level = ip.r + ip.g + ip.b; - float energy_mask = (28.f - sqrt(energy_level)) * 0.03571f; - pnoise = (pnoise - 128.f) * energy_mask; - - ip += pnoise * gNoiseStrength; - ip = clamp(ip, 0.f, 255.f); - - uchar4 p = convert_uchar4(ip); - p.a = 0xff; - return p; -} diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/grain.rs b/java/tests/ImageProcessing/src/com/android/rs/image/grain.rs new file mode 100644 index 00000000..2e62cd7f --- /dev/null +++ b/java/tests/ImageProcessing/src/com/android/rs/image/grain.rs @@ -0,0 +1,91 @@ +/* + * 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" + +uchar __attribute__((kernel)) genRand() { + return (uchar)rsRand(0xff); +} + +/* + * Convolution matrix of distance 2 with fixed point of 'kShiftBits' bits + * shifted. Thus the sum of this matrix should be 'kShiftValue'. Entries of + * small values are not calculated to gain efficiency. + * The order ot pixels represented in this matrix is: + * 1 2 3 + * 4 0 5 + * 6 7 8 + * and the matrix should be: {230, 56, 114, 56, 114, 114, 56, 114, 56}. + * However, since most of the valus are identical, we only use the first three + * entries and the entries corresponding to the pixels is: + * 1 2 1 + * 2 0 2 + * 1 2 1 + */ + +int32_t gWMask; +int32_t gHMask; + +rs_allocation gBlendSource; +uchar __attribute__((kernel)) blend9(uint32_t x, uint32_t y) { + uint32_t x1 = (x-1) & gWMask; + uint32_t x2 = (x+1) & gWMask; + uint32_t y1 = (y-1) & gHMask; + uint32_t y2 = (y+1) & gHMask; + + uint p00 = 56 * rsGetElementAt_uchar(gBlendSource, x1, y1); + uint p01 = 114 * rsGetElementAt_uchar(gBlendSource, x, y1); + uint p02 = 56 * rsGetElementAt_uchar(gBlendSource, x2, y1); + uint p10 = 114 * rsGetElementAt_uchar(gBlendSource, x1, y); + uint p11 = 230 * rsGetElementAt_uchar(gBlendSource, x, y); + uint p12 = 114 * rsGetElementAt_uchar(gBlendSource, x2, y); + uint p20 = 56 * rsGetElementAt_uchar(gBlendSource, x1, y2); + uint p21 = 114 * rsGetElementAt_uchar(gBlendSource, x, y2); + uint p22 = 56 * rsGetElementAt_uchar(gBlendSource, x2, y2); + + p00 += p01; + p02 += p10; + p11 += p12; + p20 += p21; + + p22 += p00; + p02 += p11; + + p20 += p22; + p20 += p02; + + p20 = min(p20 >> 10, (uint)255); + return (uchar)p20; +} + +float gNoiseStrength; + +rs_allocation gNoise; +uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) { + float4 ip = convert_float4(in); + float pnoise = (float) rsGetElementAt_uchar(gNoise, x & gWMask, y & gHMask); + + float energy_level = ip.r + ip.g + ip.b; + float energy_mask = (28.f - sqrt(energy_level)) * 0.03571f; + pnoise = (pnoise - 128.f) * energy_mask; + + ip += pnoise * gNoiseStrength; + ip = clamp(ip, 0.f, 255.f); + + uchar4 p = convert_uchar4(ip); + p.a = 0xff; + return p; +} diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/greyscale.fs b/java/tests/ImageProcessing/src/com/android/rs/image/greyscale.fs deleted file mode 100644 index 4e13072c..00000000 --- a/java/tests/ImageProcessing/src/com/android/rs/image/greyscale.fs +++ /dev/null @@ -1,36 +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" - -const static float3 gMonoMult = {0.299f, 0.587f, 0.114f}; - -uchar4 __attribute__((kernel)) root(uchar4 v_in) { - float4 f4 = rsUnpackColor8888(v_in); - - float3 mono = dot(f4.rgb, gMonoMult); - return rsPackColorTo8888(mono); -} - -uchar __attribute__((kernel)) toU8(uchar4 v_in) { - float4 f4 = convert_float4(v_in); - return (uchar)dot(f4.rgb, gMonoMult); -} - -uchar4 __attribute__((kernel)) toU8_4(uchar v_in) { - return (uchar4)v_in; -} - diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/greyscale.rs b/java/tests/ImageProcessing/src/com/android/rs/image/greyscale.rs new file mode 100644 index 00000000..4e13072c --- /dev/null +++ b/java/tests/ImageProcessing/src/com/android/rs/image/greyscale.rs @@ -0,0 +1,36 @@ +/* + * 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" + +const static float3 gMonoMult = {0.299f, 0.587f, 0.114f}; + +uchar4 __attribute__((kernel)) root(uchar4 v_in) { + float4 f4 = rsUnpackColor8888(v_in); + + float3 mono = dot(f4.rgb, gMonoMult); + return rsPackColorTo8888(mono); +} + +uchar __attribute__((kernel)) toU8(uchar4 v_in) { + float4 f4 = convert_float4(v_in); + return (uchar)dot(f4.rgb, gMonoMult); +} + +uchar4 __attribute__((kernel)) toU8_4(uchar v_in) { + return (uchar4)v_in; +} + 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.fs deleted file mode 100644 index 28596ba4..00000000 --- a/java/tests/ImageProcessing/src/com/android/rs/image/levels_relaxed.fs +++ /dev/null @@ -1,20 +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" - -#include "levels.rsh" - diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/levels_relaxed.rs b/java/tests/ImageProcessing/src/com/android/rs/image/levels_relaxed.rs new file mode 100644 index 00000000..c0bc4b7c --- /dev/null +++ b/java/tests/ImageProcessing/src/com/android/rs/image/levels_relaxed.rs @@ -0,0 +1,21 @@ +/* + * 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 + +#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.fs deleted file mode 100644 index 0b2c2e86..00000000 --- a/java/tests/ImageProcessing/src/com/android/rs/image/threshold.fs +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (C) 2013 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" - - -int height; -int width; -static int radius; - -rs_allocation InPixel; -rs_allocation ScratchPixel1; -rs_allocation ScratchPixel2; - -const int MAX_RADIUS = 25; - -// Store our coefficients here -static float gaussian[MAX_RADIUS * 2 + 1]; - -void setRadius(int rad) { - radius = rad; - // Compute gaussian weights for the blur - // e is the euler's number - float e = 2.718281828459045f; - float pi = 3.1415926535897932f; - // g(x) = ( 1 / sqrt( 2 * pi ) * sigma) * e ^ ( -x^2 / 2 * sigma^2 ) - // x is of the form [-radius .. 0 .. radius] - // and sigma varies with radius. - // Based on some experimental radius values and sigma's - // we approximately fit sigma = f(radius) as - // sigma = radius * 0.4 + 0.6 - // The larger the radius gets, the more our gaussian blur - // will resemble a box blur since with large sigma - // the gaussian curve begins to lose its shape - float sigma = 0.4f * (float)radius + 0.6f; - - // Now compute the coefficints - // We will store some redundant values to save some math during - // the blur calculations - // precompute some values - float coeff1 = 1.0f / (sqrt( 2.0f * pi ) * sigma); - float coeff2 = - 1.0f / (2.0f * sigma * sigma); - - float normalizeFactor = 0.0f; - float floatR = 0.0f; - for (int r = -radius; r <= radius; r ++) { - floatR = (float)r; - gaussian[r + radius] = coeff1 * pow(e, floatR * floatR * coeff2); - normalizeFactor += gaussian[r + radius]; - } - - //Now we need to normalize the weights because all our coefficients need to add up to one - normalizeFactor = 1.0f / normalizeFactor; - for (int r = -radius; r <= radius; r ++) { - floatR = (float)r; - gaussian[r + radius] *= normalizeFactor; - } -} - -float4 __attribute__((kernel)) copyIn(uchar4 in) { - return convert_float4(in); -} - -uchar4 __attribute__((kernel)) vert(uint32_t x, uint32_t y) { - float3 blurredPixel = 0; - int gi = 0; - uchar4 out; - if ((y > radius) && (y < (height - radius))) { - for (int r = -radius; r <= radius; r ++) { - float4 i = rsGetElementAt_float4(ScratchPixel2, x, y + r); - blurredPixel += i.xyz * gaussian[gi++]; - } - } else { - for (int r = -radius; r <= radius; r ++) { - int validH = rsClamp((int)y + r, (int)0, (int)(height - 1)); - float4 i = rsGetElementAt_float4(ScratchPixel2, x, validH); - blurredPixel += i.xyz * gaussian[gi++]; - } - } - - out.xyz = convert_uchar3(clamp(blurredPixel, 0.f, 255.f)); - out.w = 0xff; - return out; -} - -float4 __attribute__((kernel)) horz(uint32_t x, uint32_t y) { - float4 blurredPixel = 0; - int gi = 0; - if ((x > radius) && (x < (width - radius))) { - for (int r = -radius; r <= radius; r ++) { - float4 i = rsGetElementAt_float4(ScratchPixel1, x + r, y); - blurredPixel += i * gaussian[gi++]; - } - } else { - for (int r = -radius; r <= radius; r ++) { - // Stepping left and right away from the pixel - int validX = rsClamp((int)x + r, (int)0, (int)(width - 1)); - float4 i = rsGetElementAt_float4(ScratchPixel1, validX, y); - blurredPixel += i * gaussian[gi++]; - } - } - - return blurredPixel; -} - diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/threshold.rs b/java/tests/ImageProcessing/src/com/android/rs/image/threshold.rs new file mode 100644 index 00000000..d30a87b5 --- /dev/null +++ b/java/tests/ImageProcessing/src/com/android/rs/image/threshold.rs @@ -0,0 +1,118 @@ +/* + * Copyright (C) 2013 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 + +int height; +int width; +static int radius; + +rs_allocation InPixel; +rs_allocation ScratchPixel1; +rs_allocation ScratchPixel2; + +const int MAX_RADIUS = 25; + +// Store our coefficients here +static float gaussian[MAX_RADIUS * 2 + 1]; + +void setRadius(int rad) { + radius = rad; + // Compute gaussian weights for the blur + // e is the euler's number + float e = 2.718281828459045f; + float pi = 3.1415926535897932f; + // g(x) = ( 1 / sqrt( 2 * pi ) * sigma) * e ^ ( -x^2 / 2 * sigma^2 ) + // x is of the form [-radius .. 0 .. radius] + // and sigma varies with radius. + // Based on some experimental radius values and sigma's + // we approximately fit sigma = f(radius) as + // sigma = radius * 0.4 + 0.6 + // The larger the radius gets, the more our gaussian blur + // will resemble a box blur since with large sigma + // the gaussian curve begins to lose its shape + float sigma = 0.4f * (float)radius + 0.6f; + + // Now compute the coefficints + // We will store some redundant values to save some math during + // the blur calculations + // precompute some values + float coeff1 = 1.0f / (sqrt( 2.0f * pi ) * sigma); + float coeff2 = - 1.0f / (2.0f * sigma * sigma); + + float normalizeFactor = 0.0f; + float floatR = 0.0f; + for (int r = -radius; r <= radius; r ++) { + floatR = (float)r; + gaussian[r + radius] = coeff1 * pow(e, floatR * floatR * coeff2); + normalizeFactor += gaussian[r + radius]; + } + + //Now we need to normalize the weights because all our coefficients need to add up to one + normalizeFactor = 1.0f / normalizeFactor; + for (int r = -radius; r <= radius; r ++) { + floatR = (float)r; + gaussian[r + radius] *= normalizeFactor; + } +} + +float4 __attribute__((kernel)) copyIn(uchar4 in) { + return convert_float4(in); +} + +uchar4 __attribute__((kernel)) vert(uint32_t x, uint32_t y) { + float3 blurredPixel = 0; + int gi = 0; + uchar4 out; + if ((y > radius) && (y < (height - radius))) { + for (int r = -radius; r <= radius; r ++) { + float4 i = rsGetElementAt_float4(ScratchPixel2, x, y + r); + blurredPixel += i.xyz * gaussian[gi++]; + } + } else { + for (int r = -radius; r <= radius; r ++) { + int validH = rsClamp((int)y + r, (int)0, (int)(height - 1)); + float4 i = rsGetElementAt_float4(ScratchPixel2, x, validH); + blurredPixel += i.xyz * gaussian[gi++]; + } + } + + out.xyz = convert_uchar3(clamp(blurredPixel, 0.f, 255.f)); + out.w = 0xff; + return out; +} + +float4 __attribute__((kernel)) horz(uint32_t x, uint32_t y) { + float4 blurredPixel = 0; + int gi = 0; + if ((x > radius) && (x < (width - radius))) { + for (int r = -radius; r <= radius; r ++) { + float4 i = rsGetElementAt_float4(ScratchPixel1, x + r, y); + blurredPixel += i * gaussian[gi++]; + } + } else { + for (int r = -radius; r <= radius; r ++) { + // Stepping left and right away from the pixel + int validX = rsClamp((int)x + r, (int)0, (int)(width - 1)); + float4 i = rsGetElementAt_float4(ScratchPixel1, validX, y); + blurredPixel += i * gaussian[gi++]; + } + } + + return blurredPixel; +} + 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.fs deleted file mode 100644 index 00cbbc4d..00000000 --- a/java/tests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.fs +++ /dev/null @@ -1,20 +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" - -#include "vignette_approx.rsh" - diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.rs b/java/tests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.rs new file mode 100644 index 00000000..00cbbc4d --- /dev/null +++ b/java/tests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.rs @@ -0,0 +1,20 @@ +/* + * 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" + +#include "vignette_approx.rsh" + 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.fs deleted file mode 100644 index 8202c5c1..00000000 --- a/java/tests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.fs +++ /dev/null @@ -1,20 +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" - -#include "vignette.rsh" - diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.rs b/java/tests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.rs new file mode 100644 index 00000000..262d516b --- /dev/null +++ b/java/tests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.rs @@ -0,0 +1,21 @@ +/* + * 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 + +#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}; + } +} + -- cgit v1.2.3