SDImageCodersManager.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 "SDImageCoder.h"
  10. /**
  11. Global object holding the array of coders, so that we avoid passing them from object to object.
  12. Uses a priority queue behind scenes, which means the latest added coders have the highest priority.
  13. This is done so when encoding/decoding something, we go through the list and ask each coder if they can handle the current data.
  14. That way, users can add their custom coders while preserving our existing prebuilt ones
  15. Note: the `coders` getter will return the coders in their reversed order
  16. Example:
  17. - by default we internally set coders = `IOCoder`, `GIFCoder`, `APNGCoder`
  18. - calling `coders` will return `@[IOCoder, GIFCoder, APNGCoder]`
  19. - call `[addCoder:[MyCrazyCoder new]]`
  20. - calling `coders` now returns `@[IOCoder, GIFCoder, APNGCoder, MyCrazyCoder]`
  21. Coders
  22. ------
  23. A coder must conform to the `SDImageCoder` protocol or even to `SDProgressiveImageCoder` if it supports progressive decoding
  24. Conformance is important because that way, they will implement `canDecodeFromData` or `canEncodeToFormat`
  25. Those methods are called on each coder in the array (using the priority order) until one of them returns YES.
  26. That means that coder can decode that data / encode to that format
  27. */
  28. @interface SDImageCodersManager : NSObject <SDImageCoder>
  29. /**
  30. Returns the global shared coders manager instance.
  31. */
  32. @property (nonatomic, class, readonly, nonnull) SDImageCodersManager *sharedManager;
  33. /**
  34. All coders in coders manager. The coders array is a priority queue, which means the later added coder will have the highest priority
  35. */
  36. @property (nonatomic, copy, nullable) NSArray<id<SDImageCoder>> *coders;
  37. /**
  38. Add a new coder to the end of coders array. Which has the highest priority.
  39. @param coder coder
  40. */
  41. - (void)addCoder:(nonnull id<SDImageCoder>)coder;
  42. /**
  43. Remove a coder in the coders array.
  44. @param coder coder
  45. */
  46. - (void)removeCoder:(nonnull id<SDImageCoder>)coder;
  47. @end