Mercurial > hg > jslab
view src/samer/tools/ImageSourceBase.java @ 5:b67a33c44de7
Remove some crap, etc
author | samer |
---|---|
date | Fri, 05 Apr 2019 21:34:25 +0100 |
parents | bf79fb79ee13 |
children |
line wrap: on
line source
/* * 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.tools; import samer.core.*; import samer.core.util.*; import java.awt.image.*; import java.awt.Color; import java.util.*; import java.util.Hashtable; /** <p> Base class for image producers. Derived classes must do the following: <ul> <li> set width and height <b>before<b> any consumers are added <li> implement getHints() <li> implement sendPixels(ImageConsumer) </ul> */ public abstract class ImageSourceBase implements ImageProducer { private Hashtable properties = new Hashtable(); private Vector consumers = new Vector(); protected IndexColorModel model = GREY; protected int width, height; protected IMap map = new LinearMap(model.getMapSize()); protected abstract int getHints(); protected abstract void sendPixels(ImageConsumer ic); public IMap getMap() { return map; } public void setMap(IMap m) { map=m; m.setIntRange(model.getMapSize()); } public int getWidth() { return width; } public int getHeight() { return height; } public void setColorModel(IndexColorModel cm) { model=cm; map.setIntRange(model.getMapSize()); Enumeration cons = consumers.elements(); while (cons.hasMoreElements()) { ImageConsumer ic = (ImageConsumer)cons.nextElement(); ic.setColorModel(model); } } public void startProduction(ImageConsumer ic) { addConsumer(ic); } public void requestTopDownLeftRightResend(ImageConsumer ic) {} public synchronized boolean isConsumer(ImageConsumer ic) { return consumers.contains(ic); } public synchronized void removeConsumer(ImageConsumer ic) { consumers.removeElement(ic); } public synchronized void addConsumer(ImageConsumer ic) { if (consumers.contains(ic)) return; consumers.addElement(ic); try { ic.setDimensions(width, height); ic.setProperties(properties); ic.setColorModel(model); ic.setHints(getHints()); sendPixels(ic); ic.imageComplete( ImageConsumer.SINGLEFRAMEDONE); } catch (Exception e) { ic.imageComplete(ImageConsumer.IMAGEERROR); } } public void sendPixels() { Enumeration cons = consumers.elements(); while (cons.hasMoreElements()) { ImageConsumer ic = (ImageConsumer)cons.nextElement(); ic.setDimensions(width, height); ic.setProperties(properties); ic.setColorModel(model); ic.setHints(getHints()); sendPixels(ic); ic.imageComplete( ImageConsumer.SINGLEFRAMEDONE); } } public static IndexColorModel GREY,GREEN; static { ColorRamp r = new ColorRamp(256); r.gradient(Color.black,Color.white); GREY = r.getColorModel(); } }