Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blend mode support #1585

Merged
merged 10 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lottie.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@
6DB3BDC328245AA2002A276D /* ParsingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DB3BDBF28245A6A002A276D /* ParsingTests.swift */; };
6DEF696E2824A76C007D640F /* BundleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6DEF696D2824A76C007D640F /* BundleTests.swift */; };
A1D5BAAC27C731A500777D06 /* DataURLTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A1D5BAAB27C731A500777D06 /* DataURLTests.swift */; };
A40460592832C52B00ACFEDC /* BlendMode+Filter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A40460582832C52B00ACFEDC /* BlendMode+Filter.swift */; };
A404605A2832C52B00ACFEDC /* BlendMode+Filter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A40460582832C52B00ACFEDC /* BlendMode+Filter.swift */; };
A404605B2832C52B00ACFEDC /* BlendMode+Filter.swift in Sources */ = {isa = PBXBuildFile; fileRef = A40460582832C52B00ACFEDC /* BlendMode+Filter.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -769,6 +772,7 @@
6DB3BDBF28245A6A002A276D /* ParsingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParsingTests.swift; sourceTree = "<group>"; };
6DEF696D2824A76C007D640F /* BundleTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BundleTests.swift; sourceTree = "<group>"; };
A1D5BAAB27C731A500777D06 /* DataURLTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataURLTests.swift; sourceTree = "<group>"; };
A40460582832C52B00ACFEDC /* BlendMode+Filter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "BlendMode+Filter.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -1248,6 +1252,7 @@
2E9C95C02822F43100677516 /* Extensions */ = {
isa = PBXGroup;
children = (
A40460582832C52B00ACFEDC /* BlendMode+Filter.swift */,
2E9C95C12822F43100677516 /* CGFloatExtensions.swift */,
2E9C95C22822F43100677516 /* CGColor+RGB.swift */,
2E9C95C32822F43100677516 /* AnimationKeypathExtension.swift */,
Expand Down Expand Up @@ -1818,6 +1823,7 @@
2EAF5AE027A0798700E00531 /* Keyframe.swift in Sources */,
2E9C960F2822F43100677516 /* Animation.swift in Sources */,
2E9C969C2822F43100677516 /* StarNode.swift in Sources */,
A40460592832C52B00ACFEDC /* BlendMode+Filter.swift in Sources */,
2E9C96542822F43100677516 /* ImageCompositionLayer.swift in Sources */,
2EAF5AB327A0798700E00531 /* AnimationImageProvider.swift in Sources */,
2E9C95F12822F43100677516 /* GradientStroke.swift in Sources */,
Expand Down Expand Up @@ -2023,6 +2029,7 @@
2EAF5AE127A0798700E00531 /* Keyframe.swift in Sources */,
2E9C96102822F43100677516 /* Animation.swift in Sources */,
2E9C969D2822F43100677516 /* StarNode.swift in Sources */,
A404605A2832C52B00ACFEDC /* BlendMode+Filter.swift in Sources */,
2E9C96552822F43100677516 /* ImageCompositionLayer.swift in Sources */,
2EAF5AB427A0798700E00531 /* AnimationImageProvider.swift in Sources */,
2E9C95F22822F43100677516 /* GradientStroke.swift in Sources */,
Expand Down Expand Up @@ -2208,6 +2215,7 @@
2EAF5AE227A0798700E00531 /* Keyframe.swift in Sources */,
2E9C96112822F43100677516 /* Animation.swift in Sources */,
2E9C969E2822F43100677516 /* StarNode.swift in Sources */,
A404605B2832C52B00ACFEDC /* BlendMode+Filter.swift in Sources */,
2E9C96562822F43100677516 /* ImageCompositionLayer.swift in Sources */,
2EAF5AB527A0798700E00531 /* AnimationImageProvider.swift in Sources */,
2E9C95F32822F43100677516 /* GradientStroke.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BaseCompositionLayer: BaseAnimationLayer {
super.init()

setupSublayers()
compositingFilter = layerModel.blendMode.filterName
calda marked this conversation as resolved.
Show resolved Hide resolved
name = layerModel.name
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class CompositionLayer: CALayer, KeypathSearchable {
"sublayerTransform" : NSNull(),
"hidden" : NSNull(),
]
compositingFilter = layer.blendMode.filterName
addSublayer(contentsLayer)

if let maskLayer = maskLayer {
Expand Down
31 changes: 31 additions & 0 deletions Sources/Private/Utility/Extensions/BlendMode+Filter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// File.swift
//
//
// Created by Denis Koryttsev on 10.05.2022.
//

extension BlendMode {
/// The Core Image filter name for this `BlendMode`, that can be applied to a `CALayer`'s `compositingFilter`.
/// Supported compositing filters are defined here: https://developer.apple.com/library/archive/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/uid/TP30000136-SW71
var filterName: String? {
switch self {
case .normal: return nil
case .multiply: return "multiplyBlendMode"
case .screen: return "screenBlendMode"
case .overlay: return "overlayBlendMode"
case .darken: return "darkenBlendMode"
case .lighten: return "lightenBlendMode"
case .colorDodge: return "colorDodgeBlendMode"
case .colorBurn: return "colorBurnBlendMode"
case .hardLight: return "hardLightBlendMode"
case .softLight: return "softLightBlendMode"
case .difference: return "differenceBlendMode"
case .exclusion: return "exclusionBlendMode"
case .hue: return "hueBlendMode"
case .saturation: return "saturationBlendMode"
case .color: return "colorBlendMode"
case .luminosity: return "luminosityBlendMode"
}
}
}
1 change: 1 addition & 0 deletions Tests/Samples/Nonanimating/blend_mode_test.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Tests/SnapshotConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ extension SnapshotConfiguration {
"Issues/issue_1407": .precision(0.9),
"Nonanimating/FirstText": .precision(0.99),
"Nonanimating/verifyLineHeight": .precision(0.99),
"Nonanimating/blend_mode_test": .precision(0.99),

/// Test cases for the `AnimationKeypath` / `AnyValueProvider` system
"Nonanimating/keypathTest": .customValueProviders([
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Supports Core Animation engine
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Supports Core Animation engine
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.