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