Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void blur2(int numPixels)
- {
- double starttime = System.currentTimeMillis();
- Pixel pixel = null;
- Pixel samplePixel = null;
- int redValue = 0;
- int greenValue = 0;
- int blueValue = 0;
- int count = 0;
- // loop through the pixels
- for (int y=0; y < this.getHeight(); y++) {
- for (int x=0; x < this.getWidth(); x++) {
- // get the current pixel
- pixel = this.getPixel(x,y);
- // reset the count and red, green, and blue values
- count = 0;
- redValue = greenValue = blueValue = 0;
- // loop through pixel numPixels before x to numPixels after x
- for (int xSample = x - numPixels;
- xSample <= x + numPixels;
- xSample++) {
- // check that we are in the range of acceptable pixels
- if (xSample >= 0 && xSample < this.getWidth()) {
- samplePixel = this.getPixel(xSample,y);
- redValue = redValue + samplePixel.getRed();
- greenValue = greenValue + samplePixel.getGreen();
- blueValue = blueValue + samplePixel.getBlue();
- count = count + 1;
- }
- }
- // use average color of surrounding pixels
- Color newColor1 = new Color(redValue/count ,greenValue/count, blueValue/count);
- pixel.setColor(newColor1);
- }
- }
- // loop through the pixels
- for (int x=0; x < this.getWidth(); x++) {
- for (int y=0; y < this.getHeight(); y++) {
- // get the current pixel
- pixel = this.getPixel(x,y);
- // reset the count and red, green, and blue values
- count = 0;
- redValue = greenValue = blueValue = 0;
- // loop through pixel numPixels before x to numPixels after x
- for (int ySample = y - numPixels;
- ySample <= y + numPixels;
- ySample++) {
- // check that we are in the range of acceptable pixels
- if (ySample >= 0 && ySample < this.getHeight()) {
- samplePixel = this.getPixel(x,ySample);
- redValue = redValue + samplePixel.getRed();
- greenValue = greenValue + samplePixel.getGreen();
- blueValue = blueValue + samplePixel.getBlue();
- count = count + 1;
- }
- }
- // use average color of surrounding pixels
- Color newColor2 = new Color(redValue / count,
- greenValue / count,
- blueValue / count);
- pixel.setColor(newColor2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement