Index: Source/wtf/MathExtras.h |
diff --git a/Source/wtf/MathExtras.h b/Source/wtf/MathExtras.h |
index fa62ebb6c98ba75845e97a11923abc1332ff6d59..4ec682e8a6855f38cd4c8f28f99d2e348b25ee9d 100644 |
--- a/Source/wtf/MathExtras.h |
+++ b/Source/wtf/MathExtras.h |
@@ -434,6 +434,14 @@ inline unsigned fastLog2(unsigned i) |
return log2; |
} |
+inline uint16_t fastDivideBy255(uint16_t value) |
+{ |
+ // This is an approximate algorithm for division by 255, but it gives accurate results for 16bit values. |
+ uint16_t approximation = value >> 8; |
+ uint16_t remainder = value - (approximation * 255) + 1; |
+ return approximation + (remainder >> 8); |
+} |
+ |
} // namespace WTF |
#endif // #ifndef WTF_MathExtras_h |