diff options
11 files changed, 424 insertions, 84 deletions
diff --git a/res/drawable/ic_glare_remove_button_off.xml b/res/drawable/ic_glare_remove_button_off.xml new file mode 100644 index 000000000..0a07b4572 --- /dev/null +++ b/res/drawable/ic_glare_remove_button_off.xml @@ -0,0 +1,42 @@ +<!-- + Copyright (c) 2016, The Linux Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="75.9dp" + android:height="45.9dp" + android:viewportWidth="75.9" + android:viewportHeight="45.9"> + + <path + android:fillColor="#E2E2E2" + android:pathData="M58.3,35.8H15.6c-7.7,0-14.1-6.3-14.1-14.1v0C1.5,14,7.8,7.7,15.6,7.7h42.7c7.7,0,14.1,6.3,14.1,14.1v0 +C72.3,29.5,66,35.8,58.3,35.8z" /> + <path + android:fillColor="#E2E2E2" + android:pathData="M 21.2 2 C 32.1352380466 2 41 10.8647619534 41 21.8 C 41 32.7352380466 32.1352380466 41.6 21.2 41.6 C 10.2647619534 41.6 1.4 32.7352380466 1.4 21.8 C 1.4 10.8647619534 10.2647619534 2 21.2 2 Z" /> +</vector> diff --git a/res/drawable/ic_glare_remove_button_on.xml b/res/drawable/ic_glare_remove_button_on.xml new file mode 100644 index 000000000..59ea03b5c --- /dev/null +++ b/res/drawable/ic_glare_remove_button_on.xml @@ -0,0 +1,42 @@ +<!-- + Copyright (c) 2016, The Linux Foundation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of The Linux Foundation nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="75.9dp" + android:height="45.9dp" + android:viewportWidth="75.9" + android:viewportHeight="45.9"> + + <path + android:fillColor="#9CC2E7" + android:pathData="M58.3,35.8H15.6c-7.7,0-14.1-6.3-14.1-14.1v0C1.5,14,7.8,7.7,15.6,7.7h42.7c7.7,0,14.1,6.3,14.1,14.1v0 +C72.3,29.5,66,35.8,58.3,35.8z" /> + <path + android:fillColor="#5E92CD" + android:pathData="M 52.2 2 C 63.1352380466 2 72 10.8647619534 72 21.8 C 72 32.7352380466 63.1352380466 41.6 52.2 41.6 C 41.2647619534 41.6 32.4 32.7352380466 32.4 21.8 C 32.4 10.8647619534 41.2647619534 2 52.2 2 Z" /> +</vector> diff --git a/res/values/strings.xml b/res/values/strings.xml index 424d89e24..52016e301 100755 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1189,6 +1189,8 @@ CHAR LIMIT = NONE] --> <string name="drawer_desc" translatable="false">drawer</string> <string name="truescanner_normal">Normal</string> <string name="truescanner_white">WhiteBoard</string> + <string name="truescanner">TrueScanner</string> + <string name="truescanner_remove_glare">Remove Glare</string> <string name="hazebuster_acts">Haze Buster</string> <string name="seestraight_acts">See Straight</string> <string name="seestraight_input_image_is_small">Input image is too small to process.</string> diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index b5c4b4a91..f0af615c0 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -90,6 +90,7 @@ import com.android.gallery3d.filtershow.category.EditorCropPanel; import com.android.gallery3d.filtershow.category.MainPanel; import com.android.gallery3d.filtershow.category.StraightenPanel; import com.android.gallery3d.filtershow.category.SwipableView; +import com.android.gallery3d.filtershow.category.TrueScannerPanel; import com.android.gallery3d.filtershow.data.UserPresetsManager; import com.android.gallery3d.filtershow.editors.BasicEditor; import com.android.gallery3d.filtershow.editors.Editor; @@ -410,6 +411,22 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL }.run(); return; } + if (currentId == TrueScannerEditor.ID) { + new Runnable() { + @Override + public void run() { + TrueScannerPanel panel = new TrueScannerPanel(); + FragmentTransaction transaction = + getSupportFragmentManager().beginTransaction(); + transaction.remove(getSupportFragmentManager().findFragmentByTag( + MainPanel.FRAGMENT_TAG)); + transaction.replace(R.id.main_panel_container, panel, + MainPanel.FRAGMENT_TAG); + transaction.commit(); + } + }.run(); + return; + } Runnable showEditor = new Runnable() { @Override public void run() { @@ -444,8 +461,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL } private boolean useStraightenPanel(int EditorID) { - return (EditorID == EditorStraighten.ID || EditorID == TrueScannerEditor.ID - || EditorID == HazeBusterEditor.ID || EditorID == SeeStraightEditor.ID); + return (EditorID == EditorStraighten.ID || EditorID == HazeBusterEditor.ID || EditorID == SeeStraightEditor.ID); } public void leaveSeekBarPanel() { diff --git a/src/com/android/gallery3d/filtershow/category/TrueScannerPanel.java b/src/com/android/gallery3d/filtershow/category/TrueScannerPanel.java new file mode 100644 index 000000000..535273da9 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/category/TrueScannerPanel.java @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2016, The Linux Foundation. All rights reserved. + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.android.gallery3d.filtershow.category; + + +import android.app.Activity; +import android.graphics.Bitmap; +import android.os.Bundle; +import android.view.View; +import android.support.annotation.Nullable; +import com.android.gallery3d.filtershow.FilterShowActivity; +import com.android.gallery3d.filtershow.editors.TrueScannerEditor; + +import org.codeaurora.gallery.R; + +public class TrueScannerPanel extends BasicGeometryPanel { + private TrueScannerEditor mTrueScannerEditor; + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + FilterShowActivity filterShowActivity = (FilterShowActivity) activity; + mTrueScannerEditor = (TrueScannerEditor) filterShowActivity.getEditor(TrueScannerEditor.ID); + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + mEditorName.setText(R.string.truescanner); + + mBottomPanel.setVisibility(View.VISIBLE); + mTrueScannerEditor.initCords(); + final FilterShowActivity activity = (FilterShowActivity) getActivity(); + mExitButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + activity.cancelCurrentFilter(); + activity.backToMain(); + activity.setActionBar(); + } + }); + mApplyButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + mTrueScannerEditor.finalApplyCalled(); + activity.backToMain(); + activity.setActionBar(); + } + }); + } + + @Override + protected void initPanels() { + super.initPanels(); + int size = mPanels.length; + for (int i = 0; i < size; i++) { + View view = mPanels[i]; + view.setVisibility(View.GONE); + } + } + + @Override + public void onDetach() { + if (mTrueScannerEditor != null) { + mTrueScannerEditor.detach(); + } + super.onDetach(); + } + +} diff --git a/src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java b/src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java index 5ecee6997..d184a3cdf 100644 --- a/src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java +++ b/src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java @@ -30,19 +30,27 @@ package com.android.gallery3d.filtershow.editors; import android.content.Context; +import android.graphics.Bitmap; +import android.util.Log; +import android.view.View; import android.widget.FrameLayout; +import android.widget.SeekBar; -import org.codeaurora.gallery.R; +import com.android.gallery3d.filtershow.controller.Parameter; import com.android.gallery3d.filtershow.filters.FilterBasicRepresentation; +import com.android.gallery3d.filtershow.filters.FilterRepresentation; +import com.android.gallery3d.filtershow.filters.FilterStraightenRepresentation; import com.android.gallery3d.filtershow.filters.TrueScannerActs; import com.android.gallery3d.filtershow.imageshow.ImageShow; import com.android.gallery3d.filtershow.imageshow.ImageTrueScanner; import com.android.gallery3d.filtershow.imageshow.MasterImage; +import org.codeaurora.gallery.R; + /** * The editor with no slider for filters without UI */ -public class TrueScannerEditor extends Editor { +public class TrueScannerEditor extends Editor{ public final static int ID = R.id.trueScannerEditor; private final String LOGTAG = "TrueScannerEditor"; protected ImageTrueScanner mImageTrueScanner; @@ -51,12 +59,11 @@ public class TrueScannerEditor extends Editor { super(ID); } - protected TrueScannerEditor(int id) { - super(id); - } - - public boolean useUtilityPanel() { - return true; + public void initCords() { + mImageTrueScanner.setDetectedPoints(getPoints(MasterImage.getImage().getHighresImage()), + MasterImage.getImage().getHighresImage().getWidth(), + MasterImage.getImage().getHighresImage().getHeight()); + mImageTrueScanner.invalidate(); } @Override @@ -64,10 +71,12 @@ public class TrueScannerEditor extends Editor { super.createEditor(context, frameLayout); mView = mImageShow = mImageTrueScanner = new ImageTrueScanner(context); mImageTrueScanner.setEditor(this); + mImageTrueScanner.setCordsUI(true); } @Override public void finalApplyCalled() { + mImageTrueScanner.setCordsUI(false); super.finalApplyCalled(); } @@ -81,4 +90,5 @@ public class TrueScannerEditor extends Editor { return false; } + private native int[] getPoints(Bitmap orgBitmap); } diff --git a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java index 4a2e2d830..e6ac0a6ef 100644 --- a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java +++ b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java @@ -163,7 +163,6 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { protected void addTrueScannerClasses(Vector<Class> filters) { filters.add(TrueScannerActs.class); - filters.add(TrueScannerWhiteBoardActs.class); } protected void addHazeBusterClasses(Vector<Class> filters) { @@ -368,7 +367,6 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { public void addTrueScanner() { mTrueScanner.add(getRepresentation(TrueScannerActs.class)); - mTrueScanner.add(getRepresentation(TrueScannerWhiteBoardActs.class)); } public void addHazeBuster() { diff --git a/src/com/android/gallery3d/filtershow/filters/SeeStraightActs.java b/src/com/android/gallery3d/filtershow/filters/SeeStraightActs.java index 664b7b8b5..047c036f7 100644 --- a/src/com/android/gallery3d/filtershow/filters/SeeStraightActs.java +++ b/src/com/android/gallery3d/filtershow/filters/SeeStraightActs.java @@ -40,7 +40,8 @@ public class SeeStraightActs extends SimpleImageFilter { public static final String SERIALIZATION_NAME = "SeeStraightActs"; private static final int MIN_WIDTH = 512; private static final int MIN_HEIGHT = 512; - private static final int MIN_INPUT_REQUIREMENT = 640; + private static final int MIN_WIDTH_REQUIREMENT = 640; + private static final int MIN_HEIGHT_REQUIREMENT = 480; private static final boolean DEBUG = true; private static boolean isSeeStraightEnabled = true; @@ -75,6 +76,19 @@ public class SeeStraightActs extends SimpleImageFilter { private native int[] processImage(int width, int height, Bitmap srcBitmap, Bitmap dstBitmap); + private boolean checkSize(int w, int h) { + int t; + if(w < h) { + t = w; + w = h; + h = t; + } + if(w >= MIN_WIDTH_REQUIREMENT && h >= MIN_HEIGHT_REQUIREMENT) { + return true; + } + return false; + } + @Override public Bitmap apply(Bitmap bitmap, float not_use, int quality) { if(bitmap == null) @@ -85,7 +99,7 @@ public class SeeStraightActs extends SimpleImageFilter { if(width <= MIN_WIDTH && height <= MIN_HEIGHT) return bitmap; - if(width <= MIN_INPUT_REQUIREMENT || height <= MIN_INPUT_REQUIREMENT) { + if(!checkSize(width, height)) { sActivity.runOnUiThread(new Runnable() { public void run() { Toast.makeText(sActivity, sActivity.getResources().getString(R.string.seestraight_input_image_is_small), Toast.LENGTH_SHORT).show(); diff --git a/src/com/android/gallery3d/filtershow/filters/TrueScannerActs.java b/src/com/android/gallery3d/filtershow/filters/TrueScannerActs.java index 143d4ddf6..da6e538ab 100644 --- a/src/com/android/gallery3d/filtershow/filters/TrueScannerActs.java +++ b/src/com/android/gallery3d/filtershow/filters/TrueScannerActs.java @@ -29,17 +29,21 @@ package com.android.gallery3d.filtershow.filters; +import android.app.ProgressDialog; import android.graphics.Bitmap; import android.util.Log; +import android.view.View; +import android.widget.SeekBar; import android.widget.Toast; import org.codeaurora.gallery.R; import com.android.gallery3d.app.GalleryActivity; import com.android.gallery3d.filtershow.FilterShowActivity; +import com.android.gallery3d.filtershow.controller.Parameter; import com.android.gallery3d.filtershow.editors.TrueScannerEditor; import com.android.gallery3d.filtershow.imageshow.ImageTrueScanner; import com.android.gallery3d.filtershow.imageshow.MasterImage; - +import com.android.gallery3d.ui.MenuExecutor; import static com.android.gallery3d.filtershow.imageshow.ImageTrueScanner.*; public class TrueScannerActs extends SimpleImageFilter { @@ -54,8 +58,8 @@ public class TrueScannerActs extends SimpleImageFilter { protected boolean isWhiteBoard = false; private boolean mLocked = false; private Bitmap rectifiedImage = null; - private Bitmap whiteboardImage = null; private int[] oldPts = new int[POINTS_LEN]; + private ProgressDialog mProgressDialog; private void printDebug(String str) { if(DEBUG) @@ -87,14 +91,8 @@ public class TrueScannerActs extends SimpleImageFilter { return representation; } - private native int[] processImage(Bitmap orgBitmap, Bitmap rectifiedBitmap, Bitmap whiteboardBitmap, int[] cornerPts); - private native int[] getPoints(Bitmap orgBitmap); - - public static int[] getPoints() { - if(!isPointsAcquired) - return null; - return mAcquiredPoints; - } + private native int[] processImage(Bitmap orgBitmap, Bitmap rectifiedBitmap, int[] cornerPts); + private native int enhanceImage(Bitmap orgBitmap, Bitmap rectifiedBitmap); private synchronized boolean acquireLock(boolean isAcquiring) { if(mLocked != isAcquiring) { @@ -104,28 +102,35 @@ public class TrueScannerActs extends SimpleImageFilter { return false; } - private boolean isReNewed(int pts[]) { - if(rectifiedImage == null || whiteboardImage == null) { - return true; - } else { - for(int i=0; i<oldPts.length;i++) { - if(pts[i] != oldPts[i]) { - return true; - } + private void showProgressDialog() { + sActivity.runOnUiThread(new Runnable() { + public void run() { + mProgressDialog = ProgressDialog.show(sActivity,"", "Processing...", true, false); + mProgressDialog.show(); } - } + }); + } - return false; + private void dismissProgressDialog() { + sActivity.runOnUiThread(new Runnable() { + public void run() { + if (mProgressDialog != null && mProgressDialog.isShowing()) { + mProgressDialog.dismiss(); + mProgressDialog = null; + } + } + }); } @Override public Bitmap apply(Bitmap bitmap, float not_use, int quality) { if(bitmap == null) return null; - if(bitmap.getWidth() <= MIN_WIDTH && bitmap.getHeight() <= MIN_HEIGHT) return bitmap; - + if(ImageTrueScanner.getCordsUIState()) { + return bitmap; + } if(!acquireLock(true)) { sActivity.runOnUiThread(new Runnable() { @Override @@ -136,17 +141,7 @@ public class TrueScannerActs extends SimpleImageFilter { return bitmap; } - - if(!isPointsAcquired) { - int[] recPoints = getPoints(bitmap); - for(int i=0; i < POINTS_LEN; i++) { - mAcquiredPoints[i] = recPoints[i]; - } - mAcquiredPoints[POINTS_LEN] = bitmap.getWidth(); - mAcquiredPoints[POINTS_LEN+1] = bitmap.getHeight(); - isPointsAcquired = true; - } - + new Throwable().printStackTrace(); int[] pts = ImageTrueScanner.getDeterminedPoints(); int[] resultPts = new int[POINTS_LEN]; float xScale = ((float)bitmap.getWidth())/pts[POINTS_LEN]; @@ -158,24 +153,24 @@ public class TrueScannerActs extends SimpleImageFilter { resultPts[i] = (int)((pts[i] - pts[POINTS_LEN+3])*yScale); } - if(isReNewed(pts)) { - rectifiedImage = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); - whiteboardImage = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); - int[] outputSize = processImage(bitmap, rectifiedImage, whiteboardImage, resultPts); - rectifiedImage = Bitmap.createBitmap(rectifiedImage, 0, 0, outputSize[0], outputSize[1]); - whiteboardImage = Bitmap.createBitmap(whiteboardImage, 0, 0, outputSize[2], outputSize[3]); + rectifiedImage = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); + int[] outputSize = processImage(bitmap, rectifiedImage, resultPts); + rectifiedImage = Bitmap.createBitmap(rectifiedImage, 0, 0, outputSize[0], outputSize[1]); + if(ImageTrueScanner.getRemoveGlareButtonStatus()) { + Bitmap enhancedImage = Bitmap.createBitmap(outputSize[0], outputSize[1], Bitmap.Config.ARGB_8888); + showProgressDialog(); + enhanceImage(rectifiedImage, enhancedImage); + dismissProgressDialog(); + rectifiedImage = enhancedImage; } - acquireLock(false); - if(isWhiteBoard) - return whiteboardImage; return rectifiedImage; } static { try { - System.loadLibrary("jni_truescanner"); + System.loadLibrary("jni_truescanner_v2"); isTrueScannerEnabled = true; } catch(UnsatisfiedLinkError e) { isTrueScannerEnabled = false; diff --git a/src/com/android/gallery3d/filtershow/filters/TrueScannerWhiteBoardActs.java b/src/com/android/gallery3d/filtershow/filters/TrueScannerWhiteBoardActs.java index 62f68b2a5..a403c24fe 100644 --- a/src/com/android/gallery3d/filtershow/filters/TrueScannerWhiteBoardActs.java +++ b/src/com/android/gallery3d/filtershow/filters/TrueScannerWhiteBoardActs.java @@ -34,6 +34,7 @@ import org.codeaurora.gallery.R; import com.android.gallery3d.filtershow.editors.TrueScannerEditor; public class TrueScannerWhiteBoardActs extends TrueScannerActs { + public static final String SERIALIZATION_NAME = "TrueScannerWhiteBoardActs"; public TrueScannerWhiteBoardActs() { super(); diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageTrueScanner.java b/src/com/android/gallery3d/filtershow/imageshow/ImageTrueScanner.java index de077afed..9d8e36d07 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageTrueScanner.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageTrueScanner.java @@ -32,16 +32,17 @@ package com.android.gallery3d.filtershow.imageshow; import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; +import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; +import android.graphics.Path; import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; import android.view.MotionEvent; - import com.android.gallery3d.filtershow.crop.CropDrawingUtils; import com.android.gallery3d.filtershow.crop.CropMath; import com.android.gallery3d.filtershow.crop.CropObject; @@ -49,6 +50,8 @@ import com.android.gallery3d.filtershow.editors.TrueScannerEditor; import com.android.gallery3d.filtershow.filters.FilterCropRepresentation; import com.android.gallery3d.filtershow.filters.TrueScannerActs; +import org.codeaurora.gallery.R; + public class ImageTrueScanner extends ImageShow { private static final String TAG = ImageTrueScanner.class.getSimpleName(); TrueScannerEditor mEditor; @@ -60,11 +63,20 @@ public class ImageTrueScanner extends ImageShow { private RectF mBitmapBound = new RectF(); private Bitmap mBitmap; private Paint mSegmentPaint; + private Paint mGlareRemovalTextPaint; + private int mGlareButtonX = -1000; + private int mGlareButtonY = -1000; private final static float RADIUS = 20f; private final static float CHECK_RADIUS = 100f; private int mMarginalGapX = 10; private int mMarginalGapY = 10; - private boolean isPointsAcquired = false; + private boolean isDetectedPointsApplied = false; + private static boolean mIsCordsUIShowing = true; + private int[] mDetectedPoints = null; + private static boolean mIsGlareButtonPressed = false; + private Paint mGrayPaint; + private Bitmap mGlareButtonOnBitmap; + private Bitmap mGlareButtonOffBitmap; public ImageTrueScanner(Context context) { super(context); @@ -85,14 +97,42 @@ public class ImageTrueScanner extends ImageShow { return mSegPoints; } + public static boolean getRemoveGlareButtonStatus() { + return mIsGlareButtonPressed; + } + private void init() { - mBitmap = MasterImage.getImage().getFiltersOnlyImage(); + mBitmap = MasterImage.getImage().getHighresImage(); + mMarginalGapX = mBitmap.getWidth()/4; mMarginalGapY = mBitmap.getHeight()/4; mGeometry = new GeometryMathUtils.GeometryHolder(); mSegmentPaint = new Paint(); mSegmentPaint.setColor(Color.CYAN); + mSegmentPaint.setStyle(Paint.Style.FILL_AND_STROKE); + mGlareRemovalTextPaint = new Paint(); + mGlareRemovalTextPaint.setColor(Color.CYAN); + mGlareRemovalTextPaint.setTextSize(35); + + mGrayPaint = new Paint(); + mGrayPaint.setStyle(Paint.Style.FILL_AND_STROKE); + mGrayPaint.setColor(Color.argb(120, 0, 0, 0)); //Gray + mIsGlareButtonPressed = false; + + + Drawable d = getResources().getDrawable(R.drawable.ic_glare_remove_button_on); + mGlareButtonOnBitmap = getBitmap(d, 76, 46); + d = getResources().getDrawable(R.drawable.ic_glare_remove_button_off); + mGlareButtonOffBitmap = getBitmap(d, 76, 46); + } + + private Bitmap getBitmap(Drawable d, int width, int height) { + Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + d.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + d.draw(canvas); + return bitmap; } private void checkPointTouch(float x, float y) { @@ -102,6 +142,10 @@ public class ImageTrueScanner extends ImageShow { isTouched[i] = true; } } + if( x > mGlareButtonX - CHECK_RADIUS*2 && x < mGlareButtonX + CHECK_RADIUS*2 && + y > mGlareButtonY - CHECK_RADIUS*2 && y < mGlareButtonY + CHECK_RADIUS*2) { + mIsGlareButtonPressed = !mIsGlareButtonPressed; + } } private void moveTouch(float x, float y) { @@ -116,36 +160,36 @@ public class ImageTrueScanner extends ImageShow { switch(i) { case 0: - if(mSegPoints[0] < mBitmapBound.left) mSegPoints[0] = (int)mBitmapBound.left; if(mSegPoints[0] >= mSegPoints[2]-mMarginalGapX) mSegPoints[0] = mSegPoints[2]-mMarginalGapX; - if(mSegPoints[1] < mBitmapBound.top) mSegPoints[1] = (int)mBitmapBound.top; if(mSegPoints[1] >= mSegPoints[7]-mMarginalGapY) mSegPoints[1] = mSegPoints[7]-mMarginalGapY; + if(mSegPoints[0] < mBitmapBound.left) mSegPoints[0] = (int)mBitmapBound.left; + if(mSegPoints[1] < mBitmapBound.top) mSegPoints[1] = (int)mBitmapBound.top; break; case 1: - if(mSegPoints[2] > mBitmapBound.right) mSegPoints[2] = (int)mBitmapBound.right; if(mSegPoints[2] <= mSegPoints[0]+mMarginalGapX) mSegPoints[2] = mSegPoints[0]+mMarginalGapX; - if(mSegPoints[3] < mBitmapBound.top) mSegPoints[3] = (int)mBitmapBound.top; if(mSegPoints[3] >= mSegPoints[5]-mMarginalGapY) mSegPoints[3] = mSegPoints[5]-mMarginalGapY; + if(mSegPoints[2] > mBitmapBound.right) mSegPoints[2] = (int)mBitmapBound.right; + if(mSegPoints[3] < mBitmapBound.top) mSegPoints[3] = (int)mBitmapBound.top; break; case 2: - if(mSegPoints[4] > mBitmapBound.right) mSegPoints[4] = (int)mBitmapBound.right; if(mSegPoints[4] <= mSegPoints[6]+mMarginalGapX) mSegPoints[4] = mSegPoints[6]+mMarginalGapX; - if(mSegPoints[5] > mBitmapBound.bottom) mSegPoints[5] = (int)mBitmapBound.bottom; if(mSegPoints[5] <= mSegPoints[3]+mMarginalGapY) mSegPoints[5] = mSegPoints[3]+mMarginalGapY; + if(mSegPoints[4] > mBitmapBound.right) mSegPoints[4] = (int)mBitmapBound.right; + if(mSegPoints[5] > mBitmapBound.bottom) mSegPoints[5] = (int)mBitmapBound.bottom; break; case 3: - if(mSegPoints[6] < mBitmapBound.left) mSegPoints[6] = (int)mBitmapBound.left; if(mSegPoints[6] >= mSegPoints[4]-mMarginalGapX) mSegPoints[6] = mSegPoints[4]-mMarginalGapX; - if(mSegPoints[7] > mBitmapBound.bottom) mSegPoints[7] = (int)mBitmapBound.bottom; if(mSegPoints[7] <= mSegPoints[1]+mMarginalGapY) mSegPoints[7] = mSegPoints[1]+mMarginalGapY; + if(mSegPoints[6] < mBitmapBound.left) mSegPoints[6] = (int)mBitmapBound.left; + if(mSegPoints[7] > mBitmapBound.bottom) mSegPoints[7] = (int)mBitmapBound.bottom; break; } } @@ -185,17 +229,36 @@ public class ImageTrueScanner extends ImageShow { mDisplayMatrix.mapRect(mBitmapBound); } + public void setDetectedPoints(int[] pts, int width, int height) { + synchronized (this) { + mDetectedPoints = new int[10]; + for (int i = 0; i < 8; i++) { + mDetectedPoints[i] = pts[i]; + } + mDetectedPoints[8] = width; + mDetectedPoints[9] = height; + } + isDetectedPointsApplied = false; + invalidate(); + } + + private int[] getDetectedPoints() { + synchronized (this) { + return mDetectedPoints; + } + } + private void getInitialInput() { - int[] points = TrueScannerActs.getPoints(); + int[] points = getDetectedPoints(); if (points == null) { - mSegPoints[0] = (int) mBitmapBound.left; - mSegPoints[1] = (int) mBitmapBound.top; - mSegPoints[2] = (int) mBitmapBound.right; - mSegPoints[3] = (int) mBitmapBound.top; - mSegPoints[4] = (int) mBitmapBound.right; - mSegPoints[5] = (int) mBitmapBound.bottom; - mSegPoints[6] = (int) mBitmapBound.left; - mSegPoints[7] = (int) mBitmapBound.bottom; + mSegPoints[0] = (int) (mBitmapBound.centerX() - mBitmapBound.width()/4); + mSegPoints[1] = (int) (mBitmapBound.centerY() - mBitmapBound.height()/4); + mSegPoints[2] = (int) (mBitmapBound.centerX() + mBitmapBound.width()/4); + mSegPoints[3] = (int) (mBitmapBound.centerY() - mBitmapBound.height()/4); + mSegPoints[4] = (int) (mBitmapBound.centerX() + mBitmapBound.width()/4); + mSegPoints[5] = (int) (mBitmapBound.centerY() + mBitmapBound.height()/4); + mSegPoints[6] = (int) (mBitmapBound.centerX() - mBitmapBound.width()/4); + mSegPoints[7] = (int) (mBitmapBound.centerY() + mBitmapBound.height()/4); } else { float xScale = mBitmapBound.width()/points[8]; float yScale = mBitmapBound.height()/points[9]; @@ -207,7 +270,6 @@ public class ImageTrueScanner extends ImageShow { mSegPoints[5] = (int) (mBitmapBound.top + points[5]*yScale); mSegPoints[6] = (int) (mBitmapBound.left + points[6]*xScale); mSegPoints[7] = (int) (mBitmapBound.top + points[7]*yScale); - isPointsAcquired = true; } mSegPoints[8] = (int)mBitmapBound.width(); mSegPoints[9] = (int)mBitmapBound.height(); @@ -226,17 +288,78 @@ public class ImageTrueScanner extends ImageShow { mBitmap.getWidth(), mBitmap.getHeight(), canvas.getWidth(), canvas.getHeight()); getBitmapBound(); } - if(!isPointsAcquired) { + if(!isDetectedPointsApplied) { getInitialInput(); + isDetectedPointsApplied = true; } canvas.drawBitmap(mBitmap, mDisplayMatrix, null); - drawSegments(canvas); + if(mIsCordsUIShowing) { + drawSegments(canvas); + } + drawGlareRemovalButton(canvas); } - private void drawSegments(Canvas canvas) - { - for(int i=0; i<POINT_NUMS; i++) { - canvas.drawCircle(mSegPoints[i*2], mSegPoints[i*2+1], RADIUS, mSegmentPaint); + public void setCordsUI(boolean enable) { + mIsCordsUIShowing = enable; + } + + public static boolean getCordsUIState() { + return mIsCordsUIShowing; + } + + private void drawGlareRemovalButton(Canvas canvas) { + if(mGlareButtonX == -1000 && mGlareButtonY == -1000) { + mGlareButtonX = canvas.getWidth()/2; + mGlareButtonY = canvas.getHeight()*1/5; + } + RectF rectF = new RectF(); + Bitmap bitmap; + if(mIsGlareButtonPressed) { + bitmap = mGlareButtonOnBitmap; + } else { + bitmap = mGlareButtonOffBitmap; + } + rectF.left = mGlareButtonX - bitmap.getWidth()/2; + rectF.right = mGlareButtonX + bitmap.getWidth()/2; + rectF.top = mGlareButtonY - bitmap.getHeight()/2; + rectF.bottom = mGlareButtonY + bitmap.getHeight()/2; + canvas.drawBitmap(bitmap, null, rectF, null); + canvas.drawText(getResources().getString(R.string.truescanner_remove_glare), + mGlareButtonX + bitmap.getWidth()/2+RADIUS, mGlareButtonY + bitmap.getHeight() / 4, mGlareRemovalTextPaint); + } + + private void drawSegments(Canvas canvas) { + Path path = new Path(); + path.moveTo(mBitmapBound.left, mBitmapBound.top); + path.lineTo(mSegPoints[0], mSegPoints[1]); + path.lineTo(mSegPoints[2], mSegPoints[3]); + path.lineTo(mBitmapBound.right, mBitmapBound.top); + path.lineTo(mBitmapBound.left, mBitmapBound.top); + canvas.drawPath(path, mGrayPaint); + path.reset(); + path.moveTo(mBitmapBound.right, mBitmapBound.top); + path.lineTo(mSegPoints[2], mSegPoints[3]); + path.lineTo(mSegPoints[4], mSegPoints[5]); + path.lineTo(mBitmapBound.right, mBitmapBound.bottom); + path.lineTo(mBitmapBound.right, mBitmapBound.top); + canvas.drawPath(path, mGrayPaint); + path.reset(); + path.moveTo(mBitmapBound.right, mBitmapBound.bottom); + path.lineTo(mSegPoints[4], mSegPoints[5]); + path.lineTo(mSegPoints[6], mSegPoints[7]); + path.lineTo(mBitmapBound.left, mBitmapBound.bottom); + path.lineTo(mBitmapBound.right, mBitmapBound.bottom); + canvas.drawPath(path, mGrayPaint); + path.reset(); + path.moveTo(mBitmapBound.left, mBitmapBound.bottom); + path.lineTo(mSegPoints[6], mSegPoints[7]); + path.lineTo(mSegPoints[0], mSegPoints[1]); + path.lineTo(mBitmapBound.left, mBitmapBound.top); + path.lineTo(mBitmapBound.left, mBitmapBound.bottom); + canvas.drawPath(path, mGrayPaint); + + for (int i = 0; i < POINT_NUMS; i++) { + canvas.drawCircle(mSegPoints[i * 2], mSegPoints[i * 2 + 1], RADIUS, mSegmentPaint); } canvas.drawLine(mSegPoints[0], mSegPoints[1], mSegPoints[2], mSegPoints[3], mSegmentPaint); canvas.drawLine(mSegPoints[2], mSegPoints[3], mSegPoints[4], mSegPoints[5], mSegmentPaint); |
