+2005-04-18 Darin Adler <darin@apple.com>
+
+ Reviewed by Hyatt.
+
+ - fixed <rdar://problem/4092614> REGRESSION (Tiger): progressively loaded background images "scroll around" instead of just appearing
+
+ * WebCoreSupport.subproj/WebImageData.m:
+ (-[WebImageData _imageSourceOptions]): Moved a global inside this function, since it's only used here.
+ (-[WebImageData _cacheImages:allImages:]): Fixed a sizeof that was getting the size of the wrong thing.
+ (-[WebImageData _isSizeAvailable]): Used calloc in a more consistent way.
+ (drawPattern): Removed an unneeded cast.
+ (-[WebImageData tileInRect:fromPoint:context:]): Here's the actual bug fix. Don't use the image size
+ when deciding whether the image needs to be tiled as a pattern nor when creating the pattern: in both
+ cases, use the tile size. The old way was wrong, and the new way works perfectly. Also removed uneeded
+ error message when the image is not yet loaded enough to create a CGImageRef for it -- it's fine to
+ draw nothing in that case.
+
2005-04-14 John Sullivan <sullivan@apple.com>
Reviewed by Chris.
#import <ImageIO/CGImageSourcePrivate.h>
-static CFDictionaryRef imageSourceOptions;
-
// Forward declarations of internal methods.
@interface WebImageData (WebInternal)
- (void)_commonTermination;
- (CFDictionaryRef)_imageSourceOptions
{
+ static CFDictionaryRef imageSourceOptions;
if (!imageSourceOptions) {
const void * keys[2] = { kCGImageSourceShouldCache, kCGImageSourceShouldPreferRGB32 };
const void * values[2] = { kCFBooleanTrue, kCFBooleanTrue };
}
for (i = from; i < to; i++) {
if (!images) {
- images = (CGImageRef *)calloc (imagesSize, sizeof(CGImageRef *));
+ images = (CGImageRef *)calloc (imagesSize, sizeof(CGImageRef));
}
images[i] = CGImageSourceCreateImageAtIndex (imageSource, i, [self _imageSourceOptions]);
}
else {
imagePropertiesSize = [self numberOfImages];
- imageProperties = (CFDictionaryRef *)calloc (imagePropertiesSize * sizeof(CFDictionaryRef), 1);
+ imageProperties = (CFDictionaryRef *)calloc (imagePropertiesSize, sizeof(CFDictionaryRef));
}
imageProperties[0] = image0Properties;
{
WebImageData *data = (WebImageData *)info;
- CGImageRef image = (CGImageRef)[data imageAtIndex:[data currentFrame]];
+ CGImageRef image = [data imageAtIndex:[data currentFrame]];
float w = CGImageGetWidth(image);
float h = CGImageGetHeight(image);
CGContextDrawImage (context, CGRectMake(0, [data size].height-h, w, h), image);
}
-CGPatternCallbacks patternCallbacks = { 0, drawPattern, NULL };
+static const CGPatternCallbacks patternCallbacks = { 0, drawPattern, NULL };
- (void)tileInRect:(CGRect)rect fromPoint:(CGPoint)point context:(CGContextRef)aContext
{
size_t frame = [self currentFrame];
CGImageRef image = [self imageAtIndex:frame];
if (!image) {
- ERROR ("unable to find image");
[decodeLock unlock];
return;
}
} else {
CGSize tileSize = [self size];
- NSSize imageSize = NSMakeSize(CGImageGetWidth(image),CGImageGetHeight(image));
// Check and see if a single draw of the image can cover the entire area we are supposed to tile.
NSRect oneTileRect;
oneTileRect.origin.x = rect.origin.x + fmodf(fmodf(-point.x, tileSize.width) - tileSize.width, tileSize.width);
oneTileRect.origin.y = rect.origin.y + fmodf(fmodf(-point.y, tileSize.height) - tileSize.height, tileSize.height);
- oneTileRect.size = imageSize;
+ oneTileRect.size.height = tileSize.height;
+ oneTileRect.size.width = tileSize.width;
// If the single image draw covers the whole area, then just draw once.
if (NSContainsRect(oneTileRect, NSMakeRect(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height))) {
CGSize phase = CGSizeMake(fmodf(originInWindow.x, tileSize.width), fmodf(originInWindow.y, tileSize.height));
// Possible optimization: We may want to cache the CGPatternRef
- CGPatternRef pattern = CGPatternCreate(self, CGRectMake (0, 0, imageSize.width, imageSize.height), CGAffineTransformIdentity, tileSize.width, tileSize.height,
+ CGPatternRef pattern = CGPatternCreate(self, CGRectMake (0, 0, tileSize.width, tileSize.height), CGAffineTransformIdentity, tileSize.width, tileSize.height,
kCGPatternTilingConstantSpacing, true, &patternCallbacks);
if (pattern) {
CGContextSaveGState (aContext);