/*
 * This file is part of the YSSDWebImage package.
 * (c) Olivier Poitrey <rs@dailymotion.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

#import "UIImage+YSForceDecode.h"
#import "YSSDImageCoderHelper.h"
#import "objc/runtime.h"

@implementation UIImage (YSForceDecode)

- (BOOL)yssd_isDecoded {
    NSNumber *value = objc_getAssociatedObject(self, @selector(yssd_isDecoded));
    return value.boolValue;
}

- (void)setYssd_isDecoded:(BOOL)yssd_isDecoded {
    objc_setAssociatedObject(self, @selector(yssd_isDecoded), @(yssd_isDecoded), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

+ (nullable UIImage *)yssd_decodedImageWithImage:(nullable UIImage *)image {
    if (!image) {
        return nil;
    }
    return [YSSDImageCoderHelper decodedImageWithImage:image];
}

+ (nullable UIImage *)yssd_decodedAndScaledDownImageWithImage:(nullable UIImage *)image {
    return [self yssd_decodedAndScaledDownImageWithImage:image limitBytes:0];
}

+ (nullable UIImage *)yssd_decodedAndScaledDownImageWithImage:(nullable UIImage *)image limitBytes:(NSUInteger)bytes {
    if (!image) {
        return nil;
    }
    return [YSSDImageCoderHelper decodedAndScaledDownImageWithImage:image limitBytes:bytes];
}

@end
