Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a couple of CGContext questions



On 31/01/2007 03:16 Pm, David Duncan wrote:

> On Jan 31, 2007, at 03:18 AM, Mike Kluev wrote:
> 
>> David Duncan wrote:
>>> I would not recommend that approach, as the math is non-trivial, and
>>> you can get subtle floating point errors (due to rounding).
>> 
>> Curious, would the errors be observable on the screen or paper.
> 
> What errors you see will depend entirely on how sensitive what you
> are rendering is to rounding errors. Any errors in accuracy in the
> CTM gets propagated to every calculation in CG, which can lead to
> unexpected results. How likely you are to notice these errors is
> dependent on the context of usage and how large the error is. But the
> nature of floating point math on a computer means that small errors
> can be come large errors if you aren't careful with your order of
> operations.
> 
> In principle, performing an inverse of a 3x3 matrix (which is what a
> CG CTM basically is, we just don't store some fields since they are
> constant) requires performing a lot (about a dozen) matrix
> determinants (which leads to lots of multiplications, additions and
> subtractions). In practice, there are better methods that you can
> use, but the more intelligent/faster the method, the more code you
> have to write, maintain and test. Mathworld has a pretty good write
> up at <http://mathworld.wolfram.com/MatrixInverse.html>

Wait, what's wrong with CGAffineTransformInvert?

> At some point, it really isn't worth it, and outside of specific
> situations you aren't going to get the same results as popping the
> GState stack, and you certainly aren't going to get the result any
> faster.
> 
>>> Your far
>>> better off doing a CGContextSaveGState() when you first get the
>>> context, and if you ever need to go back to the initial CTM, popping
>>> state until you reach the default state again (then saving state
>>> again to preserve that).
>> 
>> But that will reset the whole context to the saved state. What if
>> the OP needs to reset only the CTM, while leaving other context
>> parameters intact?
> 
> Honestly, you'll just have to set them up again. In almost all cases
> this will be cheaper than inverting the CTM to, and you can always
> try to rearrange your drawing order to avoid having to setup a lot of
> state each time.

Set them again to what values? The context parameters might be set
by the outside code (e.g. written by other team) so at the point
where you need to do this you just don't know them (e.g. you are a
plugin and there is no easy way to "rearrange" the drawing order).
And there are no getters for most (or all?) context parameters
(e.g. the above mentioned alpha) to be able to grab them all and
reset them later... Besides, when your code (e.g. a plugin) first
gets the context, the context might already have a non-identity CTM...

Looks like we have two methods both of which are not that good
in general...

Mike

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: a couple of CGContext questions (From: David Duncan <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.