summaryrefslogtreecommitdiffstats
path: root/libs/rs/java
diff options
context:
space:
mode:
authorJason Sams <rjsams@android.com>2010-07-22 14:44:04 -0700
committerJason Sams <rjsams@android.com>2010-07-22 14:44:04 -0700
commitf46f25a4bdb266f05a862d51a0751b0b5316bf09 (patch)
tree91433da7d77ef2571dbf93c20b7ce6c4f5373faf /libs/rs/java
parent744f37f12d42de3f7e1b335e1c70b438ec5ff767 (diff)
downloadframeworks_base-f46f25a4bdb266f05a862d51a0751b0b5316bf09.zip
frameworks_base-f46f25a4bdb266f05a862d51a0751b0b5316bf09.tar.gz
frameworks_base-f46f25a4bdb266f05a862d51a0751b0b5316bf09.tar.bz2
Minor ImageProcessing script optimization to make it a better FP benchmark.
Change-Id: I24b11d98c9ac32d91153d3572da511b34e79f7f0
Diffstat (limited to 'libs/rs/java')
-rw-r--r--libs/rs/java/ImageProcessing/src/com/android/rs/image/horizontal_blur.rs51
-rw-r--r--libs/rs/java/ImageProcessing/src/com/android/rs/image/levels.rs9
-rw-r--r--libs/rs/java/ImageProcessing/src/com/android/rs/image/vertical_blur.rs67
3 files changed, 77 insertions, 50 deletions
diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/horizontal_blur.rs b/libs/rs/java/ImageProcessing/src/com/android/rs/image/horizontal_blur.rs
index 12180c6..4ed5aba 100644
--- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/horizontal_blur.rs
+++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/horizontal_blur.rs
@@ -7,31 +7,44 @@ void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32
const FilterStruct *fs = (const FilterStruct *)usrData;
const uchar4 *input = (const uchar4 *)rsGetElementAt(fs->ain, 0, y);
- 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;
+ float3 blurredPixel = 0;
+ float3 currentPixel = 0;
+
+ const float *gPtr = fs->gaussian;
+ if ((x > fs->radius) && (x < (fs->width - fs->radius))) {
+ const uchar4 *i = input + (x - fs->radius);
+ for(int r = -fs->radius; r <= fs->radius; r ++) {
+ currentPixel.x = (float)(i->x);
+ currentPixel.y = (float)(i->y);
+ currentPixel.z = (float)(i->z);
+ blurredPixel += currentPixel * gPtr[0];
+ gPtr++;
+ i++;
}
- //int validW = rsClamp(w + r, 0, width - 1);
+ } else {
+ 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);
+ currentPixel.x = (float)(input[validW].x);
+ currentPixel.y = (float)(input[validW].y);
+ currentPixel.z = (float)(input[validW].z);
- blurredPixel += currentPixel * weight;
+ blurredPixel += currentPixel * gPtr[0];
+ gPtr++;
+ }
}
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/src/com/android/rs/image/levels.rs b/libs/rs/java/ImageProcessing/src/com/android/rs/image/levels.rs
index 86ec56d..bb8a6fc 100644
--- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/levels.rs
+++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/levels.rs
@@ -64,17 +64,18 @@ void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32
const uchar4 *input = v_in;
uchar4 *output = v_out;
- float4 currentPixel = 0;
+ float3 currentPixel = 0;
//currentPixel.xyz = convert_float3(input.xyz);
currentPixel.x = (float)(input->x);
currentPixel.y = (float)(input->y);
currentPixel.z = (float)(input->z);
- float3 temp = rsMatrixMultiply(&colorMat, currentPixel.xyz);
+ float3 temp = rsMatrixMultiply(&colorMat, currentPixel);
temp = (clamp(temp, 0.f, 255.f) - inBlack) * overInWMinInB;
- temp = pow(temp, (float3)gamma);
- currentPixel.xyz = clamp(temp * outWMinOutB + outBlack, 0.f, 255.f);
+ if (gamma.x != 1.0f)
+ temp = pow(temp, (float3)gamma);
+ currentPixel = clamp(temp * outWMinOutB + outBlack, 0.f, 255.f);
//output.xyz = convert_uchar3(currentPixel.xyz);
output->x = (uint8_t)currentPixel.x;
diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/vertical_blur.rs b/libs/rs/java/ImageProcessing/src/com/android/rs/image/vertical_blur.rs
index 394d36a..008c8b5 100644
--- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/vertical_blur.rs
+++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/vertical_blur.rs
@@ -7,35 +7,48 @@ void root(const void *v_in, void *v_out, const void *usrData, uint32_t x, uint32
const FilterStruct *fs = (const FilterStruct *)usrData;
const uchar4 *input = (const uchar4 *)rsGetElementAt(fs->ain, x, 0);
- 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;
+ float3 blurredPixel = 0;
+ float3 currentPixel = 0;
+
+ const float *gPtr = fs->gaussian;
+ if ((y > fs->radius) && (y < (fs->height - fs->radius))) {
+ const uchar4 *i = input + ((y - fs->radius) * fs->width);
+ for(int r = -fs->radius; r <= fs->radius; r ++) {
+ currentPixel.x = (float)(i->x);
+ currentPixel.y = (float)(i->y);
+ currentPixel.z = (float)(i->z);
+ blurredPixel += currentPixel * gPtr[0];
+ gPtr++;
+ i += fs->width;
}
- if(validH > fs->height - 1) {
- validH = fs->height - 1;
+ } else {
+ 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;
+ }
+
+ const uchar4 *i = input + validH * fs->width;
+ //const uchar4 *i = (const uchar4 *)rsGetElementAt(fs->ain, x, validH);
+
+ currentPixel.x = (float)(i->x);
+ currentPixel.y = (float)(i->y);
+ currentPixel.z = (float)(i->z);
+ blurredPixel += currentPixel * gPtr[0];
+ gPtr++;
+ #else
+ int validH = rsClamp(y + r, 0, height - 1);
+ validH -= y;
+ uchar4 *i = input + validH * width + x;
+ blurredPixel.xyz += convert_float3(i->xyz) * gPtr[0];
+ gPtr++;
+ #endif
}
-
- const uchar4 *i = input + validH * fs->width;
- //const uchar4 *i = (const uchar4 *)rsGetElementAt(fs->ain, x, validH);
-
- float weight = fs->gaussian[r + fs->radius];
-
- currentPixel.x = (float)(i->x);
- currentPixel.y = (float)(i->y);
- currentPixel.z = (float)(i->z);
-
- blurredPixel.xyz += currentPixel.xyz * weight;
-#else
- int validH = rsClamp(y + r, 0, height - 1);
- validH -= y;
- uchar4 *i = input + validH * width + x;
- blurredPixel.xyz += convert_float3(i->xyz) * gaussian[r + fs->radius];
-#endif
}
//output->xyz = convert_uchar3(blurredPixel.xyz);