Re: Core Graphics: Is it better to up-sample or down-sample images when drawing into a rect?

2016-08-25 Thread Steve Christensen
> On Aug 24, 2016, at 8:37 PM, Jeff Szuhay  wrote:
> 
> 
>> On Aug 24, 2016, at 8:02 PM, Britt Durbrow 
>>  wrote:
>> 
>> 
>>> On Aug 24, 2016, at 12:59 PM, Jeff Szuhay  wrote:
>>> 
>>> I draw my images (clocks) into a “reference” sized rectangle—for simplified 
>>> position calculations—and then have CoreGraphics scale into the destination 
>>> view rect.
>> 
>> Don’t do that with bitmap scaling. It’s wasteful, and will look bad.
>> 
>> Instead, create the bitmap at the correct size for it’s destination; and use 
>> the drawing matrix transform functions (scale, translate, rotate, etc) to 
>> set up your drawing environment.
> 
> 
> Okay, so when the user changes the clock size (it’s destination), then 
> recreate the bitmap to the new size and redraw everything at the new scale?

Yep. That way you get the best-quality image since it's built to fit an 
explicit size.

And if parts of your display are cacheable, e.g., the clock background, then 
you can recreate them at that point. Keep an ivar with the size of the view 
when the image(s) were last cached and compare it against the view's current 
size.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Core Graphics: Is it better to up-sample or down-sample images when drawing into a rect?

2016-08-24 Thread Jeff Szuhay

> On Aug 24, 2016, at 8:02 PM, Britt Durbrow 
>  wrote:
> 
> 
>> On Aug 24, 2016, at 12:59 PM, Jeff Szuhay  wrote:
>> 
>> I draw my images (clocks) into a “reference” sized rectangle—for simplified 
>> position calculations—and then have CoreGraphics scale into the destination 
>> view rect.
> 
> Don’t do that with bitmap scaling. It’s wasteful, and will look bad.
> 
> Instead, create the bitmap at the correct size for it’s destination; and use 
> the drawing matrix transform functions (scale, translate, rotate, etc) to set 
> up your drawing environment.


Okay, so when the user changes the clock size (it’s destination), then recreate 
the bitmap to the new size and redraw everything at the new scale?


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Core Graphics: Is it better to up-sample or down-sample images when drawing into a rect?

2016-08-24 Thread Britt Durbrow

> On Aug 24, 2016, at 12:59 PM, Jeff Szuhay  wrote:
> 
> I draw my images (clocks) into a “reference” sized rectangle—for simplified 
> position calculations—and then have CoreGraphics scale into the destination 
> view rect.

Don’t do that with bitmap scaling. It’s wasteful, and will look bad.

Instead, create the bitmap at the correct size for it’s destination; and use 
the drawing matrix transform functions (scale, translate, rotate, etc) to set 
up your drawing environment.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Core Graphics: Is it better to up-sample or down-sample images when drawing into a rect?

2016-08-24 Thread Jeff Szuhay

> On Aug 24, 2016, at 12:59 PM, Jeff Szuhay  wrote:
> 
> 
>> On Aug 24, 2016, at 10:37 AM, Jean-Daniel Dupas > > wrote:
>> 
>>> Moreover, the performance will greatly depends the sampling algorithm you 
>>> choose. CGImage provide a couple of algorithms with different tradeoff (see 
>>> CGContextSetInterpolationQuality() and NSImage and UIImage equivalents).
>> 
>> Just for the record, here is a link with different technics available on OS 
>> X to do that: 
>> 
>> http://nshipster.com/image-resizing/ 
> 
> Yeah, but CoreImage is a different kettle of fish.  CoreImage has deprecated 
> the creation of a core image from layers, in favor of bitmaps and 
> static image sources.
> 
> I’m writing an app for Mac OS X/macOS using primarily CoreGraphics and 
> Quartz2D with a smattering of image filters for special effects.
> I draw my images (clocks) into a “reference” sized rectangle—for simplified 
> position calculations—and then have CoreGraphics scale into the destination 
> view rect.
> 
> On my rather old but quite functional 2007 MBP, I notice a considerable 
> difference in CPU use when the clocks are on the laptop main screen (low CPU) 
> versus on a 2nd monitor (high CPU—about 4x). I’ve surmised that the main 
> screen is GPU assisted wheres the 2nd monitor is not. Same clock, just on 
> different screens. I have yet to test whether this will be true on newer 
> MacBookPros with different video cabling/interfaces. 
> 
> I’m in the process of converting my clocks to draw exclusively into offscreen 
> layers (instead of drawing their parts into the device context directly), 
> composing them only when needed, and finally drawing into the view’s graphic 
> context. This, as we’ll soon see, depends upon how efficient the 
> CGContextDrawLayerInRect is when the sour layer and target context are of 
> different sizes—in a single call. 
> 
> Now I’m wondering if an intermediate transformation to scale the layer to the 
> same size as the context and then just call CGContextDrawLayerAtPoint would 
> be more efficient. 
> 
> And, yeah, I’m trying to trade off CPU work for GPU work, and get more work 
> done on the GPU.
> 

Oh, maybe I spoke too soon… Reading the Interpolation section in Programming 
With Quartz
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Core Graphics: Is it better to up-sample or down-sample images when drawing into a rect?

2016-08-24 Thread Jeff Szuhay

> On Aug 24, 2016, at 10:37 AM, Jean-Daniel Dupas  wrote:
> 
>> Moreover, the performance will greatly depends the sampling algorithm you 
>> choose. CGImage provide a couple of algorithms with different tradeoff (see 
>> CGContextSetInterpolationQuality() and NSImage and UIImage equivalents).
> 
> Just for the record, here is a link with different technics available on OS X 
> to do that: 
> 
> http://nshipster.com/image-resizing/ 

Yeah, but CoreImage is a different kettle of fish.  CoreImage has deprecated 
the creation of a core image from layers, in favor of bitmaps and 
static image sources.

I’m writing an app for Mac OS X/macOS using primarily CoreGraphics and Quartz2D 
with a smattering of image filters for special effects.
I draw my images (clocks) into a “reference” sized rectangle—for simplified 
position calculations—and then have CoreGraphics scale into the destination 
view rect.

On my rather old but quite functional 2007 MBP, I notice a considerable 
difference in CPU use when the clocks are on the laptop main screen (low CPU) 
versus on a 2nd monitor (high CPU—about 4x). I’ve surmised that the main screen 
is GPU assisted wheres the 2nd monitor is not. Same clock, just on different 
screens. I have yet to test whether this will be true on newer MacBookPros with 
different video cabling/interfaces. 

I’m in the process of converting my clocks to draw exclusively into offscreen 
layers (instead of drawing their parts into the device context directly), 
composing them only when needed, and finally drawing into the view’s graphic 
context. This, as we’ll soon see, depends upon how efficient the 
CGContextDrawLayerInRect is when the sour layer and target context are of 
different sizes—in a single call. 

Now I’m wondering if an intermediate transformation to scale the layer to the 
same size as the context and then just call CGContextDrawLayerAtPoint would be 
more efficient. 

And, yeah, I’m trying to trade off CPU work for GPU work, and get more work 
done on the GPU.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Core Graphics: Is it better to up-sample or down-sample images when drawing into a rect?

2016-08-24 Thread Jean-Daniel Dupas

> Le 24 août 2016 à 19:33, Jean-Daniel Dupas  a écrit :
> 
>> 
>> Le 24 août 2016 à 18:50, David Duncan  a écrit :
>> 
>> 
>>> On Aug 24, 2016, at 1:23 AM, Jeff Szuhay  wrote:
>>> 
>>> I’m using a bunch of layers to draw images to, compose them, and then draw 
>>> into a viewRect
>>> with 
>>> 
>>> CGContextDrawLayerInRect( viewContext, viewRect, myLayer);
>>> 
>>> Of course, I’m trying to pick the most reasonable size for my layers. I 
>>> currently use 1024x1024
>>> but could easily make them 512x512 or 768x768.
>>> 
>>> So my question is, “Is is more efficient to draw the layer into a smaller 
>>> viewRect (down-sample) 
>>> or into a larger ViewRect (up-sample)?” 
>>> 
>>> Or does it even matter?
>> 
>> It depends on if quality or performance matters more.
>> 
>> Downsampling is generally more expensive because you have to deal with more 
>> data and so you become more easily bandwidth limited, but at the same time 
>> if you must resample an image, down sampling generally produces better 
>> quality. Upsampling is the opposite of all that.
>> 
>> So if performance matters more than quality, then you probably want to 
>> upsample.
>> 
> 
> Moreover, the performance will greatly depends the sampling algorithm you 
> choose. CGImage provide a couple of algorithms with different tradeoff (see 
> CGContextSetInterpolationQuality() and NSImage and UIImage equivalents).

Just for the record, here is a link with different technics available on OS X 
to do that: 

http://nshipster.com/image-resizing/


> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/mailing%40xenonium.com
> 
> This email sent to mail...@xenonium.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Core Graphics: Is it better to up-sample or down-sample images when drawing into a rect?

2016-08-24 Thread Jean-Daniel Dupas

> Le 24 août 2016 à 18:50, David Duncan  a écrit :
> 
> 
>> On Aug 24, 2016, at 1:23 AM, Jeff Szuhay  wrote:
>> 
>> I’m using a bunch of layers to draw images to, compose them, and then draw 
>> into a viewRect
>> with 
>> 
>>  CGContextDrawLayerInRect( viewContext, viewRect, myLayer);
>> 
>> Of course, I’m trying to pick the most reasonable size for my layers. I 
>> currently use 1024x1024
>> but could easily make them 512x512 or 768x768.
>> 
>> So my question is, “Is is more efficient to draw the layer into a smaller 
>> viewRect (down-sample) 
>> or into a larger ViewRect (up-sample)?” 
>> 
>> Or does it even matter?
> 
> It depends on if quality or performance matters more.
> 
> Downsampling is generally more expensive because you have to deal with more 
> data and so you become more easily bandwidth limited, but at the same time if 
> you must resample an image, down sampling generally produces better quality. 
> Upsampling is the opposite of all that.
> 
> So if performance matters more than quality, then you probably want to 
> upsample.
> 

Moreover, the performance will greatly depends the sampling algorithm you 
choose. CGImage provide a couple of algorithms with different tradeoff (see 
CGContextSetInterpolationQuality() and NSImage and UIImage equivalents).


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Core Graphics: Is it better to up-sample or down-sample images when drawing into a rect?

2016-08-24 Thread David Duncan

> On Aug 24, 2016, at 1:23 AM, Jeff Szuhay  wrote:
> 
> I’m using a bunch of layers to draw images to, compose them, and then draw 
> into a viewRect
> with 
> 
>   CGContextDrawLayerInRect( viewContext, viewRect, myLayer);
> 
> Of course, I’m trying to pick the most reasonable size for my layers. I 
> currently use 1024x1024
> but could easily make them 512x512 or 768x768.
> 
> So my question is, “Is is more efficient to draw the layer into a smaller 
> viewRect (down-sample) 
> or into a larger ViewRect (up-sample)?” 
> 
> Or does it even matter?

It depends on if quality or performance matters more.

Downsampling is generally more expensive because you have to deal with more 
data and so you become more easily bandwidth limited, but at the same time if 
you must resample an image, down sampling generally produces better quality. 
Upsampling is the opposite of all that.

So if performance matters more than quality, then you probably want to upsample.

> 
> I have an internal goal of using less than 1% of the CPU for my 1 second 
> image drawing so it is
> actually quite important for me to know.
> 
> TIA
> 
> Jeff Szuhay
> a.k.a tickt...@quartertil2.com 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Core Graphics: Is it better to up-sample or down-sample images when drawing into a rect?

2016-08-24 Thread Jeff Szuhay
I’m using a bunch of layers to draw images to, compose them, and then draw into 
a viewRect
with 

CGContextDrawLayerInRect( viewContext, viewRect, myLayer);

Of course, I’m trying to pick the most reasonable size for my layers. I 
currently use 1024x1024
but could easily make them 512x512 or 768x768.

So my question is, “Is is more efficient to draw the layer into a smaller 
viewRect (down-sample) 
or into a larger ViewRect (up-sample)?” 

Or does it even matter?

I have an internal goal of using less than 1% of the CPU for my 1 second image 
drawing so it is
actually quite important for me to know.

TIA

Jeff Szuhay
a.k.a tickt...@quartertil2.com 


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com