1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "ip.rsh"
18#pragma rs_fp_relaxed
19
20int32_t gWidth;
21int32_t gHeight;
22rs_allocation gIn;
23
24float gCoeffs[9];
25
26uchar4 RS_KERNEL root(uint32_t x, uint32_t y) {
27    uint32_t x1 = min((int32_t)x+1, gWidth-1);
28    uint32_t x2 = max((int32_t)x-1, 0);
29    uint32_t y1 = min((int32_t)y+1, gHeight-1);
30    uint32_t y2 = max((int32_t)y-1, 0);
31
32    float4 sum = convert_float4(rsGetElementAt_uchar4(gIn, x1, y1)) * gCoeffs[0];
33    sum += convert_float4(rsGetElementAt_uchar4(gIn, x, y1)) * gCoeffs[1];
34    sum += convert_float4(rsGetElementAt_uchar4(gIn, x2, y1)) * gCoeffs[2];
35    sum += convert_float4(rsGetElementAt_uchar4(gIn, x1, y)) * gCoeffs[3];
36    sum += convert_float4(rsGetElementAt_uchar4(gIn, x, y)) * gCoeffs[4];
37    sum += convert_float4(rsGetElementAt_uchar4(gIn, x2, y)) * gCoeffs[5];
38    sum += convert_float4(rsGetElementAt_uchar4(gIn, x1, y2)) * gCoeffs[6];
39    sum += convert_float4(rsGetElementAt_uchar4(gIn, x, y2)) * gCoeffs[7];
40    sum += convert_float4(rsGetElementAt_uchar4(gIn, x2, y2)) * gCoeffs[8];
41
42    sum = clamp(sum, 0.f, 255.f);
43    return convert_uchar4(sum);
44}
45
46
47