Remove noise functions and update images processing to use new rs namespace names.

Change-Id: I2dc9b5ec7877acd630bea1a011ecc4a6d43a31eb
diff --git a/Android.mk b/Android.mk
index c1910ff..0f8de2b 100644
--- a/Android.mk
+++ b/Android.mk
@@ -88,7 +88,6 @@
 	rsMatrix.cpp \
     rsMesh.cpp \
     rsMutex.cpp \
-	rsNoise.cpp \
 	rsProgram.cpp \
 	rsProgramFragment.cpp \
 	rsProgramStore.cpp \
diff --git a/java/ImageProcessing/res/raw/threshold.rs b/java/ImageProcessing/res/raw/threshold.rs
index 0317088..6af4012 100644
--- a/java/ImageProcessing/res/raw/threshold.rs
+++ b/java/ImageProcessing/res/raw/threshold.rs
@@ -50,7 +50,7 @@
 
     float oneMinusS = 1.0f - saturation;
 
-    matrixLoadIdentity(colorMat);
+    rsMatrixLoadIdentity((rs_matrix4x4 *)colorMat);
 
     colorMat[0][0] = oneMinusS * rWeight + saturation;
     colorMat[0][1] = oneMinusS * rWeight;
@@ -165,7 +165,7 @@
             output->a = input->a;
         }
     }
-    sendToClient(&count, 1, 4, 0);
+    rsSendToClient(&count, 1, 4, 0);
 }
 
 void horizontalBlur() {
@@ -294,16 +294,15 @@
 }
 
 void filter() {
-    debugP(0, (void *)height);
-    debugP(0, (void *)width);
-    debugP(0, (void *)radius);
-
-    debugPf(10, inBlack);
-    debugPf(11, outBlack);
-    debugPf(12, inWhite);
-    debugPf(13, outWhite);
-    debugPf(14, gamma);
-    debugPf(15, saturation);
+    RS_DEBUG(height);
+    RS_DEBUG(width);
+    RS_DEBUG(radius);
+    RS_DEBUG(inBlack);
+    RS_DEBUG(outBlack);
+    RS_DEBUG(inWhite);
+    RS_DEBUG(outWhite);
+    RS_DEBUG(gamma);
+    RS_DEBUG(saturation);
 
     computeColorMatrix();
 
@@ -318,7 +317,7 @@
     verticalBlur();
 
     int count = 0;
-    sendToClient(&count, 1, 4, 0);
+    rsSendToClient(&count, 1, 4, 0);
 }
 
 void filterBenchmark() {
@@ -329,6 +328,6 @@
     verticalBlur();
 
     int count = 0;
-    sendToClient(&count, 1, 4, 0);
+    rsSendToClient(&count, 1, 4, 0);
 }
 
diff --git a/java/ImageProcessing/res/raw/threshold_bc.bc b/java/ImageProcessing/res/raw/threshold_bc.bc
index 58a93e6..29eba2d 100644
--- a/java/ImageProcessing/res/raw/threshold_bc.bc
+++ b/java/ImageProcessing/res/raw/threshold_bc.bc
Binary files differ
diff --git a/rsNoise.cpp b/rsNoise.cpp
deleted file mode 100644
index 764dc1a..0000000
--- a/rsNoise.cpp
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * This implementation of the noise functions was ported from the Java
- * implementation by Jerry Huxtable (http://www.jhlabs.com) under
- * Apache License 2.0 (see http://jhlabs.com/ip/filters/download.html)
- *
- * Original header:
- *
- * Copyright 2006 Jerry Huxtable
- *
- * 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 "rsNoise.h"
-
-#include <math.h>
-#include <stdlib.h>
-#include <time.h>
-
-namespace android {
-namespace renderscript {
-
-#define B 0x100
-#define BM 0xff
-#define N 0x1000
-
-static int p[B + B + 2];
-static float g3[B + B + 2][3];
-static float g2[B + B + 2][2];
-static float g1[B + B + 2];
-static bool noise_start = true;
-
-#define lerpf(start, stop, amount) start + (stop - start) * amount
-
-static inline float noise_sCurve(float t)
-{
-    return t * t * (3.0f - 2.0f * t);
-}
-
-inline void SC_normalizef2(float v[])
-{
-    float s = (float)sqrtf(v[0] * v[0] + v[1] * v[1]);
-    v[0] = v[0] / s;
-    v[1] = v[1] / s;
-}
-
-inline void SC_normalizef3(float v[])
-{
-    float s = (float)sqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
-    v[0] = v[0] / s;
-    v[1] = v[1] / s;
-    v[2] = v[2] / s;
-}
-
-static void noise_init()
-{
-    int i, j, k;
-    
-    for (i = 0; i < B; i++) {
-        p[i] = i;
-        
-        g1[i] = (float)((rand() % (B + B)) - B) / B;
-        
-        for (j = 0; j < 2; j++)
-            g2[i][j] = (float)((rand() % (B + B)) - B) / B;
-        SC_normalizef2(g2[i]);
-        
-        for (j = 0; j < 3; j++)
-            g3[i][j] = (float)((rand() % (B + B)) - B) / B;
-        SC_normalizef3(g3[i]);
-    }
-    
-    for (i = B-1; i >= 0; i--) {
-        k = p[i];
-        p[i] = p[j = rand() % B];
-        p[j] = k;
-    }
-    
-    for (i = 0; i < B + 2; i++) {
-        p[B + i] = p[i];
-        g1[B + i] = g1[i];
-        for (j = 0; j < 2; j++)
-            g2[B + i][j] = g2[i][j];
-        for (j = 0; j < 3; j++)
-            g3[B + i][j] = g3[i][j];
-    }
-}
-
-float SC_noisef(float x)
-{
-    srand(time(NULL));
-    int bx0, bx1;
-    float rx0, rx1, sx, t, u, v;
-    
-    if (noise_start) {
-        noise_start = false;
-        noise_init();
-    }
-    
-    t = x + N;
-    bx0 = ((int)t) & BM;
-    bx1 = (bx0+1) & BM;
-    rx0 = t - (int)t;
-    rx1 = rx0 - 1.0f;
-    
-    sx = noise_sCurve(rx0);
-    
-    u = rx0 * g1[p[bx0]];
-    v = rx1 * g1[p[bx1]];
-    return 2.3f * lerpf(u, v, sx);
-}
-
-float SC_noisef2(float x, float y)
-{
-    srand(time(NULL));
-    int bx0, bx1, by0, by1, b00, b10, b01, b11;
-    float rx0, rx1, ry0, ry1, sx, sy, a, b, t, u, v;
-    float *q;
-    int i, j;
-    
-    if (noise_start) {
-        noise_start = false;
-        noise_init();
-    }
-    
-    t = x + N;
-    bx0 = ((int)t) & BM;
-    bx1 = (bx0+1) & BM;
-    rx0 = t - (int)t;
-    rx1 = rx0 - 1.0f;
-	
-    t = y + N;
-    by0 = ((int)t) & BM;
-    by1 = (by0+1) & BM;
-    ry0 = t - (int)t;
-    ry1 = ry0 - 1.0f;
-	
-    i = p[bx0];
-    j = p[bx1];
-    
-    b00 = p[i + by0];
-    b10 = p[j + by0];
-    b01 = p[i + by1];
-    b11 = p[j + by1];
-    
-    sx = noise_sCurve(rx0);
-    sy = noise_sCurve(ry0);
-    
-    q = g2[b00]; u = rx0 * q[0] + ry0 * q[1];
-    q = g2[b10]; v = rx1 * q[0] + ry0 * q[1];
-    a = lerpf(u, v, sx);
-    
-    q = g2[b01]; u = rx0 * q[0] + ry1 * q[1];
-    q = g2[b11]; v = rx1 * q[0] + ry1 * q[1];
-    b = lerpf(u, v, sx);
-    
-    return 1.5f*lerpf(a, b, sy);
-}
-
-float SC_noisef3(float x, float y, float z)
-{
-    srand(time(NULL));
-    int bx0, bx1, by0, by1, bz0, bz1, b00, b10, b01, b11;
-    float rx0, rx1, ry0, ry1, rz0, rz1, sy, sz, a, b, c, d, t, u, v;
-    float *q;
-    int i, j;
-    
-    if (noise_start) {
-        noise_start = false;
-        noise_init();
-    }
-    
-    t = x + N;
-    bx0 = ((int)t) & BM;
-    bx1 = (bx0+1) & BM;
-    rx0 = t - (int)t;
-    rx1 = rx0 - 1.0f;
-    
-    t = y + N;
-    by0 = ((int)t) & BM;
-    by1 = (by0+1) & BM;
-    ry0 = t - (int)t;
-    ry1 = ry0 - 1.0f;
-	
-    t = z + N;
-    bz0 = ((int)t) & BM;
-    bz1 = (bz0+1) & BM;
-    rz0 = t - (int)t;
-    rz1 = rz0 - 1.0f;
-	
-    i = p[bx0];
-    j = p[bx1];
-    
-    b00 = p[i + by0];
-    b10 = p[j + by0];
-    b01 = p[i + by1];
-    b11 = p[j + by1];
-    
-    t  = noise_sCurve(rx0);
-    sy = noise_sCurve(ry0);
-    sz = noise_sCurve(rz0);
-    
-    q = g3[b00 + bz0]; u = rx0 * q[0] + ry0 * q[1] + rz0 * q[2];
-    q = g3[b10 + bz0]; v = rx1 * q[0] + ry0 * q[1] + rz0 * q[2];
-    a = lerpf(u, v, t);
-    
-    q = g3[b01 + bz0]; u = rx0 * q[0] + ry1 * q[1] + rz0 * q[2];
-    q = g3[b11 + bz0]; v = rx1 * q[0] + ry1 * q[1] + rz0 * q[2];
-    b = lerpf(u, v, t);
-    
-    c = lerpf(a, b, sy);
-    
-    q = g3[b00 + bz1]; u = rx0 * q[0] + ry0 * q[1] + rz1 * q[2];
-    q = g3[b10 + bz1]; v = rx1 * q[0] + ry0 * q[1] + rz1 * q[2];
-    a = lerpf(u, v, t);
-    
-    q = g3[b01 + bz1]; u = rx0 * q[0] + ry1 * q[1] + rz1 * q[2];
-    q = g3[b11 + bz1]; v = rx1 * q[0] + ry1 * q[1] + rz1 * q[2];
-    b = lerpf(u, v, t);
-    
-    d = lerpf(a, b, sy);
-    
-    return 1.5f*lerpf(c, d, sz);
-}
-
-float SC_turbulencef2(float x, float y, float octaves)
-{
-    srand(time(NULL));
-    float t = 0.0f;
-    
-    for (float f = 1.0f; f <= octaves; f *= 2)
-        t += fabs(SC_noisef2(f * x, f * y)) / f;
-    return t;
-}
-
-float SC_turbulencef3(float x, float y, float z, float octaves)
-{
-    srand(time(NULL));
-    float t = 0.0f;
-    
-    for (float f = 1.0f; f <= octaves; f *= 2)
-        t += fabs(SC_noisef3(f * x, f * y, f * z)) / f;
-    return t;
-}
-
-}
-}
\ No newline at end of file
diff --git a/rsNoise.h b/rsNoise.h
deleted file mode 100644
index 9040751..0000000
--- a/rsNoise.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2009 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.
- */
-
-#ifndef ANDROID_RS_NOISE_H
-#define ANDROID_RS_NOISE_H
-
-// ---------------------------------------------------------------------------
-namespace android {
-namespace renderscript {
-
-void SC_normalizef2(float v[]);
-void SC_normalizef3(float v[]);
-float SC_noisef(float x);
-float SC_noisef2(float x, float y);
-float SC_noisef3(float x, float y, float z);
-float SC_turbulencef2(float x, float y, float octaves);
-float SC_turbulencef3(float x, float y, float z, float octaves);
-
-}
-}
-
-#endif
diff --git a/rsScriptC_Lib.cpp b/rsScriptC_Lib.cpp
index 956773b..0c10fca 100644
--- a/rsScriptC_Lib.cpp
+++ b/rsScriptC_Lib.cpp
@@ -17,7 +17,6 @@
 #include "rsContext.h"
 #include "rsScriptC.h"
 #include "rsMatrix.h"
-#include "rsNoise.h"
 
 #include "acc/acc.h"
 #include "utils/Timers.h"
@@ -225,11 +224,6 @@
     return (int)SC_randf2(min, max);
 }
 
-static int SC_sign(int value)
-{
-    return (value > 0) - (value < 0);
-}
-
 static int SC_clamp(int amount, int low, int high)
 {
     return amount < low ? low : (amount > high ? high : amount);
@@ -549,21 +543,6 @@
     rsc->runScript((Script *)scriptID, 0);
 }
 
-static void SC_debugP(int i, void *p)
-{
-    LOGE("debug P  %i  %p, %i", i, p, (int)p);
-}
-
-static void SC_debugPi(int i, int p)
-{
-    LOGE("debug Pi %i  0x%08x, %i", i, p, (int)p);
-}
-
-static void SC_debugPf(int i, float p)
-{
-    LOGE("debug Pf  %i  %f,   0x%08x", i, p, reinterpret_cast<uint32_t *>(&p)[0]);
-}
-
 int SC_divsi3(int a, int b)
 {
     return a / b;
@@ -664,21 +643,14 @@
 
 ////////////////////////////////////////////////////////////////////
 
-    { "modf", (void *)&fmod },
     //{ "sinf_fast", (void *)&SC_sinf_fast },
     //{ "cosf_fast", (void *)&SC_cosf_fast },
-    //{ "sign", (void *)&SC_sign },
     //{ "clamp", (void *)&SC_clamp },
     //{ "distf2", (void *)&SC_distf2 },
     //{ "distf3", (void *)&SC_distf3 },
     //{ "magf2", (void *)&SC_magf2 },
     //{ "magf3", (void *)&SC_magf3 },
     //{ "mapf", (void *)&SC_mapf },
-    { "noisef", (void *)&SC_noisef },
-    { "noisef2", (void *)&SC_noisef2 },
-    { "noisef3", (void *)&SC_noisef3 },
-    { "turbulencef2", (void *)&SC_turbulencef2 },
-    { "turbulencef3", (void *)&SC_turbulencef3 },
 
     { "scriptCall", (void *)&SC_scriptCall },
 
diff --git a/rsScriptC_LibGL.cpp b/rsScriptC_LibGL.cpp
index a60aa80..18f873e 100644
--- a/rsScriptC_LibGL.cpp
+++ b/rsScriptC_LibGL.cpp
@@ -17,7 +17,6 @@
 #include "rsContext.h"
 #include "rsScriptC.h"
 #include "rsMatrix.h"
-#include "rsNoise.h"
 
 #include "acc/acc.h"
 #include "utils/Timers.h"
diff --git a/scriptc/rs_math.rsh b/scriptc/rs_math.rsh
index a9c163d..33e7ee4 100644
--- a/scriptc/rs_math.rsh
+++ b/scriptc/rs_math.rsh
@@ -70,9 +70,6 @@
 ///////////////////////////////////////////////////////////////////
 // non update funcs
 
-extern float turbulencef2(float x, float y, float octaves);
-extern float turbulencef3(float x, float y, float z, float octaves);
-
 /*
 extern float3 float3Norm(float3);
 extern float float3Length(float3);