From d3d6570df4f39af697ba090fa8069aef6acfbcf4 Mon Sep 17 00:00:00 2001 From: Stephen Hines Date: Thu, 11 Oct 2012 16:12:46 -0700 Subject: Port ImageProcessing to Filterscript. This enables testing of the Filterscript front-end for llvm-rs-cc. Bug: 7166741 Change-Id: I90bda9d2710c6652336a8c112b5654c5da3d14e4 --- .../src/com/android/rs/image/colormatrix.fs | 38 ++++++++ .../src/com/android/rs/image/colormatrix.rs | 38 -------- .../src/com/android/rs/image/convolve3x3.fs | 67 +++++++++++++ .../src/com/android/rs/image/convolve3x3.rs | 67 ------------- .../src/com/android/rs/image/convolve5x5.fs | 74 ++++++++++++++ .../src/com/android/rs/image/convolve5x5.rs | 74 -------------- .../src/com/android/rs/image/copy.fs | 24 +++++ .../src/com/android/rs/image/copy.rs | 24 ----- .../src/com/android/rs/image/fisheye.rsh | 10 +- .../src/com/android/rs/image/fisheye_approx.rsh | 10 +- .../com/android/rs/image/fisheye_approx_relaxed.fs | 22 +++++ .../com/android/rs/image/fisheye_approx_relaxed.rs | 22 ----- .../src/com/android/rs/image/fisheye_relaxed.fs | 22 +++++ .../src/com/android/rs/image/fisheye_relaxed.rs | 22 ----- .../src/com/android/rs/image/grain.fs | 93 ++++++++++++++++++ .../src/com/android/rs/image/grain.rs | 93 ------------------ .../src/com/android/rs/image/greyscale.fs | 30 ++++++ .../src/com/android/rs/image/greyscale.rs | 30 ------ .../src/com/android/rs/image/levels.rsh | 16 ++-- .../src/com/android/rs/image/levels_relaxed.fs | 22 +++++ .../src/com/android/rs/image/levels_relaxed.rs | 22 ----- .../src/com/android/rs/image/mandelbrot.fs | 56 +++++++++++ .../src/com/android/rs/image/mandelbrot.rs | 56 ----------- .../src/com/android/rs/image/threshold.fs | 104 ++++++++++++++++++++ .../src/com/android/rs/image/threshold.rs | 106 --------------------- .../src/com/android/rs/image/vignette.rsh | 12 +-- .../src/com/android/rs/image/vignette_approx.rsh | 10 +- .../android/rs/image/vignette_approx_relaxed.fs | 22 +++++ .../android/rs/image/vignette_approx_relaxed.rs | 22 ----- .../src/com/android/rs/image/vignette_relaxed.fs | 22 +++++ .../src/com/android/rs/image/vignette_relaxed.rs | 22 ----- 31 files changed, 626 insertions(+), 626 deletions(-) create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/colormatrix.fs delete mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/colormatrix.rs create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve3x3.fs delete mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve3x3.rs create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve5x5.fs delete mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve5x5.rs create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/copy.fs delete mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/copy.rs create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.fs delete mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.fs delete mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.rs create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.fs delete mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.rs create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/greyscale.fs delete mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/greyscale.rs create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/levels_relaxed.fs delete mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/levels_relaxed.rs create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/mandelbrot.fs delete mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/mandelbrot.rs create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.fs delete mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.rs create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.fs delete mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.rs create mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.fs delete mode 100644 tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.rs (limited to 'tests') diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/colormatrix.fs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/colormatrix.fs new file mode 100644 index 0000000..ba8711b --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/colormatrix.fs @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2012 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.image) +#pragma rs_fp_relaxed + + +static rs_matrix4x4 Mat; + +void init() { + rsMatrixLoadIdentity(&Mat); +} + +void setMatrix(rs_matrix4x4 m) { + Mat = m; +} + +uchar4 __attribute__((kernel)) root(uchar4 in) { + float4 f = convert_float4(in); + f = rsMatrixMultiply(&Mat, f); + f = clamp(f, 0.f, 255.f); + return convert_uchar4(f); +} + diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/colormatrix.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/colormatrix.rs deleted file mode 100644 index a83e819..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/colormatrix.rs +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.rs.image) -#pragma rs_fp_relaxed - - -static rs_matrix4x4 Mat; - -void init() { - rsMatrixLoadIdentity(&Mat); -} - -void setMatrix(rs_matrix4x4 m) { - Mat = m; -} - -void root(const uchar4 *in, uchar4 *out) { - float4 f = convert_float4(*in); - f = rsMatrixMultiply(&Mat, f); - f = clamp(f, 0.f, 255.f); - *out = convert_uchar4(f); -} - diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve3x3.fs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve3x3.fs new file mode 100644 index 0000000..772503f --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve3x3.fs @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2012 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.image) +#pragma rs_fp_relaxed + +int32_t gWidth; +int32_t gHeight; +rs_allocation gIn; + +float gCoeffs[9]; + +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); + uint32_t y2 = max((int32_t)y-1, 0); + + float4 p00 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y1)); + float4 p01 = convert_float4(rsGetElementAt_uchar4(gIn, x, y1)); + float4 p02 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y1)); + float4 p10 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y)); + float4 p11 = convert_float4(rsGetElementAt_uchar4(gIn, x, y)); + float4 p12 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y)); + float4 p20 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y2)); + float4 p21 = convert_float4(rsGetElementAt_uchar4(gIn, x, y2)); + float4 p22 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y2)); + p00 *= gCoeffs[0]; + p01 *= gCoeffs[1]; + p02 *= gCoeffs[2]; + p10 *= gCoeffs[3]; + p11 *= gCoeffs[4]; + p12 *= gCoeffs[5]; + p20 *= gCoeffs[6]; + p21 *= gCoeffs[7]; + p22 *= gCoeffs[8]; + + p00 += p01; + p02 += p10; + p11 += p12; + p20 += p21; + + p22 += p00; + p02 += p11; + + p20 += p22; + p20 += p02; + + p20 = clamp(p20, 0.f, 255.f); + return convert_uchar4(p20); +} + + diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve3x3.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve3x3.rs deleted file mode 100644 index 9812827..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve3x3.rs +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.rs.image) -#pragma rs_fp_relaxed - -int32_t gWidth; -int32_t gHeight; -rs_allocation gIn; - -float gCoeffs[9]; - -void root(uchar4 *out, 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); - uint32_t y2 = max((int32_t)y-1, 0); - - float4 p00 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y1)); - float4 p01 = convert_float4(rsGetElementAt_uchar4(gIn, x, y1)); - float4 p02 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y1)); - float4 p10 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y)); - float4 p11 = convert_float4(rsGetElementAt_uchar4(gIn, x, y)); - float4 p12 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y)); - float4 p20 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y2)); - float4 p21 = convert_float4(rsGetElementAt_uchar4(gIn, x, y2)); - float4 p22 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y2)); - p00 *= gCoeffs[0]; - p01 *= gCoeffs[1]; - p02 *= gCoeffs[2]; - p10 *= gCoeffs[3]; - p11 *= gCoeffs[4]; - p12 *= gCoeffs[5]; - p20 *= gCoeffs[6]; - p21 *= gCoeffs[7]; - p22 *= gCoeffs[8]; - - p00 += p01; - p02 += p10; - p11 += p12; - p20 += p21; - - p22 += p00; - p02 += p11; - - p20 += p22; - p20 += p02; - - p20 = clamp(p20, 0.f, 255.f); - *out = convert_uchar4(p20); -} - - diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve5x5.fs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve5x5.fs new file mode 100644 index 0000000..a916bfb --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve5x5.fs @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2012 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.image) +#pragma rs_fp_relaxed + +int32_t gWidth; +int32_t gHeight; +rs_allocation gIn; + +float gCoeffs[25]; + +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; + uint32_t x3 = min((int32_t)x+1, gWidth-1); + uint32_t x4 = min((int32_t)x+2, gWidth-1); + + uint32_t y0 = max((int32_t)y-2, 0); + uint32_t y1 = max((int32_t)y-1, 0); + uint32_t y2 = y; + uint32_t y3 = min((int32_t)y+1, gHeight-1); + uint32_t y4 = min((int32_t)y+2, gHeight-1); + + float4 p0 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y0)) * gCoeffs[0] + + convert_float4(rsGetElementAt_uchar4(gIn, x1, y0)) * gCoeffs[1] + + convert_float4(rsGetElementAt_uchar4(gIn, x2, y0)) * gCoeffs[2] + + convert_float4(rsGetElementAt_uchar4(gIn, x3, y0)) * gCoeffs[3] + + convert_float4(rsGetElementAt_uchar4(gIn, x4, y0)) * gCoeffs[4]; + + float4 p1 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y1)) * gCoeffs[5] + + convert_float4(rsGetElementAt_uchar4(gIn, x1, y1)) * gCoeffs[6] + + convert_float4(rsGetElementAt_uchar4(gIn, x2, y1)) * gCoeffs[7] + + convert_float4(rsGetElementAt_uchar4(gIn, x3, y1)) * gCoeffs[8] + + convert_float4(rsGetElementAt_uchar4(gIn, x4, y1)) * gCoeffs[9]; + + float4 p2 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y2)) * gCoeffs[10] + + convert_float4(rsGetElementAt_uchar4(gIn, x1, y2)) * gCoeffs[11] + + convert_float4(rsGetElementAt_uchar4(gIn, x2, y2)) * gCoeffs[12] + + convert_float4(rsGetElementAt_uchar4(gIn, x3, y2)) * gCoeffs[13] + + convert_float4(rsGetElementAt_uchar4(gIn, x4, y2)) * gCoeffs[14]; + + float4 p3 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y3)) * gCoeffs[15] + + convert_float4(rsGetElementAt_uchar4(gIn, x1, y3)) * gCoeffs[16] + + convert_float4(rsGetElementAt_uchar4(gIn, x2, y3)) * gCoeffs[17] + + convert_float4(rsGetElementAt_uchar4(gIn, x3, y3)) * gCoeffs[18] + + convert_float4(rsGetElementAt_uchar4(gIn, x4, y3)) * gCoeffs[19]; + + float4 p4 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y4)) * gCoeffs[20] + + convert_float4(rsGetElementAt_uchar4(gIn, x1, y4)) * gCoeffs[21] + + convert_float4(rsGetElementAt_uchar4(gIn, x2, y4)) * gCoeffs[22] + + convert_float4(rsGetElementAt_uchar4(gIn, x3, y4)) * gCoeffs[23] + + convert_float4(rsGetElementAt_uchar4(gIn, x4, y4)) * gCoeffs[24]; + + p0 = clamp(p0 + p1 + p2 + p3 + p4, 0.f, 255.f); + return convert_uchar4(p0); +} + + diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve5x5.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve5x5.rs deleted file mode 100644 index e6d03c9..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/convolve5x5.rs +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.rs.image) -#pragma rs_fp_relaxed - -int32_t gWidth; -int32_t gHeight; -rs_allocation gIn; - -float gCoeffs[25]; - -void root(uchar4 *out, 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; - uint32_t x3 = min((int32_t)x+1, gWidth-1); - uint32_t x4 = min((int32_t)x+2, gWidth-1); - - uint32_t y0 = max((int32_t)y-2, 0); - uint32_t y1 = max((int32_t)y-1, 0); - uint32_t y2 = y; - uint32_t y3 = min((int32_t)y+1, gHeight-1); - uint32_t y4 = min((int32_t)y+2, gHeight-1); - - float4 p0 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y0)) * gCoeffs[0] - + convert_float4(rsGetElementAt_uchar4(gIn, x1, y0)) * gCoeffs[1] - + convert_float4(rsGetElementAt_uchar4(gIn, x2, y0)) * gCoeffs[2] - + convert_float4(rsGetElementAt_uchar4(gIn, x3, y0)) * gCoeffs[3] - + convert_float4(rsGetElementAt_uchar4(gIn, x4, y0)) * gCoeffs[4]; - - float4 p1 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y1)) * gCoeffs[5] - + convert_float4(rsGetElementAt_uchar4(gIn, x1, y1)) * gCoeffs[6] - + convert_float4(rsGetElementAt_uchar4(gIn, x2, y1)) * gCoeffs[7] - + convert_float4(rsGetElementAt_uchar4(gIn, x3, y1)) * gCoeffs[8] - + convert_float4(rsGetElementAt_uchar4(gIn, x4, y1)) * gCoeffs[9]; - - float4 p2 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y2)) * gCoeffs[10] - + convert_float4(rsGetElementAt_uchar4(gIn, x1, y2)) * gCoeffs[11] - + convert_float4(rsGetElementAt_uchar4(gIn, x2, y2)) * gCoeffs[12] - + convert_float4(rsGetElementAt_uchar4(gIn, x3, y2)) * gCoeffs[13] - + convert_float4(rsGetElementAt_uchar4(gIn, x4, y2)) * gCoeffs[14]; - - float4 p3 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y3)) * gCoeffs[15] - + convert_float4(rsGetElementAt_uchar4(gIn, x1, y3)) * gCoeffs[16] - + convert_float4(rsGetElementAt_uchar4(gIn, x2, y3)) * gCoeffs[17] - + convert_float4(rsGetElementAt_uchar4(gIn, x3, y3)) * gCoeffs[18] - + convert_float4(rsGetElementAt_uchar4(gIn, x4, y3)) * gCoeffs[19]; - - float4 p4 = convert_float4(rsGetElementAt_uchar4(gIn, x0, y4)) * gCoeffs[20] - + convert_float4(rsGetElementAt_uchar4(gIn, x1, y4)) * gCoeffs[21] - + convert_float4(rsGetElementAt_uchar4(gIn, x2, y4)) * gCoeffs[22] - + convert_float4(rsGetElementAt_uchar4(gIn, x3, y4)) * gCoeffs[23] - + convert_float4(rsGetElementAt_uchar4(gIn, x4, y4)) * gCoeffs[24]; - - p0 = clamp(p0 + p1 + p2 + p3 + p4, 0.f, 255.f); - *out = convert_uchar4(p0); -} - - diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/copy.fs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/copy.fs new file mode 100644 index 0000000..5f03483 --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/copy.fs @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2012 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.image) + +uchar4 __attribute__((kernel)) root(uchar4 v_in) { + return v_in; +} + + diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/copy.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/copy.rs deleted file mode 100644 index 9eb5d43..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/copy.rs +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -#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; -} - - diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye.rsh b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye.rsh index 3809912..2eacb7d 100644 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye.rsh +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye.rsh @@ -26,7 +26,7 @@ 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) @@ -34,15 +34,15 @@ void init_filter(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y, 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); } diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx.rsh b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx.rsh index 08b4126..fcf0a3d 100644 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx.rsh +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx.rsh @@ -26,7 +26,7 @@ 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) @@ -34,15 +34,15 @@ void init_filter(uint32_t dim_x, uint32_t dim_y, float center_x, float center_y, 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); } diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.fs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.fs new file mode 100644 index 0000000..3e76368 --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.fs @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2012 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.image) +#pragma rs_fp_relaxed + +#include "fisheye_approx.rsh" + diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs deleted file mode 100644 index 3e76368..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_approx_relaxed.rs +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.rs.image) -#pragma rs_fp_relaxed - -#include "fisheye_approx.rsh" - diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.fs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.fs new file mode 100644 index 0000000..dc3ffcb --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.fs @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2012 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.image) +#pragma rs_fp_relaxed + +#include "fisheye.rsh" + diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.rs deleted file mode 100644 index dc3ffcb..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/fisheye_relaxed.rs +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.rs.image) -#pragma rs_fp_relaxed - -#include "fisheye.rsh" - diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.fs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.fs new file mode 100644 index 0000000..4ae095d --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.fs @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2012 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.image) +#pragma rs_fp_relaxed + +uchar __attribute__((kernel)) genRand() { + return (uchar)rsRand(0xff); +} + +/* + * Convolution matrix of distance 2 with fixed point of 'kShiftBits' bits + * shifted. Thus the sum of this matrix should be 'kShiftValue'. Entries of + * small values are not calculated to gain efficiency. + * The order ot pixels represented in this matrix is: + * 1 2 3 + * 4 0 5 + * 6 7 8 + * and the matrix should be: {230, 56, 114, 56, 114, 114, 56, 114, 56}. + * However, since most of the valus are identical, we only use the first three + * entries and the entries corresponding to the pixels is: + * 1 2 1 + * 2 0 2 + * 1 2 1 + */ + +int32_t gWMask; +int32_t gHMask; + +rs_allocation gBlendSource; +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; + uint32_t y2 = (y+1) & gHMask; + + uint p00 = 56 * rsGetElementAt_uchar(gBlendSource, x1, y1); + uint p01 = 114 * rsGetElementAt_uchar(gBlendSource, x, y1); + uint p02 = 56 * rsGetElementAt_uchar(gBlendSource, x2, y1); + uint p10 = 114 * rsGetElementAt_uchar(gBlendSource, x1, y); + uint p11 = 230 * rsGetElementAt_uchar(gBlendSource, x, y); + uint p12 = 114 * rsGetElementAt_uchar(gBlendSource, x2, y); + uint p20 = 56 * rsGetElementAt_uchar(gBlendSource, x1, y2); + uint p21 = 114 * rsGetElementAt_uchar(gBlendSource, x, y2); + uint p22 = 56 * rsGetElementAt_uchar(gBlendSource, x2, y2); + + p00 += p01; + p02 += p10; + p11 += p12; + p20 += p21; + + p22 += p00; + p02 += p11; + + p20 += p22; + p20 += p02; + + p20 = min(p20 >> 10, (uint)255); + return (uchar)p20; +} + +float gNoiseStrength; + +rs_allocation gNoise; +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; + float energy_mask = (28.f - sqrt(energy_level)) * 0.03571f; + pnoise = (pnoise - 128.f) * energy_mask; + + ip += pnoise * gNoiseStrength; + ip = clamp(ip, 0.f, 255.f); + + uchar4 p = convert_uchar4(ip); + p.a = 0xff; + return p; +} diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.rs deleted file mode 100644 index c8531f3..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/grain.rs +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.rs.image) -#pragma rs_fp_relaxed - -void genRand(uchar *out) { - *out = (uchar)rsRand(0xff); -} - -/* - * Convolution matrix of distance 2 with fixed point of 'kShiftBits' bits - * shifted. Thus the sum of this matrix should be 'kShiftValue'. Entries of - * small values are not calculated to gain efficiency. - * The order ot pixels represented in this matrix is: - * 1 2 3 - * 4 0 5 - * 6 7 8 - * and the matrix should be: {230, 56, 114, 56, 114, 114, 56, 114, 56}. - * However, since most of the valus are identical, we only use the first three - * entries and the entries corresponding to the pixels is: - * 1 2 1 - * 2 0 2 - * 1 2 1 - */ - -int32_t gWMask; -int32_t gHMask; - -rs_allocation gBlendSource; -void blend9(uchar *out, uint32_t x, uint32_t y) { - uint32_t x1 = (x-1) & gWMask; - uint32_t x2 = (x+1) & gWMask; - uint32_t y1 = (y-1) & gHMask; - uint32_t y2 = (y+1) & gHMask; - - uint p00 = 56 * rsGetElementAt_uchar(gBlendSource, x1, y1); - uint p01 = 114 * rsGetElementAt_uchar(gBlendSource, x, y1); - uint p02 = 56 * rsGetElementAt_uchar(gBlendSource, x2, y1); - uint p10 = 114 * rsGetElementAt_uchar(gBlendSource, x1, y); - uint p11 = 230 * rsGetElementAt_uchar(gBlendSource, x, y); - uint p12 = 114 * rsGetElementAt_uchar(gBlendSource, x2, y); - uint p20 = 56 * rsGetElementAt_uchar(gBlendSource, x1, y2); - uint p21 = 114 * rsGetElementAt_uchar(gBlendSource, x, y2); - uint p22 = 56 * rsGetElementAt_uchar(gBlendSource, x2, y2); - - p00 += p01; - p02 += p10; - p11 += p12; - p20 += p21; - - p22 += p00; - p02 += p11; - - p20 += p22; - p20 += p02; - - p20 = min(p20 >> 10, (uint)255); - *out = (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); - float pnoise = (float) rsGetElementAt_uchar(gNoise, x & gWMask, y & gHMask); - - float energy_level = ip.r + ip.g + ip.b; - float energy_mask = (28.f - sqrt(energy_level)) * 0.03571f; - pnoise = (pnoise - 128.f) * energy_mask; - - ip += pnoise * gNoiseStrength; - ip = clamp(ip, 0.f, 255.f); - - uchar4 p = convert_uchar4(ip); - p.a = 0xff; - *out = p; -} diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/greyscale.fs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/greyscale.fs new file mode 100644 index 0000000..90ba058 --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/greyscale.fs @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2012 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.image) +#pragma rs_fp_relaxed + +const static float3 gMonoMult = {0.299f, 0.587f, 0.114f}; + +uchar4 __attribute__((kernel)) root(uchar4 v_in) { + float4 f4 = rsUnpackColor8888(v_in); + + float3 mono = dot(f4.rgb, gMonoMult); + return rsPackColorTo8888(mono); +} + + diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/greyscale.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/greyscale.rs deleted file mode 100644 index c420cac..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/greyscale.rs +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.rs.image) -#pragma rs_fp_relaxed - -const static float3 gMonoMult = {0.299f, 0.587f, 0.114f}; - -void root(const uchar4 *v_in, uchar4 *v_out) { - float4 f4 = rsUnpackColor8888(*v_in); - - float3 mono = dot(f4.rgb, gMonoMult); - *v_out = rsPackColorTo8888(mono); -} - - diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/levels.rsh b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/levels.rsh index 7c5d930..e289906 100644 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/levels.rsh +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/levels.rsh @@ -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); } diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/levels_relaxed.fs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/levels_relaxed.fs new file mode 100644 index 0000000..b115445 --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/levels_relaxed.fs @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2012 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.image) +#pragma rs_fp_relaxed + +#include "levels.rsh" + diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/levels_relaxed.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/levels_relaxed.rs deleted file mode 100644 index b115445..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/levels_relaxed.rs +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.rs.image) -#pragma rs_fp_relaxed - -#include "levels.rsh" - diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/mandelbrot.fs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/mandelbrot.fs new file mode 100644 index 0000000..ac2061b --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/mandelbrot.fs @@ -0,0 +1,56 @@ +// Copyright (C) 2011 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. + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.image) + +uint32_t gMaxIteration = 500; +uint32_t gDimX = 1024; +uint32_t gDimY = 1024; + +float lowerBoundX = -2.f; +float lowerBoundY = -2.f; +float scaleFactor = 4.f; + +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; + + float2 t = 0; + float2 t2 = t * t; + int iter = 0; + while((t2.x + t2.y < 4.f) && (iter < gMaxIteration)) { + float xtemp = t2.x - t2.y + p.x; + t.y = 2 * t.x * t.y + p.y; + t.x = xtemp; + iter++; + t2 = t * t; + } + + if(iter >= gMaxIteration) { + // write a non-transparent black pixel + return (uchar4){0, 0, 0, 0xff}; + } else { + float mi3 = gMaxIteration / 3.f; + if (iter <= (gMaxIteration / 3)) + return (uchar4){0xff * (iter / mi3), 0, 0, 0xff}; + else if (iter <= (((gMaxIteration / 3) * 2))) + return (uchar4){0xff - (0xff * ((iter - mi3) / mi3)), + (0xff * ((iter - mi3) / mi3)), 0, 0xff}; + else + return (uchar4){0, 0xff - (0xff * ((iter - (mi3 * 2)) / mi3)), + (0xff * ((iter - (mi3 * 2)) / mi3)), 0xff}; + } +} diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/mandelbrot.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/mandelbrot.rs deleted file mode 100644 index da81d2e..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/mandelbrot.rs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2011 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. - -#pragma version(1) -#pragma rs java_package_name(com.android.rs.image) - -uint32_t gMaxIteration = 500; -uint32_t gDimX = 1024; -uint32_t gDimY = 1024; - -float lowerBoundX = -2.f; -float lowerBoundY = -2.f; -float scaleFactor = 4.f; - -void root(uchar4 *v_out, uint32_t x, uint32_t y) { - float2 p; - p.x = lowerBoundX + ((float)x / gDimX) * scaleFactor; - p.y = lowerBoundY + ((float)y / gDimY) * scaleFactor; - - float2 t = 0; - float2 t2 = t * t; - int iter = 0; - while((t2.x + t2.y < 4.f) && (iter < gMaxIteration)) { - float xtemp = t2.x - t2.y + p.x; - t.y = 2 * t.x * t.y + p.y; - t.x = xtemp; - iter++; - t2 = t * t; - } - - if(iter >= gMaxIteration) { - // write a non-transparent black pixel - *v_out = (uchar4){0, 0, 0, 0xff}; - } else { - float mi3 = gMaxIteration / 3.; - if (iter <= (gMaxIteration / 3)) - *v_out = (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}; - else - *v_out = (uchar4){0, 0xff - (0xff * ((iter - (mi3 * 2)) / mi3)), - (0xff * ((iter - (mi3 * 2)) / mi3)), 0xff}; - } -} diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.fs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.fs new file mode 100644 index 0000000..86e155a --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.fs @@ -0,0 +1,104 @@ +#pragma version(1) +#pragma rs java_package_name(com.android.rs.image) +#pragma rs_fp_relaxed + + +int height; +int width; +static int radius; + +rs_allocation InPixel; +rs_allocation ScratchPixel1; +rs_allocation ScratchPixel2; + +const int MAX_RADIUS = 25; + +// Store our coefficients here +static float gaussian[MAX_RADIUS * 2 + 1]; + +void setRadius(int rad) { + radius = rad; + // Compute gaussian weights for the blur + // e is the euler's number + float e = 2.718281828459045f; + float pi = 3.1415926535897932f; + // g(x) = ( 1 / sqrt( 2 * pi ) * sigma) * e ^ ( -x^2 / 2 * sigma^2 ) + // x is of the form [-radius .. 0 .. radius] + // and sigma varies with radius. + // Based on some experimental radius values and sigma's + // we approximately fit sigma = f(radius) as + // sigma = radius * 0.4 + 0.6 + // The larger the radius gets, the more our gaussian blur + // will resemble a box blur since with large sigma + // the gaussian curve begins to lose its shape + float sigma = 0.4f * (float)radius + 0.6f; + + // Now compute the coefficints + // We will store some redundant values to save some math during + // the blur calculations + // precompute some values + float coeff1 = 1.0f / (sqrt( 2.0f * pi ) * sigma); + float coeff2 = - 1.0f / (2.0f * sigma * sigma); + + float normalizeFactor = 0.0f; + float floatR = 0.0f; + for (int r = -radius; r <= radius; r ++) { + floatR = (float)r; + gaussian[r + radius] = coeff1 * pow(e, floatR * floatR * coeff2); + normalizeFactor += gaussian[r + radius]; + } + + //Now we need to normalize the weights because all our coefficients need to add up to one + normalizeFactor = 1.0f / normalizeFactor; + for (int r = -radius; r <= radius; r ++) { + floatR = (float)r; + gaussian[r + radius] *= normalizeFactor; + } +} + +float4 __attribute__((kernel)) copyIn(uchar4 in) { + return convert_float4(in); +} + +uchar4 __attribute__((kernel)) vert(uint32_t x, uint32_t y) { + float3 blurredPixel = 0; + int gi = 0; + uchar4 out; + if ((y > radius) && (y < (height - radius))) { + for (int r = -radius; r <= radius; r ++) { + 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)); + 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; + return out; +} + +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 ++) { + 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)); + float4 i = rsGetElementAt_float4(ScratchPixel1, validX, y); + blurredPixel += i * gaussian[gi++]; + } + } + + return blurredPixel; +} + diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.rs deleted file mode 100644 index 3dfa94b..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/threshold.rs +++ /dev/null @@ -1,106 +0,0 @@ -#pragma version(1) -#pragma rs java_package_name(com.android.rs.image) -#pragma rs_fp_relaxed - - -int height; -int width; -static int radius; - -rs_allocation InPixel; -rs_allocation ScratchPixel1; -rs_allocation ScratchPixel2; - -const int MAX_RADIUS = 25; - -// Store our coefficients here -static float gaussian[MAX_RADIUS * 2 + 1]; - -void setRadius(int rad) { - radius = rad; - // Compute gaussian weights for the blur - // e is the euler's number - float e = 2.718281828459045f; - float pi = 3.1415926535897932f; - // g(x) = ( 1 / sqrt( 2 * pi ) * sigma) * e ^ ( -x^2 / 2 * sigma^2 ) - // x is of the form [-radius .. 0 .. radius] - // and sigma varies with radius. - // Based on some experimental radius values and sigma's - // we approximately fit sigma = f(radius) as - // sigma = radius * 0.4 + 0.6 - // The larger the radius gets, the more our gaussian blur - // will resemble a box blur since with large sigma - // the gaussian curve begins to lose its shape - float sigma = 0.4f * (float)radius + 0.6f; - - // Now compute the coefficints - // We will store some redundant values to save some math during - // the blur calculations - // precompute some values - float coeff1 = 1.0f / (sqrt( 2.0f * pi ) * sigma); - float coeff2 = - 1.0f / (2.0f * sigma * sigma); - - float normalizeFactor = 0.0f; - float floatR = 0.0f; - for (int r = -radius; r <= radius; r ++) { - floatR = (float)r; - gaussian[r + radius] = coeff1 * pow(e, floatR * floatR * coeff2); - normalizeFactor += gaussian[r + radius]; - } - - //Now we need to normalize the weights because all our coefficients need to add up to one - normalizeFactor = 1.0f / normalizeFactor; - for (int r = -radius; r <= radius; r ++) { - floatR = (float)r; - gaussian[r + radius] *= normalizeFactor; - } -} - -void copyIn(const uchar4 *in, float4 *out) { - *out = convert_float4(*in); -} - -void vert(uchar4 *out, uint32_t x, uint32_t y) { - float3 blurredPixel = 0; - const float *gPtr = gaussian; - 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++; - } - } 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++; - } - } - - out->xyz = convert_uchar3(clamp(blurredPixel, 0.f, 255.f)); - out->w = 0xff; -} - -void horz(float4 *out, uint32_t x, uint32_t y) { - float3 blurredPixel = 0; - const float *gPtr = gaussian; - 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++; - } - } 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++; - } - } - - out->xyz = blurredPixel; -} - diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette.rsh b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette.rsh index a1e4ae5..04ca1f1 100644 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette.rsh +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette.rsh @@ -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); } diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx.rsh b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx.rsh index 7f7bdcf..05a5929 100644 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx.rsh +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx.rsh @@ -31,22 +31,22 @@ 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 = fast_length(axis_scale * coord) * sloped_inv_max_dist; @@ -55,6 +55,6 @@ void root(const uchar4 *in, uchar4 *out, uint32_t x, uint32_t y) { float4 fout; fout.rgb = fin.rgb * lumen; fout.w = fin.w; - *out = convert_uchar4(fout); + return convert_uchar4(fout); } diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.fs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.fs new file mode 100644 index 0000000..9120612 --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.fs @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2012 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.image) +#pragma rs_fp_relaxed + +#include "vignette_approx.rsh" + diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.rs deleted file mode 100644 index 9120612..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_approx_relaxed.rs +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.rs.image) -#pragma rs_fp_relaxed - -#include "vignette_approx.rsh" - diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.fs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.fs new file mode 100644 index 0000000..8e47ea9 --- /dev/null +++ b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.fs @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2012 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. + */ + +#pragma version(1) +#pragma rs java_package_name(com.android.rs.image) +#pragma rs_fp_relaxed + +#include "vignette.rsh" + diff --git a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.rs b/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.rs deleted file mode 100644 index 8e47ea9..0000000 --- a/tests/RenderScriptTests/ImageProcessing/src/com/android/rs/image/vignette_relaxed.rs +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2012 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. - */ - -#pragma version(1) -#pragma rs java_package_name(com.android.rs.image) -#pragma rs_fp_relaxed - -#include "vignette.rsh" - -- cgit v1.1