SDImageAPNGCoder.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * This file is part of the SDWebImage package.
  3. * (c) Olivier Poitrey <rs@dailymotion.com>
  4. *
  5. * For the full copyright and license information, please view the LICENSE
  6. * file that was distributed with this source code.
  7. */
  8. #import "SDImageAPNGCoder.h"
  9. #if SD_MAC
  10. #import <CoreServices/CoreServices.h>
  11. #else
  12. #import <MobileCoreServices/MobileCoreServices.h>
  13. #endif
  14. // iOS 8 Image/IO framework binary does not contains these APNG contants, so we define them. Thanks Apple :)
  15. // We can not use runtime @available check for this issue, because it's a global symbol and should be loaded during launch time by dyld. So hack if the min deployment target version < iOS 9.0, whatever it running on iOS 9+ or not.
  16. #if (__IPHONE_OS_VERSION_MIN_REQUIRED && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
  17. const CFStringRef kCGImagePropertyAPNGLoopCount = (__bridge CFStringRef)@"LoopCount";
  18. const CFStringRef kCGImagePropertyAPNGDelayTime = (__bridge CFStringRef)@"DelayTime";
  19. const CFStringRef kCGImagePropertyAPNGUnclampedDelayTime = (__bridge CFStringRef)@"UnclampedDelayTime";
  20. #endif
  21. @implementation SDImageAPNGCoder
  22. + (instancetype)sharedCoder {
  23. static SDImageAPNGCoder *coder;
  24. static dispatch_once_t onceToken;
  25. dispatch_once(&onceToken, ^{
  26. coder = [[SDImageAPNGCoder alloc] init];
  27. });
  28. return coder;
  29. }
  30. #pragma mark - Subclass Override
  31. + (SDImageFormat)imageFormat {
  32. return SDImageFormatPNG;
  33. }
  34. + (NSString *)imageUTType {
  35. return (__bridge NSString *)kUTTypePNG;
  36. }
  37. + (NSString *)dictionaryProperty {
  38. return (__bridge NSString *)kCGImagePropertyPNGDictionary;
  39. }
  40. + (NSString *)unclampedDelayTimeProperty {
  41. return (__bridge NSString *)kCGImagePropertyAPNGUnclampedDelayTime;
  42. }
  43. + (NSString *)delayTimeProperty {
  44. return (__bridge NSString *)kCGImagePropertyAPNGDelayTime;
  45. }
  46. + (NSString *)loopCountProperty {
  47. return (__bridge NSString *)kCGImagePropertyAPNGLoopCount;
  48. }
  49. + (NSUInteger)defaultLoopCount {
  50. return 0;
  51. }
  52. @end