levels.rsh revision 572a5031a5d8602db0bec0b253428a034bd4dd59
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
17float inBlack;
18float outBlack;
19float inWMinInB;
20float outWMinOutB;
21float overInWMinInB;
22rs_matrix3x3 colorMat;
23
24uchar4 __attribute__((kernel)) root(uchar4 in, uint32_t x, uint32_t y) {
25    uchar4 out;
26    float3 pixel = convert_float4(in).rgb;
27    pixel = rsMatrixMultiply(&colorMat, pixel);
28    pixel = clamp(pixel, 0.f, 255.f);
29    pixel = (pixel - inBlack) * overInWMinInB;
30    pixel = pixel * outWMinOutB + outBlack;
31    pixel = clamp(pixel, 0.f, 255.f);
32    out.xyz = convert_uchar3(pixel);
33    out.w = 0xff;
34    return out;
35}
36
37uchar4 __attribute__((kernel)) root4(uchar4 in, uint32_t x, uint32_t y) {
38    float4 pixel = convert_float4(in);
39    pixel.rgb = rsMatrixMultiply(&colorMat, pixel.rgb);
40    pixel = clamp(pixel, 0.f, 255.f);
41    pixel = (pixel - inBlack) * overInWMinInB;
42    pixel = pixel * outWMinOutB + outBlack;
43    pixel = clamp(pixel, 0.f, 255.f);
44    return convert_uchar4(pixel);
45}
46
47