Skip to content

fix: use original file when sharing image with alpha channel#343

Open
BugenZhao wants to merge 1 commit intomainfrom
bz/hidden-tick
Open

fix: use original file when sharing image with alpha channel#343
BugenZhao wants to merge 1 commit intomainfrom
bz/hidden-tick

Conversation

@BugenZhao
Copy link
Owner

No description provided.

Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Copilot AI review requested due to automatic review settings January 28, 2026 12:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes image sharing behavior to preserve the original file format when sharing images with alpha channels. Previously, all eligible images were converted to JPEG, which would lose alpha channel information. The changes ensure that images with transparency are shared in their original format.

Changes:

  • Added alpha channel detection to isPlainImage property to exclude images with alpha from JPEG conversion
  • Added diagnostic logging when transferable image creation fails

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
app/Shared/Models/ViewingImageModel.swift Adds alpha channel check to isPlainImage to prevent images with transparency from being converted to JPEG
app/iOS/Views/NewImageViewer.swift Adds warning log when TransferableImage initialization fails for debugging purposes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


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

Copilot AI Jan 28, 2026

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants