diff options
author | Jeff Vander Stoep <jeffv@google.com> | 2019-07-12 10:29:52 -0700 |
---|---|---|
committer | Jeffrey Vander Stoep <jeffv@google.com> | 2019-07-17 21:47:56 +0000 |
commit | f539a140c0b006d7483f00caca25d47715df8987 (patch) | |
tree | e4e0091061fdebe5a599fc4c18e325b982781bad /tests/java_api/ImageProcessing2/src/com/android/rs/image/resize.rscript | |
parent | b3857425e3523e855521ab28e7ad7316960bca3f (diff) | |
download | rs-f539a140c0b006d7483f00caca25d47715df8987.tar.gz |
Renderscript: rename .rs extension to .rscript
Reserve .rs extension for Rust.
Bug: 137365032
Test: make checkbuild
Test: cd frameworks/compile/slang/tests
./slang_tests.py
Test: atest CtsRenderscriptTestCases
Test: CtsRsCppTestCases
Exempt-From-Owner-Approval: Clean CP
Change-Id: I88b87b253ddb63ba4a4946d185ef76a553ba6fee
Merged-In: I88b87b253ddb63ba4a4946d185ef76a553ba6fee
(cherry picked from commit ab7b68cabd2a98b500edc2a0f8977a3f737f5cde)
Diffstat (limited to 'tests/java_api/ImageProcessing2/src/com/android/rs/image/resize.rscript')
-rw-r--r-- | tests/java_api/ImageProcessing2/src/com/android/rs/image/resize.rscript | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/java_api/ImageProcessing2/src/com/android/rs/image/resize.rscript b/tests/java_api/ImageProcessing2/src/com/android/rs/image/resize.rscript new file mode 100644 index 00000000..84855111 --- /dev/null +++ b/tests/java_api/ImageProcessing2/src/com/android/rs/image/resize.rscript @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2014 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. + */ + +#include "ip.rsh" +#pragma rs_fp_relaxed + +int32_t gWidthIn; +int32_t gHeightIn; +rs_allocation gIn; +float scale; + + +uchar4 __attribute__((kernel)) nearest(uint32_t x, uint32_t y) { + float xf = clamp(x * scale, 0.f, (float)gWidthIn - 1.f); + float yf = clamp(y * scale, 0.f, (float)gHeightIn - 1.f); + uint32_t ix = xf; + uint32_t iy = yf; + + uchar4 tmp = rsGetElementAt_uchar4(gIn, ix, iy); + tmp.a = 0xff; + return tmp; +} + + +static float4 cubicInterpolate (float4 p0,float4 p1,float4 p2,float4 p3 , float x) { + return p1 + 0.5f * x * (p2 - p0 + x * (2.f * p0 - 5.f * p1 + 4.f * p2 - p3 + + x * (3.f * (p1 - p2) + p3 - p0))); +} + +uchar4 __attribute__((kernel)) bicubic(uint32_t x, uint32_t y) { + float xf = (x + 0.5f) * scale - 0.5f; + float yf = (y + 0.5f) * scale - 0.5f; + + int startx = (int) floor(xf - 1); + int starty = (int) floor(yf - 1); + xf = xf - floor(xf); + yf = yf - floor(yf); + int maxx = gWidthIn - 1; + int maxy = gHeightIn - 1; + + uint32_t xs0 = (uint32_t) max(0, startx + 0); + uint32_t xs1 = (uint32_t) max(0, startx + 1); + uint32_t xs2 = (uint32_t) min(maxx, startx + 2); + uint32_t xs3 = (uint32_t) min(maxx, startx + 3); + + uint32_t ys0 = (uint32_t) max(0, starty + 0); + uint32_t ys1 = (uint32_t) max(0, starty + 1); + uint32_t ys2 = (uint32_t) min(maxy, starty + 2); + uint32_t ys3 = (uint32_t) min(maxy, starty + 3); + + float4 p00 = convert_float4(rsGetElementAt_uchar4(gIn, xs0, ys0)); + float4 p01 = convert_float4(rsGetElementAt_uchar4(gIn, xs1, ys0)); + float4 p02 = convert_float4(rsGetElementAt_uchar4(gIn, xs2, ys0)); + float4 p03 = convert_float4(rsGetElementAt_uchar4(gIn, xs3, ys0)); + float4 p0 = cubicInterpolate(p00, p01, p02, p03, xf); + + float4 p10 = convert_float4(rsGetElementAt_uchar4(gIn, xs0, ys1)); + float4 p11 = convert_float4(rsGetElementAt_uchar4(gIn, xs1, ys1)); + float4 p12 = convert_float4(rsGetElementAt_uchar4(gIn, xs2, ys1)); + float4 p13 = convert_float4(rsGetElementAt_uchar4(gIn, xs3, ys1)); + float4 p1 = cubicInterpolate(p10, p11, p12, p13, xf); + + float4 p20 = convert_float4(rsGetElementAt_uchar4(gIn, xs0, ys2)); + float4 p21 = convert_float4(rsGetElementAt_uchar4(gIn, xs1, ys2)); + float4 p22 = convert_float4(rsGetElementAt_uchar4(gIn, xs2, ys2)); + float4 p23 = convert_float4(rsGetElementAt_uchar4(gIn, xs3, ys2)); + float4 p2 = cubicInterpolate(p20, p21, p22, p23, xf); + + float4 p30 = convert_float4(rsGetElementAt_uchar4(gIn, xs0, ys3)); + float4 p31 = convert_float4(rsGetElementAt_uchar4(gIn, xs1, ys3)); + float4 p32 = convert_float4(rsGetElementAt_uchar4(gIn, xs2, ys3)); + float4 p33 = convert_float4(rsGetElementAt_uchar4(gIn, xs3, ys3)); + float4 p3 = cubicInterpolate(p30, p31, p32, p33, xf); + + float4 p = cubicInterpolate(p0, p1, p2, p3, yf); + p = clamp(p + 0.5f, 0.f, 255.f); + return convert_uchar4(p); +} + |