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#pragma version(1) 18#pragma rs java_package_name(com.android.rs.image) 19#pragma rs_fp_relaxed 20 21int32_t gWidth; 22int32_t gHeight; 23rs_allocation gIn; 24 25float gCoeffs[9]; 26 27uchar4 __attribute__((kernel)) root(uint32_t x, uint32_t y) { 28 uint32_t x1 = min((int32_t)x+1, gWidth-1); 29 uint32_t x2 = max((int32_t)x-1, 0); 30 uint32_t y1 = min((int32_t)y+1, gHeight-1); 31 uint32_t y2 = max((int32_t)y-1, 0); 32 33 float4 p00 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y1)); 34 float4 p01 = convert_float4(rsGetElementAt_uchar4(gIn, x, y1)); 35 float4 p02 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y1)); 36 float4 p10 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y)); 37 float4 p11 = convert_float4(rsGetElementAt_uchar4(gIn, x, y)); 38 float4 p12 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y)); 39 float4 p20 = convert_float4(rsGetElementAt_uchar4(gIn, x1, y2)); 40 float4 p21 = convert_float4(rsGetElementAt_uchar4(gIn, x, y2)); 41 float4 p22 = convert_float4(rsGetElementAt_uchar4(gIn, x2, y2)); 42 p00 *= gCoeffs[0]; 43 p01 *= gCoeffs[1]; 44 p02 *= gCoeffs[2]; 45 p10 *= gCoeffs[3]; 46 p11 *= gCoeffs[4]; 47 p12 *= gCoeffs[5]; 48 p20 *= gCoeffs[6]; 49 p21 *= gCoeffs[7]; 50 p22 *= gCoeffs[8]; 51 52 p00 += p01; 53 p02 += p10; 54 p11 += p12; 55 p20 += p21; 56 57 p22 += p00; 58 p02 += p11; 59 60 p20 += p22; 61 p20 += p02; 62 63 p20 = clamp(p20, 0.f, 255.f); 64 return convert_uchar4(p20); 65} 66 67 68