Re: Thread safe?
Re: Thread safe?
- Subject: Re: Thread safe?
- From: "Adam R. Maxwell" <email@hidden>
- Date: Sat, 29 Mar 2008 12:48:47 -0700
On Mar 29, 2008, at 12:20 PM, Trygve Inda wrote:
How about:
NSImage * image = [[[NSImage alloc] initWithContentsOfFile:path]
autorelease];
[...]
Drawing into an NSImage is explicitly documented to be thread safe in
the article you linked to,
I guess I was more concerned with the initWithContentsOfFile:path
For my own code, I'd tend to assume it's safe since it should just be
a wrapper around ImageIO. However, sometimes Cocoa adds an unexpected
layer of thread-unsafety (e.g. NSRunLoop vs. CFRunLoop), and the Cocoa
API docs aren't as helpful as the Carbon ones for thread safety.
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:.
This could work, but as I need to do pixel level manipulation, I
really need
to know the exact format of the bitmap and this does not seem to let
me
specify it.
That makes sense. You could also introspect the returned imagerep and
see if it matches your desired format, then only redraw it if
necessary. For messing with pixels, I'd avoid NSImage altogether and
just use ImageIO to create a CGImage, then draw that into your
NSBitmapImageRep with [[NSGraphicsContext
graphicsContextWithBitmapImageRep:] graphicsPort] as the CGContext.
--
adam
On Mar 29, 2008, at 12:20 PM, Trygve Inda wrote:
How about:
NSImage * image = [[[NSImage alloc] initWithContentsOfFile:path]
autorelease];
[...]
Drawing into an NSImage is explicitly documented to be thread safe in
the article you linked to,
I guess I was more concerned with the initWithContentsOfFile:path
For my own code, I'd tend to assume it's safe since it should just be
a wrapper around ImageIO. However, sometimes Cocoa adds an unexpected
layer of thread-unsafety (e.g. NSRunLoop vs. CFRunLoop), and the Cocoa
API docs aren't as helpful as the Carbon ones for thread safety.
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:.
This could work, but as I need to do pixel level manipulation, I
really need
to know the exact format of the bitmap and this does not seem to let
me
specify it.
That makes sense. You could also introspect the returned imagerep and
see if it matches your desired format, then only redraw it if
necessary. For messing with pixels, I'd avoid NSImage altogether and
just use ImageIO to create a CGImage, then draw that into your
NSBitmapImageRep with [[NSGraphicsContext
graphicsContextWithBitmapImageRep:] graphicsPort] as the CGContext.
--
adam
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden