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.Canvas; 20 import android.graphics.Paint; 21 import android.graphics.Path; 22 23 import com.android.photoeditor.actions.ColorPath; 24 import com.android.photoeditor.Photo; 25 26 import java.util.Vector; 27 28 /** 29 * Doodle filter applied to the image. 30 */ 31 public class DoodleFilter extends Filter { 32 33 private final Vector<ColorPath> doodles = new Vector<ColorPath>(); 34 private final Paint paint = ColorPath.createPaint(); 35 private final Canvas canvas = new Canvas(); 36 addPath(int color)37 public void addPath(int color) { 38 // Remove last empty path before adding a new one. 39 if (!doodles.isEmpty() && doodles.lastElement().path().isEmpty()) { 40 doodles.remove(doodles.size() - 1); 41 } 42 doodles.add(new ColorPath(color, new Path())); 43 } 44 updateLastPath(Path path)45 public synchronized void updateLastPath(Path path) { 46 if (!doodles.isEmpty()) { 47 doodles.lastElement().path().set(path); 48 validate(); 49 } 50 } 51 52 @Override process(Photo src, Photo dst)53 public void process(Photo src, Photo dst) { 54 ImageUtils.nativeCopy(src.bitmap(), dst.bitmap()); 55 56 if (!doodles.isEmpty()) { 57 canvas.setBitmap(dst.bitmap()); 58 for (ColorPath doodle : doodles) { 59 doodle.draw(canvas, paint); 60 } 61 } 62 } 63 } 64