Update the default force decode value, partial revert ff6b3b9bb5

Now it's will mark as false for not byte-aligned CGImage
This commit is contained in:
DreamPiggy 2023-07-09 20:00:04 +08:00
parent b4559994ea
commit 06589dbcc4
2 changed files with 22 additions and 9 deletions

View File

@ -15,6 +15,12 @@
/**
A bool value indicating whether the image has already been decoded. This can help to avoid extra force decode.
Force decode is used for 2 cases:
-- 1. for ImageIO created image (via `CGImageCreateWithImageSource` SPI), it's lazy and we trigger the decode before rendering
-- 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
@note For coder plugin developer, always use the SDImageCoderHelper's `colorSpaceGetDeviceRGB`/`preferredByteAlignment`/`preferredBitmapInfo:` to create CGImage.
@note For more information why force decode, see: https://github.com/path/FastImageCache#byte-alignment
@note The defaults value is calculated based on UIImage's CGImage status. Do not assume it's always work as expected. Set the value to `true` if you don't need force decode
*/
@property (nonatomic, assign) BOOL sd_isDecoded;

View File

@ -20,19 +20,26 @@
} else {
// Assume only CGImage based can use lazy decoding
CGImageRef cgImage = self.CGImage;
if (cgImage) {
if (!cgImage) {
// Assume others as non-decoded
return NO;
}
CFStringRef uttype = CGImageGetUTType(self.CGImage);
if (uttype) {
// Only ImageIO can set `com.apple.ImageIO.imageSourceTypeIdentifier`
return NO;
} else {
// Thumbnail or CGBitmapContext drawn image
// Now, let's check if the CGImage is byte-aligned (not aligned will cause extra copy)
size_t bytesPerRow = CGImageGetBytesPerRow(cgImage);
if (SDByteAlign(bytesPerRow, [SDImageCoderHelper preferredByteAlignment]) == bytesPerRow) {
// byte aligned, OK
return YES;
}
}
}
// Assume others as non-decoded
} else {
// not aligned, still need force-decode
return NO;
}
}
}
}
- (void)setSd_isDecoded:(BOOL)sd_isDecoded {