Add the test cases for WebP decoding. iOS 14 seems does not support Web Encoding currently

This commit is contained in:
DreamPiggy 2020-07-03 15:53:35 +08:00
parent 7bfd67a94f
commit 8dbc0ac7d8
5 changed files with 49 additions and 8 deletions

View File

@ -11,7 +11,8 @@
/**
This coder is used for Google WebP and Animated WebP(AWebP) image format.
Image/IO provide the WebP support in iOS 14/macOS 11/tvOS 14/watchOS 7+.
Image/IO provide the WebP decoding support in iOS 14/macOS 11/tvOS 14/watchOS 7+.
@note Currently Image/IO seems does not supports WebP encoding, if you need WebP encoding, use the custom codec below.
@note If you need to support lower firmware version for WebP, you can have a try at https://github.com/SDWebImage/SDWebImageWebPCoder
*/
@interface SDImageAWebPCoder : SDImageIOAnimatedCoder <SDProgressiveImageCoder, SDAnimatedImageCoder>

View File

@ -24,6 +24,12 @@
323B8E2020862322008952BE /* SDWebImageTestLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 323B8E1E20862322008952BE /* SDWebImageTestLoader.m */; };
324047442271956F007C53E1 /* TestEXIF.png in Resources */ = {isa = PBXBuildFile; fileRef = 324047432271956F007C53E1 /* TestEXIF.png */; };
324047452271956F007C53E1 /* TestEXIF.png in Resources */ = {isa = PBXBuildFile; fileRef = 324047432271956F007C53E1 /* TestEXIF.png */; };
32515F9924AF1919005E8F79 /* TestImageStatic.webp in Resources */ = {isa = PBXBuildFile; fileRef = 32515F9724AF1919005E8F79 /* TestImageStatic.webp */; };
32515F9A24AF1919005E8F79 /* TestImageStatic.webp in Resources */ = {isa = PBXBuildFile; fileRef = 32515F9724AF1919005E8F79 /* TestImageStatic.webp */; };
32515F9B24AF1919005E8F79 /* TestImageStatic.webp in Resources */ = {isa = PBXBuildFile; fileRef = 32515F9724AF1919005E8F79 /* TestImageStatic.webp */; };
32515F9C24AF1919005E8F79 /* TestImageAnimated.webp in Resources */ = {isa = PBXBuildFile; fileRef = 32515F9824AF1919005E8F79 /* TestImageAnimated.webp */; };
32515F9D24AF1919005E8F79 /* TestImageAnimated.webp in Resources */ = {isa = PBXBuildFile; fileRef = 32515F9824AF1919005E8F79 /* TestImageAnimated.webp */; };
32515F9E24AF1919005E8F79 /* TestImageAnimated.webp in Resources */ = {isa = PBXBuildFile; fileRef = 32515F9824AF1919005E8F79 /* TestImageAnimated.webp */; };
3254C32020641077008D1022 /* SDImageTransformerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3254C31F20641077008D1022 /* SDImageTransformerTests.m */; };
3254C32120641077008D1022 /* SDImageTransformerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3254C31F20641077008D1022 /* SDImageTransformerTests.m */; };
3264FF2F205D42CB00F6BD48 /* SDWebImageTestTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3264FF2E205D42CB00F6BD48 /* SDWebImageTestTransformer.m */; };
@ -118,6 +124,8 @@
323B8E1D20862322008952BE /* SDWebImageTestLoader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDWebImageTestLoader.h; sourceTree = "<group>"; };
323B8E1E20862322008952BE /* SDWebImageTestLoader.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDWebImageTestLoader.m; sourceTree = "<group>"; };
324047432271956F007C53E1 /* TestEXIF.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = TestEXIF.png; sourceTree = "<group>"; };
32515F9724AF1919005E8F79 /* TestImageStatic.webp */ = {isa = PBXFileReference; lastKnownFileType = file; path = TestImageStatic.webp; sourceTree = "<group>"; };
32515F9824AF1919005E8F79 /* TestImageAnimated.webp */ = {isa = PBXFileReference; lastKnownFileType = file; path = TestImageAnimated.webp; sourceTree = "<group>"; };
3254C31F20641077008D1022 /* SDImageTransformerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDImageTransformerTests.m; sourceTree = "<group>"; };
3264FF2D205D42CB00F6BD48 /* SDWebImageTestTransformer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDWebImageTestTransformer.h; sourceTree = "<group>"; };
3264FF2E205D42CB00F6BD48 /* SDWebImageTestTransformer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SDWebImageTestTransformer.m; sourceTree = "<group>"; };
@ -250,6 +258,8 @@
3234306123E2BAC800C290C8 /* TestImage.pdf */,
327054E1206CEFF3006EA328 /* TestImageAnimated.apng */,
3297A09E23374D1600814590 /* TestImageAnimated.heic */,
32515F9824AF1919005E8F79 /* TestImageAnimated.webp */,
32515F9724AF1919005E8F79 /* TestImageStatic.webp */,
);
path = Images;
sourceTree = "<group>";
@ -459,7 +469,9 @@
3299228A2365DC6C00EAFD97 /* TestImage.png in Resources */,
329922842365DC6C00EAFD97 /* MonochromeTestImage.jpg in Resources */,
329922882365DC6C00EAFD97 /* TestImage.jpg in Resources */,
32515F9E24AF1919005E8F79 /* TestImageAnimated.webp in Resources */,
3299228E2365DC6C00EAFD97 /* TestImageAnimated.heic in Resources */,
32515F9B24AF1919005E8F79 /* TestImageStatic.webp in Resources */,
329922862365DC6C00EAFD97 /* TestImage.gif in Resources */,
329922852365DC6C00EAFD97 /* TestEXIF.png in Resources */,
);
@ -479,7 +491,9 @@
3297A0A023374D1700814590 /* TestImageAnimated.heic in Resources */,
32B99EA2203B31360017FD66 /* MonochromeTestImage.jpg in Resources */,
32905E65211D786E00460FCF /* TestImage.heif in Resources */,
32515F9D24AF1919005E8F79 /* TestImageAnimated.webp in Resources */,
327A418D211D660600495442 /* TestImage.heic in Resources */,
32515F9A24AF1919005E8F79 /* TestImageStatic.webp in Resources */,
326E69482334C0C300B7252C /* TestLoopCount.gif in Resources */,
32B99EA5203B31360017FD66 /* TestImageLarge.jpg in Resources */,
);
@ -499,7 +513,9 @@
433BBBB91D7EF8260086B6E9 /* TestImage.png in Resources */,
3297A09F23374D1700814590 /* TestImageAnimated.heic in Resources */,
327054E2206CEFF3006EA328 /* TestImageAnimated.apng in Resources */,
32515F9C24AF1919005E8F79 /* TestImageAnimated.webp in Resources */,
326E69472334C0C300B7252C /* TestLoopCount.gif in Resources */,
32515F9924AF1919005E8F79 /* TestImageStatic.webp in Resources */,
433BBBBB1D7EFA8B0086B6E9 /* MonochromeTestImage.jpg in Resources */,
324047442271956F007C53E1 /* TestEXIF.png in Resources */,
);

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -169,7 +169,7 @@
}
- (void)test13ThatHEICWorks {
if (@available(iOS 11, macOS 10.13, *)) {
if (@available(iOS 11, tvOS 11, macOS 10.13, *)) {
NSURL *heicURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImage" withExtension:@"heic"];
#if SD_UIKIT
BOOL supportsEncoding = YES; // iPhone Simulator after Xcode 9.3 support HEIC encoding
@ -184,7 +184,7 @@
}
- (void)test14ThatHEIFWorks {
if (@available(iOS 11, macOS 10.13, *)) {
if (@available(iOS 11, tvOS 11, macOS 10.13, *)) {
NSURL *heifURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImage" withExtension:@"heif"];
[self verifyCoder:[SDImageIOCoder sharedCoder]
withLocalImageURL:heifURL
@ -198,12 +198,12 @@
manager.coders = @[SDImageIOCoder.sharedCoder];
expect([manager canDecodeFromData:nil]).beTruthy(); // Image/IO will return YES for future format
expect([manager decodedImageWithData:nil options:nil]).beNil();
expect([manager canEncodeToFormat:SDImageFormatWebP]).beFalsy();
expect([manager canEncodeToFormat:SDImageFormatUndefined]).beTruthy(); // Image/IO will return YES for future format
expect([manager encodedDataWithImage:nil format:SDImageFormatUndefined options:nil]).beNil();
}
- (void)test16ThatHEICAnimatedWorks {
if (@available(iOS 11, macOS 10.13, *)) {
if (@available(iOS 11, tvOS 11, macOS 10.13, *)) {
NSURL *heicURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageAnimated" withExtension:@"heic"];
#if SD_UIKIT
BOOL isAnimatedImage = YES;
@ -231,7 +231,31 @@
isVectorImage:YES];
}
- (void)test18ThatImageIOAnimatedCoderAbstractClass {
- (void)test18ThatStaticWebPWorks {
if (@available(iOS 14, tvOS 14, macOS 11, *)) {
NSURL *staticWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageStatic" withExtension:@"webp"];
[self verifyCoder:[SDImageAWebPCoder sharedCoder]
withLocalImageURL:staticWebPURL
supportsEncoding:NO // Currently (iOS 14.0) seems no encoding support
encodingFormat:SDImageFormatWebP
isAnimatedImage:NO
isVectorImage:NO];
}
}
- (void)test19ThatAnimatedWebPWorks {
if (@available(iOS 14, tvOS 14, macOS 11, *)) {
NSURL *staticWebPURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImageAnimated" withExtension:@"webp"];
[self verifyCoder:[SDImageAWebPCoder sharedCoder]
withLocalImageURL:staticWebPURL
supportsEncoding:NO // Currently (iOS 14.0) seems no encoding support
encodingFormat:SDImageFormatWebP
isAnimatedImage:YES
isVectorImage:NO];
}
}
- (void)test20ThatImageIOAnimatedCoderAbstractClass {
SDImageIOAnimatedCoder *coder = [[SDImageIOAnimatedCoder alloc] init];
@try {
[coder canEncodeToFormat:SDImageFormatPNG];
@ -241,8 +265,8 @@
}
}
- (void)test19ThatEmbedThumbnailHEICWorks {
if (@available(iOS 11, macOS 10.13, *)) {
- (void)test21ThatEmbedThumbnailHEICWorks {
if (@available(iOS 11, tvOS 11, macOS 10.13, *)) {
// The input HEIC does not contains any embed thumbnail
NSURL *heicURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImage" withExtension:@"heic"];
CGImageSourceRef source = CGImageSourceCreateWithURL((__bridge CFURLRef)heicURL, nil);