diff options
author | John Hoford <hoford@google.com> | 2013-06-27 00:32:46 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-06-27 00:32:46 +0000 |
commit | d9b2355e1e11c6f7248c902a419a36c99e6bb58c (patch) | |
tree | 6b9875bf2930c511ddb991893be44f38ba2aee02 /src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java | |
parent | 9bbe5ad57e60c0c33d64cd0a415b9506940c3c25 (diff) | |
parent | e89458e7d8b78cb3eb8d5299c50e6075131b09ef (diff) | |
download | android_packages_apps_Snap-d9b2355e1e11c6f7248c902a419a36c99e6bb58c.tar.gz android_packages_apps_Snap-d9b2355e1e11c6f7248c902a419a36c99e6bb58c.tar.bz2 android_packages_apps_Snap-d9b2355e1e11c6f7248c902a419a36c99e6bb58c.zip |
Merge "support non destructive edits of Curves" into gb-ub-photos-carlsbad
Diffstat (limited to 'src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java')
-rw-r--r-- | src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java index 4554f9b6d..a71aa8863 100644 --- a/src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java +++ b/src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java @@ -1,17 +1,24 @@ package com.android.gallery3d.filtershow.filters; +import android.util.JsonReader; +import android.util.JsonWriter; import android.util.Log; import com.android.gallery3d.R; +import com.android.gallery3d.filtershow.ui.ControlPoint; import com.android.gallery3d.filtershow.ui.Spline; +import java.io.IOException; + /** * TODO: Insert description here. (generated by hoford) */ public class FilterCurvesRepresentation extends FilterRepresentation { private static final String LOGTAG = "FilterCurvesRepresentation"; + public static final String SERIALIZATION_NAME = "Curve"; + private static final int MAX_SPLINE_NUMBER = 4; - private Spline[] mSplines = new Spline[4]; + private Spline[] mSplines = new Spline[MAX_SPLINE_NUMBER]; public FilterCurvesRepresentation() { super("Curves"); @@ -39,7 +46,7 @@ public class FilterCurvesRepresentation extends FilterRepresentation { return; } FilterCurvesRepresentation representation = (FilterCurvesRepresentation) a; - Spline[] spline = new Spline[4]; + Spline[] spline = new Spline[MAX_SPLINE_NUMBER]; for (int i = 0; i < spline.length; i++) { Spline sp = representation.mSplines[i]; if (sp != null) { @@ -52,7 +59,7 @@ public class FilterCurvesRepresentation extends FilterRepresentation { } public boolean isNil() { - for (int i = 0; i < 4; i++) { + for (int i = 0; i < MAX_SPLINE_NUMBER; i++) { if (getSpline(i) != null && !getSpline(i).isOriginal()) { return false; } @@ -66,7 +73,7 @@ public class FilterCurvesRepresentation extends FilterRepresentation { spline.addPoint(0.0f, 1.0f); spline.addPoint(1.0f, 0.0f); - for (int i = 0; i < 4; i++) { + for (int i = 0; i < MAX_SPLINE_NUMBER; i++) { mSplines[i] = new Spline(spline); } } @@ -77,4 +84,58 @@ public class FilterCurvesRepresentation extends FilterRepresentation { public Spline getSpline(int splineIndex) { return mSplines[splineIndex]; } + + @Override + public void serializeRepresentation(JsonWriter writer) throws IOException { + writer.beginObject(); + { + writer.name(NAME_TAG); + writer.value(getName()); + for (int i = 0; i < mSplines.length; i++) { + writer.name(SERIALIZATION_NAME + i); + writer.beginArray(); + int nop = mSplines[i].getNbPoints(); + for (int j = 0; j < nop; j++) { + ControlPoint p = mSplines[i].getPoint(j); + writer.beginArray(); + writer.value(p.x); + writer.value(p.y); + writer.endArray(); + } + writer.endArray(); + } + + } + writer.endObject(); + } + + @Override + public void deSerializeRepresentation(JsonReader sreader) throws IOException { + sreader.beginObject(); + Spline[] spline = new Spline[MAX_SPLINE_NUMBER]; + while (sreader.hasNext()) { + String name = sreader.nextName(); + if (NAME_TAG.equals(name)) { + setName(sreader.nextString()); + } else if (name.startsWith(SERIALIZATION_NAME)) { + int curveNo = Integer.parseInt(name.substring(SERIALIZATION_NAME.length())); + spline[curveNo] = new Spline(); + sreader.beginArray(); + while (sreader.hasNext()) { + sreader.beginArray(); + sreader.hasNext(); + float x = (float) sreader.nextDouble(); + sreader.hasNext(); + float y = (float) sreader.nextDouble(); + sreader.endArray(); + spline[curveNo].addPoint(x, y); + } + sreader.endArray(); + + } + } + mSplines = spline; + sreader.endObject(); + } + } |