<rdar://problem/3991818> REGRESSION: Images scale while loading
authorjens <jens@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Mar 2005 00:05:43 +0000 (00:05 +0000)
committerjens <jens@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Mar 2005 00:05:43 +0000 (00:05 +0000)
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@8766 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/ChangeLog
WebKit/WebCoreSupport.subproj/WebImageData.m

index 13ccd43224322e9a8f28ff4c4bc835be8464208a..b632fe80e14a92c19b1ec82f71d565596d4e8e76 100644 (file)
@@ -1,3 +1,13 @@
+2005-03-03  Jens Alfke  <jens@apple.com>
+
+        Reviewed by rjw.
+
+       <rdar://problem/3991818> 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  <hyatt@apple.com>
 
        Fix for 3841186, scrollbar shows up disabled when it should not appear at all.  Make sure updateScrollers
 2005-03-01  David Hyatt  <hyatt@apple.com>
 
        Fix for 3841186, scrollbar shows up disabled when it should not appear at all.  Make sure updateScrollers
index 6c960073068693818d16ea343daa87cc53925ffd..2e3182ea3a7c1257d8065803081f0298c5c422a2 100644 (file)
@@ -371,6 +371,16 @@ static CFDictionaryRef imageSourceOptions;
 
 - (BOOL)incrementalLoadWithBytes:(const void *)bytes length:(unsigned)length complete:(BOOL)isComplete callback:(id)callback
 {
 
 - (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) {
     CFDataRef data = CFDataCreate (NULL, bytes, length);
     
     if (callback) {
@@ -431,20 +441,26 @@ static CFDictionaryRef imageSourceOptions;
 
         } else {
             CGContextSaveGState (aContext);
 
         } 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.
             }
             
             // 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 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) {
                 image = CGImageCreateWithImageInRect (image, fr);
                 if (image) {
-                CGContextDrawImage (aContext, ir, image);
-                CFRelease (image);
+                    CGContextDrawImage (aContext, ir, image);
+                    CFRelease (image);
                 }
             }
             // otherwise draw the whole image.
                 }
             }
             // otherwise draw the whole image.