samer@0: /* samer@0: * IteratorImageSource.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: samer@0: /** samer@0: This is an image source that gets its values samer@0: from a Vec (vector) via its Vec.Iterator - ie, samer@0: it does not need access to an array of value samer@0: */ samer@0: samer@0: public class IteratorImageSource extends ImageSourceBase samer@0: { samer@0: Vec vec; samer@0: byte [] buf; samer@0: samer@0: public IteratorImageSource( Vec v) { this( v, v.size(), 1); } samer@0: public IteratorImageSource( Vec v, int w, int h) samer@0: { samer@0: vec = v; samer@0: width = w; samer@0: height = h; samer@0: buf = new byte[v.size()]; samer@0: } samer@0: 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: Vec.Iterator it=vec.iterator(); samer@0: samer@0: for (int i=0; it.more(); i++) { samer@0: buf[i] = (byte)map.clipInt(it.next()); samer@0: } samer@0: ic.setPixels(0, 0, width, height, model, buf, 0, width); samer@0: } samer@0: } samer@0: