ImageFilterDraw.java revision 915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1
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 Hofordimport android.util.Log;
28db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
29db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport com.android.gallery3d.R;
30915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hofordimport com.android.gallery3d.filtershow.editors.EditorDraw;
31db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
32db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordimport java.util.Arrays;
33db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
34db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hofordpublic class ImageFilterDraw extends ImageFilter {
35db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    private static final String LOGTAG = "ImageFilterDraw";
36915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    public final static char SIMPLE_STYLE = 0;
37915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    public final static char BRUSH_STYLE = 1;
38db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    Bitmap mOverlayBitmap; // this accelerates interaction
39915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    int mCachedStrokes = -1;
40915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    int mCurrentStyle = 0;
41915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    DrawStyle[] mDrawings = new DrawStyle[] {
42915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            new SimpleDraw(), new Brush() };
43915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
44915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    public void setStyle(char style) {
45915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mCurrentStyle = style;
46915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    }
47db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
48db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public static interface DrawStyle {
49db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public DrawStyle clone();
50db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public void setSize(float radius);
51db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public void setColor(int color);
52db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public void startStroke(float x, float y);
53db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public void stroke(float x, float y);
54db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public void endStroke(float x, float y);
55db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public int getNumberOfStrokes();
56db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public void clearCurren();
57db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public void paintCurrentStroke(Canvas canvas, Matrix toScrMatrix, boolean highQuality);
58db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public int paintLast(int from, Canvas canvas, Matrix toScrMatrix, boolean highQuality);
59db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public boolean same(DrawStyle o);
60915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        public boolean empty();
61db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    };
62db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
63db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    class SimpleDraw implements DrawStyle {
64db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        private Path[] mPaths = new Path[0];
65db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        private int[] mColors = new int[0];
66db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        private float[] mRadius = new float[0];
67db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        private int mStrokeCnt = 0;
68db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
69db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        private Path mCurrentPath;
70db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        private float mCurrentRadius;
71db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        private int mCurrentColor;
72db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
73915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
74db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public DrawStyle clone() {
75db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            SimpleDraw ret = new SimpleDraw();
76db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            ret.mPaths = new Path[mPaths.length];
77915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            for (int i = 0; i < ret.mPaths.length; i++) {
78db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                ret.mPaths[i] = new Path(mPaths[i]);
79db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            }
80db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            ret.mColors = Arrays.copyOf(mColors, mColors.length);
81db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            ret.mRadius = Arrays.copyOf(mRadius, mRadius.length);
82db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            ret.mStrokeCnt = mStrokeCnt;
83db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            return ret;
84db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
85db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
86915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
87915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        public boolean empty() {
88915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            return mStrokeCnt == -1;
89915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
90915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
91915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
92db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public void setSize(float radius) {
93db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            mCurrentRadius = radius;
94db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
95db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
96915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
97db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public void setColor(int color) {
98db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            mCurrentColor = color;
99db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
100db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
101915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
102db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public void startStroke(float x, float y) {
103db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            mCurrentPath = new Path();
104db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            mCurrentPath.moveTo(x, y);
105db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
106db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
107915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
108db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public void stroke(float x, float y) {
109db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            if (mCurrentPath != null) {
110db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                mCurrentPath.lineTo(x, y);
111db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            }
112db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
113db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
114915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
115db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public void endStroke(float x, float y) {
116db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            if (mCurrentPath != null) {
117db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                mCurrentPath.lineTo(x, y);
118db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                Path[] np = new Path[mStrokeCnt + 1];
119db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                for (int i = 0; i < mStrokeCnt; i++) {
120db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                    np[i] = mPaths[i];
121db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                }
122db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                np[mStrokeCnt] = mCurrentPath;
123db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                mColors = Arrays.copyOf(mColors, mColors.length + 1);
124db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                mRadius = Arrays.copyOf(mRadius, mRadius.length + 1);
125db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                mRadius[mStrokeCnt] = mCurrentRadius;
126db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                mColors[mStrokeCnt] = mCurrentColor;
127db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                mPaths = np;
128db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                mStrokeCnt++;
129db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            }
130db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
131915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
132915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
133db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public void clearCurren(){
134db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            mCurrentPath = null;
135db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
136915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
137915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
138db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public void paintCurrentStroke(Canvas canvas, Matrix toScrMatrix, boolean highQuality) {
139db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            Path path = mCurrentPath;
140915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            if (path == null) {
141db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                return;
142915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            }
143db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            Paint paint = new Paint();
144db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
145db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            paint.setStyle(Style.STROKE);
146db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            paint.setColor(mCurrentColor);
147db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            paint.setStrokeWidth(toScrMatrix.mapRadius(mCurrentRadius));
148db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
149db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            // don this way because a bug in path.transform(matrix)
150db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            Path mCacheTransPath = new Path();
151db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            mCacheTransPath.addPath(path, toScrMatrix);
152db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
153db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            canvas.drawPath(mCacheTransPath, paint);
154db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
155db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
156915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
157db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public int paintLast(int from, Canvas canvas, Matrix toScrMatrix, boolean highQuality) {
158db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            Paint paint = new Paint();
159db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            Matrix m = new Matrix();
160db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            canvas.save();
161db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            canvas.concat(toScrMatrix);
162db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            paint.setStyle(Style.STROKE);
163db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            for (int i = from; i < mStrokeCnt; i++) {
164db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                paint.setColor(mColors[i]);
165db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                paint.setStrokeWidth(mRadius[i]);
166db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                canvas.drawPath(mPaths[i], paint);
167db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            }
168db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            canvas.restore();
169db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            return mStrokeCnt;
170db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
171db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
172915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
173db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public boolean same(DrawStyle o) {
174db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            if (!(o instanceof SimpleDraw)) {
175db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                return false;
176db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            }
177db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            SimpleDraw sd = (SimpleDraw) o;
178db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            boolean same;
179db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            same = Arrays.equals(mRadius, sd.mRadius);
180db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            if (!same) {
181db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                return false;
182db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            }
183db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            same = Arrays.equals(mColors, sd.mColors);
184db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            if (!same) {
185db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                return false;
186db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            }
187db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            for (int i = 0; i < mPaths.length; i++) {
188db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                if (!mPaths[i].equals(sd.mPaths)) {
189db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                    return false;
190db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                }
191db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            }
192db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            return true;
193db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
194db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
195915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
196915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        public int getNumberOfStrokes() {
197915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            return mStrokeCnt;
198915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
199915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    }
200915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
201915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    class Brush implements DrawStyle {
202915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        private Path[] mPaths = new Path[0];
203915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        private int[] mColors = new int[0];
204915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        private float[] mRadius = new float[0];
205915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        private int mStrokeCnt = 0;
206915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
207915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        private Path mCurrentPath;
208915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        private float mCurrentRadius;
209915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        private int mCurrentColor;
210915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
211915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
212915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        public DrawStyle clone() {
213915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            Brush ret = new Brush();
214915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            ret.mPaths = new Path[mPaths.length];
215915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            for (int i = 0; i < ret.mPaths.length; i++) {
216915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                ret.mPaths[i] = new Path(mPaths[i]);
217915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            }
218915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            ret.mColors = Arrays.copyOf(mColors, mColors.length);
219915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            ret.mRadius = Arrays.copyOf(mRadius, mRadius.length);
220915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            ret.mStrokeCnt = mStrokeCnt;
221915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            return ret;
222915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
223915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
224915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
225915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        public boolean empty() {
226915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            return mStrokeCnt == -1;
227915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
228915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
229915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
230915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        public void setSize(float radius) {
231915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            mCurrentRadius = radius;
232915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
233915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
234915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
235915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        public void setColor(int color) {
236915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            mCurrentColor = color;
237915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
238915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
239915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
240915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        public void startStroke(float x, float y) {
241915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            mCurrentPath = new Path();
242915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            mCurrentPath.moveTo(x, y);
243915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
244915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
245915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
246915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        public void stroke(float x, float y) {
247915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            if (mCurrentPath != null) {
248915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                mCurrentPath.lineTo(x, y);
249915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            }
250915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
251915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
252915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
253915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        public void endStroke(float x, float y) {
254915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            if (mCurrentPath != null) {
255915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                mCurrentPath.lineTo(x, y);
256915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                Path[] np = new Path[mStrokeCnt + 1];
257915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                for (int i = 0; i < mStrokeCnt; i++) {
258915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                    np[i] = mPaths[i];
259915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                }
260915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                np[mStrokeCnt] = mCurrentPath;
261915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                mColors = Arrays.copyOf(mColors, mColors.length + 1);
262915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                mRadius = Arrays.copyOf(mRadius, mRadius.length + 1);
263915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                mRadius[mStrokeCnt] = mCurrentRadius;
264915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                mColors[mStrokeCnt] = mCurrentColor;
265915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                mPaths = np;
266915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                mStrokeCnt++;
267915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                clearCurren();
268915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            }
269915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
270915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
271915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
272915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        public void clearCurren() {
273915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            mCurrentPath = null;
274915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
275915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
276915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
277915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        public void paintCurrentStroke(Canvas canvas, Matrix toScrMatrix, boolean highQuality) {
278915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            Path path = mCurrentPath;
279915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            if (path == null) {
280915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                return;
281915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            }
282915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            Paint paint = new Paint();
283915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
284915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            canvas.save();
285915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            canvas.concat(toScrMatrix);
286915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            paint.setStyle(Style.STROKE);
287915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
288915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            float scale = toScrMatrix.mapRadius(1);
289915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            draw(canvas, paint, mCurrentColor, mCurrentRadius, path);
290915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            canvas.restore();
291915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
292915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
293915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
294915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        public int paintLast(int from, Canvas canvas, Matrix toScrMatrix, boolean highQuality) {
295915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            Paint paint = new Paint();
296915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
297915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            Matrix m = new Matrix();
298915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            canvas.save();
299915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            canvas.concat(toScrMatrix);
300915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            paint.setStyle(Style.STROKE);
301915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            for (int i = from; i < mStrokeCnt; i++) {
302915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
303915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                draw(canvas, paint, mColors[i], mRadius[i], mPaths[i]);
304915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            }
305915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            canvas.restore();
306915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            return mStrokeCnt;
307915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
308915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
309915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        PathMeasure mPathMeasure = new PathMeasure();
310915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
311915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        void draw(Canvas canvas, Paint paint, int color, float size, Path path) {
312915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
313915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            mPathMeasure.setPath(path, false);
314915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            float[] pos = new float[2];
315915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            float[] tan = new float[2];
316915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            paint.setColor(color);
317915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            float len = mPathMeasure.getLength();
318915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            for (float i = 0; i < len; i += (size) / 2) {
319915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                mPathMeasure.getPosTan(i, pos, tan);
320915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                canvas.drawCircle(pos[0], pos[1], size, paint);
321915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            }
322915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
323915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
324915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
325915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
326915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        public boolean same(DrawStyle o) {
327915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            if (!(o instanceof Brush)) {
328915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                return false;
329915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            }
330915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            Brush sd = (Brush) o;
331915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            boolean same;
332915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            same = Arrays.equals(mRadius, sd.mRadius);
333915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            if (!same) {
334915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                return false;
335915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            }
336915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            same = Arrays.equals(mColors, sd.mColors);
337915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            if (!same) {
338915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                return false;
339915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            }
340915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            for (int i = 0; i < mPaths.length; i++) {
341915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                if (!mPaths[i].equals(sd.mPaths)) {
342915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                    return false;
343915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                }
344915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            }
345915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            return true;
346915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
347915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
348915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        @Override
349db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        public int getNumberOfStrokes() {
350db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            return mStrokeCnt;
351db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
352db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
353db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
354915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford    public void startSection(int color, float size, float x, float y) {
355915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDrawings[mCurrentStyle].setColor(color);
356915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDrawings[mCurrentStyle].setSize(size);
357915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDrawings[mCurrentStyle].startStroke(x, y);
358db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
359db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
360db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public void addPoint(float x, float y) {
361915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDrawings[mCurrentStyle].stroke(x, y);
362db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
363db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
364db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public void endSection(float x, float y) {
365915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDrawings[mCurrentStyle].endStroke(x, y);
366db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
367db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
368db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public ImageFilterDraw() {
369db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        mName = "Image Draw";
370db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
371db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
372db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public void drawData(Canvas canvas, Matrix originalRotateToScreen, boolean highQuality) {
373db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        Paint paint = new Paint();
374db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        if (highQuality) {
375db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            paint.setAntiAlias(true);
376db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
377db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        paint.setStyle(Style.STROKE);
378db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        paint.setColor(Color.RED);
379db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        paint.setStrokeWidth(40);
380915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        boolean empty = true;
381915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        for (int i = 0; i < mDrawings.length; i++) {
382915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            empty &= mDrawings[i].empty();
383915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
384915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        if (empty) {
385db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            return;
386db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
387db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        if (highQuality) {
388915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            for (int i = 0; i < mDrawings.length; i++) {
389915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                mDrawings[i].paintLast(0, canvas, originalRotateToScreen, highQuality);
390915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            }
391915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford
392db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            return;
393db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
394db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        if (mOverlayBitmap == null ||
395db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                mOverlayBitmap.getWidth() != canvas.getWidth() ||
396db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                mOverlayBitmap.getHeight() != canvas.getHeight()) {
397db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
398db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            mOverlayBitmap = Bitmap.createBitmap(
399db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford                    canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888);
400db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            mCachedStrokes = 0;
401db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
402915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        if (mCachedStrokes < mDrawings[mCurrentStyle].getNumberOfStrokes()) {
403db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            fillBuffer(originalRotateToScreen);
404db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
405db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        canvas.drawBitmap(mOverlayBitmap, 0, 0, paint);
406db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
407db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
408db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public void fillBuffer(Matrix originalRotateToScreen) {
409db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        Canvas drawCache = new Canvas(mOverlayBitmap);
410915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        for (int i = 0; i < mDrawings.length; i++) {
411db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
412915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            mCachedStrokes = mDrawings[i].paintLast(
413915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                mCachedStrokes, drawCache, originalRotateToScreen, false);
414915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
415db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
416db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
417db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    @Override
418db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public int getButtonId() {
419db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        return R.id.drawOnImageButton;
420db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
421db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
422db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    @Override
423db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public int getTextId() {
424db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        return R.string.imageDraw;
425db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
426db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
427db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    @Override
428db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public int getEditingViewId() {
429915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        return EditorDraw.ID;
430db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
431db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
432db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    @Override
433db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public ImageFilter clone() throws CloneNotSupportedException {
434db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        ImageFilterDraw filter = (ImageFilterDraw) super.clone();
435db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
436915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        filter.mDrawings = mDrawings.clone();
437db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        return filter;
438db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
439db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
440db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    @Override
441db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public boolean isNil() {
442915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        for (int i = 0; i < mDrawings.length; i++) {
443915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            if (mDrawings[i].getNumberOfStrokes() != 0) {
444915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford                return false;
445915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            }
446db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
447db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        return true;
448db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
449db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
450db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    @Override
451db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public boolean same(ImageFilter filter) {
452db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        boolean isSuperSame = super.same(filter);
453db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        if (!isSuperSame || !(filter instanceof ImageFilterDraw)) {
454db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford            return false;
455db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        }
456db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
457db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        ImageFilterDraw dfilter = (ImageFilterDraw) filter;
458915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        boolean same = true;
459915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        for (int i = 0; i < mDrawings.length; i++) {
460915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            same &= mDrawings[i].same(dfilter.mDrawings[i]);
461915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
462915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        return same;
463db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
464db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
465db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public void clear() {
466915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        mDrawings[mCurrentStyle].clearCurren();
467db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
468db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
469db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public void draw(Canvas canvas, Matrix originalRotateToScreen) {
470915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        for (int i = 0; i < mDrawings.length; i++) {
471915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford            mDrawings[i].paintCurrentStroke(canvas, originalRotateToScreen, false);
472915d60a378b0ca7bbe3af6312ccd2f4b94eb2da1John Hoford        }
473db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
474db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
475db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    @Override
476db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    public Bitmap apply(Bitmap bitmap, float scaleFactor, boolean highQuality) {
477db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        int w = bitmap.getWidth();
478db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        int h = bitmap.getHeight();
479db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        short[] rect = new short[4];
480db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
481db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        Matrix m = new Matrix();
482db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        m.setScale(scaleFactor, scaleFactor);
483db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
484db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        drawData(new Canvas(bitmap), m, highQuality);
485db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford
486db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford        return bitmap;
487db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford    }
488db94725c415a9e16abfce05c0315bd7c1c3ecce2John Hoford}
489