ImageFilterDraw.java revision 87e889b195de98334048bb70bb1263a2ab76c76a
1db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford/* 2db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford * Copyright (C) 2012 The Android Open Source Project 3db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford * 4db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford * Licensed under the Apache License, Version 2.0 (the "License"); 5db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford * you may not use this file except in compliance with the License. 6db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford * You may obtain a copy of the License at 7db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford * 8db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford * http://www.apache.org/licenses/LICENSE-2.0 9db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford * 10db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford * Unless required by applicable law or agreed to in writing, software 11db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford * distributed under the License is distributed on an "AS IS" BASIS, 12db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford * See the License for the specific language governing permissions and 14db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford * limitations under the License. 15db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford */ 16db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 17db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordpackage com.android.gallery3d.filtershow.filters; 18db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 19db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport android.graphics.Bitmap; 20db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport android.graphics.Canvas; 21db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport android.graphics.Color; 22db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport android.graphics.Matrix; 23db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport android.graphics.Paint; 24db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport android.graphics.Paint.Style; 25915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.graphics.Path; 26915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport android.graphics.PathMeasure; 27db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 28db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport com.android.gallery3d.R; 29915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport com.android.gallery3d.filtershow.editors.EditorDraw; 30db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 31db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport java.util.Arrays; 32db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 33db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordpublic class ImageFilterDraw extends ImageFilter { 34db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford private static final String LOGTAG = "ImageFilterDraw"; 35915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public final static char SIMPLE_STYLE = 0; 36915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public final static char BRUSH_STYLE = 1; 37db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford Bitmap mOverlayBitmap; // this accelerates interaction 38915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford int mCachedStrokes = -1; 39915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford int mCurrentStyle = 0; 40915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford DrawStyle[] mDrawings = new DrawStyle[] { 41915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford new SimpleDraw(), new Brush() }; 42915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 43915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public void setStyle(char style) { 44915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mCurrentStyle = style; 45915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 46db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 47db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public static interface DrawStyle { 48db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public DrawStyle clone(); 49db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void setSize(float radius); 50db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void setColor(int color); 51db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void startStroke(float x, float y); 52db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void stroke(float x, float y); 53db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void endStroke(float x, float y); 54db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public int getNumberOfStrokes(); 55db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void clearCurren(); 56db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void paintCurrentStroke(Canvas canvas, Matrix toScrMatrix, boolean highQuality); 57db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public int paintLast(int from, Canvas canvas, Matrix toScrMatrix, boolean highQuality); 58db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public boolean same(DrawStyle o); 59915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public boolean empty(); 60db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford }; 61db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 62db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford class SimpleDraw implements DrawStyle { 63db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford private Path[] mPaths = new Path[0]; 64db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford private int[] mColors = new int[0]; 65db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford private float[] mRadius = new float[0]; 66db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford private int mStrokeCnt = 0; 67db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 68db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford private Path mCurrentPath; 69db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford private float mCurrentRadius; 70db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford private int mCurrentColor; 71db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 72915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 73db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public DrawStyle clone() { 74db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford SimpleDraw ret = new SimpleDraw(); 75db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford ret.mPaths = new Path[mPaths.length]; 76915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford for (int i = 0; i < ret.mPaths.length; i++) { 77db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford ret.mPaths[i] = new Path(mPaths[i]); 78db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 79db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford ret.mColors = Arrays.copyOf(mColors, mColors.length); 80db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford ret.mRadius = Arrays.copyOf(mRadius, mRadius.length); 81db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford ret.mStrokeCnt = mStrokeCnt; 82db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return ret; 83db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 84db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 85915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 86915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public boolean empty() { 87915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return mStrokeCnt == -1; 88915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 89915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 90915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 91db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void setSize(float radius) { 92db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mCurrentRadius = radius; 93db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 94db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 95915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 96db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void setColor(int color) { 97db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mCurrentColor = color; 98db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 99db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 100915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 101db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void startStroke(float x, float y) { 102db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mCurrentPath = new Path(); 103db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mCurrentPath.moveTo(x, y); 104db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 105db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 106915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 107db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void stroke(float x, float y) { 108db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford if (mCurrentPath != null) { 109db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mCurrentPath.lineTo(x, y); 110db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 111db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 112db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 113915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 114db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void endStroke(float x, float y) { 115db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford if (mCurrentPath != null) { 116db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mCurrentPath.lineTo(x, y); 117db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford Path[] np = new Path[mStrokeCnt + 1]; 118db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford for (int i = 0; i < mStrokeCnt; i++) { 119db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford np[i] = mPaths[i]; 120db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 121db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford np[mStrokeCnt] = mCurrentPath; 122db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mColors = Arrays.copyOf(mColors, mColors.length + 1); 123db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mRadius = Arrays.copyOf(mRadius, mRadius.length + 1); 124db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mRadius[mStrokeCnt] = mCurrentRadius; 125db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mColors[mStrokeCnt] = mCurrentColor; 126db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mPaths = np; 127db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mStrokeCnt++; 128db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 129db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 130915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 131915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 132db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void clearCurren(){ 133db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mCurrentPath = null; 134db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 135915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 136915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 137db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void paintCurrentStroke(Canvas canvas, Matrix toScrMatrix, boolean highQuality) { 138db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford Path path = mCurrentPath; 139915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford if (path == null) { 140db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return; 141915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 142db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford Paint paint = new Paint(); 143db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 144db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford paint.setStyle(Style.STROKE); 145db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford paint.setColor(mCurrentColor); 146db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford paint.setStrokeWidth(toScrMatrix.mapRadius(mCurrentRadius)); 147db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 148db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford // don this way because a bug in path.transform(matrix) 149db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford Path mCacheTransPath = new Path(); 150db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mCacheTransPath.addPath(path, toScrMatrix); 151db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 152db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford canvas.drawPath(mCacheTransPath, paint); 153db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 154db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 155915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 156db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public int paintLast(int from, Canvas canvas, Matrix toScrMatrix, boolean highQuality) { 157db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford Paint paint = new Paint(); 158db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford Matrix m = new Matrix(); 159db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford canvas.save(); 160db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford canvas.concat(toScrMatrix); 161db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford paint.setStyle(Style.STROKE); 162db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford for (int i = from; i < mStrokeCnt; i++) { 163db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford paint.setColor(mColors[i]); 164db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford paint.setStrokeWidth(mRadius[i]); 165db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford canvas.drawPath(mPaths[i], paint); 166db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 167db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford canvas.restore(); 168db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return mStrokeCnt; 169db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 170db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 171915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 172db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public boolean same(DrawStyle o) { 173db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford if (!(o instanceof SimpleDraw)) { 174db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return false; 175db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 176db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford SimpleDraw sd = (SimpleDraw) o; 177db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford boolean same; 178db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford same = Arrays.equals(mRadius, sd.mRadius); 179db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford if (!same) { 180db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return false; 181db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 182db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford same = Arrays.equals(mColors, sd.mColors); 183db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford if (!same) { 184db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return false; 185db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 186db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford for (int i = 0; i < mPaths.length; i++) { 187db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford if (!mPaths[i].equals(sd.mPaths)) { 188db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return false; 189db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 190db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 191db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return true; 192db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 193db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 194915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 195915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public int getNumberOfStrokes() { 196915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return mStrokeCnt; 197915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 198915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 199915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 200915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford class Brush implements DrawStyle { 201915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford private Path[] mPaths = new Path[0]; 202915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford private int[] mColors = new int[0]; 203915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford private float[] mRadius = new float[0]; 204915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford private int mStrokeCnt = 0; 205915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 206915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford private Path mCurrentPath; 207915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford private float mCurrentRadius; 208915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford private int mCurrentColor; 209915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 210915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 211915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public DrawStyle clone() { 212915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford Brush ret = new Brush(); 213915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford ret.mPaths = new Path[mPaths.length]; 214915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford for (int i = 0; i < ret.mPaths.length; i++) { 215915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford ret.mPaths[i] = new Path(mPaths[i]); 216915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 217915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford ret.mColors = Arrays.copyOf(mColors, mColors.length); 218915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford ret.mRadius = Arrays.copyOf(mRadius, mRadius.length); 219915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford ret.mStrokeCnt = mStrokeCnt; 220915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return ret; 221915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 222915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 223915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 224915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public boolean empty() { 225915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return mStrokeCnt == -1; 226915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 227915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 228915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 229915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public void setSize(float radius) { 230915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mCurrentRadius = radius; 231915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 232915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 233915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 234915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public void setColor(int color) { 235915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mCurrentColor = color; 236915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 237915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 238915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 239915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public void startStroke(float x, float y) { 240915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mCurrentPath = new Path(); 241915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mCurrentPath.moveTo(x, y); 242915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 243915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 244915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 245915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public void stroke(float x, float y) { 246915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford if (mCurrentPath != null) { 247915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mCurrentPath.lineTo(x, y); 248915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 249915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 250915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 251915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 252915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public void endStroke(float x, float y) { 253915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford if (mCurrentPath != null) { 254915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mCurrentPath.lineTo(x, y); 255915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford Path[] np = new Path[mStrokeCnt + 1]; 256915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford for (int i = 0; i < mStrokeCnt; i++) { 257915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford np[i] = mPaths[i]; 258915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 259915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford np[mStrokeCnt] = mCurrentPath; 260915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mColors = Arrays.copyOf(mColors, mColors.length + 1); 261915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mRadius = Arrays.copyOf(mRadius, mRadius.length + 1); 262915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mRadius[mStrokeCnt] = mCurrentRadius; 263915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mColors[mStrokeCnt] = mCurrentColor; 264915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mPaths = np; 265915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mStrokeCnt++; 266915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford clearCurren(); 267915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 268915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 269915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 270915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 271915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public void clearCurren() { 272915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mCurrentPath = null; 273915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 274915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 275915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 276915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public void paintCurrentStroke(Canvas canvas, Matrix toScrMatrix, boolean highQuality) { 277915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford Path path = mCurrentPath; 278915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford if (path == null) { 279915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return; 280915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 281915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford Paint paint = new Paint(); 282915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford paint.setStyle(Style.STROKE); 283915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 284915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford float scale = toScrMatrix.mapRadius(1); 28587e889b195de98334048bb70bb1263a2ab76c76aJohn Hoford Path mCacheTransPath = new Path(); 28687e889b195de98334048bb70bb1263a2ab76c76aJohn Hoford mCacheTransPath.addPath(path, toScrMatrix); 28787e889b195de98334048bb70bb1263a2ab76c76aJohn Hoford draw(canvas, paint, mCurrentColor, toScrMatrix.mapRadius(mCurrentRadius), 28887e889b195de98334048bb70bb1263a2ab76c76aJohn Hoford mCacheTransPath); 289915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 290915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 291915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 292915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public int paintLast(int from, Canvas canvas, Matrix toScrMatrix, boolean highQuality) { 293915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford Paint paint = new Paint(); 294915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 295915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford Matrix m = new Matrix(); 296915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford canvas.save(); 297915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford canvas.concat(toScrMatrix); 298915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford paint.setStyle(Style.STROKE); 299915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford for (int i = from; i < mStrokeCnt; i++) { 300915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 301915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford draw(canvas, paint, mColors[i], mRadius[i], mPaths[i]); 302915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 303915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford canvas.restore(); 304915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return mStrokeCnt; 305915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 306915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 307915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford PathMeasure mPathMeasure = new PathMeasure(); 308915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 309915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford void draw(Canvas canvas, Paint paint, int color, float size, Path path) { 310915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 311915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mPathMeasure.setPath(path, false); 312915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford float[] pos = new float[2]; 313915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford float[] tan = new float[2]; 314915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford paint.setColor(color); 315915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford float len = mPathMeasure.getLength(); 316915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford for (float i = 0; i < len; i += (size) / 2) { 317915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mPathMeasure.getPosTan(i, pos, tan); 318915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford canvas.drawCircle(pos[0], pos[1], size, paint); 319915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 320915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 321915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 322915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 323915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 324915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public boolean same(DrawStyle o) { 325915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford if (!(o instanceof Brush)) { 326915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return false; 327915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 328915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford Brush sd = (Brush) o; 329915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford boolean same; 330915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford same = Arrays.equals(mRadius, sd.mRadius); 331915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford if (!same) { 332915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return false; 333915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 334915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford same = Arrays.equals(mColors, sd.mColors); 335915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford if (!same) { 336915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return false; 337915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 338915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford for (int i = 0; i < mPaths.length; i++) { 339915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford if (!mPaths[i].equals(sd.mPaths)) { 340915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return false; 341915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 342915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 343915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return true; 344915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 345915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 346915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford @Override 347db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public int getNumberOfStrokes() { 348db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return mStrokeCnt; 349db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 350db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 351db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 352915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford public void startSection(int color, float size, float x, float y) { 353915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mDrawings[mCurrentStyle].setColor(color); 354915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mDrawings[mCurrentStyle].setSize(size); 355915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mDrawings[mCurrentStyle].startStroke(x, y); 356db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 357db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 358db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void addPoint(float x, float y) { 359915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mDrawings[mCurrentStyle].stroke(x, y); 360db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 361db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 362db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void endSection(float x, float y) { 363915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mDrawings[mCurrentStyle].endStroke(x, y); 364db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 365db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 366db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public ImageFilterDraw() { 367db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mName = "Image Draw"; 368db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 369db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 370db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void drawData(Canvas canvas, Matrix originalRotateToScreen, boolean highQuality) { 371db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford Paint paint = new Paint(); 372db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford if (highQuality) { 373db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford paint.setAntiAlias(true); 374db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 375db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford paint.setStyle(Style.STROKE); 376db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford paint.setColor(Color.RED); 377db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford paint.setStrokeWidth(40); 378915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford boolean empty = true; 379915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford for (int i = 0; i < mDrawings.length; i++) { 380915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford empty &= mDrawings[i].empty(); 381915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 382915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford if (empty) { 383db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return; 384db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 385db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford if (highQuality) { 386915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford for (int i = 0; i < mDrawings.length; i++) { 387915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mDrawings[i].paintLast(0, canvas, originalRotateToScreen, highQuality); 388915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 389915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford 390db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return; 391db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 392db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford if (mOverlayBitmap == null || 393db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mOverlayBitmap.getWidth() != canvas.getWidth() || 394db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mOverlayBitmap.getHeight() != canvas.getHeight()) { 395db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 396db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mOverlayBitmap = Bitmap.createBitmap( 397db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); 398db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford mCachedStrokes = 0; 399db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 400915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford if (mCachedStrokes < mDrawings[mCurrentStyle].getNumberOfStrokes()) { 401db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford fillBuffer(originalRotateToScreen); 402db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 403db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford canvas.drawBitmap(mOverlayBitmap, 0, 0, paint); 404db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 405db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 406db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void fillBuffer(Matrix originalRotateToScreen) { 407db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford Canvas drawCache = new Canvas(mOverlayBitmap); 408915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford for (int i = 0; i < mDrawings.length; i++) { 409db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 410915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mCachedStrokes = mDrawings[i].paintLast( 411915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mCachedStrokes, drawCache, originalRotateToScreen, false); 412915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 413db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 414db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 415db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford @Override 416db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public int getButtonId() { 417db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return R.id.drawOnImageButton; 418db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 419db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 420db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford @Override 421db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public int getTextId() { 422db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return R.string.imageDraw; 423db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 424db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 425db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford @Override 426db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public int getEditingViewId() { 427915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return EditorDraw.ID; 428db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 429db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 430db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford @Override 431db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public ImageFilter clone() throws CloneNotSupportedException { 432db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford ImageFilterDraw filter = (ImageFilterDraw) super.clone(); 433db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 434915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford filter.mDrawings = mDrawings.clone(); 435db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return filter; 436db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 437db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 438db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford @Override 439db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public boolean isNil() { 440915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford for (int i = 0; i < mDrawings.length; i++) { 441915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford if (mDrawings[i].getNumberOfStrokes() != 0) { 442915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return false; 443915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 444db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 445db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return true; 446db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 447db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 448db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford @Override 449db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public boolean same(ImageFilter filter) { 450db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford boolean isSuperSame = super.same(filter); 451db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford if (!isSuperSame || !(filter instanceof ImageFilterDraw)) { 452db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return false; 453db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 454db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 455db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford ImageFilterDraw dfilter = (ImageFilterDraw) filter; 456915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford boolean same = true; 457915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford for (int i = 0; i < mDrawings.length; i++) { 458915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford same &= mDrawings[i].same(dfilter.mDrawings[i]); 459915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 460915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford return same; 461db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 462db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 463db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void clear() { 464915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mDrawings[mCurrentStyle].clearCurren(); 465db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 466db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 467db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public void draw(Canvas canvas, Matrix originalRotateToScreen) { 468915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford for (int i = 0; i < mDrawings.length; i++) { 469915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford mDrawings[i].paintCurrentStroke(canvas, originalRotateToScreen, false); 470915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford } 471db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 472db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 473db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford @Override 474db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) { 475db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford int w = bitmap.getWidth(); 476db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford int h = bitmap.getHeight(); 477db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford short[] rect = new short[4]; 478db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 479db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford Matrix m = new Matrix(); 480db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford m.setScale(scaleFactor, scaleFactor); 481db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 482db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford drawData(new Canvas(bitmap), m, highQuality); 483db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford 484db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford return bitmap; 485db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford } 486db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford} 487