Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/Shared/Models/ViewingImageModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extension PlatformImage {

var isPlainImage: Bool {
if sd_isAnimated { return false }
if cgImage?.alphaInfo ?? .none != .none { return false }

Copilot AI Jan 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alpha channel detection logic may incorrectly identify images with .noneSkipFirst or .noneSkipLast alpha info as having an alpha channel. According to Apple's documentation, CGImageAlphaInfo has several cases that indicate no alpha channel:

  • .none: No alpha channel
  • .noneSkipLast: No alpha channel, ignore last component (e.g., RGB_555 format)
  • .noneSkipFirst: No alpha channel, ignore first component (e.g., BGR_555 format)

The current check only compares against .none, which means images with .noneSkipFirst or .noneSkipLast would be incorrectly treated as having an alpha channel. This would cause them to be shared as the original file instead of being converted to JPEG, which is unnecessarily conservative.

Consider checking if the alpha info actually represents an alpha channel by using a more comprehensive check. For example:

let hasAlpha = cgImage?.alphaInfo.map { info in
  info != .none && info != .noneSkipFirst && info != .noneSkipLast
} ?? false
if hasAlpha { return false }

While this issue affects relatively rare image formats and fails conservatively (preserving quality), it's worth fixing for correctness.

Suggested change
if cgImage?.alphaInfo ?? .none != .none { return false }
let hasAlpha = cgImage?.alphaInfo.map { info in
info != .none && info != .noneSkipFirst && info != .noneSkipLast
} ?? false
if hasAlpha { return false }

Copilot uses AI. Check for mistakes.

switch utType {
// This covers almost all common image formats in use.
Expand Down
3 changes: 3 additions & 0 deletions app/iOS/Views/NewImageViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ struct ViewingImageView: View {
DispatchQueue.global(qos: .userInitiated).async {
// In case the constructor is heavy, let's do it in a background thread.
let transferable = TransferableImage(url: url, image: image, forceFile: forceFile)
if transferable == nil {
logger.warning("Failed to create transferable for \(url)")
}
DispatchQueue.main.async {
self.transferable = transferable
updateCurrentTransferable()
Expand Down
Loading