Make DrawingContext initializer failable

This commit is contained in:
Ali
2022-11-15 13:40:31 +04:00
parent 59e2c74d42
commit f07c30bd5b
39 changed files with 624 additions and 415 deletions

View File

@@ -50,7 +50,9 @@ public func cacheStillSticker(path: String, width: Int, height: Int, writer: Ani
let work: () -> Void = {
if let data = try? Data(contentsOf: URL(fileURLWithPath: path)), let image = WebP.convert(fromWebP: data) {
writer.add(with: { surface in
let context = DrawingContext(size: CGSize(width: CGFloat(surface.width), height: CGFloat(surface.height)), scale: 1.0, opaque: false, clear: true, bytesPerRow: surface.bytesPerRow)
guard let context = DrawingContext(size: CGSize(width: CGFloat(surface.width), height: CGFloat(surface.height)), scale: 1.0, opaque: false, clear: true, bytesPerRow: surface.bytesPerRow) else {
return 1.0
}
context.withFlippedContext { c in
UIGraphicsPushContext(c)
c.draw(image.cgImage!, in: CGRect(origin: CGPoint(), size: context.size))