View Javadoc

1   package de.desy.acop.video.displayer;
2   
3   import java.util.Arrays;
4   
5   /**
6    * Represents a Color LookUp Table (CLUT) for TINE images.
7    * 
8    * @author David Melkumyan, DESY Zeuthen
9    * 
10   */
11  public class ImageCLUT {
12  
13  	private int nBits[];
14  	private int pixel_bits;
15  	private int numComponents;
16  	private int maxBits;
17  	private int maxValue;
18  
19  	private ColorMap colorMap;
20  
21  	public ImageCLUT(ColorMap colorMap, int[] nBits) {
22  		if (colorMap == null)
23  			throw new NullPointerException("colorMap == null!");
24  		if (nBits == null)
25  			throw new NullPointerException("nBits == null!");
26  
27  		numComponents = nBits.length;
28  		if (numComponents != 1 && numComponents != 3)
29  			throw new IllegalArgumentException("numComponents == " + numComponents);
30  		if (numComponents == 3 && !ColorMap.NONE.equals(colorMap))
31  			throw new IllegalArgumentException("colorMap = " + colorMap + " for numComponents = " + numComponents);
32  
33  		this.colorMap = colorMap;
34  		this.nBits = nBits;
35  
36  		maxBits = nBits[0];
37  		maxValue = (1 << maxBits) - 1;
38  		for (int bits : nBits) {
39  			if (bits > maxBits)
40  				maxBits = bits;
41  			pixel_bits += bits;
42  		}
43  	}
44  
45  	/**
46  	 * Returns the color map
47  	 * 
48  	 * @return the color map
49  	 */
50  	public ColorMap getColorMap() {
51  		return colorMap;
52  	}
53  
54  	/**
55  	 * Returns the number of bits for the specified color component.
56  	 * 
57  	 * @param componentIdx
58  	 *            the index of the color component
59  	 * @return the number of bits for the color component at the specified
60  	 *         index.
61  	 * @throws ArrayIndexOutOfBoundsException
62  	 *             if <code>componentIdx</code> is greater than the number of
63  	 *             components or less than zero
64  	 * @throws NullPointerException
65  	 *             if the number of bits array is <code>null</code>
66  	 */
67  	public int getComponentSize(int componentIdx) {
68  		return nBits[componentIdx];
69  	}
70  
71  	/**
72  	 * Returns an array of the number of bits per color component.
73  	 * 
74  	 * @return an array of the number of bits per color component
75  	 */
76  	public int[] getComponentSize() {
77  		return (int[]) nBits.clone();
78  	}
79  
80  	/**
81  	 * Returns the number of color components
82  	 * 
83  	 * @return the number of color components
84  	 */
85  	public int getNumComponents() {
86  		return numComponents;
87  	}
88  
89  	/**
90  	 * Returns the number of bits per pixel.
91  	 * 
92  	 * @return the number of bits per pixel
93  	 */
94  	public int getPixelSize() {
95  		return pixel_bits;
96  	}
97  
98  	/**
99  	 * Returns true if number of color components array is equal to {8, 8, 8},
100 	 * otherwise false.
101 	 * 
102 	 * @return true if number of color components array is equal to {8, 8, 8},
103 	 *         otherwise false
104 	 */
105 	public boolean isRGB() {
106 		return Arrays.equals(nBits, new int[] { 8, 8, 8 });
107 	}
108 
109 	/**
110 	 * Returns true if number of color components is equal to 1, otherwise false
111 	 * 
112 	 * @return true if number of color components is equal to 1, otherwise false
113 	 */
114 	public boolean isGreyscale() {
115 		return (numComponents == 1);
116 	}
117 
118 	public int getMaxBits() {
119 		return maxBits;
120 	}
121 
122 	public int getMinValue() {
123 		return 0;
124 	}
125 	
126 	public int getMaxValue() {
127 		return maxValue;
128 	}
129 
130 	@Override
131 	public String toString() {
132 		StringBuilder sb = new StringBuilder();
133 		sb.append("colorMap = ").append(colorMap);
134 		sb.append(", nBits = ").append(Arrays.toString(nBits));
135 		return sb.toString();
136 	}
137 
138 }