Engine.FilterBlur = class
{
	init(radius /*int*/, iterations /*int*/)
	{
		this.radius = radius;
		this.iterations = iterations;
	}

	getAddedWidth()
	{
		return 2 * this.iterations * this.radius;
	}

	getAddedHeight()
	{
		return 2 * this.iterations * this.radius;
	}

	getName()
	{
		return "Blur" + this.radius + "i" + this.iterations;
	}

	applyFilter(image /*Texture2D*/)
	{
		for (var i = 0; i < this.iterations; i++)
		{
			this.blurImage(image, this.radius, true);
			this.blurImage(image, this.radius, false);
		}
	}

	blurImage(image /*Texture2D*/, blurSize /*int*/, horizontal /*bool*/)
	{	
		// Copy the image for reference for the blur
		var temp = new PIXI.Texture(image.width, image.height, TextureFormat.ARGB32, false);
		// temp.SetPixels32(image.GetPixels32());
		// temp.Apply();
		
		// var _W = image.width;
		// var _H = image.height;
		// int xx, yy, x, y;
		
		// if (horizontal)
		// {
		// 	var (yy = 0; yy < _H; yy++)
		// 	{
		// 		var (xx = 0; xx < _W; xx++)
		// 		{
		// 			this.resetPixel();
		// 			//Right side of pixel
		// 			var (x = xx; (x < xx + blurSize && x < _W); x++)
		// 			{
		// 				this.addPixel(temp.GetPixel(x, yy));
		// 			}
					
		// 			//Left side of pixel
		// 			var (x = xx; (x > xx - blurSize && x > 0); x--)
		// 			{
		// 				this.addPixel(temp.GetPixel(x, yy));
		// 			}
					
		// 			this.calcPixel();
					
		// 			var (x = xx; x < xx + blurSize && x < _W; x++)
		// 			{
		// 				image.SetPixel(x, yy, new Color(avgR, avgG, avgB, (temp.GetPixel(x, yy).a == 1) ? 1 : avgA));
		// 			}
		// 		}
		// 	}
		// }
		// else
		// {
			
		// 	var (xx = 0; xx < _W; xx++)
		// 	{
		// 		var (yy = 0; yy < _H; yy++)
		// 		{
		// 			this.resetPixel();
		// 			//Over pixel
		// 			var (y = yy; (y < yy + blurSize && y < _H); y++)
		// 			{
		// 				this.addPixel(temp.GetPixel(xx, y));
		// 			}
					
		// 			//Under pixel
		// 			var (y = yy; (y > yy - blurSize && y > 0); y--)
		// 			{
		// 				this.addPixel(temp.GetPixel(xx, y));
		// 			}
					
		// 			this.calcPixel();
					
		// 			var (y = yy; y < yy + blurSize && y < _H; y++)
		// 			{
		// 				image.SetPixel(xx, y, new Color(avgR, avgG, avgB, (temp.GetPixel(xx, y).a == 1) ? 1 : avgA));
		// 			}
		// 		}
		// 	}
		// }
		
		// image.Apply();
	}

	addPixel(pixel /*Color*/)
	{
		if (pixel.a > 0)
		{
			this.avgR += pixel.r;
			this.avgG += pixel.g;
			this.avgB += pixel.b;
			this.avgA += pixel.a;
		}
		this.blurPixelCount++;
	}

	resetPixel()
	{
		this.avgR = 0.0;
		this.avgG = 0.0;
		this.avgB = 0.0;
		this.avgA = 0;
		this.blurPixelCount = 0;
	}

	calcPixel()
	{
		this.avgR = this.avgR / this.blurPixelCount;
		this.avgG = this.avgG / this.blurPixelCount;
		this.avgB = this.avgB / this.blurPixelCount;
		this.avgA = this.avgA / this.blurPixelCount;
	}
}