-
-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,381 additions
and
359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import AVFoundation | ||
import Foundation | ||
|
||
extension AVLayerVideoGravity { | ||
func scale(_ display: CGSize, image: CGSize) -> CGAffineTransform { | ||
switch self { | ||
case .resize: | ||
return .init(scaleX: display.width / image.width, y: display.width / image.height) | ||
case .resizeAspect: | ||
let scale = min(display.width / image.width, display.height / image.height) | ||
return .init(scaleX: scale, y: scale) | ||
case .resizeAspectFill: | ||
let scale = max(display.width / image.width, display.height / image.height) | ||
return .init(scaleX: scale, y: scale) | ||
default: | ||
return .init(scaleX: 1.0, y: 1.0) | ||
} | ||
} | ||
|
||
func region(_ display: CGRect, image: CGRect) -> CGRect { | ||
switch self { | ||
case .resize: | ||
return image | ||
case .resizeAspect: | ||
return image | ||
case .resizeAspectFill: | ||
let x = abs(display.width - image.width) / 2 | ||
let y = abs(display.height - image.height) / 2 | ||
return .init(origin: .init(x: x, y: y), size: display.size) | ||
default: | ||
return image | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import CoreGraphics | ||
import Foundation | ||
|
||
extension CGImage { | ||
var size: CGSize { | ||
return .init(width: width, height: height) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import AVFoundation | ||
import Foundation | ||
|
||
extension CMVideoDimensions { | ||
var size: CGSize { | ||
return .init(width: CGFloat(width), height: CGFloat(height)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.