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