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

Commit 962df4d3 authored by John Hoford's avatar John Hoford Committed by Android Git Automerger
Browse files

am 708753f5: fix vignette

* commit '708753f5':
  fix vignette
parents fadb56af 708753f5
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -19,8 +19,10 @@ package com.android.gallery3d.filtershow.filters;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Rect;
import com.android.gallery3d.R;
import com.android.gallery3d.filtershow.imageshow.MasterImage;
import com.android.gallery3d.filtershow.pipeline.FilterEnvironment;
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.Element;
@@ -91,16 +93,23 @@ public class ImageFilterVignette extends ImageFilterRS {
        float r = calcRadius(cx, cy, w, h);
        float rx = r;
        float ry = r;
        if (mParameters.isCenterSet()) {

            cx = mParameters.getCenterX() * w;
            cy = mParameters.getCenterY() * h;

            rx = mParameters.getRadiusX() * w;
            ry = mParameters.getRadiusY() * h;
        float[]c = new float[2];
        if (mParameters.isCenterSet()) {
            Matrix m = getOriginalToScreenMatrix(w, h);
            Rect bounds = MasterImage.getImage().getOriginalBounds();
            c[0] = bounds.right * mParameters.getCenterX();
            c[1] = bounds.bottom * mParameters.getCenterY();
            m.mapPoints(c);
            cx = c[0];
            cy = c[1];
            c[0] = bounds.right * mParameters.getRadiusX();
            c[1] = bounds.bottom * mParameters.getRadiusY();
            m.mapVectors(c);
            rx = c[0];
            ry = c[1];
        }


        mScript.set_inputWidth(w);
        mScript.set_inputHeight(h);
        int v = mParameters.getValue(MODE_VIGNETTE);
@@ -115,7 +124,6 @@ public class ImageFilterVignette extends ImageFilterRS {
        mScript.set_strength(mParameters.getValue(MODE_FALLOFF)/10.f);
        mScript.invoke_setupVignetteParams();
        mScript.forEach_vignette(getInPixelsAllocation(), getOutPixelsAllocation());

    }

    @Override
+16 −26
Original line number Diff line number Diff line
@@ -108,36 +108,26 @@ public class EclipseControl {
        return (!mImageBounds.contains((int) x1, (int) y1));
    }

    public void actionDown2(float x, float y, int iw, int ih, Oval oval) {
    public void actionDown(float x, float y, Oval oval)  {
        float[] point = new float[]{
                x, y};
        mScrToImg.mapPoints(point);
        mDownX = point[0];
        mDownY = point[1];
        mDownCenterX = oval.getCenterX() * iw;
        mDownCenterY = oval.getCenterY() * ih;
        mDownRadiusX = oval.getRadiusX() * iw;
        mDownRadiusY = oval.getRadiusY() * ih;
        mDownCenterX = oval.getCenterX();
        mDownCenterY = oval.getCenterY();
        mDownRadiusX = oval.getRadiusX();
        mDownRadiusY = oval.getRadiusY();
    }

    public void actionDown(float x, float y, Oval oval) {
        actionDown2(x, y, 1, 1, oval);
    }

    public void actionMove(int handle, float x, float y, Oval oval) {
        actionMove2(handle, x, y, 1, 1, oval);
    }

    public void actionMove2(int handle, float x, float y, int w, int h, Oval oval) {
        float[] point = new float[]{
                x, y};
        mScrToImg.mapPoints(point);
        x = point[0];
        y = point[1];
        if (w == 0) {
            w = 1;
            h = 1;
        }

        // Test if the matrix is swapping x and y
        point[0] = 0;
        point[1] = 1;
@@ -152,7 +142,7 @@ public class EclipseControl {
                if (centerIsOutside(x - ctrdx, y - ctrdy)) {
                    break;
                }
                oval.setCenter((x - ctrdx) / w, (y - ctrdy) / h);
                oval.setCenter((x - ctrdx), (y - ctrdy));
                // setRepresentation(mVignetteRep);
                break;
            case HAN_NORTH:
@@ -160,10 +150,10 @@ public class EclipseControl {
            case HAN_SOUTH:
                if (swapxy) {
                    float raddx = mDownRadiusY - Math.abs(mDownX - mDownCenterY);
                    oval.setRadiusY(Math.abs(x - oval.getCenterY() * h + sign * raddx)/h);
                    oval.setRadiusY(Math.abs(x - oval.getCenterY() + sign * raddx));
                } else {
                    float raddy = mDownRadiusY - Math.abs(mDownY - mDownCenterY);
                    oval.setRadiusY(Math.abs(y - oval.getCenterY() * h + sign * raddy)/h);
                    oval.setRadiusY(Math.abs(y - oval.getCenterY() + sign * raddy));
                }
                break;
            case HAN_EAST:
@@ -171,10 +161,10 @@ public class EclipseControl {
            case HAN_WEST:
                if (swapxy) {
                    float raddy = mDownRadiusX - Math.abs(mDownY - mDownCenterX);
                    oval.setRadiusX(Math.abs(y - oval.getCenterX() * w + sign * raddy)/w);
                    oval.setRadiusX(Math.abs(y - oval.getCenterX() + sign * raddy));
                } else {
                    float raddx = mDownRadiusX - Math.abs(mDownX - mDownCenterX);
                    oval.setRadiusX(Math.abs(x - oval.getCenterX() * w - sign * raddx)/w);
                    oval.setRadiusX(Math.abs(x - oval.getCenterX() -  sign * raddx));
                }
                break;
            case HAN_SE:
@@ -186,13 +176,13 @@ public class EclipseControl {
                float ctr_dx = mDownX - mDownCenterX;
                float ctr_dy = mDownY - mDownCenterY;
                float downRad = Math.abs(ctr_dx) + Math.abs(ctr_dy) - dr;
                float rx = oval.getRadiusX() * w;
                float ry = oval.getRadiusY() * h;
                float rx = oval.getRadiusX();
                float ry = oval.getRadiusY();
                float r = (Math.abs(rx) + Math.abs(ry)) * sin45;
                float dx = x - oval.getCenterX() * w;
                float dy = y - oval.getCenterY() * h;
                float dx = x - oval.getCenterX();
                float dy = y - oval.getCenterY();
                float nr = Math.abs(Math.abs(dx) + Math.abs(dy) - downRad);
                oval.setRadius((rx * nr / r) / w, (ry * nr / r) / h);
                oval.setRadius((rx * nr / r), (ry * nr / r));

                break;
        }
+102 −36
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

import com.android.gallery3d.filtershow.editors.EditorVignette;
@@ -31,7 +30,7 @@ public class ImageVignette extends ImageShow {

    private FilterVignetteRepresentation mVignetteRep;
    private EditorVignette mEditorVignette;

    private OvalSpaceAdapter mScreenOval = new OvalSpaceAdapter();
    private int mActiveHandle = -1;

    EclipseControl mElipse;
@@ -46,6 +45,95 @@ public class ImageVignette extends ImageShow {
        mElipse = new EclipseControl(context);
    }

    static class OvalSpaceAdapter implements Oval {
        private Oval mOval;
        Matrix mToScr;
        Matrix mToImage;
        int mImgWidth;
        int mImgHeight;
        float[] mTmp = new float[2];
        float mTmpRadiusX;
        float mTmpRadiusY;

        public void setImageOval(Oval oval) {
            mOval = oval;
        }

        public void setTransform(Matrix toScr, Matrix toImage, int imgWidth, int imgHeight) {
            mToScr = toScr;
            mToImage = toImage;
            mImgWidth = imgWidth;
            mImgHeight = imgHeight;
        }

        @Override
        public void setCenter(float x, float y) {
            mTmp[0] = x;
            mTmp[1] = y;
            mToImage.mapPoints(mTmp);
            mOval.setCenter(mTmp[0] / mImgWidth, mTmp[1] / mImgHeight);
        }

        @Override
        public void setRadius(float w, float h) {
            mTmp[0] = mTmpRadiusX = w;
            mTmp[1] = mTmpRadiusY = h;
            mToImage.mapVectors(mTmp);
            mOval.setRadius(mTmp[0] / mImgWidth, mTmp[1] / mImgHeight);
        }

        @Override
        public float getCenterX() {
            mTmp[0] = mOval.getCenterX() * mImgWidth;
            mTmp[1] = mOval.getCenterY() * mImgHeight;
            mToScr.mapPoints(mTmp);

            return mTmp[0];
        }

        @Override
        public float getCenterY() {
            mTmp[0] = mOval.getCenterX() * mImgWidth;
            mTmp[1] = mOval.getCenterY() * mImgHeight;
            mToScr.mapPoints(mTmp);
            return mTmp[1];
        }

        @Override
        public float getRadiusX() {
            mTmp[0] = mOval.getRadiusX() * mImgWidth;
            mTmp[1] = mOval.getRadiusY() * mImgHeight;
            mToScr.mapVectors(mTmp);
            return Math.abs(mTmp[0]);
        }

        @Override
        public float getRadiusY() {
            mTmp[0] = mOval.getRadiusX() * mImgWidth;
            mTmp[1] = mOval.getRadiusY() * mImgHeight;
            mToScr.mapVectors(mTmp);
            return Math.abs(mTmp[1]);
        }

        @Override
        public void setRadiusY(float y) {
            mTmp[0] = mTmpRadiusX;
            mTmp[1] = mTmpRadiusY = y;
            mToImage.mapVectors(mTmp);
            mOval.setRadiusX(mTmp[0] / mImgWidth);
            mOval.setRadiusY(mTmp[1] / mImgHeight);
        }

        @Override
        public void setRadiusX(float x) {
            mTmp[0] = mTmpRadiusX = x;
            mTmp[1] = mTmpRadiusY;
            mToImage.mapVectors(mTmp);
            mOval.setRadiusX(mTmp[0] / mImgWidth);
            mOval.setRadiusY(mTmp[1] / mImgHeight);
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        int w = MasterImage.getImage().getOriginalBounds().width();
@@ -73,17 +161,18 @@ public class ImageVignette extends ImageShow {
        float x = event.getX();
        float y = event.getY();

        mElipse.setScrImageInfo(getScreenToImageMatrix(true),
        mElipse.setScrImageInfo(new Matrix(),
                MasterImage.getImage().getOriginalBounds());

        boolean didComputeEllipses = false;
        switch (mask) {
            case (MotionEvent.ACTION_DOWN):
                mElipse.actionDown2(x, y, w, h, mVignetteRep);
                mElipse.actionDown(x, y, mScreenOval);
                break;
            case (MotionEvent.ACTION_UP):
            case (MotionEvent.ACTION_MOVE):
                mElipse.actionMove2(mActiveHandle, x, y, w, h, mVignetteRep);

                mElipse.actionMove(mActiveHandle, x, y, mScreenOval);
                setRepresentation(mVignetteRep);
                didComputeEllipses = true;
                break;
@@ -97,6 +186,7 @@ public class ImageVignette extends ImageShow {

    public void setRepresentation(FilterVignetteRepresentation vignetteRep) {
        mVignetteRep = vignetteRep;
        mScreenOval.setImageOval(mVignetteRep);
        computeEllipses();
    }

@@ -109,32 +199,11 @@ public class ImageVignette extends ImageShow {
        Matrix toImg = getScreenToImageMatrix(false);
        Matrix toScr = new Matrix();
        toImg.invert(toScr);
        mScreenOval.setTransform(toScr, toImg, (int) w, (int) h);

        float[] c = new float[] {
                mVignetteRep.getCenterX() * w, mVignetteRep.getCenterY() * h};
        if (Float.isNaN(c[0])) {
            float cx = w / 2;
            float cy = h / 2;
            float rx = Math.min(cx, cy) * .8f;
            float ry = rx;
            mVignetteRep.setCenter(cx / w, cy / h);
            mVignetteRep.setRadius(rx / w, ry / h);

            c[0] = cx;
            c[1] = cy;
            toScr.mapPoints(c);
            if (getWidth() != 0) {
                mElipse.setCenter(c[0], c[1]);
                mElipse.setRadius(c[0] * 0.8f, c[1] * 0.8f);
            }
        } else {
        mElipse.setCenter(mScreenOval.getCenterX(), mScreenOval.getCenterY());
        mElipse.setRadius(mScreenOval.getRadiusX(), mScreenOval.getRadiusY());

            toScr.mapPoints(c);

            mElipse.setCenter(c[0], c[1]);
            mElipse.setRadius(toScr.mapRadius(mVignetteRep.getRadiusX() * w),
                    toScr.mapRadius(mVignetteRep.getRadiusY() * h));
        }
        mEditorVignette.commitLocalRepresentation();
    }

@@ -159,12 +228,9 @@ public class ImageVignette extends ImageShow {
        Matrix toImg = getScreenToImageMatrix(false);
        Matrix toScr = new Matrix();
        toImg.invert(toScr);
        float[] c = new float[] {
                mVignetteRep.getCenterX() * w, mVignetteRep.getCenterY() * h };
        toScr.mapPoints(c);
        mElipse.setCenter(c[0], c[1]);
        mElipse.setRadius(toScr.mapRadius(mVignetteRep.getRadiusX() * w),
                toScr.mapRadius(mVignetteRep.getRadiusY() * h));
        mScreenOval.setTransform(toScr, toImg, (int) w, (int) h);
        mElipse.setCenter(mScreenOval.getCenterX(), mScreenOval.getCenterY());
        mElipse.setRadius(mScreenOval.getRadiusX(), mScreenOval.getRadiusY());

        mElipse.draw(canvas);
    }