2 package com.android.gallery3d.filtershow.imageshow;
4 import android.content.Context;
5 import android.graphics.Canvas;
6 import android.graphics.Color;
7 import android.graphics.Matrix;
8 import android.graphics.Paint;
9 import android.graphics.Paint.Style;
10 import android.graphics.RectF;
11 import android.util.AttributeSet;
12 import android.util.Log;
13 import android.view.MotionEvent;
15 import com.android.gallery3d.filtershow.filters.ImageFilterDraw;
16 import com.android.gallery3d.filtershow.filters.RedEyeCandidate;
18 public class ImageDraw extends ImageShow {
20 private static final String LOGTAG = "ImageDraw";
22 public ImageDraw(Context context, AttributeSet attrs) {
23 super(context, attrs);
26 public ImageDraw(Context context) {
31 public void resetParameter() {
32 ImageFilterDraw filter = (ImageFilterDraw) getCurrentFilter();
41 public void updateImage() {
46 float[] mTmpPoint = new float[2]; // so we do not malloc
48 public boolean onTouchEvent(MotionEvent event) {
49 if (event.getPointerCount() != 1) {
53 ImageFilterDraw filter = (ImageFilterDraw) getCurrentFilter();
55 if (event.getAction() == MotionEvent.ACTION_DOWN) {
57 mTmpPoint[0] = event.getX();
58 mTmpPoint[1] = event.getY();
59 mToOrig.mapPoints(mTmpPoint);
60 float[] hsv = new float[3];
61 hsv[0] = (float) (360 * Math.random());
64 int col = Color.HSVToColor(0x88, hsv);
65 filter.startSection(col, mTmpPoint[0], mTmpPoint[1]);
68 if (event.getAction() == MotionEvent.ACTION_MOVE) {
69 int historySize = event.getHistorySize();
70 final int pointerCount = event.getPointerCount();
71 for (int h = 0; h < historySize; h++) {
74 mTmpPoint[0] = event.getHistoricalX(p, h);
75 mTmpPoint[1] = event.getHistoricalY(p, h);
76 mToOrig.mapPoints(mTmpPoint);
77 filter.addPoint(mTmpPoint[0], mTmpPoint[1]);
81 if (event.getAction() == MotionEvent.ACTION_UP) {
82 mTmpPoint[0] = event.getX();
83 mTmpPoint[1] = event.getY();
84 mToOrig.mapPoints(mTmpPoint);
85 filter.endSection(mTmpPoint[0], mTmpPoint[1]);
86 this.resetImageCaches(this);
93 Matrix mRotateToScreen;
95 Matrix mToOrig = new Matrix();
96 private void calcScreenMapping() {
98 GeometryMetadata geo = getImagePreset().mGeoData;
99 mToScreen = geo.getOriginalToScreen(false,
100 mImageLoader.getOriginalBounds().width(),
101 mImageLoader.getOriginalBounds().height(), getWidth(), getHeight());
102 mRotateToScreen = geo.getOriginalToScreen(true,
103 mImageLoader.getOriginalBounds().width(),
104 mImageLoader.getOriginalBounds().height(), getWidth(), getHeight());
105 mRotateToScreen.invert(mToOrig);
106 mToOrig.invert(mRotateToScreen);
110 public void onDraw(Canvas canvas) {
111 super.onDraw(canvas);
115 ImageFilterDraw filter = (ImageFilterDraw) getCurrentFilter();
116 filter.draw(canvas, mRotateToScreen);