Skip to content
This repository has been archived by the owner on Dec 15, 2024. It is now read-only.

Commit

Permalink
Merge branch 'version_3'
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytro-anokhin committed May 9, 2021
2 parents ccab89a + 5b31c5b commit 56535f0
Show file tree
Hide file tree
Showing 46 changed files with 1,341 additions and 1,266 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
//

import Combine

#if canImport(Log)
import Log
#endif


@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
Expand All @@ -33,7 +30,7 @@ public struct DownloadPublisher: Publisher {
self.manager = manager
}

private unowned let manager: DownloadManager
private let manager: DownloadManager
}


Expand Down
5 changes: 1 addition & 4 deletions Dependencies/Sources/DownloadManager/DownloadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ public final class DownloadManager {
let coordinator: URLSessionCoordinator

public init() {
let configuration = URLSessionConfiguration.default
configuration.requestCachePolicy = .reloadIgnoringLocalCacheData

coordinator = URLSessionCoordinator(urlSessionConfiguration: configuration)
coordinator = URLSessionCoordinator(urlSessionConfiguration: .default)
}

public typealias DownloadTaskPublisher = Publishers.Share<DownloadPublisher>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

import Foundation
import Combine

#if canImport(Log)
import Log
#endif


/// `URLSessionCoordinator` manages `URLSession` instance and forwards callbacks to responding `DownloadController` instances.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
//

import Foundation

#if canImport(Log)
import Log
#endif


final class URLSessionDelegate : NSObject {
Expand Down
3 changes: 0 additions & 3 deletions Dependencies/Sources/FileIndex/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

import Foundation
import CoreData

#if canImport(PlainDatabase)
import PlainDatabase
#endif


@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
Expand Down
11 changes: 1 addition & 10 deletions Dependencies/Sources/FileIndex/FileIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,9 @@

import Foundation
import CoreData

#if canImport(PlainDatabase)
import PlainDatabase
#endif

#if canImport(Log)
import Log
#endif

#if canImport(Common)
import Common
#endif
import Model


@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@
import CoreGraphics


@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
public struct ImageInfo {

/// Decoded image
public var cgImage: CGImage
public var cgImage: CGImage {
proxy.cgImage
}

/// Image size in pixels.
///
/// This is the real size, that can be different from decoded image size.
public var size: CGSize

init(proxy: CGImageProxy, size: CGSize) {
self.proxy = proxy
self.size = size
}

private let proxy: CGImageProxy
}
50 changes: 50 additions & 0 deletions Dependencies/Sources/Model/TransientImage+ImageDecoder.swift
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)
}
}
72 changes: 72 additions & 0 deletions Dependencies/Sources/Model/TransientImage.swift
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)!
}
}
}

This file was deleted.

Loading

0 comments on commit 56535f0

Please sign in to comment.