Search in sources :

Example 21 with EditorElement

use of org.signal.imageeditor.core.model.EditorElement in project Signal-Android by WhisperSystems.

the class UriGlideRenderer method renderBlurOverlay.

private void renderBlurOverlay(RendererContext rendererContext) {
    boolean renderMask = false;
    for (EditorElement child : rendererContext.getChildren()) {
        if (child.getZOrder() == EditorModel.Z_MASK) {
            renderMask = true;
            if (blurPaint == null) {
                blurPaint = new Paint();
                blurPaint.setAntiAlias(true);
                blurPaint.setFilterBitmap(true);
                blurPaint.setDither(true);
            }
            blurPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
            rendererContext.setMaskPaint(blurPaint);
            child.draw(rendererContext);
        }
    }
    if (renderMask) {
        rendererContext.save();
        rendererContext.canvasMatrix.concat(imageProjectionMatrix);
        blurPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_ATOP));
        blurPaint.setMaskFilter(null);
        if (blurredBitmap == null) {
            blurredBitmap = blur(bitmap, rendererContext.context, blurRadius);
            blurScaleMatrix.setRectToRect(new RectF(0, 0, blurredBitmap.getWidth(), blurredBitmap.getHeight()), new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight()), Matrix.ScaleToFit.FILL);
        }
        rendererContext.canvas.concat(blurScaleMatrix);
        rendererContext.canvas.drawBitmap(blurredBitmap, 0, 0, blurPaint);
        blurPaint.setXfermode(null);
        rendererContext.restore();
    }
}
Also used : RectF(android.graphics.RectF) PorterDuffXfermode(android.graphics.PorterDuffXfermode) EditorElement(org.signal.imageeditor.core.model.EditorElement) Paint(android.graphics.Paint)

Example 22 with EditorElement

use of org.signal.imageeditor.core.model.EditorElement in project Signal-Android by signalapp.

the class ImageEditorView method startADrawingSession.

private EditSession startADrawingSession(@NonNull PointF point) {
    BezierDrawingRenderer renderer = new BezierDrawingRenderer(color, thickness * Bounds.FULL_BOUNDS.width(), cap, model.findCropRelativeToRoot());
    EditorElement element = new EditorElement(renderer, mode == Mode.Blur ? EditorModel.Z_MASK : EditorModel.Z_DRAWING);
    model.addElementCentered(element, 1);
    Matrix elementInverseMatrix = model.findElementInverseMatrix(element, viewMatrix);
    return DrawingSession.start(element, renderer, elementInverseMatrix, point);
}
Also used : BezierDrawingRenderer(org.signal.imageeditor.core.renderers.BezierDrawingRenderer) Matrix(android.graphics.Matrix) EditorElement(org.signal.imageeditor.core.model.EditorElement)

Example 23 with EditorElement

use of org.signal.imageeditor.core.model.EditorElement in project Signal-Android by signalapp.

the class ImageEditorView method startAMoveAndResizeSession.

private EditSession startAMoveAndResizeSession(@NonNull Matrix inverse, @NonNull PointF point, @Nullable EditorElement selected) {
    Matrix elementInverseMatrix;
    if (selected == null)
        return null;
    if (selected.getRenderer() instanceof ThumbRenderer) {
        ThumbRenderer thumb = (ThumbRenderer) selected.getRenderer();
        EditorElement thumbControlledElement = getModel().findById(thumb.getElementToControl());
        if (thumbControlledElement == null)
            return null;
        EditorElement thumbsParent = getModel().getRoot().findParent(selected);
        if (thumbsParent == null)
            return null;
        Matrix thumbContainerRelativeMatrix = model.findRelativeMatrix(thumbsParent, thumbControlledElement);
        if (thumbContainerRelativeMatrix == null)
            return null;
        selected = thumbControlledElement;
        elementInverseMatrix = model.findElementInverseMatrix(selected, viewMatrix);
        if (elementInverseMatrix != null) {
            return ThumbDragEditSession.startDrag(selected, elementInverseMatrix, thumbContainerRelativeMatrix, thumb.getControlPoint(), point);
        } else {
            return null;
        }
    }
    return ElementDragEditSession.startDrag(selected, inverse, point);
}
Also used : Matrix(android.graphics.Matrix) EditorElement(org.signal.imageeditor.core.model.EditorElement) ThumbRenderer(org.signal.imageeditor.core.model.ThumbRenderer)

Example 24 with EditorElement

use of org.signal.imageeditor.core.model.EditorElement in project Signal-Android by signalapp.

the class WallpaperCropActivity method setBlurred.

private void setBlurred(boolean blurred) {
    imageEditor.getModel().clearFaceRenderers();
    if (blurred) {
        EditorElement mainImage = imageEditor.getModel().getMainImage();
        if (mainImage != null) {
            EditorElement element = new EditorElement(new FaceBlurRenderer(), EditorModel.Z_MASK);
            element.getFlags().setEditable(false).setSelectable(false).persist();
            mainImage.addElement(element);
            imageEditor.invalidate();
        }
    }
}
Also used : EditorElement(org.signal.imageeditor.core.model.EditorElement) FaceBlurRenderer(org.signal.imageeditor.core.renderers.FaceBlurRenderer)

Aggregations

EditorElement (org.signal.imageeditor.core.model.EditorElement)24 EditorModel (org.signal.imageeditor.core.model.EditorModel)10 Matrix (android.graphics.Matrix)8 Point (android.graphics.Point)8 MultiLineTextRenderer (org.signal.imageeditor.core.renderers.MultiLineTextRenderer)8 Paint (android.graphics.Paint)6 BezierDrawingRenderer (org.signal.imageeditor.core.renderers.BezierDrawingRenderer)4 FaceBlurRenderer (org.signal.imageeditor.core.renderers.FaceBlurRenderer)4 Bitmap (android.graphics.Bitmap)2 PorterDuffXfermode (android.graphics.PorterDuffXfermode)2 RectF (android.graphics.RectF)2 Uri (android.net.Uri)2 DisplayMetrics (android.util.DisplayMetrics)2 MenuItem (android.view.MenuItem)2 AlertDialog (androidx.appcompat.app.AlertDialog)2 Toolbar (androidx.appcompat.widget.Toolbar)2 UriRenderer (org.signal.imageeditor.app.renderers.UriRenderer)2 UrlRenderer (org.signal.imageeditor.app.renderers.UrlRenderer)2 ColorableRenderer (org.signal.imageeditor.core.ColorableRenderer)2 ImageEditorView (org.signal.imageeditor.core.ImageEditorView)2