Home | History | Annotate | Download | only in filters
      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.gallery3d.photoeditor.filters;
     18 
     19 import android.graphics.PointF;
     20 import android.media.effect.Effect;
     21 import android.media.effect.EffectFactory;
     22 import android.os.Parcel;
     23 
     24 import com.android.gallery3d.photoeditor.Photo;
     25 
     26 import java.util.Vector;
     27 
     28 /**
     29  * Red-eye removal filter applied to the image.
     30  */
     31 public class RedEyeFilter extends Filter {
     32 
     33     public static final Creator<RedEyeFilter> CREATOR = creatorOf(RedEyeFilter.class);
     34 
     35     private final Vector<PointF> redeyes = new Vector<PointF>();
     36 
     37     /**
     38      * The point coordinates used here should range from 0 to 1.
     39      */
     40     public void addRedEyePosition(PointF point) {
     41         redeyes.add(point);
     42     }
     43 
     44     @Override
     45     public void process(Photo src, Photo dst) {
     46         Effect effect = getEffect(EffectFactory.EFFECT_REDEYE);
     47         float[] centers = new float[redeyes.size() * 2];
     48         int i = 0;
     49         for (PointF eye : redeyes) {
     50             centers[i++] = eye.x;
     51             centers[i++] = eye.y;
     52         }
     53         effect.setParameter("centers", centers);
     54         effect.apply(src.texture(), src.width(), src.height(), dst.texture());
     55     }
     56 
     57     @Override
     58     protected void writeToParcel(Parcel out) {
     59         out.writeInt(redeyes.size());
     60         for (PointF eye : redeyes) {
     61             out.writeParcelable(eye, 0);
     62         }
     63     }
     64 
     65     @Override
     66     protected void readFromParcel(Parcel in) {
     67         int size = in.readInt();
     68         for (int i = 0; i < size; i++) {
     69             redeyes.add((PointF) in.readParcelable(null));
     70         }
     71     }
     72 }
     73