Skip to content

Commit 10542ec

Browse files
Jason SamsAndroid (Google) Code Review
authored andcommitted
Merge "Port ImageProcessing to Filterscript." into jb-mr1-dev
2 parents 73db36e + d3d6570 commit 10542ec

19 files changed

+78
-77
lines changed

CleanSpec.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ $(call add-clean-step, rm -f $(PRODUCT_OUT)/system/media/video/Disco*)
136136
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/framework_intermediates)
137137
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/ImageProcessing_intermediates)
138138
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/ImageProcessing2_intermediates)
139+
$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/ImageProcessing_intermediates)
139140
# ************************************************
140141
# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
141142
# ************************************************

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/colormatrix.rs renamed to tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/colormatrix.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ void setMatrix(rs_matrix4x4 m) {
2929
Mat = m;
3030
}
3131

32-
void root(const uchar4 *in, uchar4 *out) {
33-
float4 f = convert_float4(*in);
32+
uchar4 __attribute__((kernel)) root(uchar4 in) {
33+
float4 f = convert_float4(in);
3434
f = rsMatrixMultiply(&Mat, f);
3535
f = clamp(f, 0.f, 255.f);
36-
*out = convert_uchar4(f);
36+
return convert_uchar4(f);
3737
}
3838

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve3x3.rs renamed to tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve3x3.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ rs_allocation gIn;
2424

2525
float gCoeffs[9];
2626

27-
void root(uchar4 *out, uint32_t x, uint32_t y) {
27+
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
2828
uint32_t x1 = min((int32_t)x+1, gWidth-1);
2929
uint32_t x2 = max((int32_t)x-1, 0);
3030
uint32_t y1 = min((int32_t)y+1, gHeight-1);
@@ -61,7 +61,7 @@ void root(uchar4 *out, uint32_t x, uint32_t y) {
6161
p20 += p02;
6262

6363
p20 = clamp(p20, 0.f, 255.f);
64-
*out = convert_uchar4(p20);
64+
return convert_uchar4(p20);
6565
}
6666

6767

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve5x5.rs renamed to tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve5x5.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ rs_allocation gIn;
2424

2525
float gCoeffs[25];
2626

27-
void root(uchar4 *out, uint32_t x, uint32_t y) {
27+
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
2828
uint32_t x0 = max((int32_t)x-2, 0);
2929
uint32_t x1 = max((int32_t)x-1, 0);
3030
uint32_t x2 = x;
@@ -68,7 +68,7 @@ void root(uchar4 *out, uint32_t x, uint32_t y) {
6868
+ convert_float4(rsGetElementAt_uchar4(gIn, x4, y4)) * gCoeffs[24];
6969

7070
p0 = clamp(p0 + p1 + p2 + p3 + p4, 0.f, 255.f);
71-
*out = convert_uchar4(p0);
71+
return convert_uchar4(p0);
7272
}
7373

7474

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/copy.rs renamed to tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/copy.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
#pragma version(1)
1818
#pragma rs java_package_name(com.android.rs.image)
1919

20-
void root(const uchar4 *v_in, uchar4 *v_out) {
21-
*v_out = *v_in;
20+
uchar4 __attribute__((kernel)) root(uchar4 v_in) {
21+
return v_in;
2222
}
2323

2424

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye.rsh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ void init_filter(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y,
2626
neg_center = -center;
2727
inv_dimensions.x = 1.f / (float)dim_x;
2828
inv_dimensions.y = 1.f / (float)dim_y;
29-
alpha = k * 2.0 + 0.75;
29+
alpha = k * 2.0f + 0.75f;
3030

3131
axis_scale = (float2)1.f;
3232
if (dim_x > dim_y)
3333
axis_scale.y = (float)dim_y / (float)dim_x;
3434
else
3535
axis_scale.x = (float)dim_x / (float)dim_y;
3636

37-
const float bound2 = 0.25 * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y);
37+
const float bound2 = 0.25f * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y);
3838
const float bound = sqrt(bound2);
39-
const float radius = 1.15 * bound;
39+
const float radius = 1.15f * bound;
4040
radius2 = radius*radius;
4141
const float max_radian = M_PI_2 - atan(alpha / bound * sqrt(radius2 - bound2));
4242
factor = bound / max_radian;
4343
}
4444

45-
void root(uchar4 *out, uint32_t x, uint32_t y) {
45+
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
4646
// Convert x and y to floating point coordinates with center as origin
4747
const float2 inCoord = {(float)x, (float)y};
4848
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
@@ -53,6 +53,6 @@ void root(uchar4 *out, uint32_t x, uint32_t y) {
5353
const float scalar = radian * factor * inv_dist;
5454
const float2 new_coord = mad(coord, scalar, center);
5555
const float4 fout = rsSample(in_alloc, sampler, new_coord);
56-
*out = rsPackColorTo8888(fout);
56+
return rsPackColorTo8888(fout);
5757
}
5858

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx.rsh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ void init_filter(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y,
2626
neg_center = -center;
2727
inv_dimensions.x = 1.f / (float)dim_x;
2828
inv_dimensions.y = 1.f / (float)dim_y;
29-
alpha = k * 2.0 + 0.75;
29+
alpha = k * 2.0f + 0.75f;
3030

3131
axis_scale = (float2)1.f;
3232
if (dim_x > dim_y)
3333
axis_scale.y = (float)dim_y / (float)dim_x;
3434
else
3535
axis_scale.x = (float)dim_x / (float)dim_y;
3636

37-
const float bound2 = 0.25 * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y);
37+
const float bound2 = 0.25f * (axis_scale.x*axis_scale.x + axis_scale.y*axis_scale.y);
3838
const float bound = sqrt(bound2);
39-
const float radius = 1.15 * bound;
39+
const float radius = 1.15f * bound;
4040
radius2 = radius*radius;
4141
const float max_radian = M_PI_2 - atan(alpha / bound * sqrt(radius2 - bound2));
4242
factor = bound / max_radian;
4343
}
4444

45-
void root(uchar4 *out, uint32_t x, uint32_t y) {
45+
uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) {
4646
// Convert x and y to floating point coordinates with center as origin
4747
const float2 inCoord = {(float)x, (float)y};
4848
const float2 coord = mad(inCoord, inv_dimensions, neg_center);
@@ -53,6 +53,6 @@ void root(uchar4 *out, uint32_t x, uint32_t y) {
5353
const float scalar = radian * factor * inv_dist;
5454
const float2 new_coord = mad(coord, scalar, center);
5555
const float4 fout = rsSample(in_alloc, sampler, new_coord);
56-
*out = rsPackColorTo8888(fout);
56+
return rsPackColorTo8888(fout);
5757
}
5858

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs renamed to tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.fs

File renamed without changes.

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.rs renamed to tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.fs

File renamed without changes.

tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.rs renamed to tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#pragma rs java_package_name(com.android.rs.image)
1919
#pragma rs_fp_relaxed
2020

21-
void genRand(uchar *out) {
22-
*out = (uchar)rsRand(0xff);
21+
uchar __attribute__((kernel)) genRand() {
22+
return (uchar)rsRand(0xff);
2323
}
2424

2525
/*
@@ -42,7 +42,7 @@ int32_t gWMask;
4242
int32_t gHMask;
4343

4444
rs_allocation gBlendSource;
45-
void blend9(uchar *out, uint32_t x, uint32_t y) {
45+
uchar __attribute__((kernel)) blend9(uint32_t x, uint32_t y) {
4646
uint32_t x1 = (x-1) & gWMask;
4747
uint32_t x2 = (x+1) & gWMask;
4848
uint32_t y1 = (y-1) & gHMask;
@@ -70,14 +70,14 @@ void blend9(uchar *out, uint32_t x, uint32_t y) {
7070
p20 += p02;
7171

7272
p20 = min(p20 >> 10, (uint)255);
73-
*out = (uchar)p20;
73+
return (uchar)p20;
7474
}
7575

7676
float gNoiseStrength;
7777

7878
rs_allocation gNoise;
79-
void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) {
80-
float4 ip = convert_float4(*in);
79+
uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
80+
float4 ip = convert_float4(in);
8181
float pnoise = (float) rsGetElementAt_uchar(gNoise, x & gWMask, y & gHMask);
8282

8383
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) {
8989

9090
uchar4 p = convert_uchar4(ip);
9191
p.a = 0xff;
92-
*out = p;
92+
return p;
9393
}

0 commit comments

Comments
 (0)