Skip to content

Commit

Permalink
Fixed CGImages build error with watchOS
Browse files Browse the repository at this point in the history
  • Loading branch information
rin-senpai committed Jul 12, 2024
1 parent 9a5df1b commit 4300d01
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Sources/GoogleAI/PartsRepresentable+Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import UniformTypeIdentifiers
import AppKit // For NSImage extensions.
#endif

#if os(watchOS)
import ImageIO
import CoreGraphics
#endif

private let imageCompressionQuality: CGFloat = 0.8

/// An enum describing failures that can occur when converting image types to model content data.
Expand All @@ -38,7 +43,7 @@ public enum ImageConversionError: Error {

#if canImport(UIKit)
/// Enables images to be representable as ``ThrowingPartsRepresentable``.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 8.0, *)
extension UIImage: ThrowingPartsRepresentable {
public func tryPartsValue() throws -> [ModelContent.Part] {
guard let data = jpegData(compressionQuality: imageCompressionQuality) else {
Expand All @@ -50,7 +55,7 @@ public enum ImageConversionError: Error {

#elseif canImport(AppKit)
/// Enables images to be representable as ``ThrowingPartsRepresentable``.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 8.0, *)
extension NSImage: ThrowingPartsRepresentable {
public func tryPartsValue() throws -> [ModelContent.Part] {
guard let cgImage = cgImage(forProposedRect: nil, context: nil, hints: nil) else {
Expand All @@ -67,7 +72,7 @@ public enum ImageConversionError: Error {
#endif

/// Enables `CGImages` to be representable as model content.
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, *)
@available(iOS 15.0, macOS 11.0, macCatalyst 15.0, watchOS 9.0, *)
extension CGImage: ThrowingPartsRepresentable {
public func tryPartsValue() throws -> [ModelContent.Part] {
let output = NSMutableData()
Expand Down

0 comments on commit 4300d01

Please sign in to comment.