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() {
41 scalex = 1.f / radiusx;
42 scaley = 1.f / radiusy;
44 float S = 1 + finalSaturation / 100.f;
50 float b = 1 + finalBright / 100.f;
51 float c = 1 + finalContrast / 100.f;
53 offset = .5f - c / 2.f - finalSubtract / 100.f;
54 rsMatrixSet(&colorMatrix, 0, 0, b * (Rt + S));
55 rsMatrixSet(&colorMatrix, 1, 0, b * Gt);
56 rsMatrixSet(&colorMatrix, 2, 0, b * Bt);
57 rsMatrixSet(&colorMatrix, 0, 1, b * Rt);
58 rsMatrixSet(&colorMatrix, 1, 1, b * (Gt + S));
59 rsMatrixSet(&colorMatrix, 2, 1, b * Bt);
60 rsMatrixSet(&colorMatrix, 0, 2, b * Rt);
61 rsMatrixSet(&colorMatrix, 1, 2, b * Gt);
62 rsMatrixSet(&colorMatrix, 2, 2, b * (Bt + S));
65 uchar4 __attribute__((kernel)) vignette(const uchar4 in, uint32_t x, uint32_t y) {
66 float4 pixel = rsUnpackColor8888(in);
67 float radx = (x - centerx) * scalex;
68 float rady = (y - centery) * scaley;
69 float dist = strength * (sqrt(radx * radx + rady * rady) - 1.f);
70 float t = (1.f + dist / sqrt(1.f + dist* dist)) * .5f;
72 wsum.xyz = wsum.xyz * (1 - t) + t * (rsMatrixMultiply(&colorMatrix, wsum.xyz) + offset);
74 uchar4 out = rsPackColorTo8888(clamp(wsum, 0.f, 1.0f));