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 20 21static rs_allocation gCube; 22static int4 gDims; 23static int4 gCoordMul; 24 25 26void setCube(rs_allocation c) { 27 gCube = c; 28 gDims.x = rsAllocationGetDimX(gCube); 29 gDims.y = rsAllocationGetDimY(gCube); 30 gDims.z = rsAllocationGetDimZ(gCube); 31 gDims.w = 0; 32 33 float4 m = (float4)(1.f / 255.f) * convert_float4(gDims - 1); 34 gCoordMul = convert_int4(m * (float4)0x10000); 35} 36 37uchar4 RS_KERNEL root(uchar4 in) { 38 int4 baseCoord = convert_int4(in) * gCoordMul; 39 int4 coord1 = baseCoord >> (int4)16; 40 int4 coord2 = min(coord1 + 1, gDims - 1); 41 42 int4 weight2 = baseCoord & 0xffff; 43 int4 weight1 = (int4)0x10000 - weight2; 44 45 uint4 v000 = convert_uint4(rsGetElementAt_uchar4(gCube, coord1.x, coord1.y, coord1.z)); 46 uint4 v100 = convert_uint4(rsGetElementAt_uchar4(gCube, coord2.x, coord1.y, coord1.z)); 47 uint4 v010 = convert_uint4(rsGetElementAt_uchar4(gCube, coord1.x, coord2.y, coord1.z)); 48 uint4 v110 = convert_uint4(rsGetElementAt_uchar4(gCube, coord2.x, coord2.y, coord1.z)); 49 uint4 v001 = convert_uint4(rsGetElementAt_uchar4(gCube, coord1.x, coord1.y, coord2.z)); 50 uint4 v101 = convert_uint4(rsGetElementAt_uchar4(gCube, coord2.x, coord1.y, coord2.z)); 51 uint4 v011 = convert_uint4(rsGetElementAt_uchar4(gCube, coord1.x, coord2.y, coord2.z)); 52 uint4 v111 = convert_uint4(rsGetElementAt_uchar4(gCube, coord2.x, coord2.y, coord2.z)); 53 54 uint4 yz00 = ((v000 * weight1.x) + (v100 * weight2.x)) >> (uint4)8; 55 uint4 yz10 = ((v010 * weight1.x) + (v110 * weight2.x)) >> (uint4)8; 56 uint4 yz01 = ((v001 * weight1.x) + (v101 * weight2.x)) >> (uint4)8; 57 uint4 yz11 = ((v011 * weight1.x) + (v111 * weight2.x)) >> (uint4)8; 58 59 uint4 z0 = ((yz00 * weight1.y) + (yz10 * weight2.y)) >> (uint4)16; 60 uint4 z1 = ((yz01 * weight1.y) + (yz11 * weight2.y)) >> (uint4)16; 61 62 uint4 v = ((z0 * weight1.z) + (z1 * weight2.z)) >> (uint4)16; 63 uint4 v2 = (v + 0x7f) >> (uint4)8; 64 65 uchar4 o = convert_uchar4(v2); 66 o.a = 0xff; 67 return o; 68} 69 70