bugGNUstep - Bugs: bug #34467, -[NSView...

 
 

You are not allowed to post comments on this tracker with your current authentification level.

bug #34467: -[NSView bitmapImageRepForCachingDisplayInRect:] broken

Submitted by:  julian <julian_>
Submitted on:  Mon 03 Oct 2011 06:18:24 PM UTC  
 
Category: Gui/AppKitSeverity: 3 - Normal
Item Group: BugStatus: Confirmed
Privacy: PublicAssigned to: None
Open/Closed: Open

Mon 03 Oct 2011 09:45:33 PM UTC, comment #4:

initWithFocusedViewRect: should not be affected - if you could file another bug, that would be great.

Eric Wasylishen <ericw>
Project Member
Mon 03 Oct 2011 08:38:05 PM UTC, comment #3:

is the underlying bug also responsible for the fact that the following method (works on OS X) to get the pixel data of a NSImage doesn't work - or should i file a separate bug?

NSImage *theImg = [[NSImage alloc] initWithContentsOfURL:_url];
NSBitmapImageRep* bitmap = [NSBitmapImageRep alloc];
NSSize imgSize = [theImg size];

[theImg lockFocus];
[bitmap initWithFocusedViewRect:NSMakeRect(0.0, 0.0, imgSize.width, imgSize.height)];
[theImg unlockFocus];

char _data = (char )calloc( imgSize.width * 4 * imgSize.height, 1);
memcpy(_data, [bitmap bitmapData], imgSize.width * 4 * imgSize.height);

julian <julian_>
Mon 03 Oct 2011 08:06:05 PM UTC, comment #2:

thanks for investigating

i can confirm that the workaround works...when removing the views just after taking the snapshot the user won't even see anything

julian <julian_>
Mon 03 Oct 2011 07:43:20 PM UTC, comment #1:

Thanks for reporting.

As a workaround, you can get it to work by adding the view you snapshot to the window content view before taking the snapshot, and ordering-front the window before taking the snapshot.

-[NSView bitmapImageRepForCachingDisplayInRect:] and -[NSView cacheDisplayInRect:toBitmapImageRep:] probably shouldn't rely on being able to lock focus on the view (self), but rather should use [NSGraphicsContext graphicsContextWithBitmapImageRep:] to create a context which can draw directly on the bitmap, and then just call the view's display method. The only problem is, [NSGraphicsContext graphicsContextWithBitmapImageRep:] isn't implemented currently.

Another potential bug this revealed is it seems you can't lock focus on a view before its window has been ordered front... that sounds wrong to me.

Eric Wasylishen <ericw>
Project Member
Mon 03 Oct 2011 06:18:24 PM UTC, original submission:

i am trying to use the following category (works on Mac OS X) to capture the contents of an NSView including subviews as an NSImage but it doesn't work as there is an exception somewhere deep in bitmapImageRepForCachingDisplayInRect:

@implementation NSView (NSView_Snapshot)

- (NSImage *)snapshotIncludingSubviews
{
NSBitmapImageRep *imageRep = [self bitmapImageRepForCachingDisplayInRect:self.bounds];
NSImage *renderedImage = [[NSImage alloc] initWithSize:[imageRep size]];

[self cacheDisplayInRect:self.bounds toBitmapImageRep:imageRep];
[renderedImage addRepresentation:imageRep];

return [renderedImage autorelease];
}
@end

minimal runnable sample project to illustrate the issue attached

issue occurs in SVN trunk as of today as well as a few months ago.

julian <julian_>

 

Attached Files
file #24089:  GNUstepTest.tar.gz added by julian_ (2kB - application/x-gzip)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by ericw (Posted a comment)
  • -unavailable- added by julian_ (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 03 Oct 2011 07:43:20 PM UTCericwCategoryNone=>Gui/AppKit
      Item GroupNone=>Bug
      StatusNone=>Confirmed
    Mon 03 Oct 2011 06:18:24 PM UTCjulian_Attached File-=>Added GNUstepTest.tar.gz, #24089

    Back to the top


    Powered by Savane 3.1-cleanup