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 20rs_allocation gBlur; 21 22static float gOverWm1; 23static float gOverHm1; 24static uchar gLutR[256]; 25static uchar gLutG[256]; 26static uchar gLutB[256]; 27 28void setup() { 29 int w = rsAllocationGetDimX(gBlur); 30 int h = rsAllocationGetDimY(gBlur); 31 gOverWm1 = 1.f / w; 32 gOverHm1 = 1.f / h; 33 34 for (int x=0; x < 256; x++) { 35 gLutR[x] = x;//255-x; 36 gLutG[x] = x;//255-x; 37 gLutB[x] = x;//255-x; 38 } 39} 40 41uchar4 RS_KERNEL process(uchar4 in, uint32_t x, uint32_t y) { 42 float2 xyDist; 43 xyDist.x = (x * gOverWm1 - 0.5f); 44 xyDist.y = (y * gOverHm1 - 0.5f); 45 46 // color 47 float4 v1 = rsUnpackColor8888(in); 48 float4 v2 = rsUnpackColor8888(rsGetElementAt_uchar4(gBlur, x, y)); 49 50 float dist = dot(xyDist, xyDist) * 1.4f; 51 float pdist = native_powr(dist, 2.7f * 0.5f); 52 //float pdist = powr(dist, 2.7f * 0.5f); 53 54 pdist = clamp(pdist, 0.f, 1.f); 55 v1 = mix(v1, v2, dist * 2.f); 56 v1 *= 1.f - pdist; 57 58 // apply curve 59 uchar4 out = rsPackColorTo8888(v1); 60 61 out.r = gLutR[out.r]; 62 out.g = gLutG[out.g]; 63 out.b = gLutB[out.b]; 64 return out; 65} 66 67 68