All pastes #465741 Raw Edit

misia

public text v1 · immutable
#465741 ·published 2007-04-30 15:30 UTC
rendered paste body
public void initImage()
	{
		System.out.println("INIT IMAGE function in topleftcanvas");
		if(image!=null)
		{
			
			int w=image.getWidth(null);
			int h=image.getHeight(null);
			int pixels[]=controler.getPixelsOfImage();
			
			float [][]imagearray=new float[w][h];
			for(int x=0;x<w;x++){
				for(int y=0;y<h;y++){	
						int c =pixels[y* w + x];
						int red = (c & 0x00ff0000) >> 16;
						int blue = (c & 0x0000ff00) >> 8;
						int green = c & 0x000000ff;
						imagearray[x][y]=((float)(red+blue+green))/(3*255);
					}
				}
			
			for(int x=0;x<w;x++){
				for(int y=0;y<h;y++){
			
					int color[]=new int[3];
					int c;
					if((y * w + x)<w*h)
					{
					/*	c =pixels[y* w + x];
						int red = (c & 0x00ff0000) >> 16;
						int blue = (c & 0x0000ff00) >> 8;
						int green = c & 0x000000ff;
						*/
						int K=approximate(imagearray[x][y]);
						
						//Color kolorek = new Color(red,blue,green);
					
					 	color[0]=K;
					 	color[1]=K;
					 	color[2]=K;
					 	raster.setPixel(x, y, color);
					 	
					 	float error=imagearray[x][y]-K;
					 	
					 	int f_x=1;
					 	int f_y=1;
					 	if(filtervalue==2||filtervalue==3)
					 		f_x=2;
					 	if(filtervalue==3)
					 		f_y=2;
					 	for (int i=-f_x;  i<+f_x;  i++)
					        for (int j=-f_y;  j<+f_y;  j++)
					        	if(x+i>=0&&y+j>=0&&x+i<w&&y+j<h)
					        		imagearray[x+i][y+j] += error*filter[i+f_x][j+f_y];
					}
					
				}
			}
		}
	}
	
	
	private int approximate(float x)
	{
	
		if(x>(0.5))
			return 1;
		else
			return 0;

	}