OSDN Git Service

am 51713de0: am 8141e241: Merge "Improves UI / size" into gb-ub-photos-carlsbad
[android-x86/packages-apps-Gallery2.git] / src / com / android / gallery3d / filtershow / pipeline / ImagePreset.java
1 /*
2  * Copyright (C) 2012 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package com.android.gallery3d.filtershow.pipeline;
18
19 import android.graphics.Bitmap;
20 import android.graphics.Rect;
21 import android.support.v8.renderscript.Allocation;
22 import android.util.JsonReader;
23 import android.util.JsonWriter;
24 import android.util.Log;
25
26 import com.android.gallery3d.R;
27 import com.android.gallery3d.filtershow.cache.BitmapCache;
28 import com.android.gallery3d.filtershow.cache.ImageLoader;
29 import com.android.gallery3d.filtershow.filters.BaseFiltersManager;
30 import com.android.gallery3d.filtershow.filters.FilterCropRepresentation;
31 import com.android.gallery3d.filtershow.filters.FilterFxRepresentation;
32 import com.android.gallery3d.filtershow.filters.FilterImageBorderRepresentation;
33 import com.android.gallery3d.filtershow.filters.FilterMirrorRepresentation;
34 import com.android.gallery3d.filtershow.filters.FilterRepresentation;
35 import com.android.gallery3d.filtershow.filters.FilterRotateRepresentation;
36 import com.android.gallery3d.filtershow.filters.FilterStraightenRepresentation;
37 import com.android.gallery3d.filtershow.filters.FilterUserPresetRepresentation;
38 import com.android.gallery3d.filtershow.filters.FiltersManager;
39 import com.android.gallery3d.filtershow.filters.ImageFilter;
40 import com.android.gallery3d.filtershow.imageshow.GeometryMathUtils;
41 import com.android.gallery3d.filtershow.imageshow.MasterImage;
42 import com.android.gallery3d.filtershow.state.State;
43 import com.android.gallery3d.filtershow.state.StateAdapter;
44 import com.android.gallery3d.util.UsageStatistics;
45
46 import java.io.IOException;
47 import java.io.StringReader;
48 import java.io.StringWriter;
49 import java.util.ArrayList;
50 import java.util.Collection;
51 import java.util.Vector;
52
53 public class ImagePreset {
54
55     private static final String LOGTAG = "ImagePreset";
56
57     private Vector<FilterRepresentation> mFilters = new Vector<FilterRepresentation>();
58
59     private boolean mDoApplyGeometry = true;
60     private boolean mDoApplyFilters = true;
61
62     private boolean mPartialRendering = false;
63     private Rect mPartialRenderingBounds;
64     private static final boolean DEBUG = false;
65
66     public ImagePreset() {
67     }
68
69     public ImagePreset(ImagePreset source) {
70         for (int i = 0; i < source.mFilters.size(); i++) {
71             FilterRepresentation sourceRepresentation = source.mFilters.elementAt(i);
72             mFilters.add(sourceRepresentation.copy());
73         }
74     }
75
76     public Vector<FilterRepresentation> getFilters() {
77         return mFilters;
78     }
79
80     public FilterRepresentation getFilterRepresentation(int position) {
81         FilterRepresentation representation = null;
82
83         representation = mFilters.elementAt(position).copy();
84
85         return representation;
86     }
87
88     private static boolean sameSerializationName(String a, String b) {
89         if (a != null && b != null) {
90             return a.equals(b);
91         } else {
92             return a == null && b == null;
93         }
94     }
95
96     public static boolean sameSerializationName(FilterRepresentation a, FilterRepresentation b) {
97         if (a == null || b == null) {
98             return false;
99         }
100         return sameSerializationName(a.getSerializationName(), b.getSerializationName());
101     }
102
103     public int getPositionForRepresentation(FilterRepresentation representation) {
104         for (int i = 0; i < mFilters.size(); i++) {
105             if (sameSerializationName(mFilters.elementAt(i), representation)) {
106                 return i;
107             }
108         }
109         return -1;
110     }
111
112     private FilterRepresentation getFilterRepresentationForType(int type) {
113         for (int i = 0; i < mFilters.size(); i++) {
114             if (mFilters.elementAt(i).getFilterType() == type) {
115                 return mFilters.elementAt(i);
116             }
117         }
118         return null;
119     }
120
121     public int getPositionForType(int type) {
122         for (int i = 0; i < mFilters.size(); i++) {
123             if (mFilters.elementAt(i).getFilterType() == type) {
124                 return i;
125             }
126         }
127         return -1;
128     }
129
130     public FilterRepresentation getFilterRepresentationCopyFrom(
131             FilterRepresentation filterRepresentation) {
132         // TODO: add concept of position in the filters (to allow multiple instances)
133         if (filterRepresentation == null) {
134             return null;
135         }
136         int position = getPositionForRepresentation(filterRepresentation);
137         if (position == -1) {
138             return null;
139         }
140         FilterRepresentation representation = mFilters.elementAt(position);
141         if (representation != null) {
142             representation = representation.copy();
143         }
144         return representation;
145     }
146
147     public void updateFilterRepresentations(Collection<FilterRepresentation> reps) {
148         for (FilterRepresentation r : reps) {
149             updateOrAddFilterRepresentation(r);
150         }
151     }
152
153     public void updateOrAddFilterRepresentation(FilterRepresentation rep) {
154         int pos = getPositionForRepresentation(rep);
155         if (pos != -1) {
156             mFilters.elementAt(pos).useParametersFrom(rep);
157         } else {
158             addFilter(rep.copy());
159         }
160     }
161
162     public void setDoApplyGeometry(boolean value) {
163         mDoApplyGeometry = value;
164     }
165
166     public void setDoApplyFilters(boolean value) {
167         mDoApplyFilters = value;
168     }
169
170     public boolean getDoApplyFilters() {
171         return mDoApplyFilters;
172     }
173
174     public boolean hasModifications() {
175         for (int i = 0; i < mFilters.size(); i++) {
176             FilterRepresentation filter = mFilters.elementAt(i);
177             if (!filter.isNil()) {
178                 return true;
179             }
180         }
181         return false;
182     }
183
184     public boolean isPanoramaSafe() {
185         for (FilterRepresentation representation : mFilters) {
186             if (representation.getFilterType() == FilterRepresentation.TYPE_GEOMETRY
187                     && !representation.isNil()) {
188                 return false;
189             }
190             if (representation.getFilterType() == FilterRepresentation.TYPE_BORDER
191                     && !representation.isNil()) {
192                 return false;
193             }
194             if (representation.getFilterType() == FilterRepresentation.TYPE_VIGNETTE
195                     && !representation.isNil()) {
196                 return false;
197             }
198             if (representation.getFilterType() == FilterRepresentation.TYPE_TINYPLANET
199                     && !representation.isNil()) {
200                 return false;
201             }
202         }
203         return true;
204     }
205
206     public boolean same(ImagePreset preset) {
207         if (preset == null) {
208             return false;
209         }
210
211         if (preset.mFilters.size() != mFilters.size()) {
212             return false;
213         }
214
215         if (mDoApplyGeometry != preset.mDoApplyGeometry) {
216             return false;
217         }
218
219         if (mDoApplyFilters != preset.mDoApplyFilters) {
220             if (mFilters.size() > 0 || preset.mFilters.size() > 0) {
221                 return false;
222             }
223         }
224
225         if (mDoApplyFilters && preset.mDoApplyFilters) {
226             for (int i = 0; i < preset.mFilters.size(); i++) {
227                 FilterRepresentation a = preset.mFilters.elementAt(i);
228                 FilterRepresentation b = mFilters.elementAt(i);
229
230                 if (!a.same(b)) {
231                     return false;
232                 }
233             }
234         }
235
236         return true;
237     }
238
239     public boolean equals(ImagePreset preset) {
240         if (preset == null) {
241             return false;
242         }
243
244         if (preset.mFilters.size() != mFilters.size()) {
245             return false;
246         }
247
248         if (mDoApplyGeometry != preset.mDoApplyGeometry) {
249             return false;
250         }
251
252         if (mDoApplyFilters != preset.mDoApplyFilters) {
253             if (mFilters.size() > 0 || preset.mFilters.size() > 0) {
254                 return false;
255             }
256         }
257
258         for (int i = 0; i < preset.mFilters.size(); i++) {
259             FilterRepresentation a = preset.mFilters.elementAt(i);
260             FilterRepresentation b = mFilters.elementAt(i);
261
262             if (!a.equals(b)) {
263                 return false;
264             }
265         }
266
267         return true;
268     }
269
270     public int similarUpTo(ImagePreset preset) {
271         for (int i = 0; i < preset.mFilters.size(); i++) {
272             FilterRepresentation a = preset.mFilters.elementAt(i);
273             if (i < mFilters.size()) {
274                 FilterRepresentation b = mFilters.elementAt(i);
275                 if (!a.same(b)) {
276                     return i;
277                 }
278                 if (!a.equals(b)) {
279                     return i;
280                 }
281             } else {
282                 return i;
283             }
284         }
285         return preset.mFilters.size();
286     }
287
288     public void showFilters() {
289         Log.v(LOGTAG, "\\\\\\ showFilters -- " + mFilters.size() + " filters");
290         int n = 0;
291         for (FilterRepresentation representation : mFilters) {
292             Log.v(LOGTAG, " filter " + n + " : " + representation.toString());
293             n++;
294         }
295         Log.v(LOGTAG, "/// showFilters -- " + mFilters.size() + " filters");
296     }
297
298     public FilterRepresentation getLastRepresentation() {
299         if (mFilters.size() > 0) {
300             return mFilters.lastElement();
301         }
302         return null;
303     }
304
305     public void removeFilter(FilterRepresentation filterRepresentation) {
306         if (filterRepresentation.getFilterType() == FilterRepresentation.TYPE_BORDER) {
307             for (int i = 0; i < mFilters.size(); i++) {
308                 if (mFilters.elementAt(i).getFilterType()
309                 == filterRepresentation.getFilterType()) {
310                     mFilters.remove(i);
311                     break;
312                 }
313             }
314         } else {
315             for (int i = 0; i < mFilters.size(); i++) {
316                 if (sameSerializationName(mFilters.elementAt(i), filterRepresentation)) {
317                     mFilters.remove(i);
318                     break;
319                 }
320             }
321         }
322     }
323
324     // If the filter is an "None" effect or border, then just don't add this filter.
325     public void addFilter(FilterRepresentation representation) {
326         if (representation instanceof FilterUserPresetRepresentation) {
327             ImagePreset preset = ((FilterUserPresetRepresentation) representation).getImagePreset();
328             // user preset replace everything but geometry
329             mFilters.clear();
330             for (int i = 0; i < preset.nbFilters(); i++) {
331                 addFilter(preset.getFilterRepresentation(i));
332             }
333             mFilters.add(representation);
334         } else if (representation.getFilterType() == FilterRepresentation.TYPE_GEOMETRY) {
335             // Add geometry filter, removing duplicates and do-nothing operations.
336             for (int i = 0; i < mFilters.size(); i++) {
337                 if (sameSerializationName(representation, mFilters.elementAt(i))) {
338                     mFilters.remove(i);
339                 }
340             }
341             int index = 0;
342             for (; index < mFilters.size(); index++) {
343                 FilterRepresentation rep = mFilters.elementAt(index);
344                 if (rep.getFilterType() != FilterRepresentation.TYPE_GEOMETRY) {
345                     break;
346                 }
347             }
348             if (!representation.isNil()) {
349                 mFilters.insertElementAt(representation, index);
350             }
351         } else if (representation.getFilterType() == FilterRepresentation.TYPE_BORDER) {
352             removeFilter(representation);
353             if (!isNoneBorderFilter(representation)) {
354                 mFilters.add(representation);
355             }
356         } else if (representation.getFilterType() == FilterRepresentation.TYPE_FX) {
357             boolean found = false;
358             for (int i = 0; i < mFilters.size(); i++) {
359                 FilterRepresentation current = mFilters.elementAt(i);
360                 int type = current.getFilterType();
361                 if (found) {
362                     if (type != FilterRepresentation.TYPE_VIGNETTE) {
363                         mFilters.remove(i);
364                         continue;
365                     }
366                 }
367                 if (type == FilterRepresentation.TYPE_FX) {
368                     if (current instanceof FilterUserPresetRepresentation) {
369                         ImagePreset preset = ((FilterUserPresetRepresentation) current)
370                                 .getImagePreset();
371                         // If we had an existing user preset, let's remove all the presets that
372                         // were added by it
373                         for (int j = 0; j < preset.nbFilters(); j++) {
374                             FilterRepresentation rep = preset.getFilterRepresentation(j);
375                             int pos = getPositionForRepresentation(rep);
376                             if (pos != -1) {
377                                 mFilters.remove(pos);
378                             }
379                         }
380                         int pos = getPositionForRepresentation(current);
381                         if (pos != -1) {
382                             mFilters.remove(pos);
383                         } else {
384                             pos = 0;
385                         }
386                         if (!isNoneFxFilter(representation)) {
387                             mFilters.add(pos, representation);
388                         }
389
390                     } else {
391                         mFilters.remove(i);
392                         if (!isNoneFxFilter(representation)) {
393                             mFilters.add(i, representation);
394                         }
395                     }
396                     found = true;
397                 }
398             }
399             if (!found) {
400                 if (!isNoneFxFilter(representation)) {
401                     mFilters.add(representation);
402                 }
403             }
404         } else {
405             mFilters.add(representation);
406         }
407     }
408
409     private boolean isNoneBorderFilter(FilterRepresentation representation) {
410         return representation instanceof FilterImageBorderRepresentation &&
411                 ((FilterImageBorderRepresentation) representation).getDrawableResource() == 0;
412     }
413
414     private boolean isNoneFxFilter(FilterRepresentation representation) {
415         return representation instanceof FilterFxRepresentation &&
416                 ((FilterFxRepresentation) representation).getNameResource() == R.string.none;
417     }
418
419     public FilterRepresentation getRepresentation(FilterRepresentation filterRepresentation) {
420         for (int i = 0; i < mFilters.size(); i++) {
421             FilterRepresentation representation = mFilters.elementAt(i);
422             if (sameSerializationName(representation, filterRepresentation)) {
423                 return representation;
424             }
425         }
426         return null;
427     }
428
429     public Bitmap apply(Bitmap original, FilterEnvironment environment) {
430         Bitmap bitmap = original;
431         bitmap = applyFilters(bitmap, -1, -1, environment);
432         return applyBorder(bitmap, environment);
433     }
434
435     public Collection<FilterRepresentation> getGeometryFilters() {
436         ArrayList<FilterRepresentation> geometry = new ArrayList<FilterRepresentation>();
437         for (FilterRepresentation r : mFilters) {
438             if (r.getFilterType() == FilterRepresentation.TYPE_GEOMETRY) {
439                 geometry.add(r);
440             }
441         }
442         return geometry;
443     }
444
445     public FilterRepresentation getFilterWithSerializationName(String serializationName) {
446         for (FilterRepresentation r : mFilters) {
447             if (r != null) {
448                 if (sameSerializationName(r.getSerializationName(), serializationName)) {
449                     return r.copy();
450                 }
451             }
452         }
453         return null;
454     }
455
456     public Rect finalGeometryRect(int width, int height) {
457         return GeometryMathUtils.finalGeometryRect(width, height, getGeometryFilters());
458     }
459
460     public Bitmap applyGeometry(Bitmap bitmap, FilterEnvironment environment) {
461         // Apply any transform -- 90 rotate, flip, straighten, crop
462         // Returns a new bitmap.
463         if (mDoApplyGeometry) {
464             bitmap = GeometryMathUtils.applyGeometryRepresentations(getGeometryFilters(), bitmap);
465         }
466         return bitmap;
467     }
468
469     public Bitmap applyBorder(Bitmap bitmap, FilterEnvironment environment) {
470         // get the border from the list of filters.
471         FilterRepresentation border = getFilterRepresentationForType(
472                 FilterRepresentation.TYPE_BORDER);
473         if (border != null && mDoApplyGeometry) {
474             bitmap = environment.applyRepresentation(border, bitmap);
475             if (environment.getQuality() == FilterEnvironment.QUALITY_FINAL) {
476                 UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR,
477                         "SaveBorder", border.getSerializationName(), 1);
478             }
479         }
480         return bitmap;
481     }
482
483     public int nbFilters() {
484         return mFilters.size();
485     }
486
487     public Bitmap applyFilters(Bitmap bitmap, int from, int to, FilterEnvironment environment) {
488         if (mDoApplyFilters) {
489             if (from < 0) {
490                 from = 0;
491             }
492             if (to == -1) {
493                 to = mFilters.size();
494             }
495             if (environment.getQuality() == FilterEnvironment.QUALITY_FINAL) {
496                 UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR,
497                         "SaveFilters", "Total", to - from + 1);
498             }
499             for (int i = from; i < to; i++) {
500                 FilterRepresentation representation = mFilters.elementAt(i);
501                 if (representation.getFilterType() == FilterRepresentation.TYPE_GEOMETRY) {
502                     // skip the geometry as it's already applied.
503                     continue;
504                 }
505                 if (representation.getFilterType() == FilterRepresentation.TYPE_BORDER) {
506                     // for now, let's skip the border as it will be applied in
507                     // applyBorder()
508                     // TODO: might be worth getting rid of applyBorder.
509                     continue;
510                 }
511                 Bitmap tmp = bitmap;
512                 bitmap = environment.applyRepresentation(representation, bitmap);
513                 if (tmp != bitmap) {
514                     environment.cache(tmp);
515                 }
516                 if (environment.getQuality() == FilterEnvironment.QUALITY_FINAL) {
517                     UsageStatistics.onEvent(UsageStatistics.COMPONENT_EDITOR,
518                             "SaveFilter", representation.getSerializationName(), 1);
519                 }
520                 if (environment.needsStop()) {
521                     return bitmap;
522                 }
523             }
524         }
525
526         return bitmap;
527     }
528
529     public void applyBorder(Allocation in, Allocation out,
530             boolean copyOut, FilterEnvironment environment) {
531         FilterRepresentation border = getFilterRepresentationForType(
532                 FilterRepresentation.TYPE_BORDER);
533         if (border != null && mDoApplyGeometry) {
534             // TODO: should keep the bitmap around
535             Allocation bitmapIn = in;
536             if (copyOut) {
537                 bitmapIn = Allocation.createTyped(
538                         CachingPipeline.getRenderScriptContext(), in.getType());
539                 bitmapIn.copyFrom(out);
540             }
541             environment.applyRepresentation(border, bitmapIn, out);
542         }
543     }
544
545     public void applyFilters(int from, int to, Allocation in, Allocation out,
546             FilterEnvironment environment) {
547         if (mDoApplyFilters) {
548             if (from < 0) {
549                 from = 0;
550             }
551             if (to == -1) {
552                 to = mFilters.size();
553             }
554             for (int i = from; i < to; i++) {
555                 FilterRepresentation representation = mFilters.elementAt(i);
556                 if (representation.getFilterType() == FilterRepresentation.TYPE_GEOMETRY
557                         || representation.getFilterType() == FilterRepresentation.TYPE_BORDER) {
558                     continue;
559                 }
560                 if (i > from) {
561                     in.copyFrom(out);
562                 }
563                 environment.applyRepresentation(representation, in, out);
564             }
565         }
566     }
567
568     public boolean canDoPartialRendering() {
569         if (MasterImage.getImage().getZoomOrientation() != ImageLoader.ORI_NORMAL) {
570             return false;
571         }
572         for (int i = 0; i < mFilters.size(); i++) {
573             FilterRepresentation representation = mFilters.elementAt(i);
574             if (!representation.supportsPartialRendering()) {
575                 return false;
576             }
577         }
578         return true;
579     }
580
581     public void fillImageStateAdapter(StateAdapter imageStateAdapter) {
582         if (imageStateAdapter == null) {
583             return;
584         }
585         Vector<State> states = new Vector<State>();
586         for (FilterRepresentation filter : mFilters) {
587             if (filter instanceof FilterUserPresetRepresentation) {
588                 // do not show the user preset itself in the state panel
589                 continue;
590             }
591             State state = new State(filter.getName());
592             state.setFilterRepresentation(filter);
593             states.add(state);
594         }
595         imageStateAdapter.fill(states);
596     }
597
598     public void setPartialRendering(boolean partialRendering, Rect bounds) {
599         mPartialRendering = partialRendering;
600         mPartialRenderingBounds = bounds;
601     }
602
603     public boolean isPartialRendering() {
604         return mPartialRendering;
605     }
606
607     public Rect getPartialRenderingBounds() {
608         return mPartialRenderingBounds;
609     }
610
611     public Vector<ImageFilter> getUsedFilters(BaseFiltersManager filtersManager) {
612         Vector<ImageFilter> usedFilters = new Vector<ImageFilter>();
613         for (int i = 0; i < mFilters.size(); i++) {
614             FilterRepresentation representation = mFilters.elementAt(i);
615             ImageFilter filter = filtersManager.getFilterForRepresentation(representation);
616             usedFilters.add(filter);
617         }
618         return usedFilters;
619     }
620
621     public String getJsonString(String name) {
622         StringWriter swriter = new StringWriter();
623         try {
624             JsonWriter writer = new JsonWriter(swriter);
625             writeJson(writer, name);
626             writer.close();
627         } catch (IOException e) {
628             return null;
629         }
630         return swriter.toString();
631     }
632
633     public void writeJson(JsonWriter writer, String name) {
634         int numFilters = mFilters.size();
635         try {
636             writer.beginObject();
637             for (int i = 0; i < numFilters; i++) {
638                 FilterRepresentation filter = mFilters.get(i);
639                 if (filter instanceof FilterUserPresetRepresentation) {
640                     continue;
641                 }
642                 String sname = filter.getSerializationName();
643                 if (DEBUG) {
644                     Log.v(LOGTAG, "Serialization: " + sname);
645                     if (sname == null) {
646                         Log.v(LOGTAG, "Serialization name null for filter: " + filter);
647                     }
648                 }
649                 writer.name(sname);
650                 filter.serializeRepresentation(writer);
651             }
652             writer.endObject();
653
654         } catch (IOException e) {
655            Log.e(LOGTAG,"Error encoding JASON",e);
656         }
657     }
658
659     /**
660      * populates preset from JSON string
661      *
662      * @param filterString a JSON string
663      * @return true on success if false ImagePreset is undefined
664      */
665     public boolean readJsonFromString(String filterString) {
666         if (DEBUG) {
667             Log.v(LOGTAG, "reading preset: \"" + filterString + "\"");
668         }
669         StringReader sreader = new StringReader(filterString);
670         try {
671             JsonReader reader = new JsonReader(sreader);
672             boolean ok = readJson(reader);
673             if (!ok) {
674                 reader.close();
675                 return false;
676             }
677             reader.close();
678         } catch (Exception e) {
679             Log.e(LOGTAG, "parsing the filter parameters:", e);
680             return false;
681         }
682         return true;
683     }
684
685     /**
686      * populates preset from JSON stream
687      *
688      * @param sreader a JSON string
689      * @return true on success if false ImagePreset is undefined
690      */
691     public boolean readJson(JsonReader sreader) throws IOException {
692         sreader.beginObject();
693
694         while (sreader.hasNext()) {
695             String name = sreader.nextName();
696             FilterRepresentation filter = creatFilterFromName(name);
697             if (filter == null) {
698                 Log.w(LOGTAG, "UNKNOWN FILTER! " + name);
699                 return false;
700             }
701             filter.deSerializeRepresentation(sreader);
702             addFilter(filter);
703         }
704         sreader.endObject();
705         return true;
706     }
707
708     FilterRepresentation creatFilterFromName(String name) {
709         if (FilterRotateRepresentation.SERIALIZATION_NAME.equals(name)) {
710             return new FilterRotateRepresentation();
711         } else if (FilterMirrorRepresentation.SERIALIZATION_NAME.equals(name)) {
712             return new FilterMirrorRepresentation();
713         } else if (FilterStraightenRepresentation.SERIALIZATION_NAME.equals(name)) {
714             return new FilterStraightenRepresentation();
715         } else if (FilterCropRepresentation.SERIALIZATION_NAME.equals(name)) {
716             return new FilterCropRepresentation();
717         }
718         FiltersManager filtersManager = FiltersManager.getManager();
719         return filtersManager.createFilterFromName(name);
720     }
721
722     public void updateWith(ImagePreset preset) {
723         if (preset.mFilters.size() != mFilters.size()) {
724             Log.e(LOGTAG, "Updating a preset with an incompatible one");
725             return;
726         }
727         for (int i = 0; i < mFilters.size(); i++) {
728             FilterRepresentation destRepresentation = mFilters.elementAt(i);
729             FilterRepresentation sourceRepresentation = preset.mFilters.elementAt(i);
730             destRepresentation.useParametersFrom(sourceRepresentation);
731         }
732     }
733 }