This repository has been archived by the owner on Dec 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 99
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
46 changed files
with
1,341 additions
and
1,266 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
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
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
File renamed without changes.
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
50 changes: 50 additions & 0 deletions
50
Dependencies/Sources/Model/TransientImage+ImageDecoder.swift
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,50 @@ | ||
// | ||
// TransientImage+ImageDecoder.swift | ||
// | ||
// | ||
// Created by Dmytro Anokhin on 11/01/2021. | ||
// | ||
|
||
import Foundation | ||
import CoreGraphics | ||
import ImageIO | ||
import ImageDecoder | ||
|
||
|
||
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) | ||
public extension TransientImage { | ||
|
||
init?(data: Data, maxPixelSize: CGSize?) { | ||
let decoder = ImageDecoder() | ||
decoder.setData(data, allDataReceived: true) | ||
|
||
self.init(decoder: decoder, maxPixelSize: maxPixelSize) | ||
} | ||
|
||
init?(location: URL, maxPixelSize: CGSize?) { | ||
guard let decoder = ImageDecoder(url: location) else { | ||
return nil | ||
} | ||
|
||
self.init(decoder: decoder, maxPixelSize: maxPixelSize) | ||
} | ||
|
||
init?(decoder: ImageDecoder, maxPixelSize: CGSize?) { | ||
guard let uti = decoder.uti else { | ||
// Not an image | ||
return nil | ||
} | ||
|
||
guard let size = decoder.frameSize(at: 0) else { | ||
// Can not decode an image | ||
return nil | ||
} | ||
|
||
let proxy = CGImageProxy(decoder: decoder, maxPixelSize: maxPixelSize) | ||
|
||
let info = ImageInfo(proxy: proxy, size: size) | ||
let cgOrientation: CGImagePropertyOrientation = decoder.frameOrientation(at: 0) ?? .up | ||
|
||
self.init(proxy: proxy, info: info, uti: uti, cgOrientation: cgOrientation) | ||
} | ||
} |
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,72 @@ | ||
// | ||
// TransientImage.swift | ||
// | ||
// | ||
// Created by Dmytro Anokhin on 08/01/2021. | ||
// | ||
|
||
import Foundation | ||
import ImageIO | ||
import ImageDecoder | ||
|
||
|
||
/// Temporary representation used after decoding an image from data or file on disk and before creating an image object for display. | ||
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) | ||
public struct TransientImage { | ||
|
||
public var cgImage: CGImage { | ||
proxy.cgImage | ||
} | ||
|
||
public let info: ImageInfo | ||
|
||
/// The uniform type identifier (UTI) of the source image. | ||
/// | ||
/// See [Uniform Type Identifier Concepts](https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/understanding_utis/understand_utis_conc/understand_utis_conc.html#//apple_ref/doc/uid/TP40001319-CH202) for a list of system-declared and third-party UTIs. | ||
public let uti: String | ||
|
||
public let cgOrientation: CGImagePropertyOrientation | ||
|
||
init(proxy: CGImageProxy, info: ImageInfo, uti: String, cgOrientation: CGImagePropertyOrientation) { | ||
self.proxy = proxy | ||
self.info = info | ||
self.uti = uti | ||
self.cgOrientation = cgOrientation | ||
} | ||
|
||
private let proxy: CGImageProxy | ||
} | ||
|
||
|
||
/// Proxy used to decode image lazily | ||
@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *) | ||
final class CGImageProxy { | ||
|
||
let decoder: ImageDecoder | ||
|
||
let maxPixelSize: CGSize? | ||
|
||
init(decoder: ImageDecoder, maxPixelSize: CGSize?) { | ||
self.decoder = decoder | ||
self.maxPixelSize = maxPixelSize | ||
} | ||
|
||
var cgImage: CGImage { | ||
if decodedCGImage == nil { | ||
decodeImage() | ||
} | ||
|
||
return decodedCGImage! | ||
} | ||
|
||
private var decodedCGImage: CGImage? | ||
|
||
private func decodeImage() { | ||
if let sizeForDrawing = maxPixelSize { | ||
let decodingOptions = ImageDecoder.DecodingOptions(mode: .asynchronous, sizeForDrawing: sizeForDrawing) | ||
decodedCGImage = decoder.createFrameImage(at: 0, decodingOptions: decodingOptions)! | ||
} else { | ||
decodedCGImage = decoder.createFrameImage(at: 0)! | ||
} | ||
} | ||
} |
File renamed without changes.
74 changes: 0 additions & 74 deletions
74
Dependencies/Sources/RemoteContentView/RemoteContent/RemoteContent.swift
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.