-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from SDWebImage/bugfix/webp_encoding_colorspac…
…e_mac Fix the WebP encoding which loss the image's input color space
- Loading branch information
Showing
22 changed files
with
1,556 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
11 changes: 11 additions & 0 deletions
11
Example/SDWebImageWebPCoderExample-macOS/Assets.xcassets/AccentColor.colorset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
Example/SDWebImageWebPCoderExample-macOS/Assets.xcassets/AppIcon.appiconset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
Example/SDWebImageWebPCoderExample-macOS/Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
717
Example/SDWebImageWebPCoderExample-macOS/Base.lproj/Main.storyboard
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
5 changes: 5 additions & 0 deletions
5
Example/SDWebImageWebPCoderExample-macOS/SDWebImageWebPCoderExample_macOS.entitlements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.