• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 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 
17 package com.android.photoeditor.filters;
18 
19 import android.graphics.PointF;
20 
21 import com.android.photoeditor.Photo;
22 
23 import java.util.Vector;
24 
25 /**
26  * Red-eye removal filter applied to the image.
27  */
28 public class RedEyeFilter extends Filter {
29 
30     private static final float RADIUS_RATIO = 0.06f;
31     private static final float MIN_RADIUS = 10.0f;
32     private static final float DEFAULT_RED_INTENSITY = 1.30f; // an empirical value
33 
34     private final Vector<PointF> redeyePositions = new Vector<PointF>();
35 
addRedEyePosition(PointF point)36     public void addRedEyePosition(PointF point) {
37         redeyePositions.add(point);
38         validate();
39     }
40 
41     @Override
process(Photo src, Photo dst)42     public void process(Photo src, Photo dst) {
43         float radius = Math.max(MIN_RADIUS, RADIUS_RATIO * Math.min(src.width(), src.height()));
44 
45         PointF[] a = new PointF[redeyePositions.size()];
46         ImageUtils.nativeRedEye(src.bitmap(), dst.bitmap(),
47                 redeyePositions.toArray(a), radius, DEFAULT_RED_INTENSITY);
48     }
49 }
50