All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ij.LookUpTable Maven / Gradle / Ivy

package ij;
import java.awt.*;
import java.awt.image.*;
import ij.process.*;

/** This class represents a color look-up table. */
public class LookUpTable extends Object {
	private int width, height;
	private byte[] pixels;
	private int mapSize = 0;
	private ColorModel cm;
	private byte[] rLUT, gLUT,bLUT;

	/** Constructs a LookUpTable object from an AWT Image. */
	public LookUpTable(Image img) {
		PixelGrabber pg = new PixelGrabber(img, 0, 0, 1, 1, false);
		try {
			pg.grabPixels();
			cm = pg.getColorModel();
		}
		catch (InterruptedException e){};
		getColors(cm);
	}

	/** Constructs a LookUpTable object from a ColorModel. */
	public LookUpTable(ColorModel cm) {
		this.cm = cm;
		getColors(cm);
	}
	
	void getColors(ColorModel cm) {
    	if (cm instanceof IndexColorModel) {
    		IndexColorModel m = (IndexColorModel)cm;
    		mapSize = m.getMapSize();
    		rLUT = new byte[mapSize];
    		gLUT = new byte[mapSize];
    		bLUT = new byte[mapSize];
    		m.getReds(rLUT); 
    		m.getGreens(gLUT); 
    		m.getBlues(bLUT); 
    	}
	}
	
	public int getMapSize() {
		return mapSize;
	}
    
    public byte[] getReds() {
    	return rLUT;
    }

    public byte[] getGreens() {
    	return gLUT;
    }

    public byte[] getBlues() {
    	return bLUT;
    }

	public ColorModel getColorModel() {
		return cm;
	}

	/** Returns true if this is a 256 entry grayscale LUT.
		@see ij.process.ImageProcessor#isColorLut
	*/
	public boolean isGrayscale() {
		boolean isGray = true;
		
		if (mapSize < 256)
			return false;
		for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy