FROM : Adam R. Maxwell
DATE : Sat Mar 29 18:54:28 2008
On Mar 29, 2008, at 6:44 AM, Trygve Inda wrote:
> I am finding it hard to determine in many cases exactly what is
> thread safe
> as this is not complete:
>
> http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/Thr
> eadSafetySummary/chapter_950_section_2.html
>
> Can I call the following from a thread?
>
> segImageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
> pixelsWide:100
> pixelsHigh:100
> bitsPerSample:8
> samplesPerPixel:4
> hasAlpha:YES
> isPlanar:NO
> colorSpaceName:NSDeviceRGBColorSpace
> bitmapFormat:NSAlphaFirstBitmapFormat
> bytesPerRow:100 * 4
> bitsPerPixel:32];
> segBaseAddr = [segImageRep bitmapData];
Yes. See
http://www.cocoabuilder.com/archive/message/cocoa/2007/11/15/193191
ISTR having problems specifying a nonzero bytesPerRow and passing NULL
for the bitmap data, so you might need to either manage the buffer
yourself or pass zero for bytesPerRow to allow NSBitmapImageRep to pad
it appropriately.
>
> [segImageRep dealloc];
You should never call dealloc directly (well, unless you've overridden
-retain/-release to handle your own refcounting).
> How about:
>
> NSImage * image = [[[NSImage alloc] initWithContentsOfFile:path]
> autorelease];
>
> [NSGraphicsContext saveGraphicsState];
> [NSGraphicsContext setCurrentContext:[NSGraphicsContext
> graphicsContextWithBitmapImageRep:segImageRep]];
>
> [image drawInRect:NSMakeRect(0, 0, [image size].width, [image
> size].height) fromRect:NSMakeRect(0, 0, [image size].width, [image
> size].height) operation:NSCompositeCopy fraction:1.0];
>
> [NSGraphicsContext restoreGraphicsState];
Drawing into an NSImage is explicitly documented to be thread safe in
the article you linked to, and each thread has its own graphics
context. The post I linked to does indicate that you might want to
use [image setCacheMode:NSImageCacheNever]. If your goal is just to
get an NSBitmapImageRep from a file, it's probably easier just to use
+imageRepWithContentsOfFile:.
--
adam
On Mar 29, 2008, at 6:44 AM, Trygve Inda wrote:
> I am finding it hard to determine in many cases exactly what is
> thread safe
> as this is not complete:
>
> http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/Thr
> eadSafetySummary/chapter_950_section_2.html
>
> Can I call the following from a thread?
>
> segImageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
> pixelsWide:100
> pixelsHigh:100
> bitsPerSample:8
> samplesPerPixel:4
> hasAlpha:YES
> isPlanar:NO
> colorSpaceName:NSDeviceRGBColorSpace
> bitmapFormat:NSAlphaFirstBitmapFormat
> bytesPerRow:100 * 4
> bitsPerPixel:32];
> segBaseAddr = [segImageRep bitmapData];
Yes. See
http://www.cocoabuilder.com/archive/message/cocoa/2007/11/15/193191
ISTR having problems specifying a nonzero bytesPerRow and passing NULL
for the bitmap data, so you might need to either manage the buffer
yourself or pass zero for bytesPerRow to allow NSBitmapImageRep to pad
it appropriately.
>
> [segImageRep dealloc];
You should never call dealloc directly (well, unless you've overridden
-retain/-release to handle your own refcounting).
> How about:
>
> NSImage * image = [[[NSImage alloc] initWithContentsOfFile:path]
> autorelease];
>
> [NSGraphicsContext saveGraphicsState];
> [NSGraphicsContext setCurrentContext:[NSGraphicsContext
> graphicsContextWithBitmapImageRep:segImageRep]];
>
> [image drawInRect:NSMakeRect(0, 0, [image size].width, [image
> size].height) fromRect:NSMakeRect(0, 0, [image size].width, [image
> size].height) operation:NSCompositeCopy fraction:1.0];
>
> [NSGraphicsContext restoreGraphicsState];
Drawing into an NSImage is explicitly documented to be thread safe in
the article you linked to, and each thread has its own graphics
context. The post I linked to does indicate that you might want to
use [image setCacheMode:NSImageCacheNever]. If your goal is just to
get an NSBitmapImageRep from a file, it's probably easier just to use
+imageRepWithContentsOfFile:.
--
adam
DATE : Sat Mar 29 18:54:28 2008
On Mar 29, 2008, at 6:44 AM, Trygve Inda wrote:
> I am finding it hard to determine in many cases exactly what is
> thread safe
> as this is not complete:
>
> http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/Thr
> eadSafetySummary/chapter_950_section_2.html
>
> Can I call the following from a thread?
>
> segImageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
> pixelsWide:100
> pixelsHigh:100
> bitsPerSample:8
> samplesPerPixel:4
> hasAlpha:YES
> isPlanar:NO
> colorSpaceName:NSDeviceRGBColorSpace
> bitmapFormat:NSAlphaFirstBitmapFormat
> bytesPerRow:100 * 4
> bitsPerPixel:32];
> segBaseAddr = [segImageRep bitmapData];
Yes. See
http://www.cocoabuilder.com/archive/message/cocoa/2007/11/15/193191
ISTR having problems specifying a nonzero bytesPerRow and passing NULL
for the bitmap data, so you might need to either manage the buffer
yourself or pass zero for bytesPerRow to allow NSBitmapImageRep to pad
it appropriately.
>
> [segImageRep dealloc];
You should never call dealloc directly (well, unless you've overridden
-retain/-release to handle your own refcounting).
> How about:
>
> NSImage * image = [[[NSImage alloc] initWithContentsOfFile:path]
> autorelease];
>
> [NSGraphicsContext saveGraphicsState];
> [NSGraphicsContext setCurrentContext:[NSGraphicsContext
> graphicsContextWithBitmapImageRep:segImageRep]];
>
> [image drawInRect:NSMakeRect(0, 0, [image size].width, [image
> size].height) fromRect:NSMakeRect(0, 0, [image size].width, [image
> size].height) operation:NSCompositeCopy fraction:1.0];
>
> [NSGraphicsContext restoreGraphicsState];
Drawing into an NSImage is explicitly documented to be thread safe in
the article you linked to, and each thread has its own graphics
context. The post I linked to does indicate that you might want to
use [image setCacheMode:NSImageCacheNever]. If your goal is just to
get an NSBitmapImageRep from a file, it's probably easier just to use
+imageRepWithContentsOfFile:.
--
adam
On Mar 29, 2008, at 6:44 AM, Trygve Inda wrote:
> I am finding it hard to determine in many cases exactly what is
> thread safe
> as this is not complete:
>
> http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/Thr
> eadSafetySummary/chapter_950_section_2.html
>
> Can I call the following from a thread?
>
> segImageRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
> pixelsWide:100
> pixelsHigh:100
> bitsPerSample:8
> samplesPerPixel:4
> hasAlpha:YES
> isPlanar:NO
> colorSpaceName:NSDeviceRGBColorSpace
> bitmapFormat:NSAlphaFirstBitmapFormat
> bytesPerRow:100 * 4
> bitsPerPixel:32];
> segBaseAddr = [segImageRep bitmapData];
Yes. See
http://www.cocoabuilder.com/archive/message/cocoa/2007/11/15/193191
ISTR having problems specifying a nonzero bytesPerRow and passing NULL
for the bitmap data, so you might need to either manage the buffer
yourself or pass zero for bytesPerRow to allow NSBitmapImageRep to pad
it appropriately.
>
> [segImageRep dealloc];
You should never call dealloc directly (well, unless you've overridden
-retain/-release to handle your own refcounting).
> How about:
>
> NSImage * image = [[[NSImage alloc] initWithContentsOfFile:path]
> autorelease];
>
> [NSGraphicsContext saveGraphicsState];
> [NSGraphicsContext setCurrentContext:[NSGraphicsContext
> graphicsContextWithBitmapImageRep:segImageRep]];
>
> [image drawInRect:NSMakeRect(0, 0, [image size].width, [image
> size].height) fromRect:NSMakeRect(0, 0, [image size].width, [image
> size].height) operation:NSCompositeCopy fraction:1.0];
>
> [NSGraphicsContext restoreGraphicsState];
Drawing into an NSImage is explicitly documented to be thread safe in
the article you linked to, and each thread has its own graphics
context. The post I linked to does indicate that you might want to
use [image setCacheMode:NSImageCacheNever]. If your goal is just to
get an NSBitmapImageRep from a file, it's probably easier just to use
+imageRepWithContentsOfFile:.
--
adam
| Related mails | Author | Date |
|---|---|---|
| Trygve Inda | Mar 29, 14:44 | |
| Jens Alfke | Mar 29, 18:05 | |
| Adam R. Maxwell | Mar 29, 18:54 | |
| Trygve Inda | Mar 29, 20:20 | |
| Adam R. Maxwell | Mar 29, 20:48 | |
| Thomas Engelmeier | Mar 30, 15:10 | |
| Adam R. Maxwell | Mar 30, 17:01 | |
| Trygve Inda | Mar 30, 17:34 | |
| Jens Alfke | Mar 30, 19:02 | |
| glenn andreas | Mar 30, 19:14 | |
| Trygve Inda | Mar 30, 22:21 | |
| glenn andreas | Mar 30, 22:35 | |
| Thomas Engelmeier | Mar 31, 12:30 |






Cocoa mail archive

