diff options
author | Jason Sams <jsams@google.com> | 2013-11-15 02:02:18 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-11-15 02:02:18 +0000 |
commit | ba5ed6abcf3044a88df46ccc9ccdb76511a12ce5 (patch) | |
tree | a5c692e015a2c4a96e43407ec8f2e43bfd276be8 /java/tests/ImageProcessing_jb | |
parent | 18601e5e269dfb10fd7b8094c061adbc3ad9f4a7 (diff) | |
parent | 859c4817355fcb86ea3aa103d1d1c5fa12ce81fa (diff) | |
download | rs-ba5ed6abcf3044a88df46ccc9ccdb76511a12ce5.tar.gz |
Merge "Sync changes between IP and IP_JB."
Diffstat (limited to 'java/tests/ImageProcessing_jb')
6 files changed, 165 insertions, 5 deletions
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}; + } +} + |