Skip to content

Commit 4e0d4d8

Browse files
committed
使sdwebimage支持解析webp格式图片
1 parent 5e8502e commit 4e0d4d8

7 files changed

Lines changed: 1153 additions & 0 deletions

File tree

Coding_iOS.xcodeproj/project.pbxproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,8 @@
294294
4EF818191B05C984005F974B /* ProjectTopicActivity.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EF818181B05C984005F974B /* ProjectTopicActivity.m */; };
295295
4EF8181C1B05C9AE005F974B /* TaskCommentActivity.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EF8181B1B05C9AE005F974B /* TaskCommentActivity.m */; };
296296
4EF8181F1B05C9D8005F974B /* ProjectLineNoteActivity.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EF8181E1B05C9D8005F974B /* ProjectLineNoteActivity.m */; };
297+
4EF818221B09D43D005F974B /* UIImage+WebP.m in Sources */ = {isa = PBXBuildFile; fileRef = 4EF818211B09D43D005F974B /* UIImage+WebP.m */; };
298+
4EF818241B09D8D8005F974B /* WebP.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4EF818231B09D8D8005F974B /* WebP.framework */; };
297299
4EF91F631B00B62B0021C951 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4EF91F611B00B62A0021C951 /* [email protected] */; };
298300
4EF91F641B00B62B0021C951 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 4EF91F621B00B62A0021C951 /* [email protected] */; };
299301
68D9A2AD062641F5BCA573C5 /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B024F2227BD4152BC7C9A7A /* libPods.a */; };
@@ -1094,6 +1096,9 @@
10941096
4EF8181B1B05C9AE005F974B /* TaskCommentActivity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TaskCommentActivity.m; sourceTree = "<group>"; };
10951097
4EF8181D1B05C9D8005F974B /* ProjectLineNoteActivity.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProjectLineNoteActivity.h; sourceTree = "<group>"; };
10961098
4EF8181E1B05C9D8005F974B /* ProjectLineNoteActivity.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProjectLineNoteActivity.m; sourceTree = "<group>"; };
1099+
4EF818201B09D43D005F974B /* UIImage+WebP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+WebP.h"; sourceTree = "<group>"; };
1100+
4EF818211B09D43D005F974B /* UIImage+WebP.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+WebP.m"; sourceTree = "<group>"; };
1101+
4EF818231B09D8D8005F974B /* WebP.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = WebP.framework; sourceTree = "<group>"; };
10971102
4EF91F611B00B62A0021C951 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
10981103
4EF91F621B00B62A0021C951 /* [email protected] */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "[email protected]"; sourceTree = "<group>"; };
10991104
8B18B0211092D3903D031B13 /* Pods.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.debug.xcconfig; path = "Pods/Target Support Files/Pods/Pods.debug.xcconfig"; sourceTree = "<group>"; };
@@ -1633,6 +1638,7 @@
16331638
8E477014198770E700997D05 /* Foundation.framework in Frameworks */,
16341639
4EA679031A11F18A001A0324 /* libUMessage_Sdk_1.1.0.a in Frameworks */,
16351640
68D9A2AD062641F5BCA573C5 /* libPods.a in Frameworks */,
1641+
4EF818241B09D8D8005F974B /* WebP.framework in Frameworks */,
16361642
8E03D4A219F695FE0092F8C8 /* libMobClickLibrary.a in Frameworks */,
16371643
);
16381644
runOnlyForDeploymentPostprocessing = 0;
@@ -1972,6 +1978,8 @@
19721978
4EA7F1491A6D192B00A046BD /* SDWebImagePrefetcher.m */,
19731979
4EA7F14A1A6D192B00A046BD /* UIButton+WebCache.h */,
19741980
4EA7F14B1A6D192B00A046BD /* UIButton+WebCache.m */,
1981+
4EF818201B09D43D005F974B /* UIImage+WebP.h */,
1982+
4EF818211B09D43D005F974B /* UIImage+WebP.m */,
19751983
4EA7F14C1A6D192B00A046BD /* UIImage+GIF.h */,
19761984
4EA7F14D1A6D192B00A046BD /* UIImage+GIF.m */,
19771985
4EA7F14E1A6D192B00A046BD /* UIImage+MultiFormat.h */,
@@ -2239,6 +2247,7 @@
22392247
8E477012198770E700997D05 /* Frameworks */ = {
22402248
isa = PBXGroup;
22412249
children = (
2250+
4EF818231B09D8D8005F974B /* WebP.framework */,
22422251
0A6E6BBE1AB180CB004C0107 /* CoreLocation.framework */,
22432252
0A6E6BBC1AB180AE004C0107 /* MapKit.framework */,
22442253
4E8AF7891A5406AE00CDC3AE /* QuartzCore.framework */,
@@ -3756,6 +3765,7 @@
37563765
0A782FD81AB5B69200E96661 /* TweetSendCreateLocationViewController.m in Sources */,
37573766
8EA6D1BD19E240C40076D59C /* QcTask.m in Sources */,
37583767
4E35A99F1A3EC47E00CE35F1 /* FileViewController.m in Sources */,
3768+
4EF818221B09D43D005F974B /* UIImage+WebP.m in Sources */,
37593769
0A6E6BAD1AB08540004C0107 /* TweetSendLocation.m in Sources */,
37603770
4ECE8B001A3946C10021E29C /* CodingNetAPIClient.m in Sources */,
37613771
8EF643B119FF7E2900F7EEB0 /* ConversationCell.m in Sources */,
@@ -4067,6 +4077,10 @@
40674077
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
40684078
CODE_SIGN_IDENTITY = "iPhone Developer";
40694079
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
4080+
FRAMEWORK_SEARCH_PATHS = (
4081+
"$(inherited)",
4082+
"$(PROJECT_DIR)",
4083+
);
40704084
GCC_PRECOMPILE_PREFIX_HEADER = YES;
40714085
GCC_PREFIX_HEADER = "Coding_iOS/Coding_iOS-Prefix.pch";
40724086
HEADER_SEARCH_PATHS = (
@@ -4097,6 +4111,10 @@
40974111
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
40984112
CODE_SIGN_IDENTITY = "iPhone Developer";
40994113
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
4114+
FRAMEWORK_SEARCH_PATHS = (
4115+
"$(inherited)",
4116+
"$(PROJECT_DIR)",
4117+
);
41004118
GCC_PRECOMPILE_PREFIX_HEADER = YES;
41014119
GCC_PREFIX_HEADER = "Coding_iOS/Coding_iOS-Prefix.pch";
41024120
HEADER_SEARCH_PATHS = (
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// UIImage+WebP.h
3+
// SDWebImage
4+
//
5+
// Created by Olivier Poitrey on 07/06/13.
6+
// Copyright (c) 2013 Dailymotion. All rights reserved.
7+
//
8+
9+
#ifdef SD_WEBP
10+
11+
#import <UIKit/UIKit.h>
12+
13+
// Fix for issue #416 Undefined symbols for architecture armv7 since WebP introduction when deploying to device
14+
void WebPInitPremultiplyNEON(void);
15+
16+
void WebPInitUpsamplersNEON(void);
17+
18+
void VP8DspInitNEON(void);
19+
20+
@interface UIImage (WebP)
21+
22+
+ (UIImage *)sd_imageWithWebPData:(NSData *)data;
23+
24+
@end
25+
26+
#endif
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// UIImage+WebP.m
3+
// SDWebImage
4+
//
5+
// Created by Olivier Poitrey on 07/06/13.
6+
// Copyright (c) 2013 Dailymotion. All rights reserved.
7+
//
8+
9+
#ifdef SD_WEBP
10+
#import "UIImage+WebP.h"
11+
#import "webp/decode.h"
12+
13+
// Callback for CGDataProviderRelease
14+
static void FreeImageData(void *info, const void *data, size_t size)
15+
{
16+
free((void *)data);
17+
}
18+
19+
@implementation UIImage (WebP)
20+
21+
+ (UIImage *)sd_imageWithWebPData:(NSData *)data {
22+
WebPDecoderConfig config;
23+
if (!WebPInitDecoderConfig(&config)) {
24+
return nil;
25+
}
26+
27+
if (WebPGetFeatures(data.bytes, data.length, &config.input) != VP8_STATUS_OK) {
28+
return nil;
29+
}
30+
31+
config.output.colorspace = config.input.has_alpha ? MODE_rgbA : MODE_RGB;
32+
config.options.use_threads = 1;
33+
34+
// Decode the WebP image data into a RGBA value array.
35+
if (WebPDecode(data.bytes, data.length, &config) != VP8_STATUS_OK) {
36+
return nil;
37+
}
38+
39+
int width = config.input.width;
40+
int height = config.input.height;
41+
if (config.options.use_scaling) {
42+
width = config.options.scaled_width;
43+
height = config.options.scaled_height;
44+
}
45+
46+
// Construct a UIImage from the decoded RGBA value array.
47+
CGDataProviderRef provider =
48+
CGDataProviderCreateWithData(NULL, config.output.u.RGBA.rgba, config.output.u.RGBA.size, FreeImageData);
49+
CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
50+
CGBitmapInfo bitmapInfo = config.input.has_alpha ? kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast : 0;
51+
size_t components = config.input.has_alpha ? 4 : 3;
52+
CGColorRenderingIntent renderingIntent = kCGRenderingIntentDefault;
53+
CGImageRef imageRef = CGImageCreate(width, height, 8, components * 8, components * width, colorSpaceRef, bitmapInfo, provider, NULL, NO, renderingIntent);
54+
55+
CGColorSpaceRelease(colorSpaceRef);
56+
CGDataProviderRelease(provider);
57+
58+
UIImage *image = [[UIImage alloc] initWithCGImage:imageRef];
59+
CGImageRelease(imageRef);
60+
61+
return image;
62+
}
63+
64+
@end
65+
66+
#if !COCOAPODS
67+
// Functions to resolve some undefined symbols when using WebP and force_load flag
68+
void WebPInitPremultiplyNEON(void) {}
69+
void WebPInitUpsamplersNEON(void) {}
70+
void VP8DspInitNEON(void) {}
71+
#endif
72+
73+
#endif

0 commit comments

Comments
 (0)