Skip to content

Fix the WebP encoding which loss the image's input color space #90

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

Merged
merged 6 commits into from
Nov 8, 2023
Merged
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
8 changes: 7 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ jobs:
matrix:
iosDestination: ["platform=iOS Simulator,name=iPhone 13 Pro"]
macOSDestination: ["platform=macOS,arch=x86_64"]
tvOSDestination: ["platform=tvOS Simulator,name=Apple TV 4K"]
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -76,11 +75,18 @@ jobs:
set -o pipefail
xcodebuild test -workspace "${{ env.WORKSPACE_NAME }}" -scheme "SDWebImageWebPCoderTests" -destination "${{ matrix.iosDestination }}" -configuration Debug CODE_SIGNING_ALLOWED=NO
mv ~/Library/Developer/Xcode/DerivedData/ ./DerivedData/iOS

- name: Test - ${{ matrix.macOSDestination }}
run: |
set -o pipefail
xcodebuild test -workspace "${{ env.WORKSPACE_NAME }}" -scheme "SDWebImageWebPCoderTests-macOS" -destination "${{ matrix.macOSDestination }}" -configuration Debug CODE_SIGNING_ALLOWED=NO
mv ~/Library/Developer/Xcode/DerivedData/ ./DerivedData/macOS

- name: Code Coverage
run: |
set -o pipefail
export PATH="/usr/local/opt/curl/bin:$PATH"
curl --version
bash <(curl -s https://codecov.io/bash) -v -D './DerivedData/iOS' -J '^SDWebImageWebPCoder$' -c -X gcov -F ios
bash <(curl -s https://codecov.io/bash) -v -D './DerivedData/macOS' -J '^SDWebImageWebPCoder$' -c -X gcov -F macos

4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github "SDWebImage/SDWebImage" "5.10.0"
github "SDWebImage/libwebp-Xcode" "1.1.0"
github "SDWebImage/SDWebImage" "5.18.4"
github "SDWebImage/libwebp-Xcode" "1.3.2"
15 changes: 15 additions & 0 deletions Example/SDWebImageWebPCoderExample-macOS/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This file is part of the SDWebImage package.
* (c) DreamPiggy <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

#import <Cocoa/Cocoa.h>

@interface AppDelegate : NSObject <NSApplicationDelegate>


@end

33 changes: 33 additions & 0 deletions Example/SDWebImageWebPCoderExample-macOS/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* This file is part of the SDWebImage package.
* (c) DreamPiggy <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

#import "AppDelegate.h"

@interface AppDelegate ()


@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}


- (void)applicationWillTerminate:(NSNotification *)aNotification {
// Insert code here to tear down your application
}


- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app {
return YES;
}


@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"colors" : [
{
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"images" : [
{
"idiom" : "mac",
"scale" : "1x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "16x16"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "32x32"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "128x128"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "256x256"
},
{
"idiom" : "mac",
"scale" : "1x",
"size" : "512x512"
},
{
"idiom" : "mac",
"scale" : "2x",
"size" : "512x512"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
717 changes: 717 additions & 0 deletions Example/SDWebImageWebPCoderExample-macOS/Base.lproj/Main.storyboard

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions Example/SDWebImageWebPCoderExample-macOS/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
</plist>
15 changes: 15 additions & 0 deletions Example/SDWebImageWebPCoderExample-macOS/ViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This file is part of the SDWebImage package.
* (c) DreamPiggy <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

#import <Cocoa/Cocoa.h>

@interface ViewController : NSViewController


@end

74 changes: 74 additions & 0 deletions Example/SDWebImageWebPCoderExample-macOS/ViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* This file is part of the SDWebImage package.
* (c) DreamPiggy <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

#import "ViewController.h"
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
#import <SDWebImage/SDWebImage.h>

@interface ViewController ()

@property (nonatomic, strong) UIImageView *imageView1;
@property (nonatomic, strong) SDAnimatedImageView *imageView2;

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

[SDImageCache.sharedImageCache clearDiskOnCompletion:nil];

[[SDImageCodersManager sharedManager] addCoder:[SDImageWebPCoder sharedCoder]];

self.imageView1 = [UIImageView new];
self.imageView1.imageScaling = NSImageScaleProportionallyUpOrDown;
[self.view addSubview:self.imageView1];

self.imageView2 = [SDAnimatedImageView new];
self.imageView2.imageScaling = NSImageScaleProportionallyUpOrDown;
[self.view addSubview:self.imageView2];

NSURL *staticWebPURL = [NSURL URLWithString:@"https://www.gstatic.com/webp/gallery/2.webp"];
NSURL *animatedWebPURL = [NSURL URLWithString:@"http://littlesvr.ca/apng/images/world-cup-2014-42.webp"];

[self.imageView1 sd_setImageWithURL:staticWebPURL placeholderImage:nil options:0 context:@{SDWebImageContextImageScaleDownLimitBytes : @(1024 * 100)} progress:nil completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
NSCAssert(image.size.width < 200, @"Limit Bytes should limit image size to 186");
if (image) {
NSLog(@"%@", @"Static WebP load success");
}
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSUInteger maxFileSize = 4096;
NSData *webpData = [SDImageWebPCoder.sharedCoder encodedDataWithImage:image format:SDImageFormatWebP options:@{SDImageCoderEncodeMaxFileSize : @(maxFileSize)}];
if (webpData) {
NSCAssert(webpData.length <= maxFileSize, @"WebP Encoding with max file size limit works");
NSLog(@"%@", @"WebP encoding success");
}
});
}];
[self.imageView2 sd_setImageWithURL:animatedWebPURL placeholderImage:nil options:SDWebImageProgressiveLoad completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
if (image) {
NSLog(@"%@", @"Animated WebP load success");
}
}];
}

- (void)viewWillLayout {
[super viewWillLayout];
self.imageView1.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height / 2);
self.imageView2.frame = CGRectMake(0, self.view.bounds.size.height / 2, self.view.bounds.size.width, self.view.bounds.size.height / 2);
}

- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];

// Update the view, if already loaded.
}


@end
16 changes: 16 additions & 0 deletions Example/SDWebImageWebPCoderExample-macOS/main.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// main.m
// SDWebImageWebPCoderExample-macOS
//
// Created by lizhuoli on 2023/11/8.
// Copyright © 2023 SDWebImage. All rights reserved.
//

#import <Cocoa/Cocoa.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
// Setup code that might create autoreleased objects goes here.
}
return NSApplicationMain(argc, argv);
}
Loading