annotate 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
rev   line source
samer@0 1 /*
samer@0 2 * MatrixImageSource.java
samer@0 3 *
samer@0 4 * Copyright (c) 2000, Samer Abdallah, King's College London.
samer@0 5 * All rights reserved.
samer@0 6 *
samer@0 7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
samer@0 8 * without even the implied warranty of MERCHANTABILITY or
samer@0 9 * FITNESS FOR A PARTICULAR PURPOSE.
samer@0 10 */
samer@0 11
samer@0 12 package samer.maths;
samer@0 13 import samer.tools.*;
samer@0 14 import java.awt.image.*;
samer@0 15 import Jama.Matrix;
samer@0 16
samer@0 17 /** This matrix image source sends pixels a scan line
samer@0 18 at a time
samer@0 19
samer@0 20 TODO:
samer@0 21 flip horizontally or vertically
samer@0 22 flip diagonally
samer@0 23 replaceable map (ie nonlinear map)
samer@0 24 */
samer@0 25
samer@0 26 public class MatrixImageSource extends ImageSourceBase
samer@0 27 {
samer@0 28 Matrix matrix;
samer@0 29 byte [] scanline;
samer@0 30
samer@0 31 public MatrixImageSource( Matrix mat) { this(mat,true); }
samer@0 32 public MatrixImageSource( Matrix mat, boolean fb)
samer@0 33 {
samer@0 34 matrix = mat;
samer@0 35 width = mat.getColumnDimension();
samer@0 36 height = mat.getRowDimension();
samer@0 37 scanline = new byte[width];
samer@0 38 }
samer@0 39
samer@0 40 public void newMatrix(Matrix mat) { matrix=mat; sendPixels(); }
samer@0 41
samer@0 42 protected int getHints() {
samer@0 43 return ImageConsumer.TOPDOWNLEFTRIGHT
samer@0 44 | ImageConsumer.COMPLETESCANLINES
samer@0 45 | ImageConsumer.SINGLEPASS;
samer@0 46 }
samer@0 47
samer@0 48 protected void sendPixels(ImageConsumer ic)
samer@0 49 {
samer@0 50 double[][] X=matrix.getArray();
samer@0 51
samer@0 52 for (int j=height-1; j>=0; j--) {
samer@0 53 double [] Xj = X[j];
samer@0 54 for (int i=0; i<width; i++) {
samer@0 55 scanline[i] = (byte)map.clipInt(Xj[i]);
samer@0 56 }
samer@0 57 ic.setPixels(0, height-1-j, width, 1, model, scanline, 0, 1);
samer@0 58 }
samer@0 59 }
samer@0 60 }
samer@0 61