OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 log2 += 8, i >>= 8; | 427 log2 += 8, i >>= 8; |
428 if (i >> 4) | 428 if (i >> 4) |
429 log2 += 4, i >>= 4; | 429 log2 += 4, i >>= 4; |
430 if (i >> 2) | 430 if (i >> 2) |
431 log2 += 2, i >>= 2; | 431 log2 += 2, i >>= 2; |
432 if (i >> 1) | 432 if (i >> 1) |
433 log2 += 1; | 433 log2 += 1; |
434 return log2; | 434 return log2; |
435 } | 435 } |
436 | 436 |
| 437 inline uint16_t fastDivideBy255(uint16_t value) |
| 438 { |
| 439 // This is an approximate algorithm for division by 255, but it gives accura
te results for 16bit values. |
| 440 uint16_t approximation = value >> 8; |
| 441 uint16_t remainder = value - (approximation * 255) + 1; |
| 442 return approximation + (remainder >> 8); |
| 443 } |
| 444 |
437 } // namespace WTF | 445 } // namespace WTF |
438 | 446 |
439 #endif // #ifndef WTF_MathExtras_h | 447 #endif // #ifndef WTF_MathExtras_h |
OLD | NEW |