Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b0f7a8f7 authored by Ruben Brunk's avatar Ruben Brunk
Browse files

Refactoring Geometry handling.

Bug: 9170644
Bug: 9366654
Bug: 9366263

- Consolidates all the geometry transforms in GeometryMathUtils and
  significantly reduces complexity.
- Removes GeometryMetadata object and dependent code.
- Removes ImageGeometry and geometry update callbacks.

Change-Id: I59add51907459593244c9ebaadef585efc7486d5
parent 8f442fae
Loading
Loading
Loading
Loading
+14 −19
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ public class EditorPlaceHolder {
            return null;
        }

        try {
        editor.createEditor(mActivity, mContainer);
        editor.getImageShow().bindAsImageLoadListener();
        mContainer.setVisibility(View.VISIBLE);
@@ -60,10 +59,6 @@ public class EditorPlaceHolder {
        hideOldViews();
        editor.setVisibility(View.VISIBLE);
        return editor;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public void setOldViews(Vector<ImageShow> views) {
+5 −19
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ import com.android.gallery3d.filtershow.editors.BasicEditor;
import com.android.gallery3d.filtershow.editors.Editor;
import com.android.gallery3d.filtershow.editors.EditorCrop;
import com.android.gallery3d.filtershow.editors.EditorDraw;
import com.android.gallery3d.filtershow.editors.EditorFlip;
import com.android.gallery3d.filtershow.editors.EditorMirror;
import com.android.gallery3d.filtershow.editors.EditorManager;
import com.android.gallery3d.filtershow.editors.EditorPanel;
import com.android.gallery3d.filtershow.editors.EditorRedEye;
@@ -85,7 +85,6 @@ import com.android.gallery3d.filtershow.filters.FiltersManager;
import com.android.gallery3d.filtershow.filters.ImageFilter;
import com.android.gallery3d.filtershow.history.HistoryManager;
import com.android.gallery3d.filtershow.history.HistoryItem;
import com.android.gallery3d.filtershow.imageshow.GeometryMetadata;
import com.android.gallery3d.filtershow.imageshow.ImageCrop;
import com.android.gallery3d.filtershow.imageshow.ImageShow;
import com.android.gallery3d.filtershow.imageshow.MasterImage;
@@ -394,7 +393,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
        mEditorPlaceHolder.addEditor(new EditorTinyPlanet());
        mEditorPlaceHolder.addEditor(new EditorRedEye());
        mEditorPlaceHolder.addEditor(new EditorCrop());
        mEditorPlaceHolder.addEditor(new EditorFlip());
        mEditorPlaceHolder.addEditor(new EditorMirror());
        mEditorPlaceHolder.addEditor(new EditorRotate());
        mEditorPlaceHolder.addEditor(new EditorStraighten());
    }
@@ -411,10 +410,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
        int curveHandleSize = (int) res.getDimension(R.dimen.crop_indicator_size);
        Spline.setCurveHandle(curveHandle, curveHandleSize);
        Spline.setCurveWidth((int) getPixelsFromDip(3));

        ImageCrop.setAspectTextSize((int) getPixelsFromDip(18));
        ImageCrop.setTouchTolerance((int) getPixelsFromDip(25));
        ImageCrop.setMinCropSize((int) getPixelsFromDip(55));
    }

    private void startLoadBitmap(Uri uri) {
@@ -494,6 +489,8 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
        FilterRepresentation representation = copy.getRepresentation(filterRepresentation);
        if (representation == null) {
            copy.addFilter(filterRepresentation);
        } else if (filterRepresentation.getFilterType() == FilterRepresentation.TYPE_GEOMETRY) {
            filterRepresentation = representation;
        } else {
            if (filterRepresentation.allowsSingleInstanceOnly()) {
                // Don't just update the filter representation. Centralize the
@@ -512,14 +509,7 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
            return;
        }

        // TODO: this check is needed because the GeometryMetadata doesn't quite
        // follow the same pattern as the other filters to update/sync their values.
        // We thus need to not call useFilterRepresentation() for now, as it
        // would override the current Geometry. Once GeometryMetadata is fixed,
        // let's remove the check and call useFilterRepresentation all the time.
        if (!(representation instanceof GeometryMetadata)) {
        useFilterRepresentation(representation);
        }

        // show representation
        Editor mCurrentEditor = mEditorPlaceHolder.showEditor(representation.getEditorId());
@@ -633,7 +623,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
            if (!mShowingTinyPlanet) {
                mCategoryFiltersAdapter.removeTinyPlanet();
            }
            MasterImage.getImage().setOriginalGeometry(largeBitmap);
            mCategoryLooksAdapter.imageLoaded();
            mCategoryBordersAdapter.imageLoaded();
            mCategoryGeometryAdapter.imageLoaded();
@@ -650,8 +639,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL
            if (mAction == TINY_PLANET_ACTION) {
                showRepresentation(mCategoryFiltersAdapter.getTinyPlanet());
            }

            MasterImage.getImage().notifyGeometryChange();
            LoadHighresBitmapTask highresLoad = new LoadHighresBitmapTask();
            highresLoad.execute();
            super.onPostExecute(result);
@@ -937,7 +924,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL

    public void invalidateViews() {
        for (ImageShow views : mImageViews) {
            views.invalidate();
            views.updateImage();
        }
    }
+4 −4
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.RectF;

import com.android.gallery3d.filtershow.imageshow.GeometryMath;
import com.android.gallery3d.filtershow.imageshow.GeometryMathUtils;

import java.util.Arrays;

@@ -134,7 +134,7 @@ public class BoundedRect {
                };
                float[] nearestSide = CropMath.closestSide(badCorner, outerCorners);
                float[] correctionVec =
                        GeometryMath.shortestVectorFromPointToLine(badCorner, nearestSide);
                        GeometryMathUtils.shortestVectorFromPointToLine(badCorner, nearestSide);
                correction[0] += correctionVec[0];
                correction[1] += correctionVec[1];
            }
@@ -195,7 +195,7 @@ public class BoundedRect {
                        newInnerCorners[i], newInnerCorners[i + 1],
                        oldInnerCorners[i], oldInnerCorners[i + 1]
                };
                float[] p = GeometryMath.lineIntersect(pathOfCorner, outerSide);
                float[] p = GeometryMathUtils.lineIntersect(pathOfCorner, outerSide);
                if (p == null) {
                    // lines are parallel or not well defined, so don't resize
                    p = new float[2];
@@ -288,7 +288,7 @@ public class BoundedRect {
                        newInnerCorners[i], newInnerCorners[i + 1],
                        oldInnerCorners[i], oldInnerCorners[i + 1]
                };
                float[] p = GeometryMath.lineIntersect(l1, l2);
                float[] p = GeometryMathUtils.lineIntersect(l1, l2);
                if (p == null) {
                    // lines are parallel or not well defined, so set to old
                    // corner
+5 −5
Original line number Diff line number Diff line
@@ -20,7 +20,7 @@ import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.RectF;

import com.android.gallery3d.filtershow.imageshow.GeometryMath;
import com.android.gallery3d.filtershow.imageshow.GeometryMathUtils;

import java.util.Arrays;

@@ -97,8 +97,8 @@ public class CropMath {
        if (array.length < 2)
            return;
        for (int x = 0; x < array.length; x += 2) {
            array[x] = GeometryMath.clamp(array[x], imageBound.left, imageBound.right);
            array[x + 1] = GeometryMath.clamp(array[x + 1], imageBound.top, imageBound.bottom);
            array[x] = GeometryMathUtils.clamp(array[x], imageBound.left, imageBound.right);
            array[x + 1] = GeometryMathUtils.clamp(array[x + 1], imageBound.top, imageBound.bottom);
        }
    }

@@ -119,8 +119,8 @@ public class CropMath {
                    corners[i], corners[(i + 1) % len],
                    corners[(i + 2) % len], corners[(i + 3) % len]
            };
            float mag = GeometryMath.vectorLength(
                    GeometryMath.shortestVectorFromPointToLine(point, line));
            float mag = GeometryMathUtils.vectorLength(
                    GeometryMathUtils.shortestVectorFromPointToLine(point, line));
            if (mag < oldMag) {
                oldMag = mag;
                bestLine = line;
+3 −4
Original line number Diff line number Diff line
@@ -19,10 +19,9 @@ package com.android.gallery3d.filtershow.crop;
import android.graphics.Rect;
import android.graphics.RectF;

import com.android.gallery3d.filtershow.imageshow.GeometryMath;
import com.android.gallery3d.filtershow.imageshow.GeometryMathUtils;

public class CropObject {

    private BoundedRect mBoundedRect;
    private float mAspectWidth = 1;
    private float mAspectHeight = 1;
@@ -234,8 +233,8 @@ public class CropObject {
                float[] disp = {
                        dx, dy
                };
                float[] bUnit = GeometryMath.normalize(b);
                float sp = GeometryMath.scalarProjection(disp, bUnit);
                float[] bUnit = GeometryMathUtils.normalize(b);
                float sp = GeometryMathUtils.scalarProjection(disp, bUnit);
                dx = sp * bUnit[0];
                dy = sp * bUnit[1];
                RectF newCrop = fixedCornerResize(crop, movingEdges, dx, dy);
Loading