view src/samer/maths/MatrixImageSource.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
line wrap: on
line source
/*
 *	MatrixImageSource.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 MatrixImageSource extends ImageSourceBase
{
	Matrix		matrix;
	byte []		scanline;

	public MatrixImageSource( Matrix mat) { this(mat,true); }
	public MatrixImageSource( Matrix mat, boolean fb)
	{
		matrix	= mat;
		width		= mat.getColumnDimension();
		height	= mat.getRowDimension();
		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--) {
			double [] Xj = X[j];
			for (int i=0; i<width; i++) {
				scanline[i] = (byte)map.clipInt(Xj[i]);
			}
			ic.setPixels(0, height-1-j, width, 1, model, scanline, 0, 1);
		} 
	}
}