1// Sample script for RGB888 support (compare to saturationARGB.rs)
2/*
3 * Copyright (C) 2014 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma version(1)
19#pragma rs java_package_name(com.android.rs.cppbasic)
20#pragma rs_fp_relaxed
21
22const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
23
24// global variables (parameters accessible to application code)
25float gSaturation = 1.0f;
26
27void root(const uchar3 *v_in, uchar3 *v_out) {
28    // scale 0-255 uchar to 0-1.0 float
29    float3 in = {v_in->r * 0.003921569f, v_in->g * 0.003921569f,
30            v_in->b * 0.003921569f};
31
32    // apply saturation filter
33    float3 result = dot(in, gMonoMult);
34    result = mix(result, in, gSaturation);
35
36    // convert to uchar, copied from rsPackColorTo8888
37    v_out->x = (uchar)clamp((result.r * 255.f + 0.5f), 0.f, 255.f);
38    v_out->y = (uchar)clamp((result.g * 255.f + 0.5f), 0.f, 255.f);
39    v_out->z = (uchar)clamp((result.b * 255.f + 0.5f), 0.f, 255.f);
40}
41