From 74dc245941d853c6a8204596167ad3c770a83832 Mon Sep 17 00:00:00 2001 From: jens Date: Fri, 4 Mar 2005 00:05:43 +0000 Subject: [PATCH] REGRESSION: Images scale while loading git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8766 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebKit/ChangeLog | 10 ++++ WebKit/WebCoreSupport.subproj/WebImageData.m | 58 ++++++++++++++------ 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/WebKit/ChangeLog b/WebKit/ChangeLog index 13ccd4322432..b632fe80e14a 100644 --- a/WebKit/ChangeLog +++ b/WebKit/ChangeLog @@ -1,3 +1,13 @@ +2005-03-03 Jens Alfke + + Reviewed by rjw. + + REGRESSION: Images scale while loading + The code could crop an image when not all the scanlines were available yet, and it could crop when only a sub-rect of the image was to be drawn; but if it had to do both at once, it got the coordinates wrong. Fixed that. + + * WebCoreSupport.subproj/WebImageData.m: + (-[WebImageData incrementalLoadWithBytes:length:complete:callback:]): + 2005-03-01 David Hyatt Fix for 3841186, scrollbar shows up disabled when it should not appear at all. Make sure updateScrollers diff --git a/WebKit/WebCoreSupport.subproj/WebImageData.m b/WebKit/WebCoreSupport.subproj/WebImageData.m index 6c9600730686..2e3182ea3a7c 100644 --- a/WebKit/WebCoreSupport.subproj/WebImageData.m +++ b/WebKit/WebCoreSupport.subproj/WebImageData.m @@ -371,6 +371,16 @@ static CFDictionaryRef imageSourceOptions; - (BOOL)incrementalLoadWithBytes:(const void *)bytes length:(unsigned)length complete:(BOOL)isComplete callback:(id)callback { +#ifdef kImageBytesCutoff + // This is a hack to help with testing display of partially-loaded images. + // To enable it, define kImageBytesCutoff to be a size smaller than that of the image files + // being loaded. They'll never finish loading. + if( length > kImageBytesCutoff ) { + length = kImageBytesCutoff; + isComplete = NO; + } +#endif + CFDataRef data = CFDataCreate (NULL, bytes, length); if (callback) { @@ -431,20 +441,26 @@ static CFDictionaryRef imageSourceOptions; } else { CGContextSaveGState (aContext); - - // Get the height of the portion of the image that is currently decoded. This - // could be less that the actual height. - float h = CGImageGetHeight(image); - - // Is the amount of available bands less than what we need to draw? If so, - // clip. - BOOL clipped = NO; - CGSize actualSize = [self size]; - if (h != actualSize.height) { - float proportionLoaded = h/actualSize.height; - fr.size.height = fr.size.height * proportionLoaded; - ir.size.height = ir.size.height * proportionLoaded; - clipped = YES; + + // Get the height (in adjusted, i.e. scaled, coords) of the portion of the image + // that is currently decoded. This could be less that the actual height. + CGSize selfSize = [self size]; // full image size, in pixels + float curHeight = CGImageGetHeight(image); // height of loaded portion, in pixels + + if( curHeight < selfSize.height ) { + adjustedSize.height *= curHeight / selfSize.height; + + // Is the amount of available bands less than what we need to draw? If so, + // we may have to clip 'fr' if it goes outside the available bounds. + if( CGRectGetMaxY(fr) > adjustedSize.height ) { + float frHeight = adjustedSize.height - fr.origin.y; // clip fr to available bounds + if( frHeight <= 0 ) { + [decodeLock unlock]; + return; // clipped out entirely + } + ir.size.height *= (frHeight / fr.size.height); // scale ir proportionally to fr + fr.size.height = frHeight; + } } // Flip the coords. @@ -459,11 +475,19 @@ static CFDictionaryRef imageSourceOptions; // If we're drawing a sub portion of the image then create // a image for the sub portion and draw that. // Test using example site at http://www.meyerweb.com/eric/css/edge/complexspiral/demo.html - if (clipped == NO && (fr.size.width != adjustedSize.width || fr.size.height != adjustedSize.height)) { + if (fr.size.width != adjustedSize.width || fr.size.height != adjustedSize.height) { + // Convert ft to image pixel coords: + float xscale = adjustedSize.width / selfSize.width; + float yscale = adjustedSize.height / curHeight; // yes, curHeight, not selfSize.height! + fr.origin.x /= xscale; + fr.origin.y /= yscale; + fr.size.width /= xscale; + fr.size.height /= yscale; + image = CGImageCreateWithImageInRect (image, fr); if (image) { - CGContextDrawImage (aContext, ir, image); - CFRelease (image); + CGContextDrawImage (aContext, ir, image); + CFRelease (image); } } // otherwise draw the whole image. -- 2.36.0