Procedurality.Channel.scaleDouble C# (CSharp) Method

scaleDouble() public method

public scaleDouble ( ) : Channel
return Channel
		public Channel scaleDouble() {
			if(!(width == height)) throw new Exception("square images only");
	
			// calculate filter
			Channel filter = new Channel(width<<1, height<<1);
			for (int y = 0; y < height; y++) {
				int y_shift = y<<1;
				for (int x = 0; x < width; x++) {
					int x_shift = x<<1;
					float value = 0.25f*getPixel(x, y);
					filter.putPixel(x_shift, y_shift, value);
					filter.putPixel(x_shift + 1, y_shift, value);
					filter.putPixel(x_shift, y_shift + 1, value);
					filter.putPixel(x_shift + 1, y_shift + 1, value);
				}
			}
	
			// draw image
			Channel channel = new Channel(width<<1, height<<1);
			for (int y = 1; y < (height<<1) - 1; y++) {
				for (int x = 1; x < (width<<1) - 1; x++) {
					channel.putPixel(x, y, filter.getPixel(x - 1, y) + filter.getPixel(x + 1, y) + filter.getPixel(x, y - 1) + filter.getPixel(x, y + 1));
				}
			}
	
			// fix edges
			int max = (width<<1) - 1;
			for (int i = 0; i < max; i++) {
				channel.putPixel(0, i, filter.getPixelWrap(-1, i) + filter.getPixelWrap(1, i) + filter.getPixelWrap(0, i - 1) + filter.getPixelWrap(0, i + 1));
				channel.putPixel(i, 0, filter.getPixelWrap(i, -1) + filter.getPixelWrap(i, 1) + filter.getPixelWrap(i - 1, 0) + filter.getPixelWrap(i + 1, 0));
				channel.putPixel(max, i, filter.getPixelWrap(max - 1, i) + filter.getPixelWrap(max + 1, i) + filter.getPixelWrap(max, i - 1) + filter.getPixelWrap(max, i + 1));
				channel.putPixel(i, max, filter.getPixelWrap(i, max - 1) + filter.getPixelWrap(i, max + 1) + filter.getPixelWrap(i - 1, max) + filter.getPixelWrap(i + 1, max));
			}
			pixels = channel.getPixels();
			width = width<<1;
			height = height<<1;
			return this;
		}