am a6d32f10: Merge "Update fw/rs for Clang 3.5."

* commit 'a6d32f109788d3a3275648664ea8b4452ecf7bdd':
  Update fw/rs for Clang 3.5.
diff --git a/cpu_ref/Android.mk b/cpu_ref/Android.mk
index c7565da..959376e 100644
--- a/cpu_ref/Android.mk
+++ b/cpu_ref/Android.mk
@@ -35,9 +35,9 @@
 	rsCpuIntrinsicConvolve5x5.cpp \
 	rsCpuIntrinsicHistogram.cpp \
 	rsCpuIntrinsicLoopFilter.cpp \
-	rsCpuIntrinsicYuvToRGB.cpp \
 	rsCpuIntrinsicResize.cpp \
-	rsCpuIntrinsicLUT.cpp
+	rsCpuIntrinsicLUT.cpp \
+	rsCpuIntrinsicYuvToRGB.cpp
 
 #LOCAL_CFLAGS_arm64 += -DARCH_ARM_HAVE_NEON
 LOCAL_ASFLAGS_arm64 += -no-integrated-as
diff --git a/cpu_ref/rsCpuCore.cpp b/cpu_ref/rsCpuCore.cpp
index f2ce358..9e051e5 100644
--- a/cpu_ref/rsCpuCore.cpp
+++ b/cpu_ref/rsCpuCore.cpp
@@ -566,14 +566,14 @@
     case RS_SCRIPT_INTRINSIC_ID_HISTOGRAM:
         i = rsdIntrinsic_Histogram(this, s, e);
         break;
-    case RS_SCRIPT_INTRINSIC_ID_RESIZE:
-        i = rsdIntrinsic_Resize(this, s, e);
-        break;
 #ifndef RS_COMPATIBILITY_LIB
     case RS_SCRIPT_INTRINSIC_ID_LOOP_FILTER:
         i = rsdIntrinsic_LoopFilter(this, s, e);
         break;
 #endif
+    case RS_SCRIPT_INTRINSIC_ID_RESIZE:
+        i = rsdIntrinsic_Resize(this, s, e);
+        break;
 
     default:
         rsAssert(0);
diff --git a/cpu_ref/rsCpuIntrinsicResize.cpp b/cpu_ref/rsCpuIntrinsicResize.cpp
index d18eb8f..474f82d 100644
--- a/cpu_ref/rsCpuIntrinsicResize.cpp
+++ b/cpu_ref/rsCpuIntrinsicResize.cpp
@@ -66,10 +66,6 @@
     mAlloc.set(static_cast<Allocation *>(data));
 }
 
-
-extern "C" void rsdIntrinsicConvolve3x3_K(void *dst, const void *y0, const void *y1,
-                                          const void *y2, const short *coef, uint32_t count);
-
 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)));
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 77f554a..44b40f7 100644
--- a/java/tests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
+++ b/java/tests/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
@@ -153,7 +153,9 @@
         USAGE_IO ("Usage io"),
         ARTISTIC_1("Artistic 1"),
         HISTOGRAM ("Histogram"),
-        MANDELBROT_DOUBLE ("Mandelbrot fp64");
+        MANDELBROT_DOUBLE ("Mandelbrot fp64"),
+        RESIZE_BICUBIC_SCRIPT ("Resize BiCubic Script"),
+        RESIZE_BICUBIC_INTRINSIC ("Resize BiCubic Intrinsic");
 
 
         private final String name;
@@ -418,6 +420,12 @@
         case MANDELBROT_DOUBLE:
             mTest = new Mandelbrot(true);
             break;
+        case RESIZE_BICUBIC_SCRIPT:
+            mTest = new Resize(false);
+            break;
+        case RESIZE_BICUBIC_INTRINSIC:
+            mTest = new Resize(true);
+            break;
         }
 
         mTest.createBaseTest(this);
diff --git a/java/tests/ImageProcessing/src/com/android/rs/image/Resize.java b/java/tests/ImageProcessing/src/com/android/rs/image/Resize.java
new file mode 100644
index 0000000..a9f76c4
--- /dev/null
+++ b/java/tests/ImageProcessing/src/com/android/rs/image/Resize.java
@@ -0,0 +1,83 @@
+/*
+ * 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.image;
+
+import java.lang.Math;
+
+import android.renderscript.Allocation;
+import android.renderscript.Element;
+import android.renderscript.Matrix4f;
+import android.renderscript.RenderScript;
+import android.renderscript.Script;
+import android.renderscript.ScriptC;
+import android.renderscript.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.Builder tb = new Type.Builder(mRS, mInPixelsAllocation.getElement());
+        tb.setX((int)(mWidth * scale));
+        tb.setY((int)(mHeight * scale));
+        Type t = tb.create();
+        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/src/com/android/rs/image/resize.rs b/java/tests/ImageProcessing/src/com/android/rs/image/resize.rs
new file mode 100644
index 0000000..98d61a5
--- /dev/null
+++ b/java/tests/ImageProcessing/src/com/android/rs/image/resize.rs
@@ -0,0 +1,93 @@
+/*
+ * 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);
+}
+