title: what (r+1 + (r >> 8)) >> 8 does?
body: <p>In some old C/C++ graphics related code, that I have to port to Java and JavaScript I found this:</p>
  
  <pre><code>b = (b+1 + (b &gt;&gt; 8)) &gt;&gt; 8; // very fast
  </code></pre>
  
  <p>Where <code>b</code> is <code>short int</code> for blue, and same code is seen for <code>r</code> and <code>b</code> (red &amp; blue). The comment is not helpful.</p>
  
  <p>I cannot figure out what it does, apart from obvious shifting and adding. I can port without understanding, I just ask out of curiosity.</p>