2 * Copyright (C) 2013 Unknown
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #pragma rs java_package_name(com.android.gallery3d.filtershow.filters)
28 float finalSaturation;
31 rs_matrix3x3 colorMatrix;
35 static const float Rf = 0.2999f;
36 static const float Gf = 0.587f;
37 static const float Bf = 0.114f;
40 void setupVignetteParams() {
43 scalex = 1.f / radiusx;
44 scaley = 1.f / radiusy;
46 float S = 1 + finalSaturation / 100.f;
52 float b = 1 + finalBright / 100.f;
53 float c = 1 + finalContrast / 100.f;
55 offset = .5f - c / 2.f - finalSubtract / 100.f;
56 rsMatrixSet(&colorMatrix, 0, 0, b * (Rt + S));
57 rsMatrixSet(&colorMatrix, 1, 0, b * Gt);
58 rsMatrixSet(&colorMatrix, 2, 0, b * Bt);
59 rsMatrixSet(&colorMatrix, 0, 1, b * Rt);
60 rsMatrixSet(&colorMatrix, 1, 1, b * (Gt + S));
61 rsMatrixSet(&colorMatrix, 2, 1, b * Bt);
62 rsMatrixSet(&colorMatrix, 0, 2, b * Rt);
63 rsMatrixSet(&colorMatrix, 1, 2, b * Gt);
64 rsMatrixSet(&colorMatrix, 2, 2, b * (Bt + S));
67 uchar4 __attribute__((kernel)) vignette(const uchar4 in, uint32_t x, uint32_t y) {
68 float4 pixel = rsUnpackColor8888(in);
69 float radx = (x - centerx) * scalex;
70 float rady = (y - centery) * scaley;
71 float dist = strength * (sqrt(radx * radx + rady * rady) - 1.f);
72 float t = (1.f + dist / sqrt(1.f + dist* dist)) * .5f;
74 wsum.xyz = wsum.xyz * (1 - t) + t * (rsMatrixMultiply(&colorMatrix, wsum.xyz) + offset);
76 uchar4 out = rsPackColorTo8888(clamp(wsum, 0.f, 1.0f));