X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2Fcom%2Fandroid%2Fgallery3d%2Ffiltershow%2Fpipeline%2FImagePreset.java;h=9166ee3be75c416c93166fca36999bc50e8e3f0a;hb=31ba765062fbb75d8b187fb2686e8868d695e754;hp=1876f25334c861ba803b95a647628bace84ff743;hpb=2d9330020b929cc75bbdfd645d3dc9278ca78779;p=android-x86%2Fpackages-apps-Gallery2.git diff --git a/src/com/android/gallery3d/filtershow/pipeline/ImagePreset.java b/src/com/android/gallery3d/filtershow/pipeline/ImagePreset.java index 1876f2533..9166ee3be 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; @@ -41,7 +41,6 @@ import com.android.gallery3d.filtershow.imageshow.GeometryMathUtils; import com.android.gallery3d.filtershow.imageshow.MasterImage; import com.android.gallery3d.filtershow.state.State; import com.android.gallery3d.filtershow.state.StateAdapter; -import com.android.gallery3d.util.UsageStatistics; import java.io.IOException; import java.io.StringReader; @@ -53,6 +52,7 @@ import java.util.Vector; public class ImagePreset { private static final String LOGTAG = "ImagePreset"; + public static final String JASON_SAVED = "Saved"; private Vector mFilters = new Vector(); @@ -268,8 +268,20 @@ public class ImagePreset { for (int i = 0; i < preset.mFilters.size(); i++) { FilterRepresentation a = preset.mFilters.elementAt(i); FilterRepresentation b = mFilters.elementAt(i); - - if (!a.equals(b)) { + boolean isGeometry = false; + if (a instanceof FilterRotateRepresentation + || a instanceof FilterMirrorRepresentation + || a instanceof FilterCropRepresentation + || a instanceof FilterStraightenRepresentation) { + isGeometry = true; + } + boolean evaluate = true; + if (!isGeometry && mDoApplyGeometry && !mDoApplyFilters) { + evaluate = false; + } else if (isGeometry && !mDoApplyGeometry && mDoApplyFilters) { + evaluate = false; + } + if (evaluate && !a.equals(b)) { return false; } } @@ -335,12 +347,18 @@ public class ImagePreset { public void addFilter(FilterRepresentation representation) { if (representation instanceof FilterUserPresetRepresentation) { ImagePreset preset = ((FilterUserPresetRepresentation) representation).getImagePreset(); - // user preset replace everything but geometry - mFilters.clear(); - for (int i = 0; i < preset.nbFilters(); i++) { - addFilter(preset.getFilterRepresentation(i)); + if (preset.nbFilters() == 1 + && preset.contains(FilterRepresentation.TYPE_FX)) { + FilterRepresentation rep = preset.getFilterRepresentationForType( + FilterRepresentation.TYPE_FX); + addFilter(rep); + } else { + // user preset replaces everything + mFilters.clear(); + for (int i = 0; i < preset.nbFilters(); i++) { + addFilter(preset.getFilterRepresentation(i)); + } } - mFilters.add(representation); } else if (representation.getFilterType() == FilterRepresentation.TYPE_GEOMETRY) { // Add geometry filter, removing duplicates and do-nothing operations. for (int i = 0; i < mFilters.size(); i++) { @@ -364,56 +382,38 @@ public class ImagePreset { mFilters.add(representation); } } else if (representation.getFilterType() == FilterRepresentation.TYPE_FX) { - boolean found = false; + boolean replaced = false; for (int i = 0; i < mFilters.size(); i++) { FilterRepresentation current = mFilters.elementAt(i); - int type = current.getFilterType(); - if (found) { - if (type != FilterRepresentation.TYPE_VIGNETTE) { - mFilters.remove(i); - continue; - } - } - if (type == FilterRepresentation.TYPE_FX) { - if (current instanceof FilterUserPresetRepresentation) { - ImagePreset preset = ((FilterUserPresetRepresentation) current) - .getImagePreset(); - // If we had an existing user preset, let's remove all the presets that - // were added by it - for (int j = 0; j < preset.nbFilters(); j++) { - FilterRepresentation rep = preset.getFilterRepresentation(j); - int pos = getPositionForRepresentation(rep); - if (pos != -1) { - mFilters.remove(pos); - } - } - int pos = getPositionForRepresentation(current); - if (pos != -1) { - mFilters.remove(pos); - } else { - pos = 0; - } - if (!isNoneFxFilter(representation)) { - mFilters.add(pos, representation); - } - - } else { - mFilters.remove(i); - if (!isNoneFxFilter(representation)) { - mFilters.add(i, representation); - } + if (current.getFilterType() == FilterRepresentation.TYPE_FX) { + mFilters.remove(i); + replaced = true; + if (!isNoneFxFilter(representation)) { + mFilters.add(i, representation); } - found = true; + break; } } - if (!found) { - if (!isNoneFxFilter(representation)) { - mFilters.add(representation); - } + if (!replaced && !isNoneFxFilter(representation)) { + mFilters.add(0, representation); } } else { mFilters.add(representation); } + // Enforces Filter type ordering for borders + FilterRepresentation border = null; + for (int i = 0; i < mFilters.size();) { + FilterRepresentation rep = mFilters.elementAt(i); + if (rep.getFilterType() == FilterRepresentation.TYPE_BORDER) { + border = rep; + mFilters.remove(i); + continue; + } + i++; + } + if (border != null) { + mFilters.add(border); + } } private boolean isNoneBorderFilter(FilterRepresentation representation) { @@ -488,8 +488,6 @@ public class ImagePreset { if (border != null && mDoApplyGeometry) { bitmap = environment.applyRepresentation(border, bitmap); if (environment.getQuality() == FilterEnvironment.QUALITY_FINAL) { - UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR, - "SaveBorder", border.getSerializationName(), 1); } } return bitmap; @@ -507,10 +505,6 @@ public class ImagePreset { if (to == -1) { to = mFilters.size(); } - if (environment.getQuality() == FilterEnvironment.QUALITY_FINAL) { - UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR, - "SaveFilters", "Total", to - from + 1); - } for (int i = from; i < to; i++) { FilterRepresentation representation = mFilters.elementAt(i); if (representation.getFilterType() == FilterRepresentation.TYPE_GEOMETRY) { @@ -528,10 +522,6 @@ public class ImagePreset { if (tmp != bitmap) { environment.cache(tmp); } - if (environment.getQuality() == FilterEnvironment.QUALITY_FINAL) { - UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR, - "SaveFilter", representation.getSerializationName(), 1); - } if (environment.needsStop()) { return bitmap; } @@ -691,6 +681,7 @@ public class ImagePreset { } reader.close(); } catch (Exception e) { + Log.e(LOGTAG, "\""+filterString+"\""); Log.e(LOGTAG, "parsing the filter parameters:", e); return false; }