SDProgressiveImageCoder

@protocol SDProgressiveImageCoder <SDImageCoder>

This is the image coder protocol to provide custom progressive image decoding. These methods are all required to implement.

Note

Pay attention that these methods are not called from main queue.
  • Returns YES if this coder can incremental decode some data. Otherwise, it should be passed to another coder.

    Declaration

    Objective-C

    - (BOOL)canIncrementalDecodeFromData:(nullable NSData *)data;

    Swift

    func canIncrementalDecode(from data: Data?) -> Bool

    Parameters

    data

    The image data so we can look at it

    Return Value

    YES if this coder can decode the data, NO otherwise

  • Because incremental decoding need to keep the decoded context, we will alloc a new instance with the same class for each download operation to avoid conflicts This init method should not return nil

    Declaration

    Objective-C

    - (nonnull instancetype)initIncrementalWithOptions:
        (nullable SDImageCoderOptions *)options;

    Swift

    init(incrementalWithOptions options: [SDImageCoderOption : Any]? = nil)

    Parameters

    options

    A dictionary containing any progressive decoding options (instance-level). Pass @{SDImageCoderDecodeScaleFactor: @(1.0)} to specify scale factor for progressive animated image (each frames should use the same scale).

    Return Value

    A new instance to do incremental decoding for the specify image format

  • Update the incremental decoding when new image data available

    Declaration

    Objective-C

    - (void)updateIncrementalData:(nullable NSData *)data finished:(BOOL)finished;

    Swift

    func updateIncrementalData(_ data: Data?, finished: Bool)

    Parameters

    data

    The image data has been downloaded so far

    finished

    Whether the download has finished

  • Incremental decode the current image data to image.

    Note

    Due to the performance issue for progressive decoding and the integration for image view. This method may only return the first frame image even if the image data is animated image. If you want progressive animated image decoding, conform to SDAnimatedImageCoder protocol as well and use animatedImageFrameAtIndex: instead.

    Declaration

    Objective-C

    - (nullable UIImage *)incrementalDecodedImageWithOptions:
        (nullable SDImageCoderOptions *)options;

    Swift

    func incrementalDecodedImage(options: [SDImageCoderOption : Any]? = nil) -> UIImage?

    Parameters

    options

    A dictionary containing any progressive decoding options. Pass @{SDImageCoderDecodeScaleFactor: @(1.0)} to specify scale factor for progressive image

    Return Value

    The decoded image from current data