Re: NSImage from bitmap - then delete bitmap

2016-07-26 Thread Trygve Inda
>> >> I would think that even with a retain it could get weird... >> >> The main thread wants to use the imageRef property so it calls: >> >> myRef = [window.imageRef]; >> [myref retain]; >> >> If right between these calls, the worker thread calls setImageRef (on a >> property with atomic,

Re: NSImage from bitmap - then delete bitmap

2016-07-26 Thread Roland King
> > I would think that even with a retain it could get weird... > > The main thread wants to use the imageRef property so it calls: > > myRef = [window.imageRef]; > [myref retain]; > > If right between these calls, the worker thread calls setImageRef (on a > property with atomic, copy), then

Re: NSImage from bitmap - then delete bitmap

2016-07-26 Thread Trygve Inda
> >> On 27 Jul 2016, at 12:05 PM, Trygve Inda wrote: >> >> How is it retained by the main thread without an explicit retain call? >> >> I would be no different than a main thread calling: >> >> someVar [[MyObj alloc] init] >> [someVar doSomething]; >> >> If a worker

Re: NSImage from bitmap - then delete bitmap

2016-07-26 Thread Trygve Inda
> >> On 27 Jul 2016, at 10:05, Trygve Inda wrote: >> >>> >> >> How is it retained by the main thread without an explicit retain call? > > are you not using ARC? If you are then all such references, both variable and > during method calls are retained automatically.

Re: NSImage from bitmap - then delete bitmap

2016-07-26 Thread Roland King
> On 27 Jul 2016, at 10:05, Trygve Inda wrote: > >> > > How is it retained by the main thread without an explicit retain call? are you not using ARC? If you are then all such references, both variable and during method calls are retained automatically. If you’re

Re: NSImage from bitmap - then delete bitmap

2016-07-26 Thread Graham Cox
> On 27 Jul 2016, at 12:18 PM, Graham Cox wrote: > > The atomic setter method probably looks something like this: A further thought. If the getter method is also protected, like: - (NSImageRep*) imageRep { @synchronized( self ) { return

Re: NSImage from bitmap - then delete bitmap

2016-07-26 Thread Graham Cox
> On 27 Jul 2016, at 12:05 PM, Trygve Inda wrote: > > How is it retained by the main thread without an explicit retain call? > > I would be no different than a main thread calling: > > someVar [[MyObj alloc] init] > [someVar doSomething]; > > If a worker thread were

Re: NSImage from bitmap - then delete bitmap

2016-07-26 Thread Trygve Inda
> >> On 27 Jul 2016, at 09:33, Trygve Inda wrote: >> >> >> >> If the worker thread calls window.imageRep = myResult; it is possible that >> the main thread is in the middle of a call like: >> >> [[window.imageRep] >>

Re: NSImage from bitmap - then delete bitmap

2016-07-26 Thread Roland King
> On 27 Jul 2016, at 09:33, Trygve Inda wrote: > > > > If the worker thread calls window.imageRep = myResult; it is possible that > the main thread is in the middle of a call like: > > [[window.imageRep] >

Re: NSImage from bitmap - then delete bitmap

2016-07-26 Thread Trygve Inda
> e.g. > > worker thread: > > while( self.running ) > { > // do work > > window.imageRep = myResult; // window.imageRep is (atomic, copy) > > [performOnMainThread: window.setNeedsDisplay]; // this is obviously > pseudocode! > } > > > main thread, when it needs to terminate worker

Re: NSImage from bitmap - then delete bitmap

2016-07-24 Thread Graham Cox
> On 23 Jul 2016, at 4:09 PM, Ken Thomases wrote: > > No, because the main thread may not have started servicing the > performSelector request yet. The background thread has blocked as soon as > the request is _queued_ for the main thread, not just once the main thread

Re: NSImage from bitmap - then delete bitmap

2016-07-23 Thread Trygve Inda
> On Jul 22, 2016, at 19:29 , Graham Cox wrote: >> >> If the worker thread is waiting for -performOnMainThread to complete, it >> *cannot* possibly get a call from the main thread to terminate > > I nodded agreement when I first read this, then “but wait!” … > > Your

Re: NSImage from bitmap - then delete bitmap

2016-07-23 Thread Ken Thomases
On Jul 22, 2016, at 9:29 PM, Graham Cox wrote: > > >> On 23 Jul 2016, at 12:45 AM, Trygve Inda wrote: >> >> Because the main thread sometimes needs to ask the worker threads to >> terminate. If it does this after performOnMainThread has been

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Quincey Morris
On Jul 22, 2016, at 19:29 , Graham Cox wrote: > > If the worker thread is waiting for -performOnMainThread to complete, it > *cannot* possibly get a call from the main thread to terminate I nodded agreement when I first read this, then “but wait!” … Your logic seems

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Graham Cox
> On 23 Jul 2016, at 12:45 AM, Trygve Inda wrote: > > Because the main thread sometimes needs to ask the worker threads to > terminate. If it does this after performOnMainThread has been called by a > worker thread, but before the main thread has processed it, then the

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Alan Snyder
Or better yet, have the termination request come from a thread other than the main thread. > On Jul 22, 2016, at 9:38 AM, Alan Snyder wrote: > > >> On Jul 22, 2016, at 7:45 AM, Trygve Inda wrote: >> >> Because the main thread sometimes

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Alan Snyder
> On Jul 22, 2016, at 7:45 AM, Trygve Inda wrote: > > Because the main thread sometimes needs to ask the worker threads to > terminate. If it does this after performOnMainThread has been called by a > worker thread, but before the main thread has processed it, then the

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Trygve Inda
>> Currently it blocks at this point, but I need to avoid that. > > It’s not really clear why this needs to be avoided. The time to draw the > pixels should be a few milliseconds, a small fraction of the time your thread > needs to run, even at its fastest. Because the main thread sometimes

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Graham Cox
> On 22 Jul 2016, at 11:53 PM, Trygve Inda wrote: > > How can I draw the NSImageRep directly into a window? -[NSImageRep drawInRect:fromRect:operation:fraction:respectFlipped:hints:]; i.e. same as NSImage. > > Also, the main pixel buffer is updated slowly (it

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Trygve Inda
> >> On 22 Jul 2016, at 4:08 PM, Trygve Inda wrote: >> >> I don't think the second part will work because of my workflow: >> >> At Launch: Create pixel buffer that is 1000 x 1000 pixels >> >> Looping thread >> 1. Fill pixel buffer with pixels based on some algorithm

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Trygve Inda
>> This is how it works now, but we are running into a rare deadlock situation >> where the main thread asks the worker thread to end (and waits until it does >> so) while the worker thread is waiting for the image to be displayed. > > If the window has a imageRep property that is (atomic,

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Graham Cox
> On 22 Jul 2016, at 5:30 PM, Quincey Morris > wrote: > > On Jul 22, 2016, at 00:08 , Graham Cox wrote: >> >> If the thread building images never goes faster than once per second, the >> time to draw the image is a fraction of

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Quincey Morris
On Jul 22, 2016, at 00:08 , Graham Cox wrote: > > If the thread building images never goes faster than once per second, the > time to draw the image is a fraction of that - I’m sure 60fps is achievable, > so making the thread wait for the drawing to be done isn’t going

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Trygve Inda
> >> On 22 Jul 2016, at 4:40 PM, Trygve Inda wrote: >> >> >>> With half an eye on performance, if you *do* strictly need a copy of the >>> bitmap, note that NSBitmapImageRep conforms to NSCopying. You don’t have to >>> turn it into a TIFF and back again. >>> >>>

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Graham Cox
> On 22 Jul 2016, at 5:00 PM, Roland King wrote: > > Since you need the data to persist for display whilst you write a new image > that means there’s two separate buffers, there has to be Not sure there HAS to be. Whether it’s the easiest approach is another matter. If the

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Roland King
> On 22 Jul 2016, at 14:40, Trygve Inda wrote: > > >> With half an eye on performance, if you *do* strictly need a copy of the >> bitmap, note that NSBitmapImageRep conforms to NSCopying. You don’t have to >> turn it into a TIFF and back again. >> >> Also, you don’t

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Graham Cox
> On 22 Jul 2016, at 4:40 PM, Trygve Inda wrote: > > >> With half an eye on performance, if you *do* strictly need a copy of the >> bitmap, note that NSBitmapImageRep conforms to NSCopying. You don’t have to >> turn it into a TIFF and back again. >> >> Also, you

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Trygve Inda
> With half an eye on performance, if you *do* strictly need a copy of the > bitmap, note that NSBitmapImageRep conforms to NSCopying. You don’t have to > turn it into a TIFF and back again. > > Also, you don’t even need an NSImage - the NSImageRep can be drawn directly. A little deeper

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Graham Cox
> On 22 Jul 2016, at 4:08 PM, Trygve Inda wrote: > > I don't think the second part will work because of my workflow: > > At Launch: Create pixel buffer that is 1000 x 1000 pixels > > Looping thread > 1. Fill pixel buffer with pixels based on some algorithm > 2.

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Ken Thomases
On Jul 22, 2016, at 1:08 AM, Trygve Inda wrote: > >> But that’s not a great way to do this. You’ve made an image, you’ve encoded >> it >> as TIFF data, then you’ve made a new image, which has decoded the TIFF data >> to >> make a new image rep/bitmap. >> >> You could

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Trygve Inda
> >> On 22 Jul 2016, at 3:37 PM, Trygve Inda wrote: >> >> I create an NSBitmapImageRep: >> >> [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL >> pixelsWide:pixelSize.width >> pixelsHigh:pixelSize.height >> bitsPerSample:8 >> samplesPerPixel:4 >> hasAlpha:YES

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Ken Thomases
On Jul 22, 2016, at 12:37 AM, Trygve Inda wrote: > > I create an NSBitmapImageRep: > > [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL > pixelsWide:pixelSize.width > pixelsHigh:pixelSize.height > bitsPerSample:8 > samplesPerPixel:4 > hasAlpha:YES > isPlanar:NO

Re: NSImage from bitmap - then delete bitmap

2016-07-22 Thread Graham Cox
> On 22 Jul 2016, at 3:37 PM, Trygve Inda wrote: > > I create an NSBitmapImageRep: > > [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL > pixelsWide:pixelSize.width > pixelsHigh:pixelSize.height > bitsPerSample:8 > samplesPerPixel:4 > hasAlpha:YES >

NSImage from bitmap - then delete bitmap

2016-07-21 Thread Trygve Inda
I create an NSBitmapImageRep: [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL pixelsWide:pixelSize.width pixelsHigh:pixelSize.height bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO colorSpaceName:NSDeviceRGBColorSpace bitmapFormat:NSAlphaFirstBitmapFormat