summaryrefslogtreecommitdiffstats
path: root/libs/rs/java
diff options
context:
space:
mode:
Diffstat (limited to 'libs/rs/java')
-rw-r--r--libs/rs/java/ImageProcessing/res/raw/horizontal_blur.rs43
-rw-r--r--libs/rs/java/ImageProcessing/res/raw/horizontal_blur_bc.bcbin0 -> 1324 bytes
-rw-r--r--libs/rs/java/ImageProcessing/res/raw/ip.rsh15
-rw-r--r--libs/rs/java/ImageProcessing/res/raw/threshold.rs127
-rw-r--r--libs/rs/java/ImageProcessing/res/raw/threshold_bc.bcbin8596 -> 7208 bytes
-rw-r--r--libs/rs/java/ImageProcessing/res/raw/vertical_blur.rs51
-rw-r--r--libs/rs/java/ImageProcessing/res/raw/vertical_blur_bc.bcbin0 -> 1464 bytes
-rw-r--r--libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java11
-rw-r--r--libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Horizontal_blur.java42
-rw-r--r--libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java22
-rw-r--r--libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Vertical_blur.java42
11 files changed, 255 insertions, 98 deletions
diff --git a/libs/rs/java/ImageProcessing/res/raw/horizontal_blur.rs b/libs/rs/java/ImageProcessing/res/raw/horizontal_blur.rs
new file mode 100644
index 0000000..7b0e6bc
--- /dev/null
+++ b/libs/rs/java/ImageProcessing/res/raw/horizontal_blur.rs
@@ -0,0 +1,43 @@
+#pragma version(1)
+
+#include "../../../../scriptc/rs_types.rsh"
+#include "../../../../scriptc/rs_math.rsh"
+
+#include "ip.rsh"
+
+uchar4 * ScratchPixel;
+
+#pragma rs export_var(ScratchPixel)
+
+void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) {
+ uchar4 *output = (uchar4 *)v_out;
+ const uchar4 *input = (uchar4 *)v_in;
+ const FilterStruct *fs = (const FilterStruct *)usrData;
+
+ float4 blurredPixel = 0;
+ float4 currentPixel = 0;
+ for(int r = -fs->radius; r <= fs->radius; r ++) {
+ // Stepping left and right away from the pixel
+ int validW = x + r;
+ // Clamp to zero and width max() isn't exposed for ints yet
+ if(validW < 0) {
+ validW = 0;
+ }
+ if(validW > fs->width - 1) {
+ validW = fs->width - 1;
+ }
+ //int validW = rsClamp(w + r, 0, width - 1);
+
+ float weight = fs->gaussian[r + fs->radius];
+ currentPixel.x = (float)(input[validW].x);
+ currentPixel.y = (float)(input[validW].y);
+ currentPixel.z = (float)(input[validW].z);
+ //currentPixel.w = (float)(input->a);
+
+ blurredPixel += currentPixel * weight;
+ }
+
+ output->x = (uint8_t)blurredPixel.x;
+ output->y = (uint8_t)blurredPixel.y;
+ output->z = (uint8_t)blurredPixel.z;
+}
diff --git a/libs/rs/java/ImageProcessing/res/raw/horizontal_blur_bc.bc b/libs/rs/java/ImageProcessing/res/raw/horizontal_blur_bc.bc
new file mode 100644
index 0000000..c9ba5d9
--- /dev/null
+++ b/libs/rs/java/ImageProcessing/res/raw/horizontal_blur_bc.bc
Binary files differ
diff --git a/libs/rs/java/ImageProcessing/res/raw/ip.rsh b/libs/rs/java/ImageProcessing/res/raw/ip.rsh
new file mode 100644
index 0000000..4073304
--- /dev/null
+++ b/libs/rs/java/ImageProcessing/res/raw/ip.rsh
@@ -0,0 +1,15 @@
+#pragma rs java_package_name(com.android.rs.image)
+
+#define MAX_RADIUS 25
+
+typedef struct {
+ float *gaussian; //[MAX_RADIUS * 2 + 1];
+ rs_matrix3x3 colorMat;
+
+ int height;
+ int width;
+ int radius;
+
+} FilterStruct;
+
+
diff --git a/libs/rs/java/ImageProcessing/res/raw/threshold.rs b/libs/rs/java/ImageProcessing/res/raw/threshold.rs
index 9585e92..ecbfac4 100644
--- a/libs/rs/java/ImageProcessing/res/raw/threshold.rs
+++ b/libs/rs/java/ImageProcessing/res/raw/threshold.rs
@@ -2,12 +2,8 @@
#include "../../../../scriptc/rs_types.rsh"
#include "../../../../scriptc/rs_math.rsh"
-#include "../../../../scriptc/rs_graphics.rsh"
-#pragma rs java_package_name(com.android.rs.image)
-
-
-#define MAX_RADIUS 25
+#include "ip.rsh"
int height;
int width;
@@ -28,11 +24,15 @@ float saturation;
static float inWMinInB;
static float outWMinOutB;
static float overInWMinInB;
-//static float3 gammaV;
+static FilterStruct filterStruct;
-#pragma rs export_var(height, width, radius, InPixel, OutPixel, ScratchPixel, inBlack, outBlack, inWhite, outWhite, gamma, saturation, InPixel, OutPixel, ScratchPixel)
+#pragma rs export_var(height, width, radius, InPixel, OutPixel, ScratchPixel, inBlack, outBlack, inWhite, outWhite, gamma, saturation, InPixel, OutPixel, ScratchPixel, vBlurScript, hBlurScript)
#pragma rs export_func(filter, filterBenchmark);
+rs_script vBlurScript;
+rs_script hBlurScript;
+
+
// Store our coefficients here
static float gaussian[MAX_RADIUS * 2 + 1];
static rs_matrix3x3 colorMat;
@@ -145,48 +145,6 @@ static void processNoBlur() {
rsSendToClient(&count, 1, 4, 0);
}
-static void horizontalBlur() {
- float4 blurredPixel = 0;
- float4 currentPixel = 0;
- // Horizontal blur
- int w, h, r;
- for(h = 0; h < height; h ++) {
- uchar4 *input = InPixel + h*width;
- uchar4 *output = ScratchPixel + h*width;
-
- for(w = 0; w < width; w ++) {
- blurredPixel = 0;
-
- for(r = -radius; r <= radius; r ++) {
- // Stepping left and right away from the pixel
- int validW = w + r;
- // Clamp to zero and width max() isn't exposed for ints yet
- if(validW < 0) {
- validW = 0;
- }
- if(validW > width - 1) {
- validW = width - 1;
- }
- //int validW = rsClamp(w + r, 0, width - 1);
-
- float weight = gaussian[r + radius];
- currentPixel.x = (float)(input[validW].x);
- currentPixel.y = (float)(input[validW].y);
- currentPixel.z = (float)(input[validW].z);
- //currentPixel.w = (float)(input->a);
-
- blurredPixel += currentPixel*weight;
- }
-
- output->x = (uint8_t)blurredPixel.x;
- output->y = (uint8_t)blurredPixel.y;
- output->z = (uint8_t)blurredPixel.z;
- //output->a = (uint8_t)blurredPixel.w;
- output++;
- }
- }
-}
-
static void horizontalBlurLevels() {
float4 blurredPixel = 0;
float4 currentPixel = 0;
@@ -232,52 +190,11 @@ static void horizontalBlurLevels() {
}
}
-static void verticalBlur() {
- float4 blurredPixel = 0;
- float4 currentPixel = 0;
- // Vertical blur
- int w, h, r;
- for(h = 0; h < height; h ++) {
- uchar4 *output = OutPixel + h*width;
-
- for(w = 0; w < width; w ++) {
-
- blurredPixel = 0;
- for(r = -radius; r <= radius; r ++) {
-#if 1
- int validH = h + r;
- // Clamp to zero and width
- if(validH < 0) {
- validH = 0;
- }
- if(validH > height - 1) {
- validH = height - 1;
- }
-
- uchar4 *input = ScratchPixel + validH*width + w;
-
- float weight = gaussian[r + radius];
-
- currentPixel.x = (float)(input->x);
- currentPixel.y = (float)(input->y);
- currentPixel.z = (float)(input->z);
-
- blurredPixel.xyz += currentPixel.xyz * weight;
-#else
- int validH = rsClamp(h + r, 0, height - 1);
- uchar4 *input = ScratchPixel + validH*width + w;
- blurredPixel.xyz += convert_float3(input->xyz) * gaussian[r + radius];
-#endif
- }
-
- //output->xyz = convert_uchar3(blurredPixel.xyz);
- output->x = (uint8_t)blurredPixel.x;
- output->y = (uint8_t)blurredPixel.y;
- output->z = (uint8_t)blurredPixel.z;
- //output->a = (uint8_t)blurredPixel.w;
- output++;
- }
- }
+static void initStructs() {
+ filterStruct.gaussian = gaussian;
+ filterStruct.width = width;
+ filterStruct.height = height;
+ filterStruct.radius = radius;
}
void filter() {
@@ -285,6 +202,8 @@ void filter() {
RS_DEBUG(width);
RS_DEBUG(radius);
+ initStructs();
+
computeColorMatrix();
if(radius == 0) {
@@ -295,18 +214,30 @@ void filter() {
computeGaussianWeights();
horizontalBlurLevels();
- verticalBlur();
+
+ rsForEach(vBlurScript,
+ rsGetAllocation(InPixel),
+ rsGetAllocation(OutPixel),
+ &filterStruct);
int count = 0;
rsSendToClient(&count, 1, 4, 0);
}
void filterBenchmark() {
+ initStructs();
computeGaussianWeights();
- horizontalBlur();
- verticalBlur();
+ rsForEach(hBlurScript,
+ rsGetAllocation(InPixel),
+ rsGetAllocation(OutPixel),
+ &filterStruct);
+
+ rsForEach(vBlurScript,
+ rsGetAllocation(InPixel),
+ rsGetAllocation(OutPixel),
+ &filterStruct);
int count = 0;
rsSendToClient(&count, 1, 4, 0);
diff --git a/libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc b/libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc
index 95dcd8d..8f37fdc 100644
--- a/libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc
+++ b/libs/rs/java/ImageProcessing/res/raw/threshold_bc.bc
Binary files differ
diff --git a/libs/rs/java/ImageProcessing/res/raw/vertical_blur.rs b/libs/rs/java/ImageProcessing/res/raw/vertical_blur.rs
new file mode 100644
index 0000000..846f515
--- /dev/null
+++ b/libs/rs/java/ImageProcessing/res/raw/vertical_blur.rs
@@ -0,0 +1,51 @@
+#pragma version(1)
+
+#include "../../../../scriptc/rs_types.rsh"
+#include "../../../../scriptc/rs_math.rsh"
+
+#include "ip.rsh"
+
+uchar4 * ScratchPixel;
+
+#pragma rs export_var(ScratchPixel)
+
+void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32_t y) {
+ uchar4 *output = (uchar4 *)v_out;
+ const uchar4 *input = (uchar4 *)v_in;
+ const FilterStruct *fs = (const FilterStruct *)usrData;
+
+ float4 blurredPixel = 0;
+ float4 currentPixel = 0;
+ for(int r = -fs->radius; r <= fs->radius; r ++) {
+#if 1
+ int validH = y + r;
+ // Clamp to zero and width
+ if(validH < 0) {
+ validH = 0;
+ }
+ if(validH > fs->height - 1) {
+ validH = fs->height - 1;
+ }
+
+ uchar4 *input = ScratchPixel + validH * fs->width + x;
+
+ float weight = fs->gaussian[r + fs->radius];
+
+ currentPixel.x = (float)(input->x);
+ currentPixel.y = (float)(input->y);
+ currentPixel.z = (float)(input->z);
+
+ blurredPixel.xyz += currentPixel.xyz * weight;
+#else
+ int validH = rsClamp(y + r, 0, height - 1);
+ uchar4 *input = ScratchPixel + validH * width + x;
+ blurredPixel.xyz += convert_float3(input->xyz) * gaussian[r + fs->radius];
+#endif
+ }
+
+ //output->xyz = convert_uchar3(blurredPixel.xyz);
+ output->x = (uint8_t)blurredPixel.x;
+ output->y = (uint8_t)blurredPixel.y;
+ output->z = (uint8_t)blurredPixel.z;
+}
+
diff --git a/libs/rs/java/ImageProcessing/res/raw/vertical_blur_bc.bc b/libs/rs/java/ImageProcessing/res/raw/vertical_blur_bc.bc
new file mode 100644
index 0000000..af1cd8e
--- /dev/null
+++ b/libs/rs/java/ImageProcessing/res/raw/vertical_blur_bc.bc
Binary files differ
diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
index 7bf6596..21c3d74 100644
--- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
+++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
@@ -42,6 +42,8 @@ public class ImageProcessingActivity extends Activity
private Bitmap mBitmapOut;
private Bitmap mBitmapScratch;
private ScriptC_Threshold mScript;
+ private ScriptC_Vertical_blur mScriptVBlur;
+ private ScriptC_Horizontal_blur mScriptHBlur;
private int mRadius = 0;
private SeekBar mRadiusSeekBar;
@@ -373,6 +375,12 @@ public class ImageProcessingActivity extends Activity
mOutPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapOut);
mScratchPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapScratch);
+ mScriptVBlur = new ScriptC_Vertical_blur(mRS, getResources(), R.raw.vertical_blur_bc, false);
+ mScriptVBlur.bind_ScratchPixel(mScratchPixelsAllocation);
+
+ mScriptHBlur = new ScriptC_Horizontal_blur(mRS, getResources(), R.raw.horizontal_blur_bc, false);
+ mScriptHBlur.bind_ScratchPixel(mScratchPixelsAllocation);
+
mScript = new ScriptC_Threshold(mRS, getResources(), R.raw.threshold_bc, false);
mScript.set_width(mBitmapIn.getWidth());
mScript.set_height(mBitmapIn.getHeight());
@@ -388,6 +396,9 @@ public class ImageProcessingActivity extends Activity
mScript.bind_InPixel(mInPixelsAllocation);
mScript.bind_OutPixel(mOutPixelsAllocation);
mScript.bind_ScratchPixel(mScratchPixelsAllocation);
+
+ mScript.set_vBlurScript(mScriptVBlur);
+ mScript.set_hBlurScript(mScriptHBlur);
}
private Bitmap loadBitmap(int resource) {
diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Horizontal_blur.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Horizontal_blur.java
new file mode 100644
index 0000000..8ee50a8
--- /dev/null
+++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Horizontal_blur.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2010 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 android.renderscript.*;
+import android.content.res.Resources;
+import android.util.Log;
+
+public class ScriptC_Horizontal_blur extends ScriptC {
+ // Constructor
+ public ScriptC_Horizontal_blur(RenderScript rs, Resources resources, int id, boolean isRoot) {
+ super(rs, resources, id, isRoot);
+ }
+
+ private final static int mExportVarIdx_ScratchPixel = 0;
+ private Allocation mExportVar_ScratchPixel;
+ public void bind_ScratchPixel(Allocation v) {
+ mExportVar_ScratchPixel = v;
+ if(v == null) bindAllocation(null, mExportVarIdx_ScratchPixel);
+ else bindAllocation(v, mExportVarIdx_ScratchPixel);
+ }
+
+ public Allocation get_ScratchPixel() {
+ return mExportVar_ScratchPixel;
+ }
+
+}
+
diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java
index ea363d3..c23dca1 100644
--- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java
+++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Threshold.java
@@ -161,6 +161,28 @@ public class ScriptC_Threshold extends ScriptC {
return mExportVar_saturation;
}
+ private final static int mExportVarIdx_vBlurScript = 12;
+ private Script mExportVar_vBlurScript;
+ public void set_vBlurScript(Script v) {
+ mExportVar_vBlurScript = v;
+ setVar(mExportVarIdx_vBlurScript, (v == null) ? 0 : v.getID());
+ }
+
+ public Script get_vBlurScript() {
+ return mExportVar_vBlurScript;
+ }
+
+ private final static int mExportVarIdx_hBlurScript = 13;
+ private Script mExportVar_hBlurScript;
+ public void set_hBlurScript(Script v) {
+ mExportVar_hBlurScript = v;
+ setVar(mExportVarIdx_hBlurScript, (v == null) ? 0 : v.getID());
+ }
+
+ public Script get_hBlurScript() {
+ return mExportVar_hBlurScript;
+ }
+
private final static int mExportFuncIdx_filter = 0;
public void invoke_filter() {
invoke(mExportFuncIdx_filter);
diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Vertical_blur.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Vertical_blur.java
new file mode 100644
index 0000000..0215f60
--- /dev/null
+++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ScriptC_Vertical_blur.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2010 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 android.renderscript.*;
+import android.content.res.Resources;
+import android.util.Log;
+
+public class ScriptC_Vertical_blur extends ScriptC {
+ // Constructor
+ public ScriptC_Vertical_blur(RenderScript rs, Resources resources, int id, boolean isRoot) {
+ super(rs, resources, id, isRoot);
+ }
+
+ private final static int mExportVarIdx_ScratchPixel = 0;
+ private Allocation mExportVar_ScratchPixel;
+ public void bind_ScratchPixel(Allocation v) {
+ mExportVar_ScratchPixel = v;
+ if(v == null) bindAllocation(null, mExportVarIdx_ScratchPixel);
+ else bindAllocation(v, mExportVarIdx_ScratchPixel);
+ }
+
+ public Allocation get_ScratchPixel() {
+ return mExportVar_ScratchPixel;
+ }
+
+}
+