* 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
This commit is contained in:
Eric Wasylishen 2011-04-21 05:46:06 +00:00
parent 96450245fe
commit 50e9a10212
2 changed files with 25 additions and 7 deletions

View file

@ -1,3 +1,10 @@
2011-04-20 Eric Wasylishen <ewasylishen@gmail.com>
* 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 <ewasylishen@gmail.com>
* Source/NSBitmapImageRep+PNG.m: Read DPI metadata in PNG files

View file

@ -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);
}