Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1909)

Unified Diff: Source/wtf/MathExtras.h

Issue 15466004: Make image decoders faster by refactoring hot loops that fills the lines of ImageFrame. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698