mirror of
https://github.com/GayPizzaSpecifications/voxelotl-engine.git
synced 2025-08-03 13:11:33 +00:00
Official iOS/iPadOS/visionOS/tvOS support
This commit is contained in:
@ -1,4 +1,9 @@
|
||||
#if os(macOS)
|
||||
import AppKit
|
||||
#else
|
||||
import UIKit
|
||||
#endif
|
||||
|
||||
|
||||
struct NSImageLoader {
|
||||
private static let flipVertically = true
|
||||
@ -6,11 +11,19 @@ struct NSImageLoader {
|
||||
static func open(url: URL) throws -> Image2D {
|
||||
try autoreleasepool {
|
||||
// Open as a CoreGraphics image
|
||||
#if os(macOS)
|
||||
guard let nsImage = NSImage(contentsOf: url),
|
||||
let cgImage = nsImage.cgImage(forProposedRect: nil, context: nil, hints: nil)
|
||||
else {
|
||||
throw ImageLoaderError.openFailed("Failed to open image \"\(url.absoluteString)\"")
|
||||
}
|
||||
#else
|
||||
guard let nsImage = UIImage(contentsOfFile: url.path(percentEncoded: false)),
|
||||
let cgImage = nsImage.cgImage
|
||||
else {
|
||||
throw ImageLoaderError.openFailed("Failed to open image \"\(url.absoluteString)\"")
|
||||
}
|
||||
#endif
|
||||
|
||||
// Convert 8-bit ARGB (sRGB) w/ pre-multiplied alpha
|
||||
let alphaInfo = cgImage.alphaInfo == .none
|
||||
|
Reference in New Issue
Block a user