diff options
| author | Jack Yoo <jyoo@codeaurora.org> | 2015-10-27 16:27:49 -0700 |
|---|---|---|
| committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2016-03-01 11:10:38 -0800 |
| commit | 66d214478e5f04fe2fe32026ca595ed91f7f89b1 (patch) | |
| tree | 5b0a13b4003e986d803c1ca0d5f609ef4b727a1d /src | |
| parent | 5a3b44382d3dcd218d247f7526858f1f4466bb5f (diff) | |
| download | android_packages_apps_Gallery2-66d214478e5f04fe2fe32026ca595ed91f7f89b1.tar.gz android_packages_apps_Gallery2-66d214478e5f04fe2fe32026ca595ed91f7f89b1.tar.bz2 android_packages_apps_Gallery2-66d214478e5f04fe2fe32026ca595ed91f7f89b1.zip | |
Gallery3d: TrueScanner feature
Adding TrueScanner feature
Change-Id: Ib29010f8319addf783dbdf8c91c33959bc7f56ca
CRs-Fixed: 967806
Diffstat (limited to 'src')
12 files changed, 675 insertions, 8 deletions
diff --git a/src/com/android/gallery3d/filtershow/EditorPlaceHolder.java b/src/com/android/gallery3d/filtershow/EditorPlaceHolder.java index 95fc56d4f..86cc87034 100644 --- a/src/com/android/gallery3d/filtershow/EditorPlaceHolder.java +++ b/src/com/android/gallery3d/filtershow/EditorPlaceHolder.java @@ -66,7 +66,8 @@ public class EditorPlaceHolder { } public void hide() { - mContainer.setVisibility(View.GONE); + if(mContainer != null) + mContainer.setVisibility(View.GONE); } public void hideOldViews() { diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index ab921e689..4c2e6ef67 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -94,6 +94,7 @@ import com.android.gallery3d.filtershow.editors.EditorDualCamFusion; import com.android.gallery3d.filtershow.editors.EditorManager; import com.android.gallery3d.filtershow.editors.EditorPanel; import com.android.gallery3d.filtershow.editors.ImageOnlyEditor; +import com.android.gallery3d.filtershow.editors.TrueScannerEditor; import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation; import com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation; import com.android.gallery3d.filtershow.filters.FilterRepresentation; @@ -102,6 +103,7 @@ import com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation; import com.android.gallery3d.filtershow.filters.FiltersManager; import com.android.gallery3d.filtershow.filters.ImageFilter; import com.android.gallery3d.filtershow.filters.SimpleMakeupImageFilter; +import com.android.gallery3d.filtershow.filters.TrueScannerActs; import com.android.gallery3d.filtershow.history.HistoryItem; import com.android.gallery3d.filtershow.history.HistoryManager; import com.android.gallery3d.filtershow.imageshow.ImageShow; @@ -181,6 +183,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL private CategoryAdapter mCategoryBordersAdapter = null; private CategoryAdapter mCategoryGeometryAdapter = null; private CategoryAdapter mCategoryFiltersAdapter = null; + private CategoryAdapter mCategoryTrueScannerAdapter = null; private CategoryAdapter mCategoryVersionsAdapter = null; private CategoryAdapter mCategoryMakeupAdapter = null; private CategoryAdapter mCategoryDualCamAdapter = null; @@ -571,6 +574,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL fillBorders(); fillTools(); fillEffects(); + fillTrueScanner(); fillVersions(); fillMakeup(); fillDualCamera(); @@ -696,6 +700,21 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL } } + private void fillTrueScanner() { + FiltersManager filtersManager = FiltersManager.getManager(); + ArrayList<FilterRepresentation> trueScannerRepresentations = filtersManager.getTrueScanner(); + if (mCategoryTrueScannerAdapter != null) { + mCategoryTrueScannerAdapter.clear(); + } + mCategoryTrueScannerAdapter = new CategoryAdapter(this); + for (FilterRepresentation representation : trueScannerRepresentations) { + if (representation.getTextId() != 0) { + representation.setName(getString(representation.getTextId())); + } + mCategoryTrueScannerAdapter.add(new Action(this, representation)); + } + } + private void fillTools() { FiltersManager filtersManager = FiltersManager.getManager(); ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getTools(); @@ -834,6 +853,10 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL return mCategoryFiltersAdapter; } + public CategoryAdapter getCategoryTrueScannerAdapter() { + return mCategoryTrueScannerAdapter; + } + public CategoryAdapter getCategoryVersionsAdapter() { return mCategoryVersionsAdapter; } @@ -1646,10 +1669,14 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL } public void showDefaultImageView() { - mEditorPlaceHolder.hide(); - mImageShow.setVisibility(View.VISIBLE); - MasterImage.getImage().setCurrentFilter(null); - MasterImage.getImage().setCurrentFilterRepresentation(null); + if(mEditorPlaceHolder != null) + mEditorPlaceHolder.hide(); + if(mImageShow != null) + mImageShow.setVisibility(View.VISIBLE); + if(MasterImage.getImage() != null) { + MasterImage.getImage().setCurrentFilter(null); + MasterImage.getImage().setCurrentFilterRepresentation(null); + } } public void backToMain() { diff --git a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java index 9571d8b16..83ab5b2a3 100644 --- a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java +++ b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java @@ -88,6 +88,11 @@ public class CategoryAdapter extends ArrayAdapter<Action> { if (category == MainPanel.DUALCAM) { mSelectedPosition = 0; } + + if (category == MainPanel.TRUESCANNER) { + mSelectedPosition = 0; + } + if (category == MainPanel.VERSIONS) { mAddButtonText = getContext().getString(R.string.filtershow_add_button_versions); } diff --git a/src/com/android/gallery3d/filtershow/category/CategoryPanel.java b/src/com/android/gallery3d/filtershow/category/CategoryPanel.java index 3ee9e45eb..62071f309 100644 --- a/src/com/android/gallery3d/filtershow/category/CategoryPanel.java +++ b/src/com/android/gallery3d/filtershow/category/CategoryPanel.java @@ -88,6 +88,12 @@ public class CategoryPanel extends Fragment implements View.OnClickListener { mAdapter.initializeSelection(MainPanel.DUALCAM); } activity.updateCategories(); + } + case MainPanel.TRUESCANNER: { + mAdapter = activity.getCategoryTrueScannerAdapter(); + if (mAdapter != null) { + mAdapter.initializeSelection(MainPanel.TRUESCANNER); + } break; } case MainPanel.VERSIONS: { diff --git a/src/com/android/gallery3d/filtershow/category/MainPanel.java b/src/com/android/gallery3d/filtershow/category/MainPanel.java index 0d7d6f6ce..17766dfd1 100644 --- a/src/com/android/gallery3d/filtershow/category/MainPanel.java +++ b/src/com/android/gallery3d/filtershow/category/MainPanel.java @@ -31,6 +31,7 @@ import android.util.Log; import com.android.gallery3d.R; import com.android.gallery3d.filtershow.FilterShowActivity; import com.android.gallery3d.filtershow.filters.SimpleMakeupImageFilter; +import com.android.gallery3d.filtershow.filters.TrueScannerActs; import com.android.gallery3d.filtershow.imageshow.MasterImage; import com.android.gallery3d.filtershow.state.StatePanel; import com.android.gallery3d.filtershow.tools.DualCameraNativeEngine; @@ -51,6 +52,7 @@ public class MainPanel extends Fragment { private View mEffectsTextContainer; private FrameLayout mCategoryFragment; private View mBottomView; + private ImageButton trueScannerButton; public static final String FRAGMENT_TAG = "MainPanel"; public static final String EDITOR_TAG = "coming-from-editor-panel"; @@ -61,6 +63,7 @@ public class MainPanel extends Fragment { public static final int MAKEUP = 4; public static final int DUALCAM = 5; public static final int VERSIONS = 6; + public static final int TRUESCANNER = 7; private int mCurrentSelected = -1; private int mPreviousToggleVersions = -1; @@ -98,6 +101,10 @@ public class MainPanel extends Fragment { dualCamButton.setSelected(value); break; } + case TRUESCANNER: { + //trueScannerButton.setSelected(value); + break; + } } } @@ -129,19 +136,19 @@ public class MainPanel extends Fragment { mBottomView = mMainView.findViewById(R.id.bottom_panel); mEffectsContainer = mMainView.findViewById(R.id.effectsContainer); mEffectsTextContainer = mMainView.findViewById(R.id.effectsText); - if(SimpleMakeupImageFilter.HAS_TS_MAKEUP) { + if (SimpleMakeupImageFilter.HAS_TS_MAKEUP) { makeupButton = (ImageButton) mMainView.findViewById(R.id.makeupButton); makeupButton.setVisibility(View.VISIBLE); TextView beautify = (TextView) mEffectsTextContainer .findViewById(R.id.tvBeautify); beautify.setVisibility(View.VISIBLE); } - boolean showPanel = false; + boolean showPanel = false; if (getArguments() != null) { showPanel = getArguments().getBoolean(EDITOR_TAG); } - if(makeupButton != null) { + if (makeupButton != null) { makeupButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -149,6 +156,12 @@ public class MainPanel extends Fragment { } }); } + TextView trueScannerTv = (TextView) mMainView.findViewById(R.id.tvTrueScanner); + trueScannerButton = (ImageButton) mMainView.findViewById(R.id.trueScannerButton); + if (!TrueScannerActs.isTrueScannerEnabled()) { + trueScannerTv.setVisibility(View.GONE); + trueScannerButton.setVisibility(View.GONE); + } looksButton.setOnClickListener(new View.OnClickListener() { @Override @@ -183,6 +196,13 @@ public class MainPanel extends Fragment { updateDualCameraButton(); + trueScannerButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showPanel(TRUESCANNER); + } + }); + FilterShowActivity activity = (FilterShowActivity) getActivity(); //showImageStatePanel(activity.isShowingImageStatePanel()); if (showPanel) { @@ -290,6 +310,16 @@ public class MainPanel extends Fragment { selection(mCurrentSelected, true); } + public void loadCategoryTrueScannerPanel() { + boolean fromRight = isRightAnimation(TRUESCANNER); + selection(mCurrentSelected, false); + CategoryPanel categoryPanel = new CategoryPanel(); + categoryPanel.setAdapter(TRUESCANNER); + setCategoryFragment(categoryPanel, fromRight); + mCurrentSelected = TRUESCANNER; + selection(mCurrentSelected, true); + } + public void loadCategoryFiltersPanel() { /*if (mCurrentSelected == FILTERS) { return; @@ -361,6 +391,10 @@ public class MainPanel extends Fragment { loadCategoryDualCamPanel(); break; } + case TRUESCANNER: { + loadCategoryTrueScannerPanel(); + break; + } case VERSIONS: { loadCategoryVersionsPanel(); break; diff --git a/src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java b/src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java new file mode 100644 index 000000000..30f099ca5 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/TrueScannerEditor.java @@ -0,0 +1,79 @@ +/* + * 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.editors; + +import android.content.Context; +import android.widget.FrameLayout; + +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.filters.FilterBasicRepresentation; +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; + +/** + * The editor with no slider for filters without UI + */ +public class TrueScannerEditor extends Editor { + public final static int ID = R.id.trueScannerEditor; + private final String LOGTAG = "TrueScannerEditor"; + protected ImageTrueScanner mImageTrueScanner; + + public TrueScannerEditor() { + super(ID); + } + + protected TrueScannerEditor(int id) { + super(id); + } + + public boolean useUtilityPanel() { + return true; + } + + @Override + public void createEditor(Context context, FrameLayout frameLayout) { + super.createEditor(context, frameLayout); + mView = mImageShow = mImageTrueScanner = new ImageTrueScanner(context); + mImageTrueScanner.setEditor(this); + } + + @Override + public void finalApplyCalled() { + super.finalApplyCalled(); + } + + @Override + public boolean showsSeekBar() { + return false; + } + +} diff --git a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java index 3de93cf5a..9970cfa65 100644 --- a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java +++ b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java @@ -39,6 +39,7 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { protected ArrayList<FilterRepresentation> mEffects = new ArrayList<FilterRepresentation>(); protected ArrayList<FilterRepresentation> mMakeup = new ArrayList<FilterRepresentation>(); protected ArrayList<FilterRepresentation> mDualCam = new ArrayList<FilterRepresentation>(); + protected ArrayList<FilterRepresentation> mTrueScanner = new ArrayList<FilterRepresentation>(); private static int mImageBorderSize = 4; // in percent protected void init() { @@ -46,6 +47,7 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { mRepresentationLookup = new HashMap<String, FilterRepresentation>(); Vector<Class> filters = new Vector<Class>(); addFilterClasses(filters); + addTrueScannerClasses(filters); for (Class filterClass : filters) { try { Object filterInstance = filterClass.newInstance(); @@ -155,6 +157,11 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { } } + protected void addTrueScannerClasses(Vector<Class> filters) { + filters.add(TrueScannerActs.class); + filters.add(TrueScannerWhiteBoardActs.class); + } + public ArrayList<FilterRepresentation> getLooks() { return mLooks; } @@ -178,6 +185,9 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { public ArrayList<FilterRepresentation> getMakeup() { return mMakeup; } + public ArrayList<FilterRepresentation> getTrueScanner() { + return mTrueScanner; + } public void addBorders(Context context) { // Do not localize @@ -335,6 +345,11 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { } } + public void addTrueScanner() { + mTrueScanner.add(getRepresentation(TrueScannerActs.class)); + mTrueScanner.add(getRepresentation(TrueScannerWhiteBoardActs.class)); + } + public void addTools(Context context) { int[] textId = { diff --git a/src/com/android/gallery3d/filtershow/filters/TrueScannerActs.java b/src/com/android/gallery3d/filtershow/filters/TrueScannerActs.java new file mode 100644 index 000000000..63c3a1299 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/TrueScannerActs.java @@ -0,0 +1,184 @@ +/* + * 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.filters; + +import android.graphics.Bitmap; +import android.util.Log; +import android.widget.Toast; + +import com.android.gallery3d.R; +import com.android.gallery3d.app.GalleryActivity; +import com.android.gallery3d.filtershow.FilterShowActivity; +import com.android.gallery3d.filtershow.editors.TrueScannerEditor; +import com.android.gallery3d.filtershow.imageshow.ImageTrueScanner; +import com.android.gallery3d.filtershow.imageshow.MasterImage; + +import static com.android.gallery3d.filtershow.imageshow.ImageTrueScanner.*; + +public class TrueScannerActs extends SimpleImageFilter { + public static final String SERIALIZATION_NAME = "TrueScannerActs"; + private static final int MIN_WIDTH = 512; + private static final int MIN_HEIGHT = 512; + private static final boolean DEBUG = false; + private static boolean isTrueScannerEnabled = true; + private static boolean isPointsAcquired; + private final static int POINTS_LEN = 8; + private static int[] mAcquiredPoints = new int[POINTS_LEN+2]; + protected boolean isWhiteBoard = false; + private boolean mLocked = false; + private Bitmap rectifiedImage = null; + private Bitmap whiteboardImage = null; + private int[] oldPts = new int[POINTS_LEN]; + + private void printDebug(String str) { + if(DEBUG) + android.util.Log.d("TrueScanner", str); + } + + public static boolean isTrueScannerEnabled() { + return isTrueScannerEnabled; + } + + public TrueScannerActs() { + mName = "TrueScannerActs"; + isPointsAcquired = false; + } + + public FilterRepresentation getDefaultRepresentation() { + FilterBasicRepresentation representation = (FilterBasicRepresentation) super.getDefaultRepresentation(); + representation.setName("TrueScanner"); + representation.setSerializationName(SERIALIZATION_NAME); + representation.setFilterClass(TrueScannerActs.class); + representation.setTextId(R.string.truescanner_normal); + representation.setMinimum(0); + representation.setMaximum(10); + representation.setValue(0); + representation.setDefaultValue(0); + representation.setSupportsPartialRendering(false); + representation.setEditorId(TrueScannerEditor.ID); + + 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 synchronized boolean acquireLock(boolean isAcquiring) { + if(mLocked != isAcquiring) { + mLocked = isAcquiring; + return true; + } + 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; + } + } + } + + return false; + } + + @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(!acquireLock(true)) { + sActivity.runOnUiThread(new Runnable() { + @Override + public void run() { + Toast.makeText(sActivity, "Still processing the previous request... ", Toast.LENGTH_LONG).show(); + } + }); + + 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; + } + + int[] pts = ImageTrueScanner.getDeterminedPoints(); + int[] resultPts = new int[POINTS_LEN]; + float xScale = ((float)bitmap.getWidth())/pts[POINTS_LEN]; + float yScale = ((float)bitmap.getHeight())/pts[POINTS_LEN+1]; + for(int i=0; i < POINTS_LEN; i++) { + if(i%2 == 0) + resultPts[i] = (int)((pts[i] - pts[POINTS_LEN+2])*xScale); + else + 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]); + } + + acquireLock(false); + if(isWhiteBoard) + return whiteboardImage; + + return rectifiedImage; + } + + static { + try { + System.loadLibrary("jni_truescanner"); + 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 new file mode 100644 index 000000000..9b4eedb4e --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/TrueScannerWhiteBoardActs.java @@ -0,0 +1,63 @@ +/* + * 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.filters; + +import android.graphics.Bitmap; +import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.editors.TrueScannerEditor; + +public class TrueScannerWhiteBoardActs extends TrueScannerActs { + + public TrueScannerWhiteBoardActs() { + super(); + isWhiteBoard = true; + } + + public FilterRepresentation getDefaultRepresentation() { + FilterBasicRepresentation representation = (FilterBasicRepresentation) super.getDefaultRepresentation(); + representation.setName("TrueScannerWhiteBoard"); + representation.setSerializationName(SERIALIZATION_NAME); + representation.setFilterClass(TrueScannerWhiteBoardActs.class); + representation.setTextId(R.string.truescanner_white); + representation.setMinimum(0); + representation.setMaximum(10); + representation.setValue(0); + representation.setDefaultValue(0); + representation.setSupportsPartialRendering(false); + representation.setEditorId(TrueScannerEditor.ID); + + return representation; + } + + @Override + public Bitmap apply(Bitmap bitmap, float not_use, int quality) { + return super.apply(bitmap, not_use, quality); + } +} diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java b/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java index d6f7e228b..adbb63da5 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java @@ -1034,6 +1034,8 @@ public class ImageShow extends View implements OnGestureListener, public void scaleImage(boolean isScaled, Context context) { float scale = 1.0f; Bitmap bitmap = MasterImage.getImage().getOriginalBitmapLarge(); + if(bitmap == null) + return; int bitmapWidth = bitmap.getWidth(); int bitmapheight = bitmap.getHeight(); diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageTrueScanner.java b/src/com/android/gallery3d/filtershow/imageshow/ImageTrueScanner.java new file mode 100644 index 000000000..c11729ae8 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageTrueScanner.java @@ -0,0 +1,249 @@ +/* + * 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.imageshow; + +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Matrix; +import android.graphics.Paint; +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; +import com.android.gallery3d.filtershow.editors.TrueScannerEditor; +import com.android.gallery3d.filtershow.filters.FilterCropRepresentation; +import com.android.gallery3d.filtershow.filters.TrueScannerActs; + +public class ImageTrueScanner extends ImageShow { + private static final String TAG = ImageTrueScanner.class.getSimpleName(); + TrueScannerEditor mEditor; + private Matrix mDisplayMatrix; + private GeometryMathUtils.GeometryHolder mGeometry; + public final static int POINT_NUMS = 4; + private static int[] mSegPoints = new int[POINT_NUMS*2+4]; + private boolean[] isTouched = new boolean[POINT_NUMS]; + private RectF mBitmapBound = new RectF(); + private Bitmap mBitmap; + private Paint mSegmentPaint; + 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; + + public ImageTrueScanner(Context context) { + super(context); + init(); + } + + public ImageTrueScanner(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public ImageTrueScanner(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + init(); + } + + public static int[] getDeterminedPoints() { + return mSegPoints; + } + + private void init() { + mBitmap = MasterImage.getImage().getFiltersOnlyImage(); + mMarginalGapX = mBitmap.getWidth()/4; + mMarginalGapY = mBitmap.getHeight()/4; + mGeometry = new GeometryMathUtils.GeometryHolder(); + + mSegmentPaint = new Paint(); + mSegmentPaint.setColor(Color.CYAN); + } + + private void checkPointTouch(float x, float y) { + for(int i=0; i<POINT_NUMS; i++) { + if ( x > mSegPoints[i*2] - CHECK_RADIUS && x < mSegPoints[i*2] + CHECK_RADIUS + && y > mSegPoints[i*2+1] - CHECK_RADIUS && y < mSegPoints[i*2+1] + CHECK_RADIUS) { + isTouched[i] = true; + } + } + } + + private void moveTouch(float x, float y) { + int i; + for(i=0; i<POINT_NUMS; i++) { + if(isTouched[i]) { + mSegPoints[i*2] = (int) x; + mSegPoints[i*2+1] = (int) y; + break; + } + } + 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; + 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; + 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; + 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; + break; + } + } + + @Override + public boolean onTouchEvent(MotionEvent event) { + float x = event.getX(); + float y = event.getY(); + + switch (event.getActionMasked()) { + case (MotionEvent.ACTION_DOWN): + checkPointTouch(x, y); + case (MotionEvent.ACTION_MOVE): + moveTouch(x,y); + break; + case (MotionEvent.ACTION_UP): + for(int i=0; i<POINT_NUMS; i++) { + isTouched[i] = false; + } + break; + } + + invalidate(); + return true; + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + } + + private void getBitmapBound() { + mBitmapBound.left = 0; + mBitmapBound.right = mBitmap.getWidth(); + mBitmapBound.top = 0; + mBitmapBound.bottom = mBitmap.getHeight(); + mDisplayMatrix.mapRect(mBitmapBound); + } + + private void getInitialInput() { + int[] points = TrueScannerActs.getPoints(); + 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; + } else { + float xScale = mBitmapBound.width()/points[8]; + float yScale = mBitmapBound.height()/points[9]; + mSegPoints[0] = (int) (mBitmapBound.left + points[0]*xScale); + mSegPoints[1] = (int) (mBitmapBound.top + points[1]*yScale); + mSegPoints[2] = (int) (mBitmapBound.left + points[2]*xScale); + mSegPoints[3] = (int) (mBitmapBound.top + points[3]*yScale); + mSegPoints[4] = (int) (mBitmapBound.left + points[4]*xScale); + 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(); + mSegPoints[10] = (int)mBitmapBound.left; + mSegPoints[11] = (int)mBitmapBound.top; + } + + @Override + public void onDraw(Canvas canvas) { + if(mBitmap == null) + return; + + if(mDisplayMatrix == null) { + mDisplayMatrix = GeometryMathUtils.getFullGeometryToScreenMatrix(mGeometry, + mBitmap.getWidth(), mBitmap.getHeight(), canvas.getWidth(), canvas.getHeight()); + getBitmapBound(); + } + if(!isPointsAcquired) { + getInitialInput(); + } + canvas.drawBitmap(mBitmap, mDisplayMatrix, null); + drawSegments(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); + } + canvas.drawLine(mSegPoints[0], mSegPoints[1], mSegPoints[2], mSegPoints[3], mSegmentPaint); + canvas.drawLine(mSegPoints[2], mSegPoints[3], mSegPoints[4], mSegPoints[5], mSegmentPaint); + canvas.drawLine(mSegPoints[4], mSegPoints[5], mSegPoints[6], mSegPoints[7], mSegmentPaint); + canvas.drawLine(mSegPoints[0], mSegPoints[1], mSegPoints[6], mSegPoints[7], mSegmentPaint); + } + + public void setEditor(TrueScannerEditor editor) { + mEditor = editor; + } +} diff --git a/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java b/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java index c645c3b29..899dc13c8 100644 --- a/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java +++ b/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java @@ -309,6 +309,7 @@ public class ProcessingService extends Service { filtersManager.addEffects(); filtersManager.addDualCam(this); filtersManager.addMakeups(this); + filtersManager.addTrueScanner(); FiltersManager highresFiltersManager = FiltersManager.getHighresManager(); highresFiltersManager.addLooks(this); @@ -317,6 +318,7 @@ public class ProcessingService extends Service { highresFiltersManager.addEffects(); highresFiltersManager.addDualCam(this); // highresFiltersManager.addMakeups(this); + highresFiltersManager.addTrueScanner(); } private void tearDownPipeline() { |
