diff options
author | Jason Sams <jsams@google.com> | 2014-04-18 14:59:58 -0700 |
---|---|---|
committer | Jason Sams <jsams@google.com> | 2014-04-18 14:59:58 -0700 |
commit | 0ef64c5373a119eb73cbf7b1f7cf7d1da12d97d3 (patch) | |
tree | 3bf548f8b7f9016661351237a84f6f092bf7ca6a /java/tests/ImageProcessing_jb/src/com/android/rs/image | |
parent | 1b65ec658ee50458dc124fd915bb3a658a6471e0 (diff) | |
download | rs-0ef64c5373a119eb73cbf7b1f7cf7d1da12d97d3.tar.gz |
Bicubic resize intrinsic tests
Change-Id: Ieaa728dc597c73485e4267c21c590432adbda058
Diffstat (limited to 'java/tests/ImageProcessing_jb/src/com/android/rs/image')
3 files changed, 180 insertions, 1 deletions
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 4bf99e3d..398f9c13 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 @@ -71,7 +71,9 @@ public class IPTestListJB { 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), - ARTISTIC1 ("Artistic 1", RELAXED_FP, 120.f); + ARTISTIC1 ("Artistic 1", RELAXED_FP, 120.f), + RESIZE_BI_SCRIPT ("Resize BiCubic Script", RELAXED_FP, 100.f), + RESIZE_BI_INTRINSIC ("Resize BiCubic Intrinsic", INTRINSIC, 100.f); private final String name; @@ -177,6 +179,10 @@ public class IPTestListJB { return new ColorCube(true); case ARTISTIC1: return new Artistic1(); + case RESIZE_BI_SCRIPT: + return new Resize(false); + case RESIZE_BI_INTRINSIC: + return new Resize(true); } return null; } diff --git a/java/tests/ImageProcessing_jb/src/com/android/rs/image/Resize.java b/java/tests/ImageProcessing_jb/src/com/android/rs/image/Resize.java new file mode 100644 index 00000000..014b5d7f --- /dev/null +++ b/java/tests/ImageProcessing_jb/src/com/android/rs/image/Resize.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2014 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.Allocation; +import android.renderscript.Element; +import android.renderscript.Matrix4f; +import android.renderscript.RenderScript; +import android.renderscript.Script; +import android.renderscript.ScriptC; +import android.renderscript.ScriptIntrinsicResize; +import android.renderscript.Type; +import android.util.Log; + +public class Resize extends TestBase { + private ScriptC_resize mScript; + private ScriptIntrinsicResize mIntrinsic; + + private Allocation mScratchAllocation; + private int mWidth; + private int mHeight; + private boolean mUseIntrinsic; + + public Resize(boolean useIntrinsic) { + mUseIntrinsic = useIntrinsic; + } + + public void createTest(android.content.res.Resources res) { + mWidth = mInPixelsAllocation.getType().getX(); + mHeight = mInPixelsAllocation.getType().getY(); + float scale = 1.f / 32.f; + + Type t = Type.createXY(mRS, mInPixelsAllocation.getElement(), + (int)(mWidth * scale), (int)(mHeight * scale)); + mScratchAllocation = Allocation.createTyped(mRS, t); + + // make small buffer + mScript = new ScriptC_resize(mRS); + mScript.set_gIn(mInPixelsAllocation); + mScript.set_gWidthIn(mWidth); + mScript.set_gHeightIn(mHeight); + mScript.set_scale(1.f / scale); + mScript.forEach_nearest(mScratchAllocation); + + // setup normal ops + mScript.set_gIn(mScratchAllocation); + mScript.set_gWidthIn(t.getX()); + mScript.set_gHeightIn(t.getY()); + mScript.set_scale(scale); + //mScript.forEach_nearest(mScratchAllocation); + + mIntrinsic = ScriptIntrinsicResize.create(mRS); + mIntrinsic.setInput(mScratchAllocation); + } + + public void runTest() { + if (mUseIntrinsic) { + mIntrinsic.forEach_bicubic(mOutPixelsAllocation); + } else { + mScript.forEach_bicubic(mOutPixelsAllocation); + //mScript.forEach_nearest(mOutPixelsAllocation); + } + } + +} diff --git a/java/tests/ImageProcessing_jb/src/com/android/rs/image/resize.rs b/java/tests/ImageProcessing_jb/src/com/android/rs/image/resize.rs new file mode 100644 index 00000000..ec283bea --- /dev/null +++ b/java/tests/ImageProcessing_jb/src/com/android/rs/image/resize.rs @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2014 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 gWidthIn; +int32_t gHeightIn; +rs_allocation gIn; +float scale; + + +uchar4 __attribute__((kernel)) nearest(uint32_t x, uint32_t y) { + float xf = clamp(x * scale, 0.f, (float)gWidthIn - 1.f); + float yf = clamp(y * scale, 0.f, (float)gHeightIn - 1.f); + uint32_t ix = xf; + uint32_t iy = yf; + + uchar4 tmp = rsGetElementAt_uchar4(gIn, ix, iy); + tmp.a = 0xff; + return tmp; +} + + +static float4 cubicInterpolate (float4 p0,float4 p1,float4 p2,float4 p3 , float x) { + return p1 + 0.5f * x * (p2 - p0 + x * (2.f * p0 - 5.f * p1 + 4.f * p2 - p3 + + x * (3.f * (p1 - p2) + p3 - p0))); +} + +uchar4 __attribute__((kernel)) bicubic(uint32_t x, uint32_t y) { + float xf = x * scale; + float yf = y * scale; + + int startx = (int) floor(xf - 2); + int starty = (int) floor(yf - 2); + xf = xf - floor(xf); + yf = yf - floor(yf); + int maxx = gWidthIn - 1; + int maxy = gHeightIn - 1; + + uint32_t xs0 = (uint32_t) max(0, startx + 0); + uint32_t xs1 = (uint32_t) max(0, startx + 1); + uint32_t xs2 = (uint32_t) min(maxx, startx + 2); + uint32_t xs3 = (uint32_t) min(maxx, startx + 3); + + uint32_t ys0 = (uint32_t) max(0, starty + 0); + uint32_t ys1 = (uint32_t) max(0, starty + 1); + uint32_t ys2 = (uint32_t) min(maxy, starty + 2); + uint32_t ys3 = (uint32_t) min(maxy, starty + 3); + + float4 p00 = convert_float4(rsGetElementAt_uchar4(gIn, xs0, ys0)); + float4 p01 = convert_float4(rsGetElementAt_uchar4(gIn, xs1, ys0)); + float4 p02 = convert_float4(rsGetElementAt_uchar4(gIn, xs2, ys0)); + float4 p03 = convert_float4(rsGetElementAt_uchar4(gIn, xs3, ys0)); + float4 p0 = cubicInterpolate(p00, p01, p02, p03, xf); + + float4 p10 = convert_float4(rsGetElementAt_uchar4(gIn, xs0, ys1)); + float4 p11 = convert_float4(rsGetElementAt_uchar4(gIn, xs1, ys1)); + float4 p12 = convert_float4(rsGetElementAt_uchar4(gIn, xs2, ys1)); + float4 p13 = convert_float4(rsGetElementAt_uchar4(gIn, xs3, ys1)); + float4 p1 = cubicInterpolate(p10, p11, p12, p13, xf); + + float4 p20 = convert_float4(rsGetElementAt_uchar4(gIn, xs0, ys2)); + float4 p21 = convert_float4(rsGetElementAt_uchar4(gIn, xs1, ys2)); + float4 p22 = convert_float4(rsGetElementAt_uchar4(gIn, xs2, ys2)); + float4 p23 = convert_float4(rsGetElementAt_uchar4(gIn, xs3, ys2)); + float4 p2 = cubicInterpolate(p20, p21, p22, p23, xf); + + float4 p30 = convert_float4(rsGetElementAt_uchar4(gIn, xs0, ys3)); + float4 p31 = convert_float4(rsGetElementAt_uchar4(gIn, xs1, ys3)); + float4 p32 = convert_float4(rsGetElementAt_uchar4(gIn, xs2, ys3)); + float4 p33 = convert_float4(rsGetElementAt_uchar4(gIn, xs3, ys3)); + float4 p3 = cubicInterpolate(p30, p31, p32, p33, xf); + + float4 p = cubicInterpolate(p0, p1, p2, p3, yf); + p = clamp(p, 0.f, 255.f); + return convert_uchar4(p); +} + |