All pastes #459025 Raw Edit

Someone

public text v1 · immutable
#459025 ·published 2007-04-26 07:16 UTC
rendered paste body
public Color getPixel(int x, int y)
		{
			int height = getHeight();
			int width = getWidth();
			if (x >= 0 && x <= width && y >= 0 && y <= height)
			{
				int pixel = getRGB(x, y);
				return new Color(pixel);
			}
			else
			{
				return null;
			}
		}


    public OFImage blur()
    {
			int height = getHeight();
    	int width = getWidth();
    	OFImage target = new OFImage(width, height);


    	int ox = 0;
    	int oy = 0;

			Color oPixel = new Color(0, 0, 0);
			
			int oRed = 0;
			int oGreen = 0;
			int oBlue = 0;

			int avgRed = 0;
			int avgGreen = 0;
			int avgBlue = 0;


    	for(int y = 0; y < height; y++)
    	{
    		for(int x = 0; x < width; x++)
    		{
					for(int h = -1; h <= 1; h++)
					{
						for(int v = -1; v <= 1; v++)
						{
							ox = x + h;
							oy = y + v;

// 							System.out.println(x + "," + y + "," + v + "," + h);

							oPixel = getPixel(ox, oy);

							if (oPixel != null)
							{
								oRed = oPixel.getRed();
								oGreen = oPixel.getGreen();
								oBlue = oPixel.getBlue();
							
								avgRed = (avgRed + oRed)/2;
								avgGreen = (avgGreen + oGreen)/2;
								avgBlue = (avgBlue + oBlue)/2;
							}
						}
					}

    			target.setPixel(x, y, new Color(avgRed, avgGreen, avgBlue));
    		}
    	}
    	return target;
    }