FROM : Adam R. Maxwell
DATE : Sat Mar 29 20:48:47 2008
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
DATE : Sat Mar 29 20:48:47 2008
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
| 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

