1 package com.airbnb.lottie.model.content; 2 3 import androidx.annotation.Nullable; 4 import androidx.core.graphics.BlendModeCompat; 5 6 /** 7 * Lottie BlendMode, 8 * not to be confused with Paint.BlendMode in android graphics core, 9 * which we will rely on for rendering. 10 */ 11 public enum LBlendMode { 12 NORMAL, 13 MULTIPLY, 14 SCREEN, 15 OVERLAY, 16 DARKEN, 17 LIGHTEN, 18 COLOR_DODGE, 19 COLOR_BURN, 20 HARD_LIGHT, 21 SOFT_LIGHT, 22 DIFFERENCE, 23 EXCLUSION, 24 HUE, 25 SATURATION, 26 COLOR, 27 LUMINOSITY, 28 ADD, 29 HARD_MIX; 30 31 @Nullable toNativeBlendMode()32 public BlendModeCompat toNativeBlendMode() { 33 switch (this) { 34 case NORMAL: 35 return null; 36 case MULTIPLY: 37 // BlendModeCompat.MULTIPLY does not exist on Android < Q. Instead, there's 38 // BlendModeCompat.MODULATE, which maps to PorterDuff.Mode.MODULATE and not 39 // PorterDuff.Mode.MULTIPLY. 40 // 41 // MODULATE differs from MULTIPLY in that it doesn't perform 42 // any alpha blending. It just does a component-wise multiplication 43 // of the colors. 44 // 45 // For proper results on all platforms, we will map the MULTIPLY 46 // blend mode to MODULATE, and then do a slight adjustment to 47 // how we render such layers to still achieve the correct result. 48 // See BaseLayer.draw(). 49 return BlendModeCompat.MODULATE; 50 case SCREEN: 51 return BlendModeCompat.SCREEN; 52 case OVERLAY: 53 return BlendModeCompat.OVERLAY; 54 case DARKEN: 55 return BlendModeCompat.DARKEN; 56 case LIGHTEN: 57 return BlendModeCompat.LIGHTEN; 58 case ADD: 59 return BlendModeCompat.PLUS; 60 61 // Blend modes below were not added to the platform until Q. 62 // To prevent unexpected issues where animations look correct 63 // during development but silently break for users with older devices 64 // we won't support any of these until Q is widely used. 65 case COLOR_DODGE: 66 case COLOR_BURN: 67 case HARD_LIGHT: 68 case SOFT_LIGHT: 69 case DIFFERENCE: 70 case EXCLUSION: 71 case HUE: 72 case SATURATION: 73 case COLOR: 74 case LUMINOSITY: 75 case HARD_MIX: 76 default: 77 return null; 78 } 79 } 80 81 } 82