• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Thread safe?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Thread safe?


  • Subject: Re: Thread safe?
  • From: glenn andreas <email@hidden>
  • Date: Sun, 30 Mar 2008 12:14:05 -0500


On Mar 30, 2008, at 12:02 PM, Jens Alfke wrote:


On 30 Mar '08, at 8:34 AM, Trygve Inda wrote:

How did you work around this?

Basically I am opening a bitmap drawing an NSImage into it, then pixel-level
tweaking the bitmap, and saving it to disk as a jpg.

You might want to drop down a level and use CGImage for your bitmap. CG is stateless (the graphics context is passed in to every drawing call) and doesn't do the types of offscreen caching that NSImage does, so it's more likely to be thread-safe.



Or drop down just a step to just use NSBitmapImageRep instead of NSImage which avoids all the caching issues (since you never make an NSImage). It is very well suited for "pixel level work that is saved in a file" (since you'll need it to do NSBitmapImageRep's representationUsingType: properties: to get the data for a JPG or PNG file anyway).


The only slightly tricky part is that if you want to draw in it (using the standard drawing routines, as opposed to custom pixel access stuff), you'll need to make a context using NSGraphicContext's graphicsContextWithBitmapImageRep and then set that as the current context.

Graphics contexts are thread safe (there is one for each thread) so there's no problem with threading. I've used this approach without a problem (and my rendering stuff is highly threaded - not just multiple threads rendering different things into different files, but each renderer can be multi-threaded as well)


Glenn Andreas email@hidden
<http://www.gandreas.com/> wicked fun!
quadrium2 | build, mutate, evolve, animate | images, textures, fractals, art



_______________________________________________

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


  • Follow-Ups:
    • Re: Thread safe?
      • From: Trygve Inda <email@hidden>
References: 
 >Re: Thread safe? (From: Trygve Inda <email@hidden>)
 >Re: Thread safe? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Thread safe?
  • Next by Date: NSFileHandle / NSConcreteFileHandle problem
  • Previous by thread: Re: Thread safe?
  • Next by thread: Re: Thread safe?
  • Index(es):
    • Date
    • Thread