2003-09-15 Adam Fedor * Headers/Additions/GNUstepGUI/GSMethodTable.h: Change NSReadPixel to GSReadRect * Headers/AppKit/NSGraphicsContext.h, Source/NSGraphicsContext.m: Idem. * Headers/AppKit/NSGraphics.h (NSReadPixel): Move to... * Source/Functions.m (NSReadPixel): here. * Source/NSBitmapImageRep.m (-initWithFocusedViewRect:): Implement. Index: Headers/Additions/GNUstepGUI/GSMethodTable.h =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Headers/Additions/GNUstepGUI/GSMethodTable.h,v retrieving revision 1.1 diff -u -p -r1.1 GSMethodTable.h --- Headers/Additions/GNUstepGUI/GSMethodTable.h 31 Jul 2003 23:52:08 -0000 1.1 +++ Headers/Additions/GNUstepGUI/GSMethodTable.h 16 Sep 2003 02:57:56 -0000 @@ -279,8 +279,8 @@ typedef struct { /* ----------------------------------------------------------------------- */ /* NSGraphics Ops */ /* ----------------------------------------------------------------------- */ - NSColor * (*NSReadPixel_) - (NSGraphicsContext*, SEL, NSPoint); + NSDictionary * (*GSReadRect_) + (NSGraphicsContext*, SEL, NSRect); void (*NSBeep) (NSGraphicsContext*, SEL); Index: Headers/AppKit/NSGraphics.h =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Headers/AppKit/NSGraphics.h,v retrieving revision 1.1 diff -u -p -r1.1 NSGraphics.h --- Headers/AppKit/NSGraphics.h 31 Jul 2003 23:52:08 -0000 1.1 +++ Headers/AppKit/NSGraphics.h 16 Sep 2003 02:57:56 -0000 @@ -138,13 +138,7 @@ APPKIT_EXPORT void NSDottedFrameRect(NSR APPKIT_EXPORT void NSFrameRect(const NSRect aRect); APPKIT_EXPORT void NSFrameRectWithWidth(const NSRect aRect, float frameWidth); -static inline NSColor* -NSReadPixel(NSPoint location) -{ - NSGraphicsContext *ctxt = GSCurrentContext(); - return (ctxt->methods->NSReadPixel_) - (ctxt, @selector(NSReadPixel:), location); -} +APPKIT_EXPORT NSColor* NSReadPixel(NSPoint location); APPKIT_EXPORT void NSCopyBitmapFromGState(int srcGstate, NSRect srcRect, NSRect destRect); Index: Headers/AppKit/NSGraphicsContext.h =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Headers/AppKit/NSGraphicsContext.h,v retrieving revision 1.1 diff -u -p -r1.1 NSGraphicsContext.h --- Headers/AppKit/NSGraphicsContext.h 31 Jul 2003 23:52:08 -0000 1.1 +++ Headers/AppKit/NSGraphicsContext.h 16 Sep 2003 02:57:57 -0000 @@ -373,7 +373,7 @@ APPKIT_EXPORT NSGraphicsContext *GSCurre /* NSGraphics Ops */ /* ----------------------------------------------------------------------- */ @interface NSGraphicsContext (NSGraphics) -- (NSColor *) NSReadPixel: (NSPoint) location; +- (NSDictionary *) GSReadRect: (NSRect)rect; /* Soon to be obsolete */ - (void) NSDrawBitmap: (NSRect) rect : (int) pixelsWide : (int) pixelsHigh Index: Source/Functions.m =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/Functions.m,v retrieving revision 1.28 diff -u -p -r1.28 Functions.m --- Source/Functions.m 13 Jun 2003 15:01:10 -0000 1.28 +++ Source/Functions.m 16 Sep 2003 02:57:57 -0000 @@ -301,8 +301,15 @@ NSPlanarFromDepth(NSWindowDepth depth) } /* Graphic Ops */ +NSColor* NSReadPixel(NSPoint location) +{ + NSLog(@"NSReadPixel not implemented"); + return nil; +} + void NSCopyBitmapFromGState(int srcGstate, NSRect srcRect, NSRect destRect) { + NSLog(@"NSCopyBitmapFromGState not implemented"); } void NSCopyBits(int srcGstate, NSRect srcRect, NSPoint destPoint) Index: Source/NSBitmapImageRep.m =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSBitmapImageRep.m,v retrieving revision 1.40 diff -u -p -r1.40 NSBitmapImageRep.m --- Source/NSBitmapImageRep.m 8 Sep 2003 02:07:53 -0000 1.40 +++ Source/NSBitmapImageRep.m 16 Sep 2003 02:57:58 -0000 @@ -35,9 +35,11 @@ #include #include #include +#include #include "AppKit/AppKitExceptions.h" #include "AppKit/NSBitmapImageRep.h" #include "AppKit/NSGraphics.h" +#include "AppKit/NSGraphicsContext.h" #include "AppKit/NSPasteboard.h" #include "AppKit/NSView.h" #include "GSGuiPrivate.h" @@ -224,11 +226,45 @@ static BOOL supports_lzw_compression = N - (id) initWithFocusedViewRect: (NSRect)rect { - // TODO - [self notImplemented: _cmd]; + int bps, spp, alpha; + NSSize size; + NSString *space; + unsigned char *planes[4]; + NSDictionary *dict; - RELEASE(self); - return nil; + dict = [GSCurrentContext() GSReadRect: rect]; + if (dict == nil) + { + NSLog(@"NSBitmapImageRep initWithFocusedViewRect: failed"); + RELEASE(self); + return nil; + } + _imageData = RETAIN([dict objectForKey: @"ImageData"]); + if (_imageData == nil) + { + NSLog(@"NSBitmapImageRep initWithFocusedViewRect: failed"); + RELEASE(self); + return nil; + } + bps = [[dict objectForKey: @"ImageBPS"] intValue]; + if (bps == 0) + bps = 8; + spp = [[dict objectForKey: @"ImageSPP"] intValue]; + alpha = [[dict objectForKey: @"ImageAlpha"] intValue]; + size = [[dict objectForKey: @"ImageSize"] sizeValue]; + space = [dict objectForKey: @"ImageColorSpace"]; + planes[0] = (unsigned char *)[_imageData mutableBytes]; + self = [self initWithBitmapDataPlanes: planes + pixelsWide: size.width + pixelsHigh: size.height + bitsPerSample: bps + samplesPerPixel: spp + hasAlpha: (alpha) ? YES : NO + isPlanar: NO + colorSpaceName: space + bytesPerRow: 0 + bitsPerPixel: 0]; + return self; } /** Index: Source/NSGraphicsContext.m =================================================================== RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/NSGraphicsContext.m,v retrieving revision 1.73 diff -u -p -r1.73 NSGraphicsContext.m --- Source/NSGraphicsContext.m 31 Jul 2003 23:52:09 -0000 1.73 +++ Source/NSGraphicsContext.m 16 Sep 2003 02:57:58 -0000 @@ -652,8 +652,8 @@ NSGraphicsContext *GSCurrentContext(void /* ----------------------------------------------------------------------- */ /* NSGraphics Ops */ /* ----------------------------------------------------------------------- */ - methodTable.NSReadPixel_ = - GET_IMP(@selector(NSReadPixel:)); + methodTable.GSReadRect_ = + GET_IMP(@selector(GSReadRect:)); methodTable.NSBeep = GET_IMP(@selector(NSBeep)); @@ -1454,9 +1454,13 @@ NSGraphicsContext *GSCurrentContext(void /* NSGraphics Ops */ /* ----------------------------------------------------------------------- */ @implementation NSGraphicsContext (NSGraphics) -/** Read the Color at a Screen Position +/** Read the data inside rect (defined in the current graphics state) + and return the information as a bitmap. The dictionary contains + the bitmap data plus various information about the size and format + of the data. The dictionary keys include ImageSize, ImageBPS, + ImageSPP, and ImageData. */ -- (NSColor *) NSReadPixel: (NSPoint) location +- (NSDictionary *) GSReadRect: (NSRect) rect { [self subclassResponsibility: _cmd]; return nil;