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