Permalink
Browse files

Port ImageProcessing to Filterscript.

This enables testing of the Filterscript front-end for llvm-rs-cc.

Bug: 7166741
Change-Id: I90bda9d2710c6652336a8c112b5654c5da3d14e4
  • Loading branch information...
1 parent 6b77a76 commit d3d6570df4f39af697ba090fa8069aef6acfbcf4 @stephenhines stephenhines committed Oct 11, 2012
Showing with 78 additions and 77 deletions.
  1. +1 −0 CleanSpec.mk
  2. +3 −3 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/{colormatrix.rs → colormatrix.fs}
  3. +2 −2 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/{convolve3x3.rs → convolve3x3.fs}
  4. +2 −2 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/{convolve5x5.rs → convolve5x5.fs}
  5. +2 −2 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/{copy.rs → copy.fs}
  6. +5 −5 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye.rsh
  7. +5 −5 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx.rsh
  8. 0 .../ImageProcessing/src/com/android/rs/image/{fisheye_approx_relaxed.rs → fisheye_approx_relaxed.fs}
  9. 0 ...derScriptTests/ImageProcessing/src/com/android/rs/image/{fisheye_relaxed.rs → fisheye_relaxed.fs}
  10. +7 −7 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/{grain.rs → grain.fs}
  11. +3 −3 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/{greyscale.rs → greyscale.fs}
  12. +9 −7 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/levels.rsh
  13. 0 ...enderScriptTests/ImageProcessing/src/com/android/rs/image/{levels_relaxed.rs → levels_relaxed.fs}
  14. +8 −8 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/{mandelbrot.rs → mandelbrot.fs}
  15. +20 −22 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/{threshold.rs → threshold.fs}
  16. +6 −6 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette.rsh
  17. +5 −5 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx.rsh
  18. 0 ...mageProcessing/src/com/android/rs/image/{vignette_approx_relaxed.rs → vignette_approx_relaxed.fs}
  19. 0 ...rScriptTests/ImageProcessing/src/com/android/rs/image/{vignette_relaxed.rs → vignette_relaxed.fs}
View
@@ -136,6 +136,7 @@ $(call add-clean-step, rm -f $(PRODUCT_OUT)/system/media/video/Disco*)
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates)
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/ImageProcessing_intermediates)
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/ImageProcessing2_intermediates)
+$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/ImageProcessing_intermediates)
# ************************************************
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
# ************************************************
@@ -29,10 +29,10 @@ void setMatrix(rs_matrix4x4 m) {
Mat = m;
}
-void root(const uchar4 *in, uchar4 *out) {
- float4 f = convert_float4(*in);
+uchar4 __attribute__((kernel)) root(uchar4 in) {
+ float4 f = convert_float4(in);
f = rsMatrixMultiply(&Mat, f);
f = clamp(f, 0.f, 255.f);
- *out = convert_uchar4(f);
+ return convert_uchar4(f);
}
@@ -24,7 +24,7 @@ rs_allocation gIn;
float gCoeffs[9];
-void root(uchar4 *out, uint32_t x, uint32_t y) {
+uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
uint32_t x1 = min((int32_t)x+1, gWidth-1);
uint32_t x2 = max((int32_t)x-1, 0);
uint32_t y1 = min((int32_t)y+1, gHeight-1);
@@ -61,7 +61,7 @@ void root(uchar4 *out, uint32_t x, uint32_t y) {
p20 += p02;
p20 = clamp(p20, 0.f, 255.f);
- *out = convert_uchar4(p20);
+ return convert_uchar4(p20);
}
@@ -24,7 +24,7 @@ rs_allocation gIn;
float gCoeffs[25];
-void root(uchar4 *out, uint32_t x, uint32_t y) {
+uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
uint32_t x0 = max((int32_t)x-2, 0);
uint32_t x1 = max((int32_t)x-1, 0);
uint32_t x2 = x;
@@ -68,7 +68,7 @@ void root(uchar4 *out, uint32_t x, uint32_t y) {
+ convert_float4(rsGetElementAt_uchar4(gIn, x4, y4)) * gCoeffs[24];
p0 = clamp(p0 + p1 + p2 + p3 + p4, 0.f, 255.f);
- *out = convert_uchar4(p0);
+ return convert_uchar4(p0);
}
@@ -17,8 +17,8 @@
#pragma version(1)
#pragma rs java_package_name(com.android.rs.image)
-void root(const uchar4 *v_in, uchar4 *v_out) {
- *v_out = *v_in;
+uchar4 __attribute__((kernel)) root(uchar4 v_in) {
+ return v_in;
}
@@ -26,23 +26,23 @@ void init_filter(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y,
neg_center = -center;
inv_dimensions.x = 1.f / (float)dim_x;
inv_dimensions.y = 1.f / (float)dim_y;
- alpha = k * 2.0 + 0.75;
+ alpha = k * 2.0f + 0.75f;
axis_scale = (float2)1.f;
if (dim_x > dim_y)
axis_scale.y = (float)dim_y / (float)dim_x;
else
axis_scale.x = (float)dim_x / (float)dim_y;
- const float bound2 = 0.25 * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y);
+ const float bound2 = 0.25f * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y);
const float bound = sqrt(bound2);
- const float radius = 1.15 * bound;
+ const float radius = 1.15f * bound;
radius2 = radius*radius;
const float max_radian = M_PI_2 - atan(alpha / bound * sqrt(radius2 - bound2));
factor = bound / max_radian;
}
-void root(uchar4 *out, uint32_t x, uint32_t y) {
+uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
// Convert x and y to floating point coordinates with center as origin
const float2 inCoord = {(float)x, (float)y};
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
@@ -53,6 +53,6 @@ void root(uchar4 *out, uint32_t x, uint32_t y) {
const float scalar = radian * factor * inv_dist;
const float2 new_coord = mad(coord, scalar, center);
const float4 fout = rsSample(in_alloc, sampler, new_coord);
- *out = rsPackColorTo8888(fout);
+ return rsPackColorTo8888(fout);
}
@@ -26,23 +26,23 @@ void init_filter(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y,
neg_center = -center;
inv_dimensions.x = 1.f / (float)dim_x;
inv_dimensions.y = 1.f / (float)dim_y;
- alpha = k * 2.0 + 0.75;
+ alpha = k * 2.0f + 0.75f;
axis_scale = (float2)1.f;
if (dim_x > dim_y)
axis_scale.y = (float)dim_y / (float)dim_x;
else
axis_scale.x = (float)dim_x / (float)dim_y;
- const float bound2 = 0.25 * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y);
+ const float bound2 = 0.25f * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y);
const float bound = sqrt(bound2);
- const float radius = 1.15 * bound;
+ const float radius = 1.15f * bound;
radius2 = radius*radius;
const float max_radian = M_PI_2 - atan(alpha / bound * sqrt(radius2 - bound2));
factor = bound / max_radian;
}
-void root(uchar4 *out, uint32_t x, uint32_t y) {
+uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
// Convert x and y to floating point coordinates with center as origin
const float2 inCoord = {(float)x, (float)y};
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
@@ -53,6 +53,6 @@ void root(uchar4 *out, uint32_t x, uint32_t y) {
const float scalar = radian * factor * inv_dist;
const float2 new_coord = mad(coord, scalar, center);
const float4 fout = rsSample(in_alloc, sampler, new_coord);
- *out = rsPackColorTo8888(fout);
+ return rsPackColorTo8888(fout);
}
@@ -18,8 +18,8 @@
#pragma rs java_package_name(com.android.rs.image)
#pragma rs_fp_relaxed
-void genRand(uchar *out) {
- *out = (uchar)rsRand(0xff);
+uchar __attribute__((kernel)) genRand() {
+ return (uchar)rsRand(0xff);
}
/*
@@ -42,7 +42,7 @@ int32_t gWMask;
int32_t gHMask;
rs_allocation gBlendSource;
-void blend9(uchar *out, uint32_t x, uint32_t y) {
+uchar __attribute__((kernel)) blend9(uint32_t x, uint32_t y) {
uint32_t x1 = (x-1) & gWMask;
uint32_t x2 = (x+1) & gWMask;
uint32_t y1 = (y-1) & gHMask;
@@ -70,14 +70,14 @@ void blend9(uchar *out, uint32_t x, uint32_t y) {
p20 += p02;
p20 = min(p20 >> 10, (uint)255);
- *out = (uchar)p20;
+ return (uchar)p20;
}
float gNoiseStrength;
rs_allocation gNoise;
-void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
- float4 ip = convert_float4(*in);
+uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
+ float4 ip = convert_float4(in);
float pnoise = (float) rsGetElementAt_uchar(gNoise, x & gWMask, y & gHMask);
float energy_level = ip.r + ip.g + ip.b;
@@ -89,5 +89,5 @@ void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
uchar4 p = convert_uchar4(ip);
p.a = 0xff;
- *out = p;
+ return p;
}
@@ -20,11 +20,11 @@
const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
-void root(const uchar4 *v_in, uchar4 *v_out) {
- float4 f4 = rsUnpackColor8888(*v_in);
+uchar4 __attribute__((kernel)) root(uchar4 v_in) {
+ float4 f4 = rsUnpackColor8888(v_in);
float3 mono = dot(f4.rgb, gMonoMult);
- *v_out = rsPackColorTo8888(mono);
+ return rsPackColorTo8888(mono);
}
@@ -21,24 +21,26 @@ float outWMinOutB;
float overInWMinInB;
rs_matrix3x3 colorMat;
-void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
- float3 pixel = convert_float4(in[0]).rgb;
+uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
+ uchar4 out;
+ float3 pixel = convert_float4(in).rgb;
pixel = rsMatrixMultiply(&colorMat, pixel);
pixel = clamp(pixel, 0.f, 255.f);
pixel = (pixel - inBlack) * overInWMinInB;
pixel = pixel * outWMinOutB + outBlack;
pixel = clamp(pixel, 0.f, 255.f);
- out->xyz = convert_uchar3(pixel);
- out->w = 0xff;
+ out.xyz = convert_uchar3(pixel);
+ out.w = 0xff;
+ return out;
}
-void root4(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
- float4 pixel = convert_float4(in[0]);
+uchar4 __attribute__((kernel)) root4(uchar4 in, uint32_t x, uint32_t y) {
+ float4 pixel = convert_float4(in);
pixel.rgb = rsMatrixMultiply(&colorMat, pixel.rgb);
pixel = clamp(pixel, 0.f, 255.f);
pixel = (pixel - inBlack) * overInWMinInB;
pixel = pixel * outWMinOutB + outBlack;
pixel = clamp(pixel, 0.f, 255.f);
- out->xyzw = convert_uchar4(pixel);
+ return convert_uchar4(pixel);
}
@@ -23,7 +23,7 @@ float lowerBoundX = -2.f;
float lowerBoundY = -2.f;
float scaleFactor = 4.f;
-void root(uchar4 *v_out, uint32_t x, uint32_t y) {
+uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
float2 p;
p.x = lowerBoundX + ((float)x / gDimX) * scaleFactor;
p.y = lowerBoundY + ((float)y / gDimY) * scaleFactor;
@@ -41,16 +41,16 @@ void root(uchar4 *v_out, uint32_t x, uint32_t y) {
if(iter >= gMaxIteration) {
// write a non-transparent black pixel
- *v_out = (uchar4){0, 0, 0, 0xff};
+ return (uchar4){0, 0, 0, 0xff};
} else {
- float mi3 = gMaxIteration / 3.;
+ float mi3 = gMaxIteration / 3.f;
if (iter <= (gMaxIteration / 3))
- *v_out = (uchar4){0xff * (iter / mi3), 0, 0, 0xff};
+ return (uchar4){0xff * (iter / mi3), 0, 0, 0xff};
else if (iter <= (((gMaxIteration / 3) * 2)))
- *v_out = (uchar4){0xff - (0xff * ((iter - mi3) / mi3)),
- (0xff * ((iter - mi3) / mi3)), 0, 0xff};
+ return (uchar4){0xff - (0xff * ((iter - mi3) / mi3)),
+ (0xff * ((iter - mi3) / mi3)), 0, 0xff};
else
- *v_out = (uchar4){0, 0xff - (0xff * ((iter - (mi3 * 2)) / mi3)),
- (0xff * ((iter - (mi3 * 2)) / mi3)), 0xff};
+ return (uchar4){0, 0xff - (0xff * ((iter - (mi3 * 2)) / mi3)),
+ (0xff * ((iter - (mi3 * 2)) / mi3)), 0xff};
}
}
@@ -56,51 +56,49 @@ void setRadius(int rad) {
}
}
-void copyIn(const uchar4 *in, float4 *out) {
- *out = convert_float4(*in);
+float4 __attribute__((kernel)) copyIn(uchar4 in) {
+ return convert_float4(in);
}
-void vert(uchar4 *out, uint32_t x, uint32_t y) {
+uchar4 __attribute__((kernel)) vert(uint32_t x, uint32_t y) {
float3 blurredPixel = 0;
- const float *gPtr = gaussian;
+ int gi = 0;
+ uchar4 out;
if ((y > radius) && (y < (height - radius))) {
for (int r = -radius; r <= radius; r ++) {
- const float4 *i = (const float4 *)rsGetElementAt(ScratchPixel2, x, y + r);
- blurredPixel += i->xyz * gPtr[0];
- gPtr++;
+ float4 i = rsGetElementAt_float4(ScratchPixel2, x, y + r);
+ blurredPixel += i.xyz * gaussian[gi++];
}
} else {
for (int r = -radius; r <= radius; r ++) {
int validH = rsClamp((int)y + r, (int)0, (int)(height - 1));
- const float4 *i = (const float4 *)rsGetElementAt(ScratchPixel2, x, validH);
- blurredPixel += i->xyz * gPtr[0];
- gPtr++;
+ float4 i = rsGetElementAt_float4(ScratchPixel2, x, validH);
+ blurredPixel += i.xyz * gaussian[gi++];
}
}
- out->xyz = convert_uchar3(clamp(blurredPixel, 0.f, 255.f));
- out->w = 0xff;
+ out.xyz = convert_uchar3(clamp(blurredPixel, 0.f, 255.f));
+ out.w = 0xff;
+ return out;
}
-void horz(float4 *out, uint32_t x, uint32_t y) {
- float3 blurredPixel = 0;
- const float *gPtr = gaussian;
+float4 __attribute__((kernel)) horz(uint32_t x, uint32_t y) {
+ float4 blurredPixel = 0;
+ int gi = 0;
if ((x > radius) && (x < (width - radius))) {
for (int r = -radius; r <= radius; r ++) {
- const float4 *i = (const float4 *)rsGetElementAt(ScratchPixel1, x + r, y);
- blurredPixel += i->xyz * gPtr[0];
- gPtr++;
+ float4 i = rsGetElementAt_float4(ScratchPixel1, x + r, y);
+ blurredPixel += i * gaussian[gi++];
}
} else {
for (int r = -radius; r <= radius; r ++) {
// Stepping left and right away from the pixel
int validX = rsClamp((int)x + r, (int)0, (int)(width - 1));
- const float4 *i = (const float4 *)rsGetElementAt(ScratchPixel1, validX, y);
- blurredPixel += i->xyz * gPtr[0];
- gPtr++;
+ float4 i = rsGetElementAt_float4(ScratchPixel1, validX, y);
+ blurredPixel += i * gaussian[gi++];
}
}
- out->xyz = blurredPixel;
+ return blurredPixel;
}
@@ -31,29 +31,29 @@ void init_vignette(uint32_t dim_x, uint32_t dim_y, float center_x, float center_
else
axis_scale.x = (float)dim_x / (float)dim_y;
- const float max_dist = 0.5 * length(axis_scale);
+ const float max_dist = 0.5f * length(axis_scale);
sloped_inv_max_dist = desired_slope * 1.f/max_dist;
// Range needs to be between 1.3 to 0.6. When scale is zero then range is
// 1.3 which means no vignette at all because the luminousity difference is
// less than 1/256. Expect input scale to be between 0.0 and 1.0.
- const float neg_range = 0.7*sqrt(desired_scale) - 1.3;
+ const float neg_range = 0.7f*sqrt(desired_scale) - 1.3f;
sloped_neg_range = exp(neg_range * desired_slope);
shade = desired_shade;
opp_shade = 1.f - desired_shade;
}
-void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
+uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
// Convert x and y to floating point coordinates with center as origin
- const float4 fin = convert_float4(*in);
+ const float4 fin = convert_float4(in);
const float2 inCoord = {(float)x, (float)y};
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
const float sloped_dist_ratio = length(axis_scale * coord) * sloped_inv_max_dist;
- const float lumen = opp_shade + shade / ( 1.0 + sloped_neg_range * exp(sloped_dist_ratio) );
+ const float lumen = opp_shade + shade / ( 1.0f + sloped_neg_range * exp(sloped_dist_ratio) );
float4 fout;
fout.rgb = fin.rgb * lumen;
fout.w = fin.w;
- *out = convert_uchar4(fout);
+ return convert_uchar4(fout);
}
Oops, something went wrong.

0 comments on commit d3d6570

Please sign in to comment.