summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d
diff options
context:
space:
mode:
authorJohn Hoford <hoford@google.com>2013-06-27 00:32:46 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-06-27 00:32:46 +0000
commit47b0417a6cd824e8bf153ad905d679cec24c447a (patch)
tree4b32ac23b213c4a50b264e14c1d93b37455c10bb /src/com/android/gallery3d
parent58571d95c24053bb816fe4c8fbc4dd634612dd20 (diff)
parentca0ecc627396c69bf21f6fae5b1e6b1ac3ea36d9 (diff)
downloadandroid_packages_apps_Snap-47b0417a6cd824e8bf153ad905d679cec24c447a.tar.gz
android_packages_apps_Snap-47b0417a6cd824e8bf153ad905d679cec24c447a.tar.bz2
android_packages_apps_Snap-47b0417a6cd824e8bf153ad905d679cec24c447a.zip
Merge "support non destructive edits of Curves" into gb-ub-photos-carlsbad
Diffstat (limited to 'src/com/android/gallery3d')
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterCurvesRepresentation.java69
-rw-r--r--src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java43
-rw-r--r--src/com/android/gallery3d/filtershow/presets/ImagePreset.java39
3 files changed, 132 insertions, 19 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();
+ }
+
}
diff --git a/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java b/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java
index b192b5aaa..096bedac9 100644
--- a/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java
+++ b/src/com/android/gallery3d/filtershow/filters/FilterRepresentation.java
@@ -16,10 +16,15 @@
package com.android.gallery3d.filtershow.filters;
+import android.util.JsonReader;
+import android.util.JsonWriter;
import android.util.Log;
import com.android.gallery3d.filtershow.editors.BasicEditor;
+import java.io.IOException;
+import java.util.ArrayList;
+
public class FilterRepresentation implements Cloneable {
private static final String LOGTAG = "FilterRepresentation";
private static final boolean DEBUG = false;
@@ -40,6 +45,7 @@ public class FilterRepresentation implements Cloneable {
public static final byte TYPE_VIGNETTE = 4;
public static final byte TYPE_NORMAL = 5;
public static final byte TYPE_TINYPLANET = 6;
+ protected static final String NAME_TAG = "Name";
private FilterRepresentation mTempRepresentation = null;
@@ -222,14 +228,47 @@ public class FilterRepresentation implements Cloneable {
return "";
}
+ /**
+ * Method must "beginObject()" add its info and "endObject()"
+ * @param writer
+ * @throws IOException
+ */
+ public void serializeRepresentation(JsonWriter writer) throws IOException {
+ writer.beginObject();
+ {
+ String[][] rep = serializeRepresentation();
+ for (int k = 0; k < rep.length; k++) {
+ writer.name(rep[k][0]);
+ writer.value(rep[k][1]);
+ }
+ }
+ writer.endObject();
+ }
+
+ // this is the old way of doing this and will be removed soon
public String[][] serializeRepresentation() {
- String[][] ret = { { "Name" , getName() }};
+ String[][] ret = {{NAME_TAG, getName()}};
return ret;
}
+ public void deSerializeRepresentation(JsonReader reader) throws IOException {
+ ArrayList<String[]> al = new ArrayList<String[]>();
+ reader.beginObject();
+ while (reader.hasNext()) {
+ String[] kv = {reader.nextName(), reader.nextString()};
+ al.add(kv);
+
+ }
+ reader.endObject();
+ String[][] oldFormat = al.toArray(new String[al.size()][]);
+
+ deSerializeRepresentation(oldFormat);
+ }
+
+ // this is the old way of doing this and will be removed soon
public void deSerializeRepresentation(String[][] rep) {
for (int i = 0; i < rep.length; i++) {
- if ("Name".equals(rep[i][0])) {
+ if (NAME_TAG.equals(rep[i][0])) {
mName = rep[i][1];
break;
}
diff --git a/src/com/android/gallery3d/filtershow/presets/ImagePreset.java b/src/com/android/gallery3d/filtershow/presets/ImagePreset.java
index 3ac75e950..1c4463062 100644
--- a/src/com/android/gallery3d/filtershow/presets/ImagePreset.java
+++ b/src/com/android/gallery3d/filtershow/presets/ImagePreset.java
@@ -65,7 +65,7 @@ public class ImagePreset {
private boolean mPartialRendering = false;
private Rect mPartialRenderingBounds;
-
+ private static final boolean DEBUG = false;
private Bitmap mPreviewImage;
public ImagePreset() {
@@ -642,10 +642,9 @@ public class ImagePreset {
JsonWriter writer = new JsonWriter(swriter);
writeJson(writer, name);
writer.close();
- } catch (Exception e) {
- e.printStackTrace();
+ } catch (IOException e) {
+ return null;
}
-
return swriter.toString();
}
@@ -672,16 +671,14 @@ public class ImagePreset {
continue;
}
String sname = filter.getSerializationName();
- writer.name(sname);
- writer.beginObject();
- {
- String[][] rep = filter.serializeRepresentation();
- for (int k = 0; k < rep.length; k++) {
- writer.name(rep[k][0]);
- writer.value(rep[k][1]);
+ if (DEBUG) {
+ Log.v(LOGTAG, "Serialization: " + sname);
+ if (sname == null) {
+ Log.v(LOGTAG, "Serialization: " + filter);
}
}
- writer.endObject();
+ writer.name(sname);
+ filter.serializeRepresentation(writer);
}
writer.endObject();
@@ -690,21 +687,36 @@ public class ImagePreset {
}
}
+ /**
+ * populates preset from JSON string
+ * @param filterString a JSON string
+ * @return true on success if false ImagePreset is undefined
+ */
public boolean readJsonFromString(String filterString) {
+ if (DEBUG) {
+ Log.v(LOGTAG,"reading preset: \""+filterString+"\"");
+ }
StringReader sreader = new StringReader(filterString);
try {
JsonReader reader = new JsonReader(sreader);
boolean ok = readJson(reader);
if (!ok) {
+ reader.close();
return false;
}
reader.close();
} catch (Exception e) {
- e.printStackTrace();
+ Log.e(LOGTAG,"parsing the filter parameters:",e);
+ return false;
}
return true;
}
+ /**
+ * populates preset from JSON stream
+ * @param sreader a JSON string
+ * @return true on success if false ImagePreset is undefined
+ */
public boolean readJson(JsonReader sreader) throws IOException {
sreader.beginObject();
sreader.nextName();
@@ -714,6 +726,7 @@ public class ImagePreset {
String name = sreader.nextName();
FilterRepresentation filter = creatFilterFromName(name);
if (filter == null) {
+ Log.w(LOGTAG,"UNKNOWN FILTER! "+name);
return false;
}
filter.deSerializeRepresentation(read(sreader));