Skip to content

Commit

Permalink
support for luma nad ivluma matte mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhirkevich Alexander Y authored and Zhirkevich Alexander Y committed Jun 4, 2024
1 parent d863d92 commit d43a2e2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,16 @@ static BaseLayer forModel(
this.lottieDrawable = lottieDrawable;
this.layerModel = layerModel;
drawTraceName = layerModel.getName() + "#draw";
if (layerModel.getMatteType() == Layer.MatteType.INVERT) {
if (layerModel.getMatteType() == Layer.MatteType.INVERT || layerModel.getMatteType() == Layer.MatteType.LUMA_INVERTED) {
mattePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
} else {
mattePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));
}

if (layerModel.getMatteType() == Layer.MatteType.LUMA || layerModel.getMatteType() == Layer.MatteType.LUMA_INVERTED){
mattePaint.setColorFilter(Utils.getLumaColorFilter());
}

this.transform = layerModel.getTransform().createAnimation();
transform.addListener(this);

Expand Down Expand Up @@ -449,7 +453,7 @@ private void intersectBoundsWithMatte(RectF rect, Matrix matrix) {
return;
}

if (layerModel.getMatteType() == Layer.MatteType.INVERT) {
if (layerModel.getMatteType() == Layer.MatteType.INVERT || layerModel.getMatteType() == Layer.MatteType.LUMA_INVERTED) {
// We can't trim the bounds if the mask is inverted since it extends all the way to the
// composition bounds.
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public CompositionLayer(LottieDrawable lottieDrawable, Layer layerModel, List<La
switch (lm.getMatteType()) {
case ADD:
case INVERT:
case LUMA:
case LUMA_INVERTED:
mattedLayer = layer;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,6 @@ public static Layer parse(JsonReader reader, LottieComposition composition) thro
break;
}
matteType = Layer.MatteType.values()[matteTypeIndex];
switch (matteType) {
case LUMA:
composition.addWarning("Unsupported matte type: Luma");
break;
case LUMA_INVERTED:
composition.addWarning("Unsupported matte type: Luma Inverted");
break;
}
composition.incrementMatteOrMaskCount(1);
break;
case 10:
Expand Down
15 changes: 15 additions & 0 deletions lottie/src/main/java/com/airbnb/lottie/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
Expand Down Expand Up @@ -67,6 +69,15 @@ protected float[] initialValue() {

private static final float INV_SQRT_2 = (float) (Math.sqrt(2) / 2.0);

private static final ColorFilter lumaColorFilter = new ColorMatrixColorFilter(
new float[]{
0f, 0f, 0f, 0f, 0f,
0f, 0f, 0f, 0f, 0f,
0f, 0f, 0f, 0f, 0f,
0.2126f, 0.7152f, 0.0722f, 0f, 0f
}
);

private Utils() {
}

Expand Down Expand Up @@ -331,4 +342,8 @@ public static Bitmap renderPath(Path path) {
canvas.drawPath(path, paint);
return bitmap;
}

public static ColorFilter getLumaColorFilter() {
return lumaColorFilter;
}
}

0 comments on commit d43a2e2

Please sign in to comment.