Advertisement
Guest User

Untitled

a guest
Nov 17th, 2010
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.63 KB | None | 0 0
  1.  public void blur2(int numPixels)
  2.   {
  3.     double starttime = System.currentTimeMillis();
  4.    
  5.     Pixel pixel = null;
  6.     Pixel samplePixel = null;
  7.     int redValue = 0;
  8.     int greenValue = 0;
  9.     int blueValue = 0;
  10.     int count = 0;
  11.  
  12.           // loop through the pixels
  13.       for (int y=0; y < this.getHeight(); y++) {
  14.       for (int x=0; x < this.getWidth(); x++) {
  15.  
  16.         // get the current pixel
  17.         pixel = this.getPixel(x,y);
  18.  
  19.         // reset the count and red, green, and blue values
  20.         count = 0;
  21.         redValue = greenValue = blueValue = 0;
  22.  
  23.         // loop through pixel numPixels before x to numPixels after x
  24.           for (int xSample = x - numPixels;  
  25.                xSample <= x + numPixels;
  26.                xSample++) {
  27.  
  28.             // check that we are in the range of acceptable pixels
  29.             if (xSample >= 0 && xSample < this.getWidth()) {
  30.               samplePixel = this.getPixel(xSample,y);
  31.               redValue = redValue + samplePixel.getRed();
  32.               greenValue = greenValue + samplePixel.getGreen();
  33.               blueValue = blueValue + samplePixel.getBlue();
  34.               count = count + 1;
  35.             }
  36.         }
  37.  
  38.         // use average color of surrounding pixels
  39.         Color newColor1 = new Color(redValue/count ,greenValue/count, blueValue/count);
  40.         pixel.setColor(newColor1);
  41.       }
  42.     }
  43.    
  44.     // loop through the pixels
  45.     for (int x=0; x < this.getWidth(); x++) {
  46.       for (int y=0; y < this.getHeight(); y++) {
  47.  
  48.         // get the current pixel
  49.         pixel = this.getPixel(x,y);
  50.  
  51.         // reset the count and red, green, and blue values
  52.         count = 0;
  53.         redValue = greenValue = blueValue = 0;
  54.  
  55.         // loop through pixel numPixels before x to numPixels after x
  56.           for (int ySample = y - numPixels;  
  57.                ySample <= y + numPixels;
  58.                ySample++) {
  59.  
  60.             // check that we are in the range of acceptable pixels
  61.             if (ySample >= 0 && ySample < this.getHeight()) {
  62.               samplePixel = this.getPixel(x,ySample);
  63.               redValue = redValue + samplePixel.getRed();
  64.               greenValue = greenValue + samplePixel.getGreen();
  65.               blueValue = blueValue + samplePixel.getBlue();
  66.               count = count + 1;
  67.             }
  68.         }
  69.  
  70.         // use average color of surrounding pixels
  71.         Color newColor2 = new Color(redValue / count,
  72.                                    greenValue / count,
  73.                                    blueValue / count);
  74.         pixel.setColor(newColor2);
  75.       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement