Re: Best way to composite/tile multiple CGImages to one image
Re: Best way to composite/tile multiple CGImages to one image
- Subject: Re: Best way to composite/tile multiple CGImages to one image
- From: Trygve Inda <email@hidden>
- Date: Sat, 08 Mar 2014 05:12:23 +0000
- Thread-topic: Best way to composite/tile multiple CGImages to one image
>
> On 8 Mar 2014, at 2:38 pm, Trygve Inda <email@hidden> wrote:
>
>> Profiling this shows lots of time (90%) is spent in drawInRect and it takes
>> about 2 seconds to run. Is there a better way to do this that is faster?
>>
>> Maybe keep everything in CG and only convert to NSImage at the end?
>
>
> Sounds like you answered your own question...
>
>
>> Not sure
>> how to do this.
>
>
> Instead of creating canvas as a NSImage, create a NSBitmapImageRep and then a
> graphics context from it, using +[NSGraphicsContext
> graphicsContextWithBitmapImageRep]. Then you can use CGContextDrawImage with
> your CGImageRef data, targetting that context. Once you're done, just add the
> bitmap image rep to an NSImage.
>
> Essentially, you want to avoid copying any image data that you don't need to,
> though in fact your original code *may* already be avoiding that and just
> wrapping things. Spending 90% of your time in drawInRect is probably a good
> sign - it means that only the copy that really needs to happen is taking time.
> It might be that you can't do better (though 2 seconds sounds high, but you
> haven't said what size these images are). The other thing to ensure is that
> everything uses the same colour space throughout - if any conversion is needed
> it will hit performance hard. Lesser performance hits can come from mismatched
> image buffer formats, so if all your CGImageRefs are the same, use the format
> information associated with them to create your NSBitMapImageRep to match. If
> format and colour space are the same, the actual bitblit needed should be very
> fast as it's just a straight copy, no conversion.
>
> --Graham
I get the same times doing it this way, but maybe my color spaces are
different. The CGImage returned from my AVAsset is:
<CGColorSpace 0x100550490> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB;
Composite NTSC)
I am not really sure what color space to pass into:
[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL.....
Currently I am using NSDeviceRGBColorSpace.
Any thoughts?
T.
_______________________________________________
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