InteractionMode mInteractionMode = InteractionMode.NONE;
protected GeometryMetadata getGeometry() {
- return new GeometryMetadata(getImagePreset().mGeoData);
+ return new GeometryMetadata(getImagePreset().getGeometry());
}
private FilterShowActivity mActivity = null;
public Rect getImageBounds() {
Rect dst = new Rect();
- getImagePreset().mGeoData.getPhotoBounds().roundOut(dst);
+ getImagePreset().getGeometry().getPhotoBounds().roundOut(dst);
return dst;
}
public Rect getImageCropBounds() {
- return GeometryMath.roundNearest(getImagePreset().mGeoData.getPreviewCropBounds());
+ return GeometryMath.roundNearest(getImagePreset().getGeometry().getPreviewCropBounds());
}
/* consider moving the following 2 methods into a subclass */
* @return Image to Screen transformation matrix
*/
protected Matrix getImageToScreenMatrix(boolean reflectRotation) {
- GeometryMetadata geo = getImagePreset().mGeoData;
+ GeometryMetadata geo = getImagePreset().getGeometry();
if (geo == null || mImageLoader == null
|| mImageLoader.getOriginalBounds() == null) {
return new Matrix();
return;
float w = image.getWidth();
float h = image.getHeight();
- GeometryMetadata geo = getImagePreset().mGeoData;
+ GeometryMetadata geo = getImagePreset().getGeometry();
RectF pb = geo.getPhotoBounds();
if (w == pb.width() && h == pb.height()) {
return;
}
RectF r = new RectF(0, 0, w, h);
- getImagePreset().mGeoData.setPhotoBounds(r);
- getImagePreset().mGeoData.setCropBounds(r);
-
+ geo.setPhotoBounds(r);
+ geo.setCropBounds(r);
+ getImagePreset().setGeometry(geo);
}
public void updateImage() {
private boolean mDoApplyGeometry = true;
private boolean mDoApplyFilters = true;
- public final GeometryMetadata mGeoData = new GeometryMetadata();
private boolean mPartialRendering = false;
private Rect mPartialRenderingBounds;
private Bitmap mPreviewImage;
public ImagePreset() {
- setup();
}
public ImagePreset(String historyName) {
setHistoryName(historyName);
- setup();
}
public ImagePreset(ImagePreset source, String historyName) {
public ImagePreset(ImagePreset source) {
try {
for (int i = 0; i < source.mFilters.size(); i++) {
- FilterRepresentation representation = source.mFilters.elementAt(i).clone();
+ FilterRepresentation representation = null;
+ FilterRepresentation sourceRepresentation = source.mFilters.elementAt(i);
+ if (sourceRepresentation instanceof GeometryMetadata) {
+ GeometryMetadata geoData = new GeometryMetadata();
+ GeometryMetadata srcGeo = (GeometryMetadata) sourceRepresentation;
+ geoData.set(srcGeo);
+ representation = geoData;
+ } else {
+ // TODO: get rid of clone()...
+ representation = sourceRepresentation.clone();
+ }
addFilter(representation);
}
} catch (java.lang.CloneNotSupportedException e) {
mIsFxPreset = source.isFx();
mImageLoader = source.getImageLoader();
mPreviewImage = source.getPreviewImage();
-
- mGeoData.set(source.mGeoData);
}
public FilterRepresentation getFilterRepresentation(int position) {
}
public synchronized GeometryMetadata getGeometry() {
- return mGeoData;
+ for (FilterRepresentation representation : mFilters) {
+ if (representation instanceof GeometryMetadata) {
+ return (GeometryMetadata) representation;
+ }
+ }
+ GeometryMetadata geo = new GeometryMetadata();
+ mFilters.add(0, geo); // Hard Requirement for now -- Geometry ought to be first.
+ return geo;
}
public boolean hasModifications() {
- if (mGeoData.hasModifications()) {
- return true;
- }
for (int i = 0; i < mFilters.size(); i++) {
FilterRepresentation filter = mFilters.elementAt(i);
+ if (filter instanceof GeometryMetadata) {
+ if (((GeometryMetadata) filter).hasModifications()) {
+ return true;
+ }
+ }
if (!filter.isNil() && !filter.getName().equalsIgnoreCase("none")) {
return true;
}
}
public boolean isPanoramaSafe() {
- if (mGeoData.hasModifications()) {
- return false;
- }
for (FilterRepresentation representation : mFilters) {
+ if (representation instanceof GeometryMetadata) {
+ if (((GeometryMetadata) representation).hasModifications()) {
+ return false;
+ }
+ }
if (representation.getFilterType() == FilterRepresentation.TYPE_BORDER
&& !representation.isNil()) {
return false;
return true;
}
- public synchronized void setGeometry(GeometryMetadata m) {
- mGeoData.set(m);
+ public synchronized void setGeometry(GeometryMetadata representation) {
+ GeometryMetadata geoData = getGeometry();
+ if (geoData != representation) {
+ geoData.set(representation);
+ }
MasterImage.getImage().notifyGeometryChange();
}
return false;
}
- if (mDoApplyGeometry && !mGeoData.equals(preset.mGeoData)) {
+ if (mDoApplyGeometry && !getGeometry().equals(preset.getGeometry())) {
return false;
}
for (int i = 0; i < preset.mFilters.size(); i++) {
FilterRepresentation a = preset.mFilters.elementAt(i);
FilterRepresentation b = mFilters.elementAt(i);
+ if (a instanceof GeometryMetadata) {
+ // Note: Geometry will always be at the same place
+ continue;
+ }
if (!a.same(b)) {
return false;
}
}
public int similarUpTo(ImagePreset preset) {
- if (!mGeoData.equals(preset.mGeoData)) {
+ if (!getGeometry().equals(preset.getGeometry())) {
return -1;
}
}
public FilterRepresentation getRepresentation(FilterRepresentation filterRepresentation) {
- if (filterRepresentation instanceof GeometryMetadata) {
- return mGeoData;
- }
for (int i = 0; i < mFilters.size(); i++) {
FilterRepresentation representation = mFilters.elementAt(i);
if (representation.getFilterClass() == filterRepresentation.getFilterClass()) {
return null;
}
- public void setup() {
- // do nothing here
- }
-
public Bitmap apply(Bitmap original, FilterEnvironment environment) {
Bitmap bitmap = original;
bitmap = applyFilters(bitmap, -1, -1, environment);
// Apply any transform -- 90 rotate, flip, straighten, crop
// Returns a new bitmap.
if (mDoApplyGeometry) {
- mGeoData.synchronizeRepresentation();
- bitmap = environment.applyRepresentation(mGeoData, bitmap);
+ GeometryMetadata geoData = getGeometry();
+ geoData.synchronizeRepresentation();
+ bitmap = environment.applyRepresentation(geoData, bitmap);
}
return bitmap;
}
representation = mFilters.elementAt(i);
representation.synchronizeRepresentation();
}
+ if (representation instanceof GeometryMetadata) {
+ // skip the geometry as it's already applied.
+ continue;
+ }
if (representation.getFilterType() == FilterRepresentation.TYPE_BORDER) {
// for now, let's skip the border as it will be applied in applyBorder()
// TODO: might be worth getting rid of applyBorder.
representation = mFilters.elementAt(i);
representation.synchronizeRepresentation();
}
+ if (representation instanceof GeometryMetadata) {
+ // skip the geometry as it's already applied.
+ continue;
+ }
if (representation.getFilterType() == FilterRepresentation.TYPE_BORDER) {
// for now, let's skip the border as it will be applied in applyBorder()
continue;
}
public boolean canDoPartialRendering() {
- if (mGeoData.hasModifications()) {
- return false;
- }
if (ImageLoader.getZoomOrientation() != ImageLoader.ORI_NORMAL) {
return false;
}
synchronized (mFilters) {
representation = mFilters.elementAt(i);
}
+ if (representation instanceof GeometryMetadata
+ && ((GeometryMetadata) representation).hasModifications()) {
+ return false;
+ }
if (!representation.supportsPartialRendering()) {
return false;
}
return;
}
Vector<State> states = new Vector<State>();
- // TODO: supports Geometry representations in the state panel.
- if (false && mGeoData != null && mGeoData.hasModifications()) {
- State geo = new State("Geometry");
- geo.setFilterRepresentation(mGeoData);
- states.add(geo);
- }
for (FilterRepresentation filter : mFilters) {
+ if (filter instanceof GeometryMetadata) {
+ // TODO: supports Geometry representations in the state panel.
+ continue;
+ }
State state = new State(filter.getName());
state.setFilterRepresentation(filter);
states.add(state);
try {
writer.beginObject();
writer.name(PRESET_NAME).value(name);
- writer.name(mGeoData.getSerializationName());
+ GeometryMetadata geoData = getGeometry();
+ writer.name(geoData.getSerializationName());
writer.beginObject();
{
- String[][] rep = mGeoData.serializeRepresentation();
+ String[][] rep = geoData.serializeRepresentation();
for (int i = 0; i < rep.length; i++) {
writer.name(rep[i][0]);
writer.value(rep[i][1]);
for (int i = 0; i < numFilters; i++) {
FilterRepresentation filter = mFilters.get(i);
+ if (filter instanceof GeometryMetadata) {
+ continue;
+ }
String sname = filter.getSerializationName();
writer.name(sname);
writer.beginObject();
while (sreader.hasNext()) {
String name = sreader.nextName();
-
- if (mGeoData.getSerializationName().equals(name)) {
- mGeoData.deSerializeRepresentation(read(sreader));
- } else {
- FilterRepresentation filter = creatFilterFromName(name);
- if (filter == null)
- return false;
- filter.deSerializeRepresentation(read(sreader));
- addFilter(filter);
+ FilterRepresentation filter = creatFilterFromName(name);
+ if (filter == null) {
+ return false;
}
+ filter.deSerializeRepresentation(read(sreader));
+ addFilter(filter);
}
sreader.endObject();
return true;
}
FilterRepresentation creatFilterFromName(String name) {
+ if (GeometryMetadata.SERIALIZATION_NAME.equalsIgnoreCase(name)) {
+ return new GeometryMetadata();
+ }
FiltersManager filtersManager = FiltersManager.getManager();
return filtersManager.createFilterFromName(name);
}