Re: float to int (kinda OT)
- Subject: Re: float to int (kinda OT)
- From: Chris Cox <email@hidden>
- Date: Thu, 21 Oct 2004 13:09:01 -0700
- Delivered-to: email@hidden
- Delivered-to: email@hidden
r = (a * r) >> 8;
g = (a * g) >> 8;
b = (a * b) >> 8;
Ouch - No.
255 * 255 / 256 = 254
Even rounding won't fix that mistake.
When you multiply 8 bit components, you have to divide by 255.
Fortunately, there are some tricks to do that without using an actual divide.
Note that the right shift by 8 is an approximation to dividing by
255, but it shouldn't make that much difference.
I hope you don't ship applications that do that.
And you still should use rounding.
Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
PerfOptimization-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/perfoptimization-dev/email@hidden
This email sent to 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.