SDWebImageCoderHelper.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 <Foundation/Foundation.h>
  9. #import "SDWebImageCompat.h"
  10. #import "SDWebImageFrame.h"
  11. @interface SDWebImageCoderHelper : NSObject
  12. /**
  13. Return an animated image with frames array.
  14. For UIKit, this will apply the patch and then create animated UIImage. The patch is because that `+[UIImage animatedImageWithImages:duration:]` just use the average of duration for each image. So it will not work if different frame has different duration. Therefore we repeat the specify frame for specify times to let it work.
  15. For AppKit, NSImage does not support animates other than GIF. This will try to encode the frames to GIF format and then create an animated NSImage for rendering. Attention the animated image may loss some detail if the input frames contain full alpha channel because GIF only supports 1 bit alpha channel. (For 1 pixel, either transparent or not)
  16. @param frames The frames array. If no frames or frames is empty, return nil
  17. @return A animated image for rendering on UIImageView(UIKit) or NSImageView(AppKit)
  18. */
  19. + (UIImage * _Nullable)animatedImageWithFrames:(NSArray<SDWebImageFrame *> * _Nullable)frames;
  20. /**
  21. Return frames array from an animated image.
  22. For UIKit, this will unapply the patch for the description above and then create frames array. This will also work for normal animated UIImage.
  23. For AppKit, NSImage does not support animates other than GIF. This will try to decode the GIF imageRep and then create frames array.
  24. @param animatedImage A animated image. If it's not animated, return nil
  25. @return The frames array
  26. */
  27. + (NSArray<SDWebImageFrame *> * _Nullable)framesFromAnimatedImage:(UIImage * _Nullable)animatedImage;
  28. #if SD_UIKIT || SD_WATCH
  29. /**
  30. Convert an EXIF image orientation to an iOS one.
  31. @param exifOrientation EXIF orientation
  32. @return iOS orientation
  33. */
  34. + (UIImageOrientation)imageOrientationFromEXIFOrientation:(NSInteger)exifOrientation;
  35. /**
  36. Convert an iOS orientation to an EXIF image orientation.
  37. @param imageOrientation iOS orientation
  38. @return EXIF orientation
  39. */
  40. + (NSInteger)exifOrientationFromImageOrientation:(UIImageOrientation)imageOrientation;
  41. #endif
  42. @end