document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /* SOURCE
  2. http://download.oracle.com/javase/tutorial/essential/concurrency/forkjoin.html
  3. */
  4.  
  5. public class ForkBlur extends RecursiveAction {
  6.   private int[] mSource;
  7.   private int mStart;
  8.   private int mLength;
  9.   private int[] mDestination;
  10.  
  11.   private int mBlurWidth = 15; // Processing window size, should be odd.
  12.  
  13.   public ForkBlur(int[] src, int start, int length, int[] dst) {
  14.     mSource = src;
  15.     mStart = start;
  16.     mLength = length;
  17.     mDestination = dst;
  18.   }
  19.  
  20.   protected void computeDirectly() {
  21.     int sidePixels = (mBlurWidth - 1) / 2;
  22.     for (int index = mStart; index < mStart + mLength; index++) {
  23.       // Calculate average.
  24.       float rt = 0, gt = 0, bt = 0;
  25.       for (int mi = -sidePixels; mi <= sidePixels; mi++) {
  26.         int mindex = Math.min(Math.max(mi + index, 0), mSource.length - 1);
  27.         int pixel = mSource[mindex];
  28.         rt += (float)((pixel & 0x00ff0000) >> 16) / mBlurWidth;
  29.         gt += (float)((pixel & 0x0000ff00) >>  8) / mBlurWidth;
  30.         bt += (float)((pixel & 0x000000ff) >>  0) / mBlurWidth;
  31.       }
  32.      
  33.       // Re-assemble destination pixel.
  34.       int dpixel = (0xff000000     ) |
  35.                    (((int)rt) << 16) |
  36.                    (((int)gt) <<  8) |
  37.                    (((int)bt) <<  0);
  38.       mDestination[index] = dpixel;
  39.     }
  40.   }
  41.  
  42.   .
  43.   .
  44.   .
');