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
21const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
22const static float3 gNightVisionMult = {0.5f, 1.f, 0.5f};
23
24// calculates luminance of pixel, then biases color balance toward green
25void root(const uchar4 *v_in, uchar4 *v_out) {
26    v_out->x = v_in->x; // don't modify A
27
28    // get RGB, scale 0-255 uchar to 0-1.0 float
29    float3 rgb = {v_in->y * 0.003921569f, v_in->z * 0.003921569f,
30            v_in->w * 0.003921569f};
31
32    // apply filter
33    float3 result = dot(rgb, gMonoMult) * gNightVisionMult;
34
35    v_out->y = (uchar)clamp((result.r * 255.f + 0.5f), 0.f, 255.f);
36    v_out->z = (uchar)clamp((result.g * 255.f + 0.5f), 0.f, 255.f);
37    v_out->w = (uchar)clamp((result.b * 255.f + 0.5f), 0.f, 255.f);
38}
39