Re: Forcing NSImage to cache images at certain sizes
Re: Forcing NSImage to cache images at certain sizes
- Subject: Re: Forcing NSImage to cache images at certain sizes
- From: Ken Ferry <email@hidden>
- Date: Sat, 22 May 2010 14:33:41 -0700
On Sat, May 22, 2010 at 12:14 AM, B.J. Buchalter <email@hidden> wrote:
>
> On May 21, 2010, at 10:10 PM, Ken Ferry wrote:
>
> Hi BJ,
>>
>> On Fri, May 21, 2010 at 2:44 PM, B.J. Buchalter <email@hidden> wrote:
>> I read the NSImage and Cocoa drawing guide docs, which tends to indicate
>> that calling drawInRect:fromRect:operation:fraction: on an NSImage will
>> cause it to create a cached image rep that matches the scaled image so that
>> the next time it is drawn it does not need to be scaled again.
>>
>> The docs haven't fully integrated new info from 10.6, when NSImage changed
>> a bunch. Take a look at the AppKit release notes.
>>
>
> Oh -- sorry; I am testing on 10.5 -- I should have mentioned that.
>
>
> That is not what I am seeing here, and the scaling is definitely taking a
>> nontrivial amount of time when redrawing my views. I have played around with
>> setting the caching and scaling on the NSImage, but it doesn't appear to be
>> having any impact (the internal image rep for the image never changes).
>>
>> Could you attach a test app please? There's more than one thing that
>> could be the issue.
>>
>
> I'll try to reduce my code to something very simple.
>
> Basically what I am seeing is that when I call
> drawInRect:fromRect:operation:fraction:, no mater what I pass in the for
> drawInRect (which causes the image to draw scaled), if I NSLog(@"%@",
> theImage) after doing the drawing I get:
>
> Drawing Image with width: 49.000000 and height: 49.000000
> NSImage 0x13e770 Size={64, 64} Reps=(
> NSBitmapImageRep 0x13c4f0 Size={64, 64}
> ColorSpace=NSCalibratedRGBColorSpace BPS=8 BPP=32 Pixels=64x64 Alpha=YES
> Planar=NO Format=2 CGImage=0x16007270
> )
>
> Note that the image has not cached a reduced NSBitmapImageRep or
> NSCachedImageRep with Size={49, 49}
>
I would want to profile your code, the description method is not enough to
debug a perf problem of this sort.
In 10.6 at least, if you are simply drawing with an NSImage that is backed
by a single CGImage, that CGImage itself would normally be considered the
Cocoa-level cache - there would be no extra allocation. This is because CG
should have enough info to cache correctly in this case, so anything Cocoa
did on top we would expect to be a waste. A cache (which itself is a
CGImage) would be generated for something like a PDF.
The applicability of caches may depend on how you're drawing the image. Is
it always targeting new contexts? Different colorspaces? Different pixel
alignments? Alternating sizes? etc. Perhaps the CG-level cache is never
judged applicable. Or, perhaps caches get expired because there's too much
stuff that wants caching. Etc.
-Ken
_______________________________________________
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