Update the new test cases about this new behavior
This commit is contained in:
parent
01e5e429fd
commit
6b0ef2e741
|
@ -92,7 +92,7 @@
|
|||
|
||||
/**
|
||||
Return the decoded and probably scaled down image by the provided image. If the image pixels bytes size large than the limit bytes, will try to scale down. Or just works as `decodedImageWithImage:`, never scale up.
|
||||
@warning You should not pass a too smaller bytes limit, the suggestion value should be larger than 1MB. We use Tile Decoding to avoid OOM, however, this will consume much more CPU time because we need to iterate and draw each tile (which may be hundreds).
|
||||
@warning You should not pass a too small bytes limit, the suggestion value should be larger than 1MB. We use Tile Decoding to avoid OOM, however, this will consume much more CPU time because we need to iterate and draw each tile line by line.
|
||||
|
||||
@param image The image to be decoded and scaled down
|
||||
@param bytes The limit bytes size. Provide 0 to use the build-in limit.
|
||||
|
|
|
@ -597,6 +597,7 @@ static const CGFloat kDestSeemOverlap = 2.0f; // the numbers of pixels to over
|
|||
if (bytes == 0) {
|
||||
bytes = [self defaultScaleDownLimitBytes];
|
||||
}
|
||||
bytes = MAX(bytes, kBytesPerPixel);
|
||||
destTotalPixels = bytes / kBytesPerPixel;
|
||||
float imageScale = destTotalPixels / sourceTotalPixels;
|
||||
if (imageScale < 1) {
|
||||
|
|
|
@ -74,6 +74,7 @@
|
|||
}
|
||||
|
||||
- (void)test07ThatDecodeAndScaleDownImageDoesNotScaleSmallerImage {
|
||||
// check when user use the larget bytes than image pixels byets, we do not scale up the image (defaults 60MB means 3965x3965 pixels)
|
||||
NSString *testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"jpg"];
|
||||
UIImage *image = [[UIImage alloc] initWithContentsOfFile:testImagePath];
|
||||
UIImage *decodedImage = [UIImage sd_decodedAndScaledDownImageWithImage:image];
|
||||
|
@ -83,27 +84,15 @@
|
|||
expect(decodedImage.size.height).to.equal(image.size.height);
|
||||
}
|
||||
|
||||
- (void)test07ThatDecodeAndScaleDownImageDoesNotScaleSmallerBytes {
|
||||
// Check when user provide a limit bytes, which cause the tile rectangle too small to calculate
|
||||
NSString *testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImageLarge" ofType:@"jpg"];
|
||||
- (void)test07ThatDecodeAndScaleDownImageScaleSmallerBytes {
|
||||
// Check when user provide too smaller bytes, we scale it down to 1x1, but not return the force decoded original size image
|
||||
NSString *testImagePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"TestImage" ofType:@"jpg"];
|
||||
UIImage *image = [[UIImage alloc] initWithContentsOfFile:testImagePath];
|
||||
CGFloat sourceWidth = CGImageGetWidth(image.CGImage);
|
||||
CGFloat tileMinPixels = sourceWidth * 1;
|
||||
NSUInteger kBytesPerPixel = 4;
|
||||
NSUInteger kBytesPerMB = 1024 * 1024;
|
||||
NSUInteger limitBytes = MAX(tileMinPixels * 3 * kBytesPerPixel, kBytesPerMB);
|
||||
// Image 1 should be scaled down size (shouldScaleDownImage returns YES)
|
||||
UIImage *decodedImage1 = [UIImage sd_decodedAndScaledDownImageWithImage:image limitBytes:limitBytes + kBytesPerPixel];
|
||||
expect(decodedImage1).toNot.beNil();
|
||||
expect(decodedImage1).toNot.equal(image);
|
||||
expect(decodedImage1.size.width).toNot.equal(image.size.width);
|
||||
expect(decodedImage1.size.height).toNot.equal(image.size.height);
|
||||
// Image 2 should not be scaled down, only force decode (shouldScaleDownImage returns NO)
|
||||
UIImage *decodedImage2 = [UIImage sd_decodedAndScaledDownImageWithImage:image limitBytes:limitBytes - kBytesPerPixel];
|
||||
expect(decodedImage2).toNot.beNil();
|
||||
expect(decodedImage2).toNot.equal(image);
|
||||
expect(decodedImage2.size.width).to.equal(image.size.width);
|
||||
expect(decodedImage2.size.height).to.equal(image.size.height);
|
||||
UIImage *decodedImage = [UIImage sd_decodedAndScaledDownImageWithImage:image limitBytes:1];
|
||||
expect(decodedImage).toNot.beNil();
|
||||
expect(decodedImage).toNot.equal(image);
|
||||
expect(decodedImage.size.width).to.equal(1);
|
||||
expect(decodedImage.size.height).to.equal(1);
|
||||
}
|
||||
|
||||
- (void)test08ThatEncodeAlphaImageToJPGWithBackgroundColor {
|
||||
|
|
Loading…
Reference in New Issue