Skip to content

Commit

Permalink
Fix an issue with grayscale images
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed May 18, 2024
1 parent 7257617 commit db3f39d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Add an optimization that loads local resources with `file` and `data` schemes quickly without using `DataLoader` and `URLSession`. If you rely on the existing behavior, this optimization can be turned off using the `isLocalResourcesSupportEnabled` configuration option. https://github.com/kean/Nuke/pull/779
- Deprecate `ImagePipeline.Configuration.dataCachingQueue` and perform data cache lookups on the pipeline's queue, reducing the amount of context switching
- Update the infrastructure for coalescing image-processing tasks to use the task-dependency used for other operations
- Fix [#782], an issue with grayscale images (8 bpp) not being rendered correctly when `Resize` processor is used

## Nuke 12.5

Expand Down
13 changes: 12 additions & 1 deletion Sources/Nuke/Internal/Graphics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ extension PlatformImage {

private extension CGContext {
static func make(_ image: CGImage, size: CGSize, alphaInfo: CGImageAlphaInfo? = nil) -> CGContext? {
let alphaInfo: CGImageAlphaInfo = alphaInfo ?? (image.isOpaque ? .noneSkipLast : .premultipliedLast)
let alphaInfo: CGImageAlphaInfo = alphaInfo ?? preferredAlphaInfo(for: image)

// Create the context which matches the input image.
if let ctx = CGContext(
Expand Down Expand Up @@ -189,6 +189,17 @@ private extension CGContext {
bitmapInfo: alphaInfo.rawValue
)
}

/// - See https://developer.apple.com/library/archive/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_context/dq_context.html#//apple_ref/doc/uid/TP30001066-CH203-BCIBHHBB
private static func preferredAlphaInfo(for image: CGImage) -> CGImageAlphaInfo {
guard image.isOpaque else {
return .premultipliedLast
}
if image.bitsPerPixel == 8 {
return .none // The only pixel format supported for grayscale CS
}
return .premultipliedLast
}
}

extension CGFloat {
Expand Down

0 comments on commit db3f39d

Please sign in to comment.