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

Commit 655afcf4 authored by nicolasroard's avatar nicolasroard
Browse files

Fix param border

needed to replace bitmap borders

bug:9470514
Change-Id: I69f6324246ee8c9491ec430c5e20d87574302fcf
parent 8141e241
Loading
Loading
Loading
Loading
+40 −3
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
package com.android.gallery3d.filtershow.filters;

import android.graphics.Color;
import android.util.JsonReader;
import android.util.JsonWriter;

import com.android.gallery3d.R;
import com.android.gallery3d.filtershow.controller.BasicParameterInt;
@@ -26,6 +28,9 @@ import com.android.gallery3d.filtershow.controller.ParameterColor;
import com.android.gallery3d.filtershow.editors.EditorColorBorder;
import com.android.gallery3d.filtershow.editors.ImageOnlyEditor;

import java.io.IOException;
import java.util.ArrayList;

public class FilterColorBorderRepresentation extends FilterRepresentation {
    private static final String LOGTAG = "FilterColorBorderRepresentation";
    private static final String SERIALIZATION_NAME = "COLORBORDER";
@@ -38,8 +43,8 @@ public class FilterColorBorderRepresentation extends FilterRepresentation {
    public static int DEFAULT_MENU_COLOR3 = Color.GRAY;
    public static int DEFAULT_MENU_COLOR4 = 0xFFFFCCAA;
    public static int DEFAULT_MENU_COLOR5 = 0xFFAAAAAA;
    private BasicParameterInt mParamSize = new BasicParameterInt(PARAM_SIZE, 20, 2, 300);
    private BasicParameterInt mParamRadius = new BasicParameterInt(PARAM_RADIUS, 4, 2, 300);
    private BasicParameterInt mParamSize = new BasicParameterInt(PARAM_SIZE, 4, 2, 30);
    private BasicParameterInt mParamRadius = new BasicParameterInt(PARAM_RADIUS, 4, 2, 100);
    private ParameterColor mParamColor = new ParameterColor(PARAM_COLOR, DEFAULT_MENU_COLOR1);

    private Parameter[] mAllParam = {
@@ -59,7 +64,7 @@ public class FilterColorBorderRepresentation extends FilterRepresentation {
        setFilterClass(ImageFilterColorBorder.class);
        mParamColor.setValue(color);
        mParamSize.setValue(size);
        mParamColor.setValue(radius);
        mParamRadius.setValue(radius);
    }

    public String toString() {
@@ -155,4 +160,36 @@ public class FilterColorBorderRepresentation extends FilterRepresentation {
    public String getValueString() {
        return "";
    }

    // Serialization...

    public void serializeRepresentation(JsonWriter writer) throws IOException {
        writer.beginObject();
        {
            writer.name("size");
            writer.value(mParamSize.getValue());
            writer.name("radius");
            writer.value(mParamRadius.getValue());
            writer.name("color");
            writer.value(mParamColor.getValue());
        }
        writer.endObject();
    }

    public void deSerializeRepresentation(JsonReader reader) throws IOException {
        reader.beginObject();
        while (reader.hasNext()) {
            String name = reader.nextName();
            if (name.equalsIgnoreCase("size")) {
                mParamSize.setValue(reader.nextInt());
            } else if (name.equalsIgnoreCase("radius")) {
                mParamRadius.setValue(reader.nextInt());
            } else if (name.equalsIgnoreCase("color")) {
                mParamColor.setValue(reader.nextInt());
            } else {
                reader.skipValue();
            }
        }
        reader.endObject();
    }
}
+27 −15
Original line number Diff line number Diff line
@@ -19,26 +19,24 @@ package com.android.gallery3d.filtershow.filters;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;

import com.android.gallery3d.app.Log;

public class ImageFilterColorBorder extends ImageFilter {
    private static final String LOGTAG = "ImageFilterColorBorder";
    private FilterColorBorderRepresentation mParameters = null;
    Paint mPaint = new Paint();
    RectF mRect = new RectF();
    RectF mBounds = new RectF();
    RectF mInsideBounds = new RectF();
    Path mBorderPath = new Path();

    public ImageFilterColorBorder() {
        mName = "Border";
        mPaint.setStyle(Paint.Style.STROKE);
    }

    public FilterRepresentation getDefaultRepresentation() {
        return new FilterColorBorderRepresentation(Color.WHITE, 4, 4);
        return new FilterColorBorderRepresentation(Color.WHITE, 3, 2);
    }

    public void useRepresentation(FilterRepresentation representation) {
@@ -55,17 +53,31 @@ public class ImageFilterColorBorder extends ImageFilter {
        if (getParameters() == null) {
            return;
        }
        mRect.set(0, 0, w, h);
        mPaint.setColor(getParameters().getColor());
        float size = getParameters().getBorderSize();
        float radius = getParameters().getBorderRadius();
        Matrix m = getOriginalToScreenMatrix(w, h);
        radius = m.mapRadius(radius);
        size = m.mapRadius(size);
        mPaint.setStrokeWidth(size);
        canvas.drawRoundRect(mRect, radius, radius, mPaint);
        mRect.set(0 - radius, -radius, w + radius, h + radius);
        canvas.drawRoundRect(mRect, 0, 0, mPaint);

        mPaint.reset();
        mPaint.setColor(getParameters().getColor());
        mPaint.setAntiAlias(true);
        mBounds.set(0, 0, w, h);
        mBorderPath.reset();
        mBorderPath.moveTo(0, 0);

        float bs = size / 100.f * mBounds.width();
        float r = radius / 100.f * mBounds.width();

        mInsideBounds.set(mBounds.left + bs,
                mBounds.top + bs, mBounds.right - bs,
                mBounds.bottom - bs);

        mBorderPath.moveTo(mBounds.left, mBounds.top);
        mBorderPath.lineTo(mBounds.right, mBounds.top);
        mBorderPath.lineTo(mBounds.right, mBounds.bottom);
        mBorderPath.lineTo(mBounds.left, mBounds.bottom);
        mBorderPath.addRoundRect(mInsideBounds,
                r, r, Path.Direction.CCW);

        canvas.drawPath(mBorderPath, mPaint);
    }

    @Override