Search in sources :

Example 1 with Renderer

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

the class ImageEditorFragment method renderFaceBlurs.

private void renderFaceBlurs(@NonNull FaceDetectionResult result) {
    List<FaceDetector.Face> faces = result.faces;
    if (faces.isEmpty()) {
        cachedFaceDetection = null;
        return;
    }
    imageEditorView.getModel().pushUndoPoint();
    Matrix faceMatrix = new Matrix();
    for (FaceDetector.Face face : faces) {
        Renderer faceBlurRenderer = new FaceBlurRenderer();
        EditorElement element = new EditorElement(faceBlurRenderer, EditorModel.Z_MASK);
        Matrix localMatrix = element.getLocalMatrix();
        faceMatrix.setRectToRect(Bounds.FULL_BOUNDS, face.getBounds(), Matrix.ScaleToFit.FILL);
        localMatrix.set(result.position);
        localMatrix.preConcat(faceMatrix);
        element.getFlags().setEditable(false).setSelectable(false).persist();
        imageEditorView.getModel().addElementWithoutPushUndo(element);
    }
    imageEditorView.invalidate();
    cachedFaceDetection = new Pair<>(getUri(), result);
}
Also used : Matrix(android.graphics.Matrix) SelectableRenderer(org.signal.imageeditor.core.SelectableRenderer) Renderer(org.signal.imageeditor.core.Renderer) ColorableRenderer(org.signal.imageeditor.core.ColorableRenderer) BezierDrawingRenderer(org.signal.imageeditor.core.renderers.BezierDrawingRenderer) MultiLineTextRenderer(org.signal.imageeditor.core.renderers.MultiLineTextRenderer) FaceBlurRenderer(org.signal.imageeditor.core.renderers.FaceBlurRenderer) EditorElement(org.signal.imageeditor.core.model.EditorElement) FaceBlurRenderer(org.signal.imageeditor.core.renderers.FaceBlurRenderer)

Example 2 with Renderer

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

the class ImageEditorFragment method changeEntityColor.

private void changeEntityColor(int selectedColor) {
    if (currentSelection != null) {
        Renderer renderer = currentSelection.getRenderer();
        if (renderer instanceof ColorableRenderer) {
            ((ColorableRenderer) renderer).setColor(selectedColor);
            onDrawingChanged(false, true);
        }
    }
}
Also used : SelectableRenderer(org.signal.imageeditor.core.SelectableRenderer) Renderer(org.signal.imageeditor.core.Renderer) ColorableRenderer(org.signal.imageeditor.core.ColorableRenderer) BezierDrawingRenderer(org.signal.imageeditor.core.renderers.BezierDrawingRenderer) MultiLineTextRenderer(org.signal.imageeditor.core.renderers.MultiLineTextRenderer) FaceBlurRenderer(org.signal.imageeditor.core.renderers.FaceBlurRenderer) ColorableRenderer(org.signal.imageeditor.core.ColorableRenderer)

Example 3 with Renderer

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

the class EditorModel method getUniqueColorsIgnoringAlpha.

public Set<Integer> getUniqueColorsIgnoringAlpha() {
    final Set<Integer> colors = new LinkedHashSet<>();
    editorElementHierarchy.getRoot().forAllInTree(element -> {
        Renderer renderer = element.getRenderer();
        if (renderer instanceof ColorableRenderer) {
            colors.add(((ColorableRenderer) renderer).getColor() | 0xff000000);
        }
    });
    return colors;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MultiLineTextRenderer(org.signal.imageeditor.core.renderers.MultiLineTextRenderer) Renderer(org.signal.imageeditor.core.Renderer) ColorableRenderer(org.signal.imageeditor.core.ColorableRenderer) FaceBlurRenderer(org.signal.imageeditor.core.renderers.FaceBlurRenderer) ColorableRenderer(org.signal.imageeditor.core.ColorableRenderer)

Example 4 with Renderer

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

the class EditorModel method isRendererOfMainImage.

private boolean isRendererOfMainImage(@NonNull Renderer renderer) {
    EditorElement mainImage = editorElementHierarchy.getMainImage();
    Renderer mainImageRenderer = mainImage != null ? mainImage.getRenderer() : null;
    return mainImageRenderer == renderer;
}
Also used : MultiLineTextRenderer(org.signal.imageeditor.core.renderers.MultiLineTextRenderer) Renderer(org.signal.imageeditor.core.Renderer) ColorableRenderer(org.signal.imageeditor.core.ColorableRenderer) FaceBlurRenderer(org.signal.imageeditor.core.renderers.FaceBlurRenderer)

Example 5 with Renderer

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

the class EditorElement method findElementAt.

EditorElement findElementAt(float x, float y, @NonNull Matrix viewModelMatrix, @NonNull Matrix outInverseModelMatrix) {
    final float[] dst = new float[2];
    final float[] src = { x, y };
    return findElement(viewModelMatrix, outInverseModelMatrix, (element, inverseMatrix) -> {
        Renderer renderer = element.renderer;
        if (renderer == null)
            return false;
        inverseMatrix.mapPoints(dst, src);
        return element.flags.isSelectable() && renderer.hitTest(dst[0], dst[1]);
    });
}
Also used : Renderer(org.signal.imageeditor.core.Renderer)

Aggregations

Renderer (org.signal.imageeditor.core.Renderer)5 ColorableRenderer (org.signal.imageeditor.core.ColorableRenderer)4 FaceBlurRenderer (org.signal.imageeditor.core.renderers.FaceBlurRenderer)4 MultiLineTextRenderer (org.signal.imageeditor.core.renderers.MultiLineTextRenderer)4 SelectableRenderer (org.signal.imageeditor.core.SelectableRenderer)2 BezierDrawingRenderer (org.signal.imageeditor.core.renderers.BezierDrawingRenderer)2 Matrix (android.graphics.Matrix)1 LinkedHashSet (java.util.LinkedHashSet)1 EditorElement (org.signal.imageeditor.core.model.EditorElement)1