view src/samer/maths/MatrixTImageSource.java @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
line wrap: on
line source
/*
 *	MatrixTImageSource.java	
 *
 *	Copyright (c) 2000, Samer Abdallah, King's College London.
 *	All rights reserved.
 *
 *	This software is provided AS iS and WITHOUT ANY WARRANTY; 
 *	without even the implied warranty of MERCHANTABILITY or 
 *	FITNESS FOR A PARTICULAR PURPOSE.
 */

package samer.maths;
import  samer.tools.*;
import  java.awt.image.*;
import  Jama.Matrix;

/** This matrix image source sends pixels a scan line
	at a time

	TODO:
		flip horizontally or vertically
		flip diagonally
		replaceable map (ie nonlinear map)
*/

public class MatrixTImageSource extends ImageSourceBase
{
	Matrix		matrix;
	byte []		scanline;

	public MatrixTImageSource( Matrix mat) { this(mat,true); }
	public MatrixTImageSource( Matrix mat, boolean fb)
	{
		matrix	= mat;
		width		= mat.getRowDimension();
		height	= mat.getColumnDimension();
		scanline	= new byte[width];
	}

	public void newMatrix(Matrix mat) { matrix=mat; sendPixels();	}

	protected int getHints() {
		return  ImageConsumer.TOPDOWNLEFTRIGHT 
				| ImageConsumer.COMPLETESCANLINES
				| ImageConsumer.SINGLEPASS;
	}

	protected void sendPixels(ImageConsumer ic)
	{
		double[][] X=matrix.getArray();

		for (int j=height-1; j>=0; j--) {
			for (int i=0; i<width; i++) {
				scanline[i] = (byte)map.clipInt(X[i][j]);
			}
			ic.setPixels(0, height-1-j, width, 1, model, scanline, 0, 1);
		} 
	}
}