Modify the CTS resize to support Float32.

Change-Id: Iaaa4036397839c0b9fa9732f9ca1b7408e8cf51e
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicResize.java b/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicResize.java
index d593bff..9028c37 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicResize.java
+++ b/tests/tests/renderscript/src/android/renderscript/cts/IntrinsicResize.java
@@ -67,8 +67,24 @@
                 sr.forEach_bicubic_U1(mAllocDst);
                 break;
             }
+        } else {
+            switch(vecSize) {
+            case 4:
+                sr.forEach_bicubic_F4(mAllocDst);
+                break;
+            case 3:
+                sr.forEach_bicubic_F3(mAllocDst);
+                break;
+            case 2:
+                sr.forEach_bicubic_F2(mAllocDst);
+                break;
+            case 1:
+                sr.forEach_bicubic_F1(mAllocDst);
+                break;
+            }
         }
 
+
         mVerify.invoke_verify(mAllocRef, mAllocDst, mAllocSrc);
         if (outW == w && outH == h) {
             //when scale = 1, check with the original.
@@ -248,4 +264,176 @@
         testReszie(inX, inY, Element.DataType.UNSIGNED_8, 1, 0.5f, 0.5f);
         checkError();
     }
+
+
+    public void test_F32_4_SCALE10_10_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 1.f, 1.f);
+        checkError();
+    }
+    public void test_F32_3_SCALE10_10_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 1.f, 1.f);
+        checkError();
+    }
+    public void test_F32_2_SCALE10_10_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 1.f, 1.f);
+        checkError();
+    }
+    public void test_F32_1_SCALE10_10_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 1.f, 1.f);
+        checkError();
+    }
+
+    public void test_F32_4_SCALE20_20_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 2.f, 2.f);
+        checkError();
+    }
+    public void test_F32_3_SCALE20_20_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 2.f, 2.f);
+        checkError();
+    }
+    public void test_F32_2_SCALE20_20_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 2.f, 2.f);
+        checkError();
+    }
+    public void test_F32_1_SCALE20_20_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 2.f, 2.f);
+        checkError();
+    }
+
+    public void test_F32_4_SCALE05_20_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 0.5f, 2.f);
+        checkError();
+    }
+    public void test_F32_3_SCALE05_20_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 0.5f, 2.f);
+        checkError();
+    }
+    public void test_F32_2_SCALE05_20_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 0.5f, 2.f);
+        checkError();
+    }
+    public void test_F32_1_SCALE05_20_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 0.5f, 2.f);
+        checkError();
+    }
+
+    public void test_F32_4_SCALE20_05_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 2.f, 0.5f);
+        checkError();
+    }
+    public void test_F32_3_SCALE20_05_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 2.f, 0.5f);
+        checkError();
+    }
+    public void test_F32_2_SCALE20_05_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 2.f, 0.5f);
+        checkError();
+    }
+    public void test_F32_1_SCALE20_05_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 2.f, 0.5f);
+        checkError();
+    }
+
+    public void test_F32_4_SCALE05_05_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 4, 0.5f, 0.5f);
+        checkError();
+    }
+    public void test_F32_3_SCALE05_05_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 3, 0.5f, 0.5f);
+        checkError();
+    }
+    public void test_F32_2_SCALE05_05_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 2, 0.5f, 0.5f);
+        checkError();
+    }
+    public void test_F32_1_SCALE05_05_inSqure() {
+        testReszie(inX, inX, Element.DataType.FLOAT_32, 1, 0.5f, 0.5f);
+        checkError();
+    }
+
+    public void test_F32_4_SCALE10_10_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 1.f, 1.f);
+        checkError();
+    }
+    public void test_F32_3_SCALE10_10_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 1.f, 1.f);
+        checkError();
+    }
+    public void test_F32_2_SCALE10_10_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 1.f, 1.f);
+        checkError();
+    }
+    public void test_F32_1_SCALE10_10_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 1.f, 1.f);
+        checkError();
+    }
+
+    public void test_F32_4_SCALE20_20_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 2.f, 2.f);
+        checkError();
+    }
+    public void test_F32_3_SCALE20_20_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 2.f, 2.f);
+        checkError();
+    }
+    public void test_F32_2_SCALE20_20_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 2.f, 2.f);
+        checkError();
+    }
+    public void test_F32_1_SCALE20_20_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 2.f, 2.f);
+        checkError();
+    }
+
+    public void test_F32_4_SCALE05_20_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 0.5f, 2.f);
+        checkError();
+    }
+    public void test_F32_3_SCALE05_20_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 0.5f, 2.f);
+        checkError();
+    }
+    public void test_F32_2_SCALE05_20_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 0.5f, 2.f);
+        checkError();
+    }
+    public void test_F32_1_SCALE05_20_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 0.5f, 2.f);
+        checkError();
+    }
+
+    public void test_F32_4_SCALE20_05_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 2.f, 0.5f);
+        checkError();
+    }
+    public void test_F32_3_SCALE20_05_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 2.f, 0.5f);
+        checkError();
+    }
+    public void test_F32_2_SCALE20_05_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 2.f, 0.5f);
+        checkError();
+    }
+    public void test_F32_1_SCALE20_05_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 2.f, 0.5f);
+        checkError();
+    }
+
+    public void test_F32_4_SCALE05_05_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 4, 0.5f, 0.5f);
+        checkError();
+    }
+    public void test_F32_3_SCALE05_05_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 3, 0.5f, 0.5f);
+        checkError();
+    }
+    public void test_F32_2_SCALE05_05_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 2, 0.5f, 0.5f);
+        checkError();
+    }
+    public void test_F32_1_SCALE05_05_inRectangle() {
+        testReszie(inX, inY, Element.DataType.FLOAT_32, 1, 0.5f, 0.5f);
+        checkError();
+    }
+
 }
diff --git a/tests/tests/renderscript/src/android/renderscript/cts/intrinsic_resize.rs b/tests/tests/renderscript/src/android/renderscript/cts/intrinsic_resize.rs
index fa8c8dd..ccdf42f 100644
--- a/tests/tests/renderscript/src/android/renderscript/cts/intrinsic_resize.rs
+++ b/tests/tests/renderscript/src/android/renderscript/cts/intrinsic_resize.rs
@@ -242,3 +242,203 @@
     return (uchar)p;
 }
 
+float4 __attribute__((kernel)) bicubic_F4(uint32_t x, uint32_t y) {
+    float xf = (x + 0.5f) * scaleX - 0.5f;
+    float yf = (y + 0.5f) * scaleY - 0.5f;
+
+    int startx = (int) floor(xf - 1);
+    int starty = (int) floor(yf - 1);
+    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 = rsGetElementAt_float4(gIn, xs0, ys0);
+    float4 p01 = rsGetElementAt_float4(gIn, xs1, ys0);
+    float4 p02 = rsGetElementAt_float4(gIn, xs2, ys0);
+    float4 p03 = rsGetElementAt_float4(gIn, xs3, ys0);
+    float4 p0  = cubicInterpolate_F4(p00, p01, p02, p03, xf);
+
+    float4 p10 = rsGetElementAt_float4(gIn, xs0, ys1);
+    float4 p11 = rsGetElementAt_float4(gIn, xs1, ys1);
+    float4 p12 = rsGetElementAt_float4(gIn, xs2, ys1);
+    float4 p13 = rsGetElementAt_float4(gIn, xs3, ys1);
+    float4 p1  = cubicInterpolate_F4(p10, p11, p12, p13, xf);
+
+    float4 p20 = rsGetElementAt_float4(gIn, xs0, ys2);
+    float4 p21 = rsGetElementAt_float4(gIn, xs1, ys2);
+    float4 p22 = rsGetElementAt_float4(gIn, xs2, ys2);
+    float4 p23 = rsGetElementAt_float4(gIn, xs3, ys2);
+    float4 p2  = cubicInterpolate_F4(p20, p21, p22, p23, xf);
+
+    float4 p30 = rsGetElementAt_float4(gIn, xs0, ys3);
+    float4 p31 = rsGetElementAt_float4(gIn, xs1, ys3);
+    float4 p32 = rsGetElementAt_float4(gIn, xs2, ys3);
+    float4 p33 = rsGetElementAt_float4(gIn, xs3, ys3);
+    float4 p3  = cubicInterpolate_F4(p30, p31, p32, p33, xf);
+
+    float4 p  = cubicInterpolate_F4(p0, p1, p2, p3, yf);
+
+    return p;
+}
+
+float3 __attribute__((kernel)) bicubic_F3(uint32_t x, uint32_t y) {
+    float xf = (x + 0.5f) * scaleX - 0.5f;
+    float yf = (y + 0.5f) * scaleY - 0.5f;
+
+    int startx = (int) floor(xf - 1);
+    int starty = (int) floor(yf - 1);
+    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);
+
+    float3 p00 = rsGetElementAt_float3(gIn, xs0, ys0);
+    float3 p01 = rsGetElementAt_float3(gIn, xs1, ys0);
+    float3 p02 = rsGetElementAt_float3(gIn, xs2, ys0);
+    float3 p03 = rsGetElementAt_float3(gIn, xs3, ys0);
+    float3 p0  = cubicInterpolate_F3(p00, p01, p02, p03, xf);
+
+    float3 p10 = rsGetElementAt_float3(gIn, xs0, ys1);
+    float3 p11 = rsGetElementAt_float3(gIn, xs1, ys1);
+    float3 p12 = rsGetElementAt_float3(gIn, xs2, ys1);
+    float3 p13 = rsGetElementAt_float3(gIn, xs3, ys1);
+    float3 p1  = cubicInterpolate_F3(p10, p11, p12, p13, xf);
+
+    float3 p20 = rsGetElementAt_float3(gIn, xs0, ys2);
+    float3 p21 = rsGetElementAt_float3(gIn, xs1, ys2);
+    float3 p22 = rsGetElementAt_float3(gIn, xs2, ys2);
+    float3 p23 = rsGetElementAt_float3(gIn, xs3, ys2);
+    float3 p2  = cubicInterpolate_F3(p20, p21, p22, p23, xf);
+
+    float3 p30 = rsGetElementAt_float3(gIn, xs0, ys3);
+    float3 p31 = rsGetElementAt_float3(gIn, xs1, ys3);
+    float3 p32 = rsGetElementAt_float3(gIn, xs2, ys3);
+    float3 p33 = rsGetElementAt_float3(gIn, xs3, ys3);
+    float3 p3  = cubicInterpolate_F3(p30, p31, p32, p33, xf);
+
+    float3 p  = cubicInterpolate_F3(p0, p1, p2, p3, yf);
+
+    return p;
+}
+
+float2 __attribute__((kernel)) bicubic_F2(uint32_t x, uint32_t y) {
+    float xf = (x + 0.5f) * scaleX - 0.5f;
+    float yf = (y + 0.5f) * scaleY - 0.5f;
+
+    int startx = (int) floor(xf - 1);
+    int starty = (int) floor(yf - 1);
+    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);
+
+    float2 p00 = rsGetElementAt_float2(gIn, xs0, ys0);
+    float2 p01 = rsGetElementAt_float2(gIn, xs1, ys0);
+    float2 p02 = rsGetElementAt_float2(gIn, xs2, ys0);
+    float2 p03 = rsGetElementAt_float2(gIn, xs3, ys0);
+    float2 p0  = cubicInterpolate_F2(p00, p01, p02, p03, xf);
+
+    float2 p10 = rsGetElementAt_float2(gIn, xs0, ys1);
+    float2 p11 = rsGetElementAt_float2(gIn, xs1, ys1);
+    float2 p12 = rsGetElementAt_float2(gIn, xs2, ys1);
+    float2 p13 = rsGetElementAt_float2(gIn, xs3, ys1);
+    float2 p1  = cubicInterpolate_F2(p10, p11, p12, p13, xf);
+
+    float2 p20 = rsGetElementAt_float2(gIn, xs0, ys2);
+    float2 p21 = rsGetElementAt_float2(gIn, xs1, ys2);
+    float2 p22 = rsGetElementAt_float2(gIn, xs2, ys2);
+    float2 p23 = rsGetElementAt_float2(gIn, xs3, ys2);
+    float2 p2  = cubicInterpolate_F2(p20, p21, p22, p23, xf);
+
+    float2 p30 = rsGetElementAt_float2(gIn, xs0, ys3);
+    float2 p31 = rsGetElementAt_float2(gIn, xs1, ys3);
+    float2 p32 = rsGetElementAt_float2(gIn, xs2, ys3);
+    float2 p33 = rsGetElementAt_float2(gIn, xs3, ys3);
+    float2 p3  = cubicInterpolate_F2(p30, p31, p32, p33, xf);
+
+    float2 p  = cubicInterpolate_F2(p0, p1, p2, p3, yf);
+
+    return p;
+}
+
+float __attribute__((kernel)) bicubic_F1(uint32_t x, uint32_t y) {
+    float xf = (x + 0.5f) * scaleX - 0.5f;
+    float yf = (y + 0.5f) * scaleY - 0.5f;
+
+    int startx = (int) floor(xf - 1);
+    int starty = (int) floor(yf - 1);
+    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);
+
+    float p00 = rsGetElementAt_float(gIn, xs0, ys0);
+    float p01 = rsGetElementAt_float(gIn, xs1, ys0);
+    float p02 = rsGetElementAt_float(gIn, xs2, ys0);
+    float p03 = rsGetElementAt_float(gIn, xs3, ys0);
+    float p0  = cubicInterpolate_F1(p00, p01, p02, p03, xf);
+
+    float p10 = rsGetElementAt_float(gIn, xs0, ys1);
+    float p11 = rsGetElementAt_float(gIn, xs1, ys1);
+    float p12 = rsGetElementAt_float(gIn, xs2, ys1);
+    float p13 = rsGetElementAt_float(gIn, xs3, ys1);
+    float p1  = cubicInterpolate_F1(p10, p11, p12, p13, xf);
+
+    float p20 = rsGetElementAt_float(gIn, xs0, ys2);
+    float p21 = rsGetElementAt_float(gIn, xs1, ys2);
+    float p22 = rsGetElementAt_float(gIn, xs2, ys2);
+    float p23 = rsGetElementAt_float(gIn, xs3, ys2);
+    float p2  = cubicInterpolate_F1(p20, p21, p22, p23, xf);
+
+    float p30 = rsGetElementAt_float(gIn, xs0, ys3);
+    float p31 = rsGetElementAt_float(gIn, xs1, ys3);
+    float p32 = rsGetElementAt_float(gIn, xs2, ys3);
+    float p33 = rsGetElementAt_float(gIn, xs3, ys3);
+    float p3  = cubicInterpolate_F1(p30, p31, p32, p33, xf);
+
+    float p  = cubicInterpolate_F1(p0, p1, p2, p3, yf);
+
+    return p;
+}
+