1 /* 2 * Copyright (C) 2014 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 #pragma version(1) 18 #pragma rs java_package_name(com.android.rs.cppbasic) 19 #pragma rs_fp_relaxed 20 21 const static float3 gMonoMult = {0.299f, 0.587f, 0.114f}; 22 23 // global variables (parameters accessible to application code) 24 float gSaturation = 1.0f; 25 26 void root(const uchar4 *v_in, uchar4 *v_out) { 27 v_out->x = v_in->x; // don't modify A 28 29 // get RGB, scale 0-255 uchar to 0-1.0 float 30 float3 rgb = {v_in->y * 0.003921569f, v_in->z * 0.003921569f, 31 v_in->w * 0.003921569f}; 32 33 // apply saturation filter 34 float3 result = dot(rgb, gMonoMult); 35 result = mix(result, rgb, gSaturation); 36 37 v_out->y = (uchar)clamp((result.r * 255.f + 0.5f), 0.f, 255.f); 38 v_out->z = (uchar)clamp((result.g * 255.f + 0.5f), 0.f, 255.f); 39 v_out->w = (uchar)clamp((result.b * 255.f + 0.5f), 0.f, 255.f); 40 } 41