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 20float vibrance = 0.f; 21 22static const float Rf = 0.2999f; 23static const float Gf = 0.587f; 24static const float Bf = 0.114f; 25 26static float Vib = 0.f; 27 28uchar4 RS_KERNEL vibranceKernel(uchar4 in) { 29 int r = in.r; 30 int g = in.g; 31 int b = in.b; 32 float red = (r-max(g, b)) * (1.f / 256.f); 33 float S = (float)(Vib/(1+native_exp(-red*3)))+1; 34 float MS = 1.0f - S; 35 float Rt = Rf * MS; 36 float Gt = Gf * MS; 37 float Bt = Bf * MS; 38 39 float R = r; 40 float G = g; 41 float B = b; 42 43 float Rc = R * (Rt + S) + G * Gt + B * Bt; 44 float Gc = R * Rt + G * (Gt + S) + B * Bt; 45 float Bc = R * Rt + G * Gt + B * (Bt + S); 46 47 uchar4 o; 48 o.r = clamp((int) Rc, 0, 255); 49 o.g = clamp((int) Gc, 0, 255); 50 o.b = clamp((int) Bc, 0, 255); 51 o.a = 0xff; 52 return o; 53} 54 55void prepareVibrance() { 56 Vib = vibrance/100.f; 57} 58