2 * Copyright (C) 2012 The Android Open Source Project
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.
17 package com.android.gallery3d.filtershow.filters;
19 import android.content.res.Resources;
20 import android.graphics.Bitmap;
21 import android.graphics.Canvas;
22 import android.graphics.Matrix;
23 import android.graphics.Rect;
24 import com.android.gallery3d.R;
25 import com.android.gallery3d.filtershow.presets.FilterEnvironment;
27 public class ImageFilterVignette extends SimpleImageFilter {
28 private static final String LOGTAG = "ImageFilterVignette";
29 private Bitmap mOverlayBitmap;
31 public ImageFilterVignette() {
36 public FilterRepresentation getDefaultRepresentation() {
37 FilterVignetteRepresentation representation = new FilterVignetteRepresentation();
38 return representation;
41 native protected void nativeApplyFilter(
42 Bitmap bitmap, int w, int h, int cx, int cy, float radx, float rady, float strength);
44 private float calcRadius(float cx, float cy, int w, int h) {
59 public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
60 if (SIMPLE_ICONS && FilterEnvironment.QUALITY_ICON == quality) {
61 if (mOverlayBitmap == null) {
62 Resources res = getEnvironment().getPipeline().getResources();
63 mOverlayBitmap = IconUtilities.getFXBitmap(res,
64 R.drawable.filtershow_icon_vignette);
66 Canvas c = new Canvas(bitmap);
67 int dim = Math.max(bitmap.getWidth(), bitmap.getHeight());
68 Rect r = new Rect(0, 0, dim, dim);
69 c.drawBitmap(mOverlayBitmap, null, r, null);
72 FilterVignetteRepresentation rep = (FilterVignetteRepresentation) getParameters();
76 int w = bitmap.getWidth();
77 int h = bitmap.getHeight();
78 float value = rep.getValue() / 100.0f;
81 float r = calcRadius(cx, cy, w, h);
84 if (rep.isCenterSet()) {
85 Matrix m = getOriginalToScreenMatrix(w, h);
86 cx = rep.getCenterX();
87 cy = rep.getCenterY();
88 float[] center = new float[] { cx, cy };
92 rx = m.mapRadius(rep.getRadiusX());
93 ry = m.mapRadius(rep.getRadiusY());
95 nativeApplyFilter(bitmap, w, h, (int) cx, (int) cy, rx, ry, value);