Extract the bitmap conversion into a local function and use it througout the file.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@32643 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2011-03-18 09:29:01 +00:00
parent a7cb5ca55e
commit 80eab30de7
2 changed files with 63 additions and 68 deletions

View file

@ -1,3 +1,8 @@
2011-03-18 Fred Kiefer <FredKiefer@gmx.de>
* Source/x11/XGServerWindow.m: Extract the bitmap conversion into
a local function and use it througout the file.
2011-03-13 Eric Wasylishen <ewasylishen@gmail.com>
* configure.ac: Check for the X extention libraries (Xext, Xt, Xmu)

View file

@ -105,6 +105,50 @@ static int last_win_num = 0;
bitsPerPixel: (int)pixelBits;
@end
static NSBitmapImageRep *getStandardBitmap(NSImage *image)
{
NSBitmapImageRep *rep;
if (image == nil)
{
return nil;
}
/*
We should rather convert the image to a bitmap representation here via
the following code, but this is currently not supported by the libart backend
{
NSSize size = [image size];
[image lockFocus];
rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:
NSMakeRect(0, 0, size.width, size.height)];
AUTORELEASE(rep);
[image unlockFocus];
}
*/
rep = (NSBitmapImageRep *)[image bestRepresentationForDevice: nil];
if (!rep || ![rep respondsToSelector: @selector(samplesPerPixel)])
{
return nil;
}
else
{
// Convert into something usable by the backend
return [rep _convertToFormatBitsPerSample: 8
samplesPerPixel: [rep hasAlpha] ? 4 : 3
hasAlpha: [rep hasAlpha]
isPlanar: NO
colorSpaceName: NSCalibratedRGBColorSpace
bitmapFormat: 0
bytesPerRow: 0
bitsPerPixel: 0];
}
}
void __objc_xgcontextwindow_linking (void)
{
}
@ -367,6 +411,7 @@ static void setWindowHintsForStyle (Display *dpy, Window window,
* End of motif hints for window manager code
*/
@interface NSEvent (WindowHack)
- (void) _patchLocation: (NSPoint)loc;
@end
@ -1761,17 +1806,8 @@ _get_next_prop_new_event(Display *display, XEvent *event, char *arg)
long *iconPropertyData;
int iconSize;
rep = (NSBitmapImageRep *)[image bestRepresentationForDevice:nil];
if (![rep isKindOfClass: [NSBitmapImageRep class]])
{
NSLog(@"Wrong bitmap class for WM icon %@ %@", rep, image);
return NO;
}
if ([rep bitsPerSample] != 8
|| (![[rep colorSpaceName] isEqual: NSDeviceRGBColorSpace]
&& ![[rep colorSpaceName] isEqual: NSCalibratedRGBColorSpace])
|| [rep isPlanar])
rep = getStandardBitmap(image);
if (rep == nil)
{
NSLog(@"Wrong image type for WM icon");
return NO;
@ -2697,17 +2733,10 @@ static BOOL didCreatePixmaps;
didCreatePixmaps = YES;
image = [NSApp applicationIconImage];
rep = (NSBitmapImageRep *)[image bestRepresentationForDevice:nil];
if (![rep isKindOfClass: [NSBitmapImageRep class]])
rep = getStandardBitmap(image);
if (rep == nil)
return 0;
if ([rep bitsPerSample] != 8
|| (![[rep colorSpaceName] isEqual: NSDeviceRGBColorSpace]
&& ![[rep colorSpaceName] isEqual: NSCalibratedRGBColorSpace])
|| [rep isPlanar])
return 0;
data = [rep bitmapData];
screen = [[[self screenList] objectAtIndex: 0] intValue];
xIconPixmap = XCreatePixmap(dpy,
@ -3003,17 +3032,16 @@ static BOOL didCreatePixmaps;
if ([[image backgroundColor] alphaComponent] * 256 <= ALPHA_THRESHOLD)
{
// The mask computed here is only correct for unscaled images.
NSImageRep *rep = [image bestRepresentationForDevice: nil];
NSBitmapImageRep *rep = getStandardBitmap(image);
if ([rep isKindOfClass: [NSBitmapImageRep class]])
if (rep != nil)
{
if (![(NSBitmapImageRep*)rep isPlanar] &&
([(NSBitmapImageRep*)rep samplesPerPixel] == 4))
if ([rep samplesPerPixel] == 4)
{
pixmap = xgps_cursor_mask(dpy, GET_XDRAWABLE(window),
[(NSBitmapImageRep*)rep bitmapData],
[rep bitmapData],
[rep pixelsWide], [rep pixelsHigh],
[(NSBitmapImageRep*)rep samplesPerPixel]);
[rep samplesPerPixel]);
}
}
}
@ -4178,53 +4206,15 @@ xgps_cursor_image(Display *xdpy, Drawable draw, const unsigned char *data,
int colors;
const unsigned char *data;
/* FIXME: We might create a blank cursor here? */
if (image == nil)
rep = getStandardBitmap(image);
if (rep == nil)
{
/* FIXME: We might create a blank cursor here? */
NSLog(@"Could not convert cursor bitmap data");
*cid = NULL;
return;
}
/*
We should rather convert the image to a bitmap representation here via
the following code, but this is currently not supported by the libart backend
{
NSSize size = [image size];
[image lockFocus];
rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:
NSMakeRect(0, 0, size.width, size.height)];
AUTORELEASE(rep);
[image unlockFocus];
}
*/
rep = (NSBitmapImageRep *)[image bestRepresentationForDevice: nil];
if (!rep || ![rep respondsToSelector: @selector(samplesPerPixel)])
{
NSLog(@"NSCursor can only handle NSBitmapImageReps for now");
*cid = NULL;
return;
}
else
{
// Convert into something usable by the backend
rep = [rep _convertToFormatBitsPerSample: 8
samplesPerPixel: [rep hasAlpha] ? 4 : 3
hasAlpha: [rep hasAlpha]
isPlanar: NO
colorSpaceName: NSCalibratedRGBColorSpace
bitmapFormat: 0
bytesPerRow: 0
bitsPerPixel: 0];
if (rep == nil)
{
NSLog(@"Could not convert bitmap data");
*cid = NULL;
return;
}
}
if (hotp.x >= [rep pixelsWide])
hotp.x = [rep pixelsWide]-1;