UIImage+ForceDecode.h 2.0 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 "SDWebImageCompat.h"
  9. /**
  10. UIImage category about force decode feature (avoid Image/IO's lazy decoding during rendering behavior).
  11. */
  12. @interface UIImage (ForceDecode)
  13. /**
  14. A bool value indicating whether the image has already been decoded. This can help to avoid extra force decode.
  15. Force decode is used for 2 cases:
  16. -- 1. for ImageIO created image (via `CGImageCreateWithImageSource` SPI), it's lazy and we trigger the decode before rendering
  17. -- 2. for non-ImageIO created image (via `CGImageCreate` API), we can ensure it's alignment is suitable to render on screen without copy by CoreAnimation
  18. @note For coder plugin developer, always use the SDImageCoderHelper's `colorSpaceGetDeviceRGB`/`preferredPixelFormat` to create CGImage.
  19. @note For more information why force decode, see: https://github.com/path/FastImageCache#byte-alignment
  20. @note From v5.17.0, the default value is always NO. Use `SDImageForceDecodePolicy` to control complicated policy.
  21. */
  22. @property (nonatomic, assign) BOOL sd_isDecoded;
  23. /**
  24. Decode the provided image. This is useful if you want to force decode the image before rendering to improve performance.
  25. @param image The image to be decoded
  26. @return The decoded image
  27. */
  28. + (nullable UIImage *)sd_decodedImageWithImage:(nullable UIImage *)image;
  29. /**
  30. Decode and scale down the provided image
  31. @param image The image to be decoded
  32. @return The decoded and scaled down image
  33. */
  34. + (nullable UIImage *)sd_decodedAndScaledDownImageWithImage:(nullable UIImage *)image;
  35. /**
  36. Decode and scale down the provided image with limit bytes
  37. @param image The image to be decoded
  38. @param bytes The limit bytes size. Provide 0 to use the build-in limit.
  39. @return The decoded and scaled down image
  40. */
  41. + (nullable UIImage *)sd_decodedAndScaledDownImageWithImage:(nullable UIImage *)image limitBytes:(NSUInteger)bytes;
  42. @end