samer@0: /* samer@0: * MatrixImageSource.java samer@0: * samer@0: * Copyright (c) 2000, Samer Abdallah, King's College London. samer@0: * All rights reserved. samer@0: * samer@0: * This software is provided AS iS and WITHOUT ANY WARRANTY; samer@0: * without even the implied warranty of MERCHANTABILITY or samer@0: * FITNESS FOR A PARTICULAR PURPOSE. samer@0: */ samer@0: samer@0: package samer.maths; samer@0: import samer.tools.*; samer@0: import java.awt.image.*; samer@0: import Jama.Matrix; samer@0: samer@0: /** This matrix image source sends pixels a scan line samer@0: at a time samer@0: samer@0: TODO: samer@0: flip horizontally or vertically samer@0: flip diagonally samer@0: replaceable map (ie nonlinear map) samer@0: */ samer@0: samer@0: public class MatrixImageSource extends ImageSourceBase samer@0: { samer@0: Matrix matrix; samer@0: byte [] scanline; samer@0: samer@0: public MatrixImageSource( Matrix mat) { this(mat,true); } samer@0: public MatrixImageSource( Matrix mat, boolean fb) samer@0: { samer@0: matrix = mat; samer@0: width = mat.getColumnDimension(); samer@0: height = mat.getRowDimension(); samer@0: scanline = new byte[width]; samer@0: } samer@0: samer@0: public void newMatrix(Matrix mat) { matrix=mat; sendPixels(); } samer@0: samer@0: protected int getHints() { samer@0: return ImageConsumer.TOPDOWNLEFTRIGHT samer@0: | ImageConsumer.COMPLETESCANLINES samer@0: | ImageConsumer.SINGLEPASS; samer@0: } samer@0: samer@0: protected void sendPixels(ImageConsumer ic) samer@0: { samer@0: double[][] X=matrix.getArray(); samer@0: samer@0: for (int j=height-1; j>=0; j--) { samer@0: double [] Xj = X[j]; samer@0: for (int i=0; i