2 * Copyright (C) 2013 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.graphics.Bitmap;
20 import android.graphics.Matrix;
21 import android.graphics.RectF;
23 import java.util.Vector;
25 public class ImageFilterRedEye extends ImageFilter {
26 private static final String LOGTAG = "ImageFilterRedEye";
27 FilterRedEyeRepresentation mParameters = new FilterRedEyeRepresentation();
29 public ImageFilterRedEye() {
34 public FilterRepresentation getDefaultRepresentation() {
35 return new FilterRedEyeRepresentation();
38 public boolean isNil() {
39 return mParameters.isNil();
42 public Vector<FilterPoint> getCandidates() {
43 return mParameters.getCandidates();
47 mParameters.clearCandidates();
50 native protected void nativeApplyFilter(Bitmap bitmap, int w, int h, short[] matrix);
53 public void useRepresentation(FilterRepresentation representation) {
54 FilterRedEyeRepresentation parameters = (FilterRedEyeRepresentation) representation;
55 mParameters = parameters;
59 public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) {
60 int w = bitmap.getWidth();
61 int h = bitmap.getHeight();
62 short[] rect = new short[4];
64 int size = mParameters.getNumberOfCandidates();
65 Matrix originalToScreen = getOriginalToScreenMatrix(w, h);
66 for (int i = 0; i < size; i++) {
67 RectF r = new RectF(((RedEyeCandidate) (mParameters.getCandidate(i))).mRect);
68 originalToScreen.mapRect(r);
69 if (r.intersect(0, 0, w, h)) {
70 rect[0] = (short) r.left;
71 rect[1] = (short) r.top;
72 rect[2] = (short) r.width();
73 rect[3] = (short) r.height();
74 nativeApplyFilter(bitmap, w, h, rect);