Skip to content

Commit

Permalink
Add tentative support for unsupported colorspace for output #128
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii committed Jun 5, 2021
1 parent bb07848 commit 9ad3365
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
15 changes: 14 additions & 1 deletion Sources/BrightroomEngine/Engine/CoreGraphics+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,26 @@ extension CGContext {
*/
bitmapInfo.remove(.byteOrder32Little)

/**
Ref: https://github.com/guoyingtao/Mantis/issues/12
*/
let outputColorSpace: CGColorSpace

if let colorSpace = image.colorSpace, colorSpace.supportsOutput {
outputColorSpace = colorSpace
} else {
EngineLog.error(.default, "CGImage's color-space does not support output. \(image.colorSpace as Any)")
outputColorSpace = CGColorSpaceCreateDeviceRGB()
}

let context = try CGContext.init(
data: nil,
width: size.map { Int($0.width) } ?? image.width,
height: size.map { Int($0.height) } ?? image.height,
bitsPerComponent: image.bitsPerComponent,
bytesPerRow: 0,
space: try image.colorSpace.unwrap(),
space: outputColorSpace,
bitmapInfo: bitmapInfo.rawValue
)
.unwrap()
Expand Down
5 changes: 4 additions & 1 deletion Tests/BrightroomEngineTests/CGContextCreationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ final class CGContextCreationTests: XCTestCase {
do {
_ = try CGContext.makeContext(for: cgImage)
} catch {
print("", imageName, error.localizedDescription)
print("❌===")
print(cgImage.colorSpace)
print(imageName, error.localizedDescription)
print("===")
XCTFail(error.localizedDescription)
}
}
Expand Down

0 comments on commit 9ad3365

Please sign in to comment.