Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Gaussian blur is expensive to do accurately. A much faster approximation can be done by just iteratively averaging the pixels. It's still expensive to blur the image a lot but you can redraw between each iteration to at least give instant feedback and a nice animation of the image blurring.</p> <pre><code>static void blurfast(Bitmap bmp, int radius) { int w = bmp.getWidth(); int h = bmp.getHeight(); int[] pix = new int[w * h]; bmp.getPixels(pix, 0, w, 0, 0, w, h); for(int r = radius; r &gt;= 1; r /= 2) { for(int i = r; i &lt; h - r; i++) { for(int j = r; j &lt; w - r; j++) { int tl = pix[(i - r) * w + j - r]; int tr = pix[(i - r) * w + j + r]; int tc = pix[(i - r) * w + j]; int bl = pix[(i + r) * w + j - r]; int br = pix[(i + r) * w + j + r]; int bc = pix[(i + r) * w + j]; int cl = pix[i * w + j - r]; int cr = pix[i * w + j + r]; pix[(i * w) + j] = 0xFF000000 | (((tl &amp; 0xFF) + (tr &amp; 0xFF) + (tc &amp; 0xFF) + (bl &amp; 0xFF) + (br &amp; 0xFF) + (bc &amp; 0xFF) + (cl &amp; 0xFF) + (cr &amp; 0xFF)) &gt;&gt; 3) &amp; 0xFF | (((tl &amp; 0xFF00) + (tr &amp; 0xFF00) + (tc &amp; 0xFF00) + (bl &amp; 0xFF00) + (br &amp; 0xFF00) + (bc &amp; 0xFF00) + (cl &amp; 0xFF00) + (cr &amp; 0xFF00)) &gt;&gt; 3) &amp; 0xFF00 | (((tl &amp; 0xFF0000) + (tr &amp; 0xFF0000) + (tc &amp; 0xFF0000) + (bl &amp; 0xFF0000) + (br &amp; 0xFF0000) + (bc &amp; 0xFF0000) + (cl &amp; 0xFF0000) + (cr &amp; 0xFF0000)) &gt;&gt; 3) &amp; 0xFF0000; } } } bmp.setPixels(pix, 0, w, 0, 0, w, h); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload