File: PlotVirtualStack.java

package info (click to toggle)
imagej 1.54g-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,520 kB
  • sloc: java: 132,209; sh: 286; xml: 255; makefile: 6
file content (85 lines) | stat: -rw-r--r-- 2,005 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package ij.gui;
import ij.*;
import ij.process.*;
import java.util.*;
import java.io.*;

/** This is a virtual stack of frozen plots. */
public class PlotVirtualStack extends VirtualStack {
	private Vector plots = new Vector(50);
	private int bitDepth = 8;
	
	public PlotVirtualStack(int width, int height) {
		super(width, height);
	}
	
	/** Adds a plot to the end of the stack. */
	public void addPlot(Plot plot) {
		plots.add(plot.toByteArray());
		if (plot.isColored())
			bitDepth = 24;
	}
	   
   /** Returns the pixel array for the specified slice, where {@literal 1<=n<=nslices}. */
	public Object getPixels(int n) {
		ImageProcessor ip = getProcessor(n);
		if (ip!=null)
			return ip.getPixels();
		else
			return null;
	}		
	
	/** Returns an ImageProcessor for the specified slice,
		where {@literal 1<=n<=nslices}. Returns null if the stack is empty. */
	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);
				ip.setSliceNumber(n);
				return ip;
			} catch (Exception e) {
				IJ.handleException(e);
			}
		}
		return null;
	}
	 
	 /** Returns the number of slices in this stack. */
	public int getSize() {
		return plots.size();
	}
		
	/** Returns either 24 (RGB) or 8 (grayscale). */
	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) {
	}
	
	/** Deletes the specified slice, where {@literal 1<=n<=nslices}. */
	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);
	}


} // PlotVirtualStack