Added NEF test case, as well as BMP type enum

The file extension hint works on iOS/macOS for current
This commit is contained in:
DreamPiggy 2022-10-29 18:13:36 +08:00
parent b1b16a17b3
commit 8dd6e25cd8
6 changed files with 56 additions and 0 deletions

View File

@ -25,6 +25,8 @@ static const SDImageFormat SDImageFormatHEIC = 5;
static const SDImageFormat SDImageFormatHEIF = 6;
static const SDImageFormat SDImageFormatPDF = 7;
static const SDImageFormat SDImageFormatSVG = 8;
static const SDImageFormat SDImageFormatBMP = 9;
static const SDImageFormat SDImageFormatRAW = 10;
/**
NSData category about the image content type and UTI.

View File

@ -37,6 +37,8 @@
case 0x49:
case 0x4D:
return SDImageFormatTIFF;
case 0x42:
return SDImageFormatBMP;
case 0x52: {
if (data.length >= 12) {
//RIFF....WEBP
@ -113,6 +115,12 @@
case SDImageFormatSVG:
UTType = kSDUTTypeSVG;
break;
case SDImageFormatBMP:
UTType = kSDUTTypeBMP;
break;
case SDImageFormatRAW:
UTType = kSDUTTypeRAW;
break;
default:
// default is kUTTypeImage abstract type
UTType = kSDUTTypeImage;
@ -144,6 +152,10 @@
imageFormat = SDImageFormatPDF;
} else if (CFStringCompare(uttype, kSDUTTypeSVG, 0) == kCFCompareEqualTo) {
imageFormat = SDImageFormatSVG;
} else if (CFStringCompare(uttype, kSDUTTypeBMP, 0) == kCFCompareEqualTo) {
imageFormat = SDImageFormatBMP;
} else if (UTTypeConformsTo(uttype, kSDUTTypeRAW)) {
imageFormat = SDImageFormatRAW;
} else {
imageFormat = SDImageFormatUndefined;
}

View File

@ -25,6 +25,8 @@
#define kSDUTTypeSVG ((__bridge CFStringRef)@"public.svg-image")
#define kSDUTTypeGIF ((__bridge CFStringRef)@"com.compuserve.gif")
#define kSDUTTypePDF ((__bridge CFStringRef)@"com.adobe.pdf")
#define kSDUTTypeBMP ((__bridge CFStringRef)@"com.microsoft.bmp")
#define kSDUTTypeRAW ((__bridge CFStringRef)@"public.camera-raw-image")
@interface SDImageIOAnimatedCoder ()

View File

@ -98,6 +98,9 @@
32B99EAD203B36690017FD66 /* SDWebImagePrefetcherTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4369C1D01D97F80F007E863A /* SDWebImagePrefetcherTests.m */; };
32B99EAE203B366C0017FD66 /* SDWebCacheCategoriesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4369C2731D9804B1007E863A /* SDWebCacheCategoriesTests.m */; };
32E6F0321F3A1B4700A945E6 /* SDWebImageTestCoder.m in Sources */ = {isa = PBXBuildFile; fileRef = 32E6F0311F3A1B4700A945E6 /* SDWebImageTestCoder.m */; };
32F788A3290D252200B57A1C /* TestImage.nef in Resources */ = {isa = PBXBuildFile; fileRef = 32F788A2290D252200B57A1C /* TestImage.nef */; };
32F788A4290D252200B57A1C /* TestImage.nef in Resources */ = {isa = PBXBuildFile; fileRef = 32F788A2290D252200B57A1C /* TestImage.nef */; };
32F788A5290D252200B57A1C /* TestImage.nef in Resources */ = {isa = PBXBuildFile; fileRef = 32F788A2290D252200B57A1C /* TestImage.nef */; };
37D122881EC48B5E00D98CEB /* SDMockFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 37D122871EC48B5E00D98CEB /* SDMockFileManager.m */; };
433BBBB51D7EF5C00086B6E9 /* SDImageCoderTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 433BBBB41D7EF5C00086B6E9 /* SDImageCoderTests.m */; };
433BBBB71D7EF8200086B6E9 /* TestImage.gif in Resources */ = {isa = PBXBuildFile; fileRef = 433BBBB61D7EF8200086B6E9 /* TestImage.gif */; };
@ -158,6 +161,7 @@
32B99E96203B2DF90017FD66 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
32E6F0301F3A1B4700A945E6 /* SDWebImageTestCoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDWebImageTestCoder.h; sourceTree = "<group>"; };
32E6F0311F3A1B4700A945E6 /* SDWebImageTestCoder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDWebImageTestCoder.m; sourceTree = "<group>"; };
32F788A2290D252200B57A1C /* TestImage.nef */ = {isa = PBXFileReference; lastKnownFileType = file; path = TestImage.nef; sourceTree = "<group>"; };
37D122861EC48B5E00D98CEB /* SDMockFileManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDMockFileManager.h; sourceTree = "<group>"; };
37D122871EC48B5E00D98CEB /* SDMockFileManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDMockFileManager.m; sourceTree = "<group>"; };
433BBBB41D7EF5C00086B6E9 /* SDImageCoderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDImageCoderTests.m; sourceTree = "<group>"; };
@ -270,6 +274,7 @@
327A418B211D660600495442 /* TestImage.heic */,
32905E63211D786E00460FCF /* TestImage.heif */,
3234306123E2BAC800C290C8 /* TestImage.pdf */,
32F788A2290D252200B57A1C /* TestImage.nef */,
327054E1206CEFF3006EA328 /* TestImageAnimated.apng */,
3297A09E23374D1600814590 /* TestImageAnimated.heic */,
32515F9824AF1919005E8F79 /* TestImageAnimated.webp */,
@ -474,6 +479,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
32F788A5290D252200B57A1C /* TestImage.nef in Resources */,
6BC1C210270F073A003FFAB1 /* TestAnimatedImageMemory.webp in Resources */,
3299228D2365DC6C00EAFD97 /* TestImageAnimated.apng in Resources */,
3299228B2365DC6C00EAFD97 /* TestImage.heic in Resources */,
@ -499,6 +505,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
32F788A4290D252200B57A1C /* TestImage.nef in Resources */,
6BC1C20F270F0193003FFAB1 /* TestAnimatedImageMemory.webp in Resources */,
327054E3206CEFF3006EA328 /* TestImageAnimated.apng in Resources */,
32B99EA3203B31360017FD66 /* TestImage.gif in Resources */,
@ -524,6 +531,7 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
32F788A3290D252200B57A1C /* TestImage.nef in Resources */,
327A418C211D660600495442 /* TestImage.heic in Resources */,
6B181A1B265757ED00BD06B3 /* TestAnimatedImageMemory.webp in Resources */,
5F7F38AD1AE2A77A00B0E330 /* TestImage.jpg in Resources */,

Binary file not shown.

View File

@ -396,6 +396,38 @@
expect(size8).equal(CGSizeMake(999, 999));
}
- (void)test25ThatBMPWorks {
NSURL *bmpURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImage" withExtension:@"bmp"];
[self verifyCoder:[SDImageIOCoder sharedCoder]
withLocalImageURL:bmpURL
supportsEncoding:YES
encodingFormat:SDImageFormatBMP
isAnimatedImage:NO
isVectorImage:NO];
}
- (void)test26ThatRawImageTypeHintWorks {
NSURL *url = [[NSBundle bundleForClass:[self class]] URLForResource:@"TestImage" withExtension:@"nef"];
NSData *data = [NSData dataWithContentsOfURL:url];
// 1. Test without hint will use TIFF's IFD#0, which size should always be 160x120, see: http://lclevy.free.fr/nef/
UIImage *image1 = [SDImageIOCoder.sharedCoder decodedImageWithData:data options:nil];
expect(image1.size).equal(CGSizeMake(160, 120));
expect(image1.sd_imageFormat).equal(SDImageFormatTIFF);
#if SD_MAC || SD_IOS
// 2. Test with NEF file extension should be NEF
UIImage *image2 = [SDImageIOCoder.sharedCoder decodedImageWithData:data options:@{SDImageCoderDecodeFileExtensionHint : @"nef"}];
expect(image2.size).equal(CGSizeMake(3008, 2000));
expect(image2.sd_imageFormat).equal(SDImageFormatRAW);
// 3. Test with UTType hint should be NEF
UIImage *image3 = [SDImageIOCoder.sharedCoder decodedImageWithData:data options:@{SDImageCoderDecodeTypeIdentifierHint : @"com.nikon.raw-image"}];
expect(image3.size).equal(CGSizeMake(3008, 2000));
expect(image3.sd_imageFormat).equal(SDImageFormatRAW);
#endif
}
#pragma mark - Utils
- (void)verifyCoder:(id<SDImageCoder>)coder