-
Notifications
You must be signed in to change notification settings - Fork 94
Add ICC Profile Embedding Support for WebP Encoding #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ICC Profile Embedding Support for WebP Encoding #120
Conversation
- Extract ICC profile from input color space using CGColorSpaceCopyICCData - Use WebPMux API to embed ICCP chunk in WebP container with copy_data=1 - Automatically convert Simple Format (VP8) to Extended Format (VP8X) - Add iOS 10+ availability check for CGColorSpaceCopyICCData - Skip ICC profile when maxFileSize is set (size limit takes priority) - Add comprehensive test (testWebPEncodingEmbedICCProfile) This fixes color reproduction issues with wide color gamut images (Display P3, Adobe RGB, etc.) on platforms that assume sRGB when ICC profile is missing. Fixes SDWebImage#119
- Add TestDisplayP3.png test image with Display P3 color space - Add testWebPEncodingDisplayP3 to verify wide color gamut support - Verify ICC profile embedding works correctly for Display P3 images (536 bytes) This test demonstrates that ICC profile embedding preserves wide color gamut information, preventing washed-out colors on Android and web browsers.
- Use copy_data=0 in WebPMuxSetImage and WebPMuxSetChunk to avoid unnecessary memory copies - Ensure writer.mem and iccData remain valid until WebPMuxAssemble completes - Release iccData only after WebPMuxAssemble finishes - Clear writer memory as the final step This reduces memory operations by 50% for images with ICC profiles. Performance improvement: - Before: Image data copied twice (SetImage copy + Assemble) - After: Image data copied once (Assemble only) - Benefit: ~50% reduction in memory operations for 1MB+ images
WalkthroughThis pull request implements ICC color profile embedding in WebP encoding. When encoding images with color spaces like Display P3, the code now extracts the ICC profile and embeds it in the output WebP file using WebPMux API, with fallback to original encoding if muxing fails, accompanied by comprehensive tests. Changes
Sequence DiagramsequenceDiagram
participant Encoder as WebP Encoder
participant ColorSpace as ColorSpace
participant Writer as Memory Writer
participant Mux as WebP Mux
participant Output as Output Data
Note over Encoder: Old Flow (No ICC)
Encoder->>Writer: Encode image (WebPEncode)
Writer-->>Encoder: Encoded data
Note over Encoder: New Flow (With ICC)
Encoder->>ColorSpace: Extract ICC profile
ColorSpace-->>Encoder: ICC data (if available)
Encoder->>Writer: Encode image (WebPEncode)
Writer-->>Encoder: Encoded data
alt ICC data exists and maxFileSize == 0
Encoder->>Mux: Create WebPMux
Encoder->>Mux: SetImage (creates VP8X)
Encoder->>Mux: SetChunk ICCP
Encoder->>Mux: Assemble with ICCP
Mux-->>Output: WebP with ICC profile
else Fallback
Encoder-->>Output: Original encoded data
end
rect rgb(200, 220, 255)
Note over Encoder,Output: New: ICC profile embedded in ICCP chunk
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Areas requiring extra attention:
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
🔇 Additional comments (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
LGTM. Will release a version with this PR Released in https://github.com/SDWebImage/SDWebImageWebPCoder/releases/tag/0.15.0 |
|
Thank you so much for taking a stab at fixing this issue. The new 0.15.0 release doesn't compile for me with the following errors: Help would be appreciated. |
|
Maybe you need to upgrade libwebp's min dependency. Means we use API which requires some high version libwebp. You can use cocoapods or SPM package update to do so. I could not rember which of these API was introduced in libwebp. Maybe @KYHyeon can have a check (so that we can edit the |
|
Currently you can just use the latest 1.5.0 libwebp, see https://github.com/SDWebImage/libwebp-Xcode/releases |
|
Read again about sharpyuv: https://github.com/SDWebImage/libwebp-Xcode?tab=readme-ov-file#about-sharpyuv Maybe at least v1.3.0 |
|
It seems that https://chromium.googlesource.com/webm/libwebp/%2B/25d94f473b10882b8bee9288d00539001b692042%5E%21 |
|
Thank you for the quick help. My |
|
It didn't work with I now added a new entry to my .package(url: "https://github.com/SDWebImage/libwebp-Xcode.git", exact: "1.3.2"),Previously I didn't have to add the IMO this should get fixed in this project's |
Add ICC Profile Embedding Support for WebP Encoding
Fixes #119
Problem
When encoding images with wide color gamut (Display P3, Adobe RGB) to WebP, the ICC color profile was not embedded in the output file. This caused colors to appear washed out on Android devices and web browsers that assume sRGB.
Before
After
Implementation
Key points:
copy_data=0- avoids redundant 10MB+ memory copiesmaxFileSizeis set - size limit takes priority over color accuracyCGColorSpaceCopyICCData(iOS 9 deployment target)Test Results
sRGB: 3,144 bytes ICC embedded ✅
Display P3: 536 bytes ICC embedded ✅
All tests: 20/20 passed ✅
Verified with
hexdumpand WebPDemux that ICCP chunk is correctly present.ScreenShot
Summary by CodeRabbit
New Features
Tests
Chores