Tread a zero source rectangle as the full image and clip to the

image bounds.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25649 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2007-11-30 19:52:26 +00:00
parent 296fd50a2e
commit ff79c63530
2 changed files with 45 additions and 29 deletions

View file

@ -1,3 +1,9 @@
2007-11-30 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSImage.m (-drawInRect:fromRect:operation:fraction:):
Tread a zero source rectangle as the full image and clip to the
image bounds.
2007-11-30 Richard Frith-Macdonald <rfm@gnu.org> 2007-11-30 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSClipView.m: ([scrollToPoint]) reset cursor rectangles when * Source/NSClipView.m: ([scrollToPoint]) reset cursor rectangles when

View file

@ -957,35 +957,48 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
fraction: (float)delta fraction: (float)delta
{ {
[self drawInRect: NSMakeRect(point.x, point.y, srcRect.size.width, [self drawInRect: NSMakeRect(point.x, point.y, srcRect.size.width,
srcRect.size.height) srcRect.size.height)
fromRect: srcRect fromRect: srcRect
operation: op operation: op
fraction: delta]; fraction: delta];
} }
- (void) drawInRect: (NSRect)dstRect - (void) drawInRect: (NSRect)dstRect
fromRect: (NSRect)srcRect fromRect: (NSRect)srcRect
operation: (NSCompositingOperation)op operation: (NSCompositingOperation)op
fraction: (float)delta fraction: (float)delta
{ {
NSGraphicsContext *ctxt = GSCurrentContext(); NSGraphicsContext *ctxt = GSCurrentContext();
NSAffineTransform *transform; NSAffineTransform *transform;
NSSize s;
s = [self size];
if (NSEqualRects(srcRect, NSZeroRect))
srcRect = NSMakeRect(0, 0, s.width, s.height);
if (!dstRect.size.width || !dstRect.size.height if (!dstRect.size.width || !dstRect.size.height
|| !srcRect.size.width || !srcRect.size.height) || !srcRect.size.width || !srcRect.size.height)
return; return;
// CLip to image bounds
if (srcRect.origin.x < 0)
srcRect.origin.x = 0;
if (srcRect.origin.y < 0)
srcRect.origin.y = 0;
if (NSMaxX(srcRect) > s.width)
srcRect.size.width = s.width - srcRect.origin.x;
if (NSMaxY(srcRect) > s.height)
srcRect.size.height = s.height - srcRect.origin.y;
if (![ctxt isDrawingToScreen]) if (![ctxt isDrawingToScreen])
{ {
/* We can't composite or dissolve if we aren't drawing to a screen, /* We can't composite or dissolve if we aren't drawing to a screen,
so we'll just draw the right part of the image in the right so we'll just draw the right part of the image in the right
place. */ place. */
NSSize s;
NSPoint p; NSPoint p;
double fx, fy; double fx, fy;
s = [self size];
fx = dstRect.size.width / srcRect.size.width; fx = dstRect.size.width / srcRect.size.width;
fy = dstRect.size.height / srcRect.size.height; fy = dstRect.size.height / srcRect.size.height;
@ -994,10 +1007,10 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
DPSgsave(ctxt); DPSgsave(ctxt);
DPSrectclip(ctxt, dstRect.origin.x, dstRect.origin.y, DPSrectclip(ctxt, dstRect.origin.x, dstRect.origin.y,
dstRect.size.width, dstRect.size.height); dstRect.size.width, dstRect.size.height);
DPSscale(ctxt, fx, fy); DPSscale(ctxt, fx, fy);
[self drawRepresentation: [self bestRepresentationForDevice: nil] [self drawRepresentation: [self bestRepresentationForDevice: nil]
inRect: NSMakeRect(p.x, p.y, s.width, s.height)]; inRect: NSMakeRect(p.x, p.y, s.width, s.height)];
DPSgrestore(ctxt); DPSgrestore(ctxt);
return; return;
@ -1019,13 +1032,13 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
NSAffineTransformStruct ts = [transform transformStruct]; NSAffineTransformStruct ts = [transform transformStruct];
if (fabs(ts.m11 - 1.0) < 0.01 && fabs(ts.m12) < 0.01 if (fabs(ts.m11 - 1.0) < 0.01 && fabs(ts.m12) < 0.01
&& fabs(ts.m21) < 0.01 && fabs(ts.m22 - 1.0) < 0.01) && fabs(ts.m21) < 0.01 && fabs(ts.m22 - 1.0) < 0.01)
{ {
[self compositeToPoint: dstRect.origin [self compositeToPoint: dstRect.origin
fromRect: srcRect fromRect: srcRect
operation: op]; operation: op];
return; return;
} }
} }
/* We can't composite or dissolve directly from the image reps, so we /* We can't composite or dissolve directly from the image reps, so we
@ -1038,25 +1051,22 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
things we could do to: things we could do to:
1. Take srcRect into account and only process the parts of the image 1. Take srcRect into account and only process the parts of the image
we really need. we really need.
2. Take the clipping path into account. Desirable, especially if we're 2. Take the clipping path into account. Desirable, especially if we're
being drawn as lots of small strips in a scrollview. We don't have being drawn as lots of small strips in a scrollview. We don't have
the clipping path here, though. the clipping path here, though.
3. Allocate a permanent but small buffer and process the image 3. Allocate a permanent but small buffer and process the image
piecewise. piecewise.
*/ */
{ {
NSCachedImageRep *cache; NSCachedImageRep *cache;
NSAffineTransformStruct ts; NSAffineTransformStruct ts;
NSSize s;
NSPoint p; NSPoint p;
double x0, y0, x1, y1, w, h; double x0, y0, x1, y1, w, h;
int gState; int gState;
NSGraphicsContext *ctxt1; NSGraphicsContext *ctxt1;
s = [self size];
/* Figure out how big we need to make the window that'll hold the /* Figure out how big we need to make the window that'll hold the
transformed image. */ transformed image. */
p = [transform transformPoint: NSMakePoint(0, s.height)]; p = [transform transformPoint: NSMakePoint(0, s.height)];