From b145e686b0f62e89f5f08a24316660e0cb481e27 Mon Sep 17 00:00:00 2001 From: ericwa Date: Thu, 21 Apr 2011 05:46:06 +0000 Subject: [PATCH] * Source/NSImage.m (-nativeDrawInRect:...): Make the cache window large enough so that detail is preserved when drawing using a scale factor larger than 1. This change should only improve output quality but not affect image drawing otherwise. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@32917 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 7 +++++++ Source/NSImage.m | 25 ++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index c996d098e..2a1959e2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-04-20 Eric Wasylishen + + * Source/NSImage.m (-nativeDrawInRect:...): Make the cache window + large enough so that detail is preserved when drawing using a scale factor + larger than 1. This change should only improve output quality but not + affect image drawing otherwise. + 2011-04-20 Eric Wasylishen * Source/NSBitmapImageRep+PNG.m: Read DPI metadata in PNG files diff --git a/Source/NSImage.m b/Source/NSImage.m index 6d191890d..0c1c54a21 100644 --- a/Source/NSImage.m +++ b/Source/NSImage.m @@ -478,7 +478,6 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep) - (id) initWithPasteboard: (NSPasteboard *)pasteboard { NSArray *reps; - if (!(self = [self init])) return nil; @@ -1014,12 +1013,15 @@ behavior precisely matches Cocoa. */ /* The context of the cache window */ NSGraphicsContext *cacheCtxt; /* The size of the cache window that will hold the scaled image */ - NSSize cacheSize = NSMakeSize(imgSize.width * widthScaleFactor, - imgSize.height * heightScaleFactor); - NSRect srcRectInCache = NSMakeRect(srcRect.origin.x * widthScaleFactor, - srcRect.origin.y * heightScaleFactor, - srcRect.size.width * widthScaleFactor, - srcRect.size.height * heightScaleFactor); + NSSize cacheSize = [[ctxt GSCurrentCTM] transformSize: dstRect.size]; + CGFloat imgToCacheWidthScaleFactor = cacheSize.width / imgSize.width; + CGFloat imgToCacheHeightScaleFactor = cacheSize.height / imgSize.height; + + NSRect srcRectInCache = NSMakeRect(srcRect.origin.x * imgToCacheWidthScaleFactor, + srcRect.origin.y * imgToCacheHeightScaleFactor, + srcRect.size.width * imgToCacheWidthScaleFactor, + srcRect.size.height * imgToCacheHeightScaleFactor); + NSAffineTransform *transform; cache = [[NSCachedImageRep alloc] initWithSize: cacheSize @@ -1054,12 +1056,21 @@ behavior precisely matches Cocoa. */ //NSLog(@"Draw in %@ from %@ from cache rect %@", NSStringFromRect(dstRect), // NSStringFromRect(srcRect), NSStringFromRect(srcRectInCache)); + DPSgsave(ctxt); + + transform = [NSAffineTransform transform]; + [transform scaleXBy: dstRect.size.width / cacheSize.width + yBy: dstRect.size.height / cacheSize.height]; + [transform concat]; + [ctxt GSdraw: gState toPoint: dstRect.origin fromRect: srcRectInCache operation: op fraction: delta]; + DPSgrestore(ctxt); + [ctxt GSUndefineGState: gState]; DESTROY(cache); }