diff options
Diffstat (limited to 'src/com/android/gallery3d/filtershow')
39 files changed, 595 insertions, 93 deletions
diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index e627a612b..fe383cef7 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -84,6 +84,7 @@ import com.android.gallery3d.filtershow.editors.EditorColorBorder; import com.android.gallery3d.filtershow.editors.EditorCrop; import com.android.gallery3d.filtershow.editors.EditorDraw; import com.android.gallery3d.filtershow.editors.EditorGrad; +import com.android.gallery3d.filtershow.editors.EditorMakeup; import com.android.gallery3d.filtershow.editors.EditorManager; import com.android.gallery3d.filtershow.editors.EditorMirror; import com.android.gallery3d.filtershow.editors.EditorPanel; @@ -100,6 +101,7 @@ import com.android.gallery3d.filtershow.filters.FilterStraightenRepresentation; 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.history.HistoryItem; import com.android.gallery3d.filtershow.history.HistoryManager; import com.android.gallery3d.filtershow.imageshow.ImageShow; @@ -120,6 +122,7 @@ import com.android.gallery3d.filtershow.ui.ExportDialog; import com.android.gallery3d.filtershow.ui.FramedTextButton; import com.android.gallery3d.util.GalleryUtils; import com.android.photos.data.GalleryBitmapPool; +import com.thundersoft.hz.selfportrait.makeup.engine.MakeupEngine; import java.io.File; import java.io.FileDescriptor; @@ -178,6 +181,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL private CategoryAdapter mCategoryGeometryAdapter = null; private CategoryAdapter mCategoryFiltersAdapter = null; private CategoryAdapter mCategoryVersionsAdapter = null; + private CategoryAdapter mCategoryMakeupAdapter = null; private int mCurrentPanel = MainPanel.LOOKS; private Vector<FilterUserPresetRepresentation> mVersions = new Vector<FilterUserPresetRepresentation>(); @@ -195,6 +199,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL private DialogInterface mCurrentDialog = null; private PopupMenu mCurrentMenu = null; private boolean mLoadingVisible = true; + private boolean mLoadingComplete = false; public ProcessingService getProcessingService() { return mBoundService; @@ -283,6 +288,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL doBindService(); getWindow().setBackgroundDrawable(new ColorDrawable(Color.GRAY)); setContentView(R.layout.filtershow_splashscreen); + mLoadingComplete = false; } public boolean isShowingImageStatePanel() { @@ -351,8 +357,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL ActionBar actionBar = getActionBar(); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); actionBar.setCustomView(R.layout.filtershow_actionbar); - actionBar.setBackgroundDrawable(new ColorDrawable( - getResources().getColor(R.color.background_screen))); mSaveButton = actionBar.getCustomView(); mSaveButton.setOnClickListener(new OnClickListener() { @@ -380,6 +384,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL fillTools(); fillEffects(); fillVersions(); + fillMakeup(); } public void setupStatePanel() { @@ -468,6 +473,25 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL } } + private void fillMakeup() { + if(!SimpleMakeupImageFilter.HAS_TS_MAKEUP) { + return; + } + + FiltersManager filtersManager = FiltersManager.getManager(); + ArrayList<FilterRepresentation> makeups = filtersManager.getMakeup(); + if (mCategoryMakeupAdapter != null) { + mCategoryMakeupAdapter.clear(); + } + mCategoryMakeupAdapter = new CategoryAdapter(this); + for (FilterRepresentation makeup : makeups) { + if (makeup.getTextId() != 0) { + makeup.setName(getString(makeup.getTextId())); + } + mCategoryMakeupAdapter.add(new Action(this, makeup)); + } + } + private void fillTools() { FiltersManager filtersManager = FiltersManager.getManager(); ArrayList<FilterRepresentation> filtersRepresentations = filtersManager.getTools(); @@ -483,7 +507,8 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL } } if (!found) { - FilterRepresentation representation = new FilterDrawRepresentation(); + FilterRepresentation representation = + new FilterDrawRepresentation(getString(R.string.imageDraw)); Action action = new Action(this, representation); action.setIsDoubleAction(true); mCategoryGeometryAdapter.add(action); @@ -528,6 +553,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL mEditorPlaceHolder.addEditor(new EditorMirror()); mEditorPlaceHolder.addEditor(new EditorRotate()); mEditorPlaceHolder.addEditor(new EditorStraighten()); + mEditorPlaceHolder.addEditor(new EditorMakeup()); } private void setDefaultValues() { @@ -558,24 +584,15 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL private void fillBorders() { FiltersManager filtersManager = FiltersManager.getManager(); ArrayList<FilterRepresentation> borders = filtersManager.getBorders(); + mCategoryBordersAdapter = new CategoryAdapter(this); for (int i = 0; i < borders.size(); i++) { FilterRepresentation filter = borders.get(i); - filter.setName(getString(R.string.borders)); + filter.setName(getString(R.string.borders) + "" + i); if (i == 0) { filter.setName(getString(R.string.none)); } - } - - if (mCategoryBordersAdapter != null) { - mCategoryBordersAdapter.clear(); - } - mCategoryBordersAdapter = new CategoryAdapter(this); - for (FilterRepresentation representation : borders) { - if (representation.getTextId() != 0) { - representation.setName(getString(representation.getTextId())); - } - mCategoryBordersAdapter.add(new Action(this, representation, Action.FULL_VIEW)); + mCategoryBordersAdapter.add(new Action(this, filter, Action.FULL_VIEW)); } } @@ -591,6 +608,10 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL return mCategoryBordersAdapter; } + public CategoryAdapter getCategoryMakeupAdapter() { + return mCategoryMakeupAdapter; + } + public CategoryAdapter getCategoryGeometryAdapter() { return mCategoryGeometryAdapter; } @@ -744,16 +765,16 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL MasterImage master = MasterImage.getImage(); Rect originalBounds = master.getOriginalBounds(); if (master.supportsHighRes()) { - int highresPreviewSize = master.getOriginalBitmapLarge().getWidth() * 2; - if (highresPreviewSize > originalBounds.width()) { - highresPreviewSize = originalBounds.width(); - } + int highresPreviewSize = Math.min(MasterImage.MAX_BITMAP_DIM, getScreenImageSize()); + Log.d(LOGTAG, "FilterShowActivity.LoadHighresBitmapTask.doInBackground(): after, highresPreviewSize is " + highresPreviewSize); Rect bounds = new Rect(); Bitmap originalHires = ImageLoader.loadOrientedConstrainedBitmap(master.getUri(), master.getActivity(), highresPreviewSize, master.getOrientation(), bounds); master.setOriginalBounds(bounds); master.setOriginalBitmapHighres(originalHires); + Log.d(LOGTAG, "FilterShowActivity.LoadHighresBitmapTask.doInBackground(): originalHires.WH is (" + originalHires.getWidth() + + ", " + originalHires.getHeight() +"), bounds is " + bounds.toString()); mBoundService.setOriginalBitmapHighres(originalHires); master.warnListeners(); } @@ -766,6 +787,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL if (highresBitmap != null) { float highResPreviewScale = (float) highresBitmap.getWidth() / (float) MasterImage.getImage().getOriginalBounds().width(); + Log.d(LOGTAG, "FilterShowActivity.LoadHighresBitmapTask.onPostExecute(): highResPreviewScale is " + highResPreviewScale); mBoundService.setHighresPreviewScaleFactor(highResPreviewScale); } MasterImage.getImage().warnListeners(); @@ -793,6 +815,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL public LoadBitmapTask() { mBitmapSize = getScreenImageSize(); + Log.d(LOGTAG, "FilterShowActivity.LoadBtimapTask(): mBitmapSize is " + mBitmapSize); } @Override @@ -849,6 +872,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL float previewScale = (float) largeBitmap.getWidth() / (float) MasterImage.getImage().getOriginalBounds().width(); + Log.d(LOGTAG, "FilterShowActivity.LoadBitmapTask.onPostExecute(): previewScale is " + previewScale); mBoundService.setPreviewScaleFactor(previewScale); if (!mShowingTinyPlanet) { mCategoryFiltersAdapter.removeTinyPlanet(); @@ -857,10 +881,14 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL mCategoryBordersAdapter.imageLoaded(); mCategoryGeometryAdapter.imageLoaded(); mCategoryFiltersAdapter.imageLoaded(); + if(mCategoryMakeupAdapter != null) { + mCategoryMakeupAdapter.imageLoaded(); + } mLoadBitmapTask = null; MasterImage.getImage().warnListeners(); loadActions(); + mLoadingComplete = false; if (mOriginalPreset != null) { MasterImage.getImage().setLoadedPreset(mOriginalPreset); @@ -1030,6 +1058,9 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL if (mShareActionProvider != null) { mShareActionProvider.setOnShareTargetSelectedListener(this); } + if(SimpleMakeupImageFilter.HAS_TS_MAKEUP) { + MakeupEngine.getMakeupObj().setContext(getBaseContext()); + } } @Override @@ -1162,6 +1193,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL } public void enableSave(boolean enable) { + mLoadingComplete = true; if (mSaveButton != null) { mSaveButton.setEnabled(enable); } @@ -1329,6 +1361,10 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL Fragment currentPanel = getSupportFragmentManager().findFragmentByTag(MainPanel.FRAGMENT_TAG); if (currentPanel instanceof MainPanel) { if (!mImageShow.hasModifications()) { + if (!mLoadingComplete) { + Log.v(LOGTAG,"Background processing is ON, rejecting back key event"); + return; + } done(); } else { AlertDialog.Builder builder = new AlertDialog.Builder(this); diff --git a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java index 52c296c78..30d535d77 100644 --- a/src/com/android/gallery3d/filtershow/cache/ImageLoader.java +++ b/src/com/android/gallery3d/filtershow/cache/ImageLoader.java @@ -108,7 +108,7 @@ public final class ImageLoader { new String[] { MediaStore.Images.ImageColumns.ORIENTATION }, null, null, null); if (cursor != null && cursor.moveToNext()) { - int ori = cursor.getInt(0); + int ori = cursor.getColumnIndexOrThrow(MediaStore.Images.ImageColumns.ORIENTATION); switch (ori) { case 90: return ORI_ROTATE_90; @@ -147,6 +147,8 @@ public final class ImageLoader { return parseExif(exif); } catch (IOException e) { Log.w(LOGTAG, "Failed to read EXIF orientation", e); + } catch (NullPointerException e) { + Log.w(LOGTAG, "Invalid EXIF data", e); } finally { try { if (is != null) { @@ -576,6 +578,8 @@ public final class ImageLoader { return taglist; } catch (IOException e) { Log.w(LOGTAG, "Failed to read EXIF tags", e); + } catch (NullPointerException e) { + Log.e(LOGTAG, "Failed to read EXIF tags", e); } } return null; diff --git a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java index 09f02dd37..50f0e9436 100644 --- a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java +++ b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java @@ -79,6 +79,9 @@ public class CategoryAdapter extends ArrayAdapter<Action> { mSelectedPosition = 0; mAddButtonText = getContext().getString(R.string.filtershow_add_button_looks); } +// if (category == MainPanel.MAKEUP) { +// mSelectedPosition = 0; +// } if (category == MainPanel.BORDERS) { mSelectedPosition = 0; } diff --git a/src/com/android/gallery3d/filtershow/category/CategoryPanel.java b/src/com/android/gallery3d/filtershow/category/CategoryPanel.java index fb51bf5ad..66b352ffb 100644 --- a/src/com/android/gallery3d/filtershow/category/CategoryPanel.java +++ b/src/com/android/gallery3d/filtershow/category/CategoryPanel.java @@ -29,7 +29,7 @@ import android.widget.ListView; import android.widget.TextView; import com.android.gallery3d.R; import com.android.gallery3d.filtershow.FilterShowActivity; - +import android.util.Log; public class CategoryPanel extends Fragment implements View.OnClickListener { public static final String FRAGMENT_TAG = "CategoryPanel"; @@ -89,6 +89,13 @@ public class CategoryPanel extends Fragment implements View.OnClickListener { } break; } + case MainPanel.MAKEUP: { + mAdapter = activity.getCategoryMakeupAdapter(); + if (mAdapter != null) { + mAdapter.initializeSelection(MainPanel.MAKEUP); + } + break; + } } updateAddButtonVisibility(); } @@ -148,7 +155,7 @@ public class CategoryPanel extends Fragment implements View.OnClickListener { return; } FilterShowActivity activity = (FilterShowActivity) getActivity(); - if (activity.isShowingImageStatePanel() && mAdapter.showAddButton()) { + if (activity.isShowingImageStatePanel() && mAdapter != null && mAdapter.showAddButton()) { mAddButton.setVisibility(View.VISIBLE); if (mAdapter != null) { mAddButton.setText(mAdapter.getAddButtonText()); diff --git a/src/com/android/gallery3d/filtershow/category/MainPanel.java b/src/com/android/gallery3d/filtershow/category/MainPanel.java index 082bf143a..1dbe42083 100644 --- a/src/com/android/gallery3d/filtershow/category/MainPanel.java +++ b/src/com/android/gallery3d/filtershow/category/MainPanel.java @@ -24,9 +24,10 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageButton; import android.widget.LinearLayout; - +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.imageshow.MasterImage; import com.android.gallery3d.filtershow.state.StatePanel; @@ -39,6 +40,7 @@ public class MainPanel extends Fragment { private ImageButton bordersButton; private ImageButton geometryButton; private ImageButton filtersButton; + private ImageButton makeupButton; public static final String FRAGMENT_TAG = "MainPanel"; public static final int LOOKS = 0; @@ -46,6 +48,7 @@ public class MainPanel extends Fragment { public static final int GEOMETRY = 2; public static final int FILTERS = 3; public static final int VERSIONS = 4; + public static final int MAKEUP = 5; private int mCurrentSelected = -1; private int mPreviousToggleVersions = -1; @@ -72,6 +75,12 @@ public class MainPanel extends Fragment { filtersButton.setSelected(value); break; } + case MAKEUP: { + if(makeupButton != null) { + makeupButton.setSelected(value); + } + break; + } } } @@ -97,6 +106,19 @@ public class MainPanel extends Fragment { bordersButton = (ImageButton) mMainView.findViewById(R.id.borderButton); geometryButton = (ImageButton) mMainView.findViewById(R.id.geometryButton); filtersButton = (ImageButton) mMainView.findViewById(R.id.colorsButton); + if(SimpleMakeupImageFilter.HAS_TS_MAKEUP) { + makeupButton = (ImageButton) mMainView.findViewById(R.id.makeupButton); + makeupButton.setVisibility(View.VISIBLE); + } + + if(makeupButton != null) { + makeupButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + showPanel(MAKEUP); + } + }); + } looksButton.setOnClickListener(new View.OnClickListener() { @Override @@ -173,6 +195,19 @@ public class MainPanel extends Fragment { selection(mCurrentSelected, true); } + public void loadCategoryMakeupPanel() { + if (makeupButton == null || mCurrentSelected == MAKEUP) { + return; + } + boolean fromRight = isRightAnimation(MAKEUP); + selection(mCurrentSelected, false); + CategoryPanel categoryPanel = new CategoryPanel(); + categoryPanel.setAdapter(MAKEUP); + setCategoryFragment(categoryPanel, fromRight); + mCurrentSelected = MAKEUP; + selection(mCurrentSelected, true); + } + public void loadCategoryGeometryPanel() { if (mCurrentSelected == GEOMETRY) { return; @@ -239,6 +274,10 @@ public class MainPanel extends Fragment { loadCategoryVersionsPanel(); break; } + case MAKEUP: { + loadCategoryMakeupPanel(); + break; + } } } diff --git a/src/com/android/gallery3d/filtershow/controller/ColorChooser.java b/src/com/android/gallery3d/filtershow/controller/ColorChooser.java index f9f29bccc..82ce80bbf 100644 --- a/src/com/android/gallery3d/filtershow/controller/ColorChooser.java +++ b/src/com/android/gallery3d/filtershow/controller/ColorChooser.java @@ -68,9 +68,16 @@ public class ColorChooser implements Control { Color.colorToHSV(palette[i], hsvo); hsvo[OPACITY_OFFSET] = (0xFF & (palette[i] >> 24)) / (float) 255; button.setTag(hsvo); + + String colorString = "(" + Integer.toHexString(palette[i]) + ")"; + boolean colorSelect = false; + if (parameter.getValueString().equals(colorString)) { + mSelectedButton = i; + colorSelect = true; + } GradientDrawable sd = ((GradientDrawable) button.getBackground()); sd.setColor(palette[i]); - sd.setStroke(3, (mSelectedButton == i) ? mSelected : mTransparent); + sd.setStroke(3, colorSelect? mSelected : mTransparent); final int buttonNo = i; button.setOnClickListener(new View.OnClickListener() { diff --git a/src/com/android/gallery3d/filtershow/controller/StyleChooser.java b/src/com/android/gallery3d/filtershow/controller/StyleChooser.java index f5afec921..dc31401e0 100644 --- a/src/com/android/gallery3d/filtershow/controller/StyleChooser.java +++ b/src/com/android/gallery3d/filtershow/controller/StyleChooser.java @@ -41,7 +41,7 @@ public class StyleChooser implements Control { int n = mParameter.getNumberOfStyles(); mIconButton.clear(); Resources res = context.getResources(); - int dim = res.getDimensionPixelSize(R.dimen.draw_style_icon_dim); + int dim = mTopView.getMeasuredWidth() / n; LayoutParams lp = new LayoutParams(dim, dim); for (int i = 0; i < n; i++) { final ImageButton button = new ImageButton(context); diff --git a/src/com/android/gallery3d/filtershow/crop/CropActivity.java b/src/com/android/gallery3d/filtershow/crop/CropActivity.java index 3a7829681..94c859333 100644 --- a/src/com/android/gallery3d/filtershow/crop/CropActivity.java +++ b/src/com/android/gallery3d/filtershow/crop/CropActivity.java @@ -83,7 +83,7 @@ public class CropActivity extends Activity { * sure the intent stays below 1MB.We should consider just returning a byte * array instead of a Bitmap instance to avoid overhead. */ - public static final int MAX_BMAP_IN_INTENT = 750000; + public static final int MAX_BMAP_IN_INTENT = 520000; // Flags private static final int DO_SET_WALLPAPER = 1; @@ -400,16 +400,8 @@ public class CropActivity extends Activity { mOutputX = outputX; mOutputY = outputY; - if ((flags & DO_EXTRA_OUTPUT) != 0) { - if (mOutUri == null) { - Log.w(LOGTAG, "cannot write file, no output URI given"); - } else { - try { - mOutStream = getContentResolver().openOutputStream(mOutUri); - } catch (FileNotFoundException e) { - Log.w(LOGTAG, "cannot write file: " + mOutUri.toString(), e); - } - } + if ((flags & DO_EXTRA_OUTPUT) != 0 && mOutUri == null) { + Log.w(LOGTAG, "cannot write file, no output URI given"); } if ((flags & (DO_EXTRA_OUTPUT | DO_SET_WALLPAPER)) != 0) { @@ -542,7 +534,14 @@ public class CropActivity extends Activity { // Get output compression format CompressFormat cf = convertExtensionToCompressFormat(getFileExtension(mOutputFormat)); - + Utils.closeSilently(mInStream); + if (mOutUri != null) { + try { + mOutStream = getContentResolver().openOutputStream(mOutUri); + } catch (FileNotFoundException e) { + Log.w(LOGTAG, "cannot write file: " + mOutUri.toString(), e); + } + } // If we only need to output to a URI, compress straight to file if (mFlags == DO_EXTRA_OUTPUT) { if (mOutStream == null @@ -604,7 +603,7 @@ public class CropActivity extends Activity { @Override protected void onPostExecute(Boolean result) { Utils.closeSilently(mOutStream); - Utils.closeSilently(mInStream); + // Utils.closeSilently(mInStream); doneBitmapIO(result.booleanValue(), mResultIntent); } diff --git a/src/com/android/gallery3d/filtershow/editors/EditorMakeup.java b/src/com/android/gallery3d/filtershow/editors/EditorMakeup.java new file mode 100644 index 000000000..331d31b57 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/editors/EditorMakeup.java @@ -0,0 +1,44 @@ +/* +* Copyright (C) 2014,2015 Thundersoft Corporation +* All rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.android.gallery3d.filtershow.editors; + +import android.view.View; +import android.widget.SeekBar; + +import com.android.gallery3d.R; + +public class EditorMakeup extends BasicEditor { + public static int ID = R.id.editorMakeup; + private final String LOGTAG = "EditorMakeup"; + + public EditorMakeup() { + super(ID, R.layout.filtershow_default_editor, R.id.basicEditor); + } + + @Override + public void setUtilityPanelUI(View actionButton, View editControl) { + super.setUtilityPanelUI(actionButton, editControl); + mSeekBar = (SeekBar) editControl.findViewById(R.id.primarySeekBar); + if (mSeekBar != null) { + mSeekBar.setVisibility(View.INVISIBLE); + } + } + + + +} diff --git a/src/com/android/gallery3d/filtershow/editors/EditorPanel.java b/src/com/android/gallery3d/filtershow/editors/EditorPanel.java index a60b6722c..0581835f4 100644 --- a/src/com/android/gallery3d/filtershow/editors/EditorPanel.java +++ b/src/com/android/gallery3d/filtershow/editors/EditorPanel.java @@ -20,6 +20,7 @@ import android.app.Activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentTransaction; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -50,6 +51,7 @@ public class EditorPanel extends Fragment { super.onAttach(activity); FilterShowActivity filterShowActivity = (FilterShowActivity) activity; mEditor = filterShowActivity.getEditor(mEditorID); + Log.d(LOGTAG, "EditorPanle.onAttach(): mEditorID is " + mEditorID + ", mEditor is " + mEditor); } public void cancelCurrentFilter() { diff --git a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java index 8350ff356..e93175a92 100644 --- a/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java +++ b/src/com/android/gallery3d/filtershow/filters/BaseFiltersManager.java @@ -36,6 +36,7 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { protected ArrayList<FilterRepresentation> mBorders = new ArrayList<FilterRepresentation>(); protected ArrayList<FilterRepresentation> mTools = new ArrayList<FilterRepresentation>(); protected ArrayList<FilterRepresentation> mEffects = new ArrayList<FilterRepresentation>(); + protected ArrayList<FilterRepresentation> mMakeup = new ArrayList<FilterRepresentation>(); private static int mImageBorderSize = 4; // in percent protected void init() { @@ -140,6 +141,12 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { filters.add(ImageFilterFx.class); filters.add(ImageFilterBorder.class); filters.add(ImageFilterColorBorder.class); + if(SimpleMakeupImageFilter.HAS_TS_MAKEUP) { + filters.add(ImageFilterMakeupWhiten.class); + filters.add(ImageFilterMakeupSoften.class); + filters.add(ImageFilterMakeupTrimface.class); + filters.add(ImageFilterMakeupBigeye.class); + } } public ArrayList<FilterRepresentation> getLooks() { @@ -158,8 +165,11 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { return mEffects; } - public void addBorders(Context context) { + public ArrayList<FilterRepresentation> getMakeup() { + return mMakeup; + } + public void addBorders(Context context) { // Do not localize String[] serializationNames = { "FRAME_4X5", @@ -305,6 +315,15 @@ public abstract class BaseFiltersManager implements FiltersManagerInterface { mEffects.add(getRepresentation(ImageFilterKMeans.class)); } + public void addMakeups(Context context) { + if(SimpleMakeupImageFilter.HAS_TS_MAKEUP) { + mMakeup.add(getRepresentation(ImageFilterMakeupWhiten.class)); + mMakeup.add(getRepresentation(ImageFilterMakeupSoften.class)); + mMakeup.add(getRepresentation(ImageFilterMakeupTrimface.class)); + mMakeup.add(getRepresentation(ImageFilterMakeupBigeye.class)); + } + } + public void addTools(Context context) { int[] textId = { diff --git a/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java index ba697d87f..98afc3a08 100644 --- a/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java +++ b/src/com/android/gallery3d/filtershow/filters/FilterCropRepresentation.java @@ -65,6 +65,9 @@ public class FilterCropRepresentation extends FilterRepresentation { return false; } FilterCropRepresentation crop = (FilterCropRepresentation) rep; + if (crop.isNil()) { + return true; + } if (mCrop.bottom != crop.mCrop.bottom || mCrop.left != crop.mCrop.left || mCrop.right != crop.mCrop.right diff --git a/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java index 48d3d9077..5c5e561ca 100644 --- a/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java +++ b/src/com/android/gallery3d/filtershow/filters/FilterDrawRepresentation.java @@ -157,15 +157,20 @@ public class FilterDrawRepresentation extends FilterRepresentation { private Vector<StrokeData> mDrawing = new Vector<StrokeData>(); private StrokeData mCurrent; // used in the currently drawing style - public FilterDrawRepresentation() { - super("Draw"); + public FilterDrawRepresentation(String name) { + super(name); setFilterClass(ImageFilterDraw.class); - setSerializationName("DRAW"); + setSerializationName(name); setFilterType(FilterRepresentation.TYPE_VIGNETTE); setTextId(R.string.imageDraw); setEditorId(EditorDraw.ID); setOverlayId(R.drawable.filtershow_drawing); setOverlayOnly(true); + setDefaultColor(); + } + + private void setDefaultColor() { + mParamColor.setValue(DEFAULT_MENU_COLOR1); } @Override @@ -185,7 +190,7 @@ public class FilterDrawRepresentation extends FilterRepresentation { @Override public FilterRepresentation copy() { - FilterDrawRepresentation representation = new FilterDrawRepresentation(); + FilterDrawRepresentation representation = new FilterDrawRepresentation(getName()); copyAllParameters(representation); return representation; } diff --git a/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java index 0fb157d7b..36675b71b 100644 --- a/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java +++ b/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java @@ -47,6 +47,7 @@ public class FilterRepresentation { public static final byte TYPE_NORMAL = 5; public static final byte TYPE_TINYPLANET = 6; public static final byte TYPE_GEOMETRY = 7; + public static final byte TYPE_MAKEUP = 8; protected static final String NAME_TAG = "Name"; public FilterRepresentation(String name) { diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilter.java b/src/com/android/gallery3d/filtershow/filters/ImageFilter.java index 437137416..1fcd3008c 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilter.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilter.java @@ -19,7 +19,7 @@ package com.android.gallery3d.filtershow.filters; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.Matrix; -import android.support.v8.renderscript.Allocation; +import android.renderscript.Allocation; import android.widget.Toast; import com.android.gallery3d.filtershow.imageshow.GeometryMathUtils; diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java index a7286f0fa..5f3502272 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterBorder.java @@ -18,13 +18,15 @@ package com.android.gallery3d.filtershow.filters; import android.content.res.Resources; import android.graphics.Bitmap; -import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; +import com.android.gallery3d.data.DecodeUtils; + import java.util.HashMap; +import java.lang.ref.WeakReference; public class ImageFilterBorder extends ImageFilter { private static final float NINEPATCH_ICON_SCALING = 10; @@ -32,7 +34,7 @@ public class ImageFilterBorder extends ImageFilter { private FilterImageBorderRepresentation mParameters = null; private Resources mResources = null; - private HashMap<Integer, Drawable> mDrawables = new HashMap<Integer, Drawable>(); + private HashMap<Integer, WeakReference<Drawable>> mDrawables = new HashMap<Integer, WeakReference<Drawable>>(); public ImageFilterBorder() { mName = "Border"; @@ -57,7 +59,7 @@ public class ImageFilterBorder extends ImageFilter { Rect bounds = new Rect(0, 0, (int) (w * scale1), (int) (h * scale1)); Canvas canvas = new Canvas(bitmap); canvas.scale(scale2, scale2); - Drawable drawable = getDrawable(getParameters().getDrawableResource()); + Drawable drawable = getDrawable(getParameters().getDrawableResource(), w, h); drawable.setBounds(bounds); drawable.draw(canvas); return bitmap; @@ -80,11 +82,12 @@ public class ImageFilterBorder extends ImageFilter { } } - public Drawable getDrawable(int rsc) { - Drawable drawable = mDrawables.get(rsc); + public Drawable getDrawable(int rsc, int reqWidth, int reqHeight) { + Drawable drawable = (mDrawables.get(rsc) != null) ? mDrawables.get(rsc).get() : null; if (drawable == null && mResources != null && rsc != 0) { - drawable = new BitmapDrawable(mResources, BitmapFactory.decodeResource(mResources, rsc)); - mDrawables.put(rsc, drawable); + drawable = new BitmapDrawable(mResources, DecodeUtils.decodeBitmap( + mResources, rsc, reqWidth, reqHeight)); + mDrawables.put(rsc, new WeakReference<Drawable>(drawable)); } return drawable; } diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterChanSat.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterChanSat.java index 5d3856ebc..6c48a6a9f 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterChanSat.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterChanSat.java @@ -18,11 +18,11 @@ package com.android.gallery3d.filtershow.filters; import android.graphics.Bitmap; import android.graphics.Matrix; -import android.support.v8.renderscript.Allocation; -import android.support.v8.renderscript.Element; -import android.support.v8.renderscript.RenderScript; -import android.support.v8.renderscript.Script.LaunchOptions; -import android.support.v8.renderscript.Type; +import android.renderscript.Allocation; +import android.renderscript.Element; +import android.renderscript.RenderScript; +import android.renderscript.Script; +import android.renderscript.Type; import com.android.gallery3d.R; import com.android.gallery3d.filtershow.pipeline.FilterEnvironment; @@ -132,7 +132,7 @@ public class ImageFilterChanSat extends ImageFilterRS { int width = in.getType().getX(); int height = in.getType().getY(); - LaunchOptions options = new LaunchOptions(); + Script.LaunchOptions options = new Script.LaunchOptions(); int ty; options.setX(0, width); diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java index 8fd5b029e..da7de9379 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterDraw.java @@ -29,6 +29,7 @@ import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import com.android.gallery3d.R; +import com.android.gallery3d.app.GalleryAppImpl; import com.android.gallery3d.app.Log; import com.android.gallery3d.filtershow.cache.ImageLoader; import com.android.gallery3d.filtershow.filters.FilterDrawRepresentation.StrokeData; @@ -47,7 +48,8 @@ public class ImageFilterDraw extends ImageFilter { int mCachedStrokes = -1; int mCurrentStyle = 0; - FilterDrawRepresentation mParameters = new FilterDrawRepresentation(); + FilterDrawRepresentation mParameters = new FilterDrawRepresentation( + GalleryAppImpl.getContext().getString(R.string.imageDraw)); public ImageFilterDraw() { mName = "Image Draw"; @@ -69,7 +71,8 @@ public class ImageFilterDraw extends ImageFilter { @Override public FilterRepresentation getDefaultRepresentation() { - return new FilterDrawRepresentation(); + return new FilterDrawRepresentation( + GalleryAppImpl.getContext().getString(R.string.imageDraw)); } @Override diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterGrad.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterGrad.java index 0a615afd4..7f10af990 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterGrad.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterGrad.java @@ -26,11 +26,12 @@ import com.android.gallery3d.filtershow.pipeline.FilterEnvironment; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.Matrix; -import android.support.v8.renderscript.Allocation; -import android.support.v8.renderscript.Element; -import android.support.v8.renderscript.RenderScript; -import android.support.v8.renderscript.Script.LaunchOptions; -import android.support.v8.renderscript.Type; + +import android.renderscript.Allocation; +import android.renderscript.Element; +import android.renderscript.RenderScript; +import android.renderscript.Script; +import android.renderscript.Type; import android.util.Log; import com.android.gallery3d.R; @@ -161,7 +162,7 @@ public class ImageFilterGrad extends ImageFilterRS { int width = in.getType().getX(); int height = in.getType().getY(); - LaunchOptions options = new LaunchOptions(); + Script.LaunchOptions options = new Script.LaunchOptions(); int ty; options.setX(0, width); diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterMakeupBigeye.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterMakeupBigeye.java new file mode 100644 index 000000000..64067881e --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterMakeupBigeye.java @@ -0,0 +1,54 @@ +/* +* Copyright (C) 2014,2015 Thundersoft Corporation +* All rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.android.gallery3d.filtershow.filters; + +import android.graphics.Bitmap; + +import com.android.gallery3d.R; + +import com.thundersoft.hz.selfportrait.detect.FaceInfo; +import com.thundersoft.hz.selfportrait.makeup.engine.MakeupEngine; + +public class ImageFilterMakeupBigeye extends SimpleMakeupImageFilter { + private static final String SERIALIZATION_NAME = "BIGEYE"; + + public ImageFilterMakeupBigeye() { + mName = "Bigeye"; + } + + public FilterRepresentation getDefaultRepresentation() { + FilterBasicRepresentation representation = + (FilterBasicRepresentation) super.getDefaultRepresentation(); + representation.setName("Bigeye"); + representation.setSerializationName(SERIALIZATION_NAME); + representation.setFilterClass(ImageFilterMakeupBigeye.class); + representation.setTextId(R.string.text_makeup_bigeye); + representation.setOverlayOnly(true); + representation.setOverlayId(R.drawable.ic_ts_makeup_bigeye); + representation.setMinimum(0); + representation.setMaximum(100); + representation.setSupportsPartialRendering(true); + return representation; + } + + protected void doMakeupEffect(Bitmap bitmap, FaceInfo faceInfo, int width, int height, + int value) { + MakeupEngine.doWarpFace(bitmap, bitmap, width, height, faceInfo.eye1, faceInfo.eye2, + faceInfo.mouth, value, 0); + } +} diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterMakeupSoften.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterMakeupSoften.java new file mode 100644 index 000000000..8587158c3 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterMakeupSoften.java @@ -0,0 +1,52 @@ +/* +* Copyright (C) 2014,2015 Thundersoft Corporation +* All rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.android.gallery3d.filtershow.filters; + +import android.graphics.Bitmap; + +import com.android.gallery3d.R; + +import com.thundersoft.hz.selfportrait.detect.FaceInfo; +import com.thundersoft.hz.selfportrait.makeup.engine.MakeupEngine; + +public class ImageFilterMakeupSoften extends SimpleMakeupImageFilter { + private static final String SERIALIZATION_NAME = "SOFTEN"; + + public ImageFilterMakeupSoften() { + mName = "Soften"; + } + + public FilterRepresentation getDefaultRepresentation() { + FilterBasicRepresentation representation = + (FilterBasicRepresentation) super.getDefaultRepresentation(); + representation.setName("Soften"); + representation.setSerializationName(SERIALIZATION_NAME); + representation.setFilterClass(ImageFilterMakeupSoften.class); + representation.setTextId(R.string.text_makeup_Soften); + representation.setOverlayOnly(true); + representation.setOverlayId(R.drawable.ic_ts_makeup_soften); + representation.setMinimum(0); + representation.setMaximum(100); + representation.setSupportsPartialRendering(true); + return representation; + } + + protected void doMakeupEffect(Bitmap bitmap, FaceInfo faceInfo, int width, int height, int value) { + MakeupEngine.doProcessBeautify(bitmap, bitmap, width, height, faceInfo.face, value, 0); + } +} diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterMakeupTrimface.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterMakeupTrimface.java new file mode 100644 index 000000000..4b0499036 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterMakeupTrimface.java @@ -0,0 +1,55 @@ +/* +* Copyright (C) 2014,2015 Thundersoft Corporation +* All rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.android.gallery3d.filtershow.filters; + +import android.graphics.Bitmap; + +import com.android.gallery3d.R; + +import com.thundersoft.hz.selfportrait.detect.FaceInfo; +import com.thundersoft.hz.selfportrait.makeup.engine.MakeupEngine; + +public class ImageFilterMakeupTrimface extends SimpleMakeupImageFilter { + private static final String SERIALIZATION_NAME = "TRIMFACE"; + + public ImageFilterMakeupTrimface() { + mName = "Trimface"; + } + + public FilterRepresentation getDefaultRepresentation() { + FilterBasicRepresentation representation = + (FilterBasicRepresentation) super.getDefaultRepresentation(); + representation.setName("Trimface"); + representation.setSerializationName(SERIALIZATION_NAME); + representation.setFilterClass(ImageFilterMakeupTrimface.class); + representation.setTextId(R.string.text_makeup_trimface); + representation.setOverlayOnly(true); + representation.setOverlayId(R.drawable.ic_ts_makeup_trimface); + representation.setMinimum(0); + representation.setMaximum(100); + representation.setSupportsPartialRendering(true); + return representation; + } + + protected void doMakeupEffect(Bitmap bitmap, FaceInfo faceInfo, int width, int height, + int value) { + MakeupEngine.doWarpFace(bitmap, bitmap, width, height, faceInfo.eye1, faceInfo.eye2, + faceInfo.mouth, 0, value); + } + +} diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterMakeupWhiten.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterMakeupWhiten.java new file mode 100644 index 000000000..e60be84d7 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterMakeupWhiten.java @@ -0,0 +1,53 @@ +/* +* Copyright (C) 2014,2015 Thundersoft Corporation +* All rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.android.gallery3d.filtershow.filters; + +import android.graphics.Bitmap; + +import com.android.gallery3d.R; + +import com.thundersoft.hz.selfportrait.detect.FaceInfo; +import com.thundersoft.hz.selfportrait.makeup.engine.MakeupEngine; + +public class ImageFilterMakeupWhiten extends SimpleMakeupImageFilter { + private static final String SERIALIZATION_NAME = "WHITEN"; + + public ImageFilterMakeupWhiten() { + mName = "Whiten"; + } + + public FilterRepresentation getDefaultRepresentation() { + FilterBasicRepresentation representation = + (FilterBasicRepresentation) super.getDefaultRepresentation(); + representation.setName("Whiten"); + representation.setSerializationName(SERIALIZATION_NAME); + representation.setFilterClass(ImageFilterMakeupWhiten.class); + representation.setTextId(R.string.text_makeup_whiten); + representation.setOverlayOnly(true); + representation.setOverlayId(R.drawable.ic_ts_makeup_whiten); + representation.setMinimum(0); + representation.setMaximum(100); + representation.setSupportsPartialRendering(true); + return representation; + } + + protected void doMakeupEffect(Bitmap bitmap, FaceInfo faceInfo, int width, int height, int value) { + MakeupEngine.doProcessBeautify(bitmap, bitmap, width, height, faceInfo.face, 0, value); + } + +} diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java index e94e2a63a..b7c4d80e0 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterRS.java @@ -18,7 +18,10 @@ package com.android.gallery3d.filtershow.filters; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.support.v8.renderscript.*; +import android.renderscript.Allocation; +import android.renderscript.Element; +import android.renderscript.RenderScript; +import android.renderscript.Type; import android.util.Log; import android.content.res.Resources; import com.android.gallery3d.R; diff --git a/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java b/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java index e0b4cf687..279bd1857 100644 --- a/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java +++ b/src/com/android/gallery3d/filtershow/filters/ImageFilterVignette.java @@ -24,11 +24,8 @@ import android.graphics.Rect; import com.android.gallery3d.R; import com.android.gallery3d.filtershow.imageshow.MasterImage; import com.android.gallery3d.filtershow.pipeline.FilterEnvironment; -import android.support.v8.renderscript.Allocation; -import android.support.v8.renderscript.Element; -import android.support.v8.renderscript.RenderScript; -import android.support.v8.renderscript.Script.LaunchOptions; -import android.support.v8.renderscript.Type; + +import android.renderscript.RenderScript; import android.util.Log; public class ImageFilterVignette extends ImageFilterRS { diff --git a/src/com/android/gallery3d/filtershow/filters/SimpleMakeupImageFilter.java b/src/com/android/gallery3d/filtershow/filters/SimpleMakeupImageFilter.java new file mode 100644 index 000000000..584074c02 --- /dev/null +++ b/src/com/android/gallery3d/filtershow/filters/SimpleMakeupImageFilter.java @@ -0,0 +1,82 @@ +/* +* Copyright (C) 2014,2015 Thundersoft Corporation +* All rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +package com.android.gallery3d.filtershow.filters; + +import android.graphics.Bitmap; +import android.util.Log; + +import com.thundersoft.hz.selfportrait.detect.FaceDetect; +import com.thundersoft.hz.selfportrait.detect.FaceInfo; + +public abstract class SimpleMakeupImageFilter extends SimpleImageFilter { + private static final String LOGTAG = "SimpleMakeupImageFilter"; + protected static final int MAKEUP_INTENSITY = 50; + + public static final boolean HAS_TS_MAKEUP = android.os.SystemProperties.getBoolean("persist.ts.postmakeup", false); + + public SimpleMakeupImageFilter() { + } + + public FilterRepresentation getDefaultRepresentation() { + FilterRepresentation representation = new FilterBasicRepresentation("Default", 0, + MAKEUP_INTENSITY, 100); + representation.setShowParameterValue(true); + return representation; + } + + protected FaceInfo detectFaceInfo(Bitmap bitmap) { + FaceDetect faceDetect = new FaceDetect(); + faceDetect.initialize(); + FaceInfo[] faceInfos = faceDetect.dectectFeatures(bitmap); + faceDetect.uninitialize(); + + Log.v(LOGTAG, "SimpleMakeupImageFilter.detectFaceInfo(): detect faceNum is " + + (faceInfos != null ? faceInfos.length : "NULL")); + if (faceInfos == null || faceInfos.length <= 0) { + return null; + } + + return faceInfos[0]; + } + + @Override + public Bitmap apply(Bitmap bitmap, float scaleFactor, int quality) { + if (getParameters() == null) { + return bitmap; + } + int w = bitmap.getWidth(); + int h = bitmap.getHeight(); + if(w % 2 != 0 || h % 2 != 0) { + return bitmap; + } + int value = getParameters().getValue(); + applyHelper(bitmap, w, h, value); + return bitmap; + } + + private void applyHelper(Bitmap bitmap, int w, int h, int value) { + FaceInfo faceInfo = detectFaceInfo(bitmap); + if(faceInfo != null) { + doMakeupEffect(bitmap, faceInfo, w, h, value); + } + } + + abstract void doMakeupEffect(Bitmap bitmap, FaceInfo faceInfo, int width, int height, + int value); + +} diff --git a/src/com/android/gallery3d/filtershow/history/HistoryManager.java b/src/com/android/gallery3d/filtershow/history/HistoryManager.java index 569b299cc..9d5065a28 100644 --- a/src/com/android/gallery3d/filtershow/history/HistoryManager.java +++ b/src/com/android/gallery3d/filtershow/history/HistoryManager.java @@ -68,7 +68,7 @@ public class HistoryManager { } public boolean canUndo() { - if (mCurrentPresetPosition == getCount() - 1) { + if (mCurrentPresetPosition >= getCount() - 1) { return false; } return true; diff --git a/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java b/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java index 2022ffd7e..d7c2eb4f8 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java +++ b/src/com/android/gallery3d/filtershow/imageshow/ImageShow.java @@ -288,7 +288,7 @@ public class ImageShow extends View implements OnGestureListener, drawImageAndAnimate(canvas, highresPreview); } - drawHighresImage(canvas, fullHighres); +// drawHighresImage(canvas, fullHighres); drawCompareImage(canvas, getGeometryOnlyImage()); canvas.restore(); diff --git a/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java b/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java index f6b97f11f..5e27f4213 100644 --- a/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java +++ b/src/com/android/gallery3d/filtershow/imageshow/MasterImage.java @@ -25,6 +25,7 @@ import android.graphics.Point; import android.graphics.Rect; import android.graphics.RectF; import android.net.Uri; +import android.util.Log; import com.android.gallery3d.exif.ExifTag; import com.android.gallery3d.filtershow.FilterShowActivity; @@ -211,6 +212,9 @@ public class MasterImage implements RenderingRequestCaller { int sh = (int) (sw * (float) mOriginalBitmapLarge.getHeight() / mOriginalBitmapLarge .getWidth()); mOriginalBitmapSmall = Bitmap.createScaledBitmap(mOriginalBitmapLarge, sw, sh, true); + Log.d(LOGTAG, "MasterImage.loadBitmap(): OriginalBitmapLarge.WH is (" + mOriginalBitmapLarge.getWidth() + ", " + + mOriginalBitmapLarge.getHeight() + "), OriginalBitmapSmall.WH is (" + sw + ", " + sh + "), originalBounds is " + + originalBounds.toString()); mZoomOrientation = mOrientation; warnListeners(); return true; @@ -271,6 +275,9 @@ public class MasterImage implements RenderingRequestCaller { public void onHistoryItemClick(int position) { HistoryItem historyItem = mHistory.getItem(position); // We need a copy from the history + if (historyItem == null) { + return; + } ImagePreset newPreset = new ImagePreset(historyItem.getImagePreset()); // don't need to add it to the history setPreset(newPreset, historyItem.getFilterRepresentation(), false); diff --git a/src/com/android/gallery3d/filtershow/pipeline/Buffer.java b/src/com/android/gallery3d/filtershow/pipeline/Buffer.java index c378eb994..a487a5d8d 100644 --- a/src/com/android/gallery3d/filtershow/pipeline/Buffer.java +++ b/src/com/android/gallery3d/filtershow/pipeline/Buffer.java @@ -18,8 +18,8 @@ package com.android.gallery3d.filtershow.pipeline; import android.graphics.Bitmap; import android.graphics.Canvas; -import android.support.v8.renderscript.Allocation; -import android.support.v8.renderscript.RenderScript; +import android.renderscript.Allocation; +import android.renderscript.RenderScript; import android.util.Log; import com.android.gallery3d.filtershow.cache.BitmapCache; import com.android.gallery3d.filtershow.imageshow.MasterImage; diff --git a/src/com/android/gallery3d/filtershow/pipeline/CachingPipeline.java b/src/com/android/gallery3d/filtershow/pipeline/CachingPipeline.java index 8ae9a7c7b..06ce9e9df 100644 --- a/src/com/android/gallery3d/filtershow/pipeline/CachingPipeline.java +++ b/src/com/android/gallery3d/filtershow/pipeline/CachingPipeline.java @@ -24,8 +24,9 @@ import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.RectF; -import android.support.v8.renderscript.Allocation; -import android.support.v8.renderscript.RenderScript; + +import android.renderscript.Allocation; +import android.renderscript.RenderScript; import android.util.Log; import com.android.gallery3d.filtershow.cache.BitmapCache; @@ -175,6 +176,9 @@ public class CachingPipeline implements PipelineInterface { } public void setOriginal(Bitmap bitmap) { + if (mOriginalBitmap != null) { + mOriginalBitmap.recycle(); + } mOriginalBitmap = bitmap; Log.v(LOGTAG,"setOriginal, size " + bitmap.getWidth() + " x " + bitmap.getHeight()); ImagePreset preset = MasterImage.getImage().getPreset(); diff --git a/src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java b/src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java index ebf83b720..0b84f5203 100644 --- a/src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java +++ b/src/com/android/gallery3d/filtershow/pipeline/FilterEnvironment.java @@ -18,7 +18,7 @@ package com.android.gallery3d.filtershow.pipeline; import android.graphics.Bitmap; import android.graphics.Canvas; -import android.support.v8.renderscript.Allocation; +import android.renderscript.Allocation; import com.android.gallery3d.app.Log; import com.android.gallery3d.filtershow.cache.BitmapCache; diff --git a/src/com/android/gallery3d/filtershow/pipeline/ImagePreset.java b/src/com/android/gallery3d/filtershow/pipeline/ImagePreset.java index 4765a5990..1460ad434 100644 --- a/src/com/android/gallery3d/filtershow/pipeline/ImagePreset.java +++ b/src/com/android/gallery3d/filtershow/pipeline/ImagePreset.java @@ -18,7 +18,7 @@ package com.android.gallery3d.filtershow.pipeline; import android.graphics.Bitmap; import android.graphics.Rect; -import android.support.v8.renderscript.Allocation; +import android.renderscript.Allocation; import android.util.JsonReader; import android.util.JsonWriter; import android.util.Log; @@ -67,9 +67,11 @@ public class ImagePreset { } public ImagePreset(ImagePreset source) { - for (int i = 0; i < source.mFilters.size(); i++) { - FilterRepresentation sourceRepresentation = source.mFilters.elementAt(i); - mFilters.add(sourceRepresentation.copy()); + if (source != null && source.mFilters != null) { + for (int i = 0; i < source.mFilters.size(); i++) { + FilterRepresentation sourceRepresentation = source.mFilters.elementAt(i); + mFilters.add(sourceRepresentation.copy()); + } } } @@ -237,7 +239,7 @@ public class ImagePreset { FilterRepresentation a = preset.mFilters.elementAt(i); FilterRepresentation b = mFilters.elementAt(i); - if (!a.same(b)) { + if (!a.equals(b)) { return false; } } diff --git a/src/com/android/gallery3d/filtershow/pipeline/PipelineInterface.java b/src/com/android/gallery3d/filtershow/pipeline/PipelineInterface.java index d53768c95..ad59e0c44 100644 --- a/src/com/android/gallery3d/filtershow/pipeline/PipelineInterface.java +++ b/src/com/android/gallery3d/filtershow/pipeline/PipelineInterface.java @@ -18,8 +18,8 @@ package com.android.gallery3d.filtershow.pipeline; import android.content.res.Resources; import android.graphics.Bitmap; -import android.support.v8.renderscript.Allocation; -import android.support.v8.renderscript.RenderScript; +import android.renderscript.Allocation; +import android.renderscript.RenderScript; public interface PipelineInterface { public String getName(); diff --git a/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java b/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java index e5736d43c..e334e8798 100644 --- a/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java +++ b/src/com/android/gallery3d/filtershow/pipeline/ProcessingService.java @@ -304,12 +304,14 @@ public class ProcessingService extends Service { filtersManager.addBorders(this); filtersManager.addTools(this); filtersManager.addEffects(); + filtersManager.addMakeups(this); FiltersManager highresFiltersManager = FiltersManager.getHighresManager(); highresFiltersManager.addLooks(this); highresFiltersManager.addBorders(this); highresFiltersManager.addTools(this); highresFiltersManager.addEffects(); +// highresFiltersManager.addMakeups(this); } private void tearDownPipeline() { diff --git a/src/com/android/gallery3d/filtershow/pipeline/UpdatePreviewTask.java b/src/com/android/gallery3d/filtershow/pipeline/UpdatePreviewTask.java index 61ee8eb71..a55abca3d 100644 --- a/src/com/android/gallery3d/filtershow/pipeline/UpdatePreviewTask.java +++ b/src/com/android/gallery3d/filtershow/pipeline/UpdatePreviewTask.java @@ -57,8 +57,11 @@ public class UpdatePreviewTask extends ProcessingTask { SharedBuffer buffer = MasterImage.getImage().getPreviewBuffer(); SharedPreset preset = MasterImage.getImage().getPreviewPreset(); ImagePreset renderingPreset = preset.dequeuePreset(); - if (renderingPreset != null) { + if ( (buffer != null) && (renderingPreset != null)) { mPreviewPipeline.compute(buffer, renderingPreset, 0); + if ( buffer.getProducer() == null) { + return null; + } // set the preset we used in the buffer for later inspection UI-side buffer.getProducer().setPreset(renderingPreset); buffer.getProducer().sync(); diff --git a/src/com/android/gallery3d/filtershow/state/StatePanel.java b/src/com/android/gallery3d/filtershow/state/StatePanel.java index 95c2df991..192400315 100644 --- a/src/com/android/gallery3d/filtershow/state/StatePanel.java +++ b/src/com/android/gallery3d/filtershow/state/StatePanel.java @@ -48,7 +48,9 @@ public class StatePanel extends Fragment { View panel = mMainView.findViewById(R.id.listStates); track = (StatePanelTrack) panel; - track.setAdapter(MasterImage.getImage().getState()); + StateAdapter imageStateAdapter = MasterImage.getImage().getState(); + if (imageStateAdapter == null) return null; + track.setAdapter(imageStateAdapter); mToggleVersionsPanel = (ImageButton) mMainView.findViewById(R.id.toggleVersionsPanel); if (FilterShowHelper.shouldUseVersions()) { if (mToggleVersionsPanel.getVisibility() == View.GONE diff --git a/src/com/android/gallery3d/filtershow/tools/SaveImage.java b/src/com/android/gallery3d/filtershow/tools/SaveImage.java index 17d698f15..e07dd2ce8 100644 --- a/src/com/android/gallery3d/filtershow/tools/SaveImage.java +++ b/src/com/android/gallery3d/filtershow/tools/SaveImage.java @@ -247,7 +247,7 @@ public class SaveImage { if (mimeType == null) { mimeType = ImageLoader.getMimeType(mSelectedImageUri); } - if (mimeType.equals(ImageLoader.JPEG_MIME_TYPE)) { + if (ImageLoader.JPEG_MIME_TYPE.equals(mimeType)) { InputStream inStream = null; try { inStream = mContext.getContentResolver().openInputStream(source); @@ -256,6 +256,8 @@ public class SaveImage { Log.w(LOGTAG, "Cannot find file: " + source, e); } catch (IOException e) { Log.w(LOGTAG, "Cannot read exif for: " + source, e); + } catch (NullPointerException e) { + Log.w(LOGTAG, "Invalid exif data for: " + source, e); } finally { Utils.closeSilently(inStream); } @@ -346,9 +348,9 @@ public class SaveImage { // newSourceUri is then pointing to the new location. // If no file is moved, newSourceUri will be the same as mSourceUri. Uri newSourceUri = mSourceUri; - if (!flatten) { - newSourceUri = moveSrcToAuxIfNeeded(mSourceUri, mDestinationFile); - } + /* + * if (!flatten) { newSourceUri = moveSrcToAuxIfNeeded(mSourceUri, mDestinationFile); } + */ Uri savedUri = mSelectedImageUri; if (mPreviewImage != null) { @@ -380,7 +382,7 @@ public class SaveImage { // After this call, mSelectedImageUri will be actually // pointing at the new file mDestinationFile. savedUri = SaveImage.linkNewFileToUri(mContext, mSelectedImageUri, - mDestinationFile, time, !flatten); + mDestinationFile, time, false); } } if (mCallback != null) { @@ -700,7 +702,7 @@ public class SaveImage { values.put(Images.Media.TITLE, file.getName()); values.put(Images.Media.DISPLAY_NAME, file.getName()); values.put(Images.Media.MIME_TYPE, "image/jpeg"); - values.put(Images.Media.DATE_TAKEN, time); + values.put(Images.Media.DATE_TAKEN, time * 1000); values.put(Images.Media.DATE_MODIFIED, time); values.put(Images.Media.DATE_ADDED, time); values.put(Images.Media.ORIENTATION, 0); diff --git a/src/com/android/gallery3d/filtershow/ui/ExportDialog.java b/src/com/android/gallery3d/filtershow/ui/ExportDialog.java index b42c9f367..001e07589 100644 --- a/src/com/android/gallery3d/filtershow/ui/ExportDialog.java +++ b/src/com/android/gallery3d/filtershow/ui/ExportDialog.java @@ -107,8 +107,16 @@ public class ExportDialog extends DialogFragment implements View.OnClickListener mOriginalBounds = MasterImage.getImage().getOriginalBounds(); ImagePreset preset = MasterImage.getImage().getPreset(); + if (mOriginalBounds == null || preset == null) return null; mOriginalBounds = preset.finalGeometryRect(mOriginalBounds.width(), mOriginalBounds.height()); + if (preset != null) { + mOriginalBounds = preset.finalGeometryRect(mOriginalBounds.width(), + mOriginalBounds.height()); + } + if (mOriginalBounds == null) { + return null; + } mRatio = mOriginalBounds.width() / (float) mOriginalBounds.height(); mWidthText.setText("" + mOriginalBounds.width()); mHeightText.setText("" + mOriginalBounds.height()); |