package ij.gui;
import ij.*;
import ij.process.*;
import java.util.*;
import java.io.*;
public class PlotVirtualStack extends VirtualStack {
private Vector plots = new Vector(50);
private int bitDepth = 8;
public PlotVirtualStack(int width, int height) {
super(width, height);
this.bitDepth = bitDepth;
}
public void addPlot(Plot plot) {
plots.add(plot.toByteArray());
if (plot.isColored())
bitDepth = 24;
}
public Object getPixels(int n) {
ImageProcessor ip = getProcessor(n);
if (ip!=null)
return ip.getPixels();
else
return null;
}
public ImageProcessor getProcessor(int n) {
byte[] bytes = (byte[])plots.get(n-1);
if (bytes!=null) {
try {
Plot plot = new Plot(null, new ByteArrayInputStream(bytes));
ImageProcessor ip = plot.getProcessor();
if (bitDepth==24)
ip = ip.convertToRGB();
else if (bitDepth==8)
ip = ip.convertToByte(false);
return ip;
} catch (Exception e) {
IJ.handleException(e);
}
}
return null;
}
public int getSize() {
return plots.size();
}
public int getBitDepth() {
return bitDepth;
}
public void setBitDepth(int bitDepth) {
this.bitDepth = bitDepth;
}
public String getSliceLabel(int n) {
return null;
}
public void setPixels(Object pixels, int n) {
}
public void deleteSlice(int n) {
if (n<1 || n>plots.size())
throw new IllegalArgumentException("Argument out of range: "+n);
if (plots.size()<1)
return;
plots.remove(n-1);
}
}