Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.legend / org.gvsig.raster.lib.legend.impl / src / test / java / org / gvsig / raster / lib / legend / impl / DefaultColorInterpretationTest.java @ 6900

History | View | Annotate | Download (10 KB)

1
package org.gvsig.raster.lib.legend.impl;
2

    
3
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
4
import org.gvsig.raster.lib.legend.api.RasterLegendManager;
5
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation;
6
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
7

    
8
/**
9
 * @author <a href="mailto:lmarques@disid.com">Lluis Marques</a>
10
 *
11
 */
12
@SuppressWarnings("javadoc")
13
public class DefaultColorInterpretationTest extends AbstractLibraryAutoInitTestCase {
14

    
15
    private ColorInterpretation colorInterpretation;
16
    private ColorInterpretation colorInterpretationRGB;
17
    private ColorInterpretation colorInterpretationARGB;
18
    private ColorInterpretation colorInterpretationBGR;
19
    private ColorInterpretation colorInterpretationGray;
20
    private ColorInterpretation colorInterpretationPalette;
21

    
22
    @Override
23
    protected void doSetUp() throws Exception {
24
        RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager();
25

    
26
        colorInterpretation =
27
            rasterLegendManager.createColorInterpretation(new String[] {
28
                ColorInterpretation.GREEN_BAND, ColorInterpretation.BLUE_BAND,
29
                ColorInterpretation.RED_BAND, ColorInterpretation.ALPHA_BAND });
30

    
31
        colorInterpretationRGB =
32
            rasterLegendManager.createColorInterpretation(ColorInterpretation.RGB);
33
        colorInterpretationARGB =
34
            rasterLegendManager.createColorInterpretation(ColorInterpretation.ARGB);
35
        colorInterpretationBGR =
36
            rasterLegendManager.createColorInterpretation(ColorInterpretation.BGR);
37
        colorInterpretationGray =
38
            rasterLegendManager.createColorInterpretation(ColorInterpretation.GRAYSCALE);
39
        colorInterpretationPalette =
40
            rasterLegendManager.createColorInterpretation(ColorInterpretation.PALETTE);
41
    }
42

    
43
    public void testSetColorInterpValue() {
44
        assertEquals(ColorInterpretation.GREEN_BAND, colorInterpretation.get(0));
45
        colorInterpretation.setColorInterpValue(0, ColorInterpretation.GRAY_BAND);
46
        assertEquals(ColorInterpretation.GRAY_BAND, colorInterpretation.get(0));
47
    }
48

    
49
    public void testLength() {
50
        assertEquals(colorInterpretation.length(), 4);
51
        assertEquals(colorInterpretationRGB.length(), 3);
52
        assertEquals(colorInterpretationBGR.length(), 3);
53
        assertEquals(colorInterpretationARGB.length(), 4);
54
        assertEquals(colorInterpretationGray.length(), 1);
55
    }
56

    
57
    public void testHasInterpretation() {
58
        ColorInterpretation tmpColorInterpretation =
59
            RasterLegendLocator.getRasterLegendManager().createColorInterpretation(
60
                new String[] { ColorInterpretation.ALPHA_BAND });
61
        assertFalse(tmpColorInterpretation.hasInterpretation());
62

    
63
        assertTrue(colorInterpretation.hasInterpretation());
64
        assertTrue(colorInterpretationRGB.hasInterpretation());
65
        assertTrue(colorInterpretationARGB.hasInterpretation());
66
        assertTrue(colorInterpretationBGR.hasInterpretation());
67
        assertTrue(colorInterpretationGray.hasInterpretation());
68
    }
69

    
70
    public void testIsBGR() {
71
        assertFalse(colorInterpretation.isBGR());
72
        assertFalse(colorInterpretationARGB.isBGR());
73
        assertFalse(colorInterpretationRGB.isBGR());
74
        assertTrue(colorInterpretationBGR.isBGR());
75
        assertFalse(colorInterpretationGray.isBGR());
76
    }
77

    
78
    public void testIsRGB() {
79
        assertFalse(colorInterpretation.isRGB());
80
        assertFalse(colorInterpretationARGB.isRGB());
81
        assertTrue(colorInterpretationRGB.isRGB());
82
        assertTrue(colorInterpretationBGR.isRGB());
83
        assertFalse(colorInterpretationGray.isRGB());
84
    }
85

    
86
    public void testIsRGBA() {
87
        assertTrue(colorInterpretation.isRGBA());
88
        assertTrue(colorInterpretationARGB.isRGBA());
89
        assertFalse(colorInterpretationRGB.isRGBA());
90
        assertFalse(colorInterpretationBGR.isRGBA());
91
        assertFalse(colorInterpretationGray.isRGBA());
92
    }
93

    
94
    public void testIsGray() {
95
        assertFalse(colorInterpretation.isGray());
96
        assertFalse(colorInterpretationARGB.isGray());
97
        assertFalse(colorInterpretationRGB.isGray());
98
        assertFalse(colorInterpretationBGR.isGray());
99
        assertTrue(colorInterpretationGray.isGray());
100
    }
101

    
102
    public void testIsColorInterpretation() {
103

    
104
        assertTrue(colorInterpretation.isColorInterpretation(0));
105
        assertTrue(colorInterpretation.isColorInterpretation(1));
106
        assertTrue(colorInterpretation.isColorInterpretation(2));
107
        assertFalse(colorInterpretation.isColorInterpretation(3));
108

    
109
        assertTrue(colorInterpretationRGB.isColorInterpretation(0));
110
        assertTrue(colorInterpretationRGB.isColorInterpretation(1));
111
        assertTrue(colorInterpretationRGB.isColorInterpretation(2));
112

    
113
        assertTrue(colorInterpretationARGB.isColorInterpretation(0));
114
        assertTrue(colorInterpretationARGB.isColorInterpretation(1));
115
        assertTrue(colorInterpretationARGB.isColorInterpretation(2));
116
        assertFalse(colorInterpretationARGB.isColorInterpretation(3));
117

    
118
        assertTrue(colorInterpretationBGR.isColorInterpretation(0));
119
        assertTrue(colorInterpretationBGR.isColorInterpretation(1));
120
        assertTrue(colorInterpretationBGR.isColorInterpretation(2));
121

    
122
        assertFalse(colorInterpretationGray.isColorInterpretation(0));
123
    }
124

    
125
    public void testIsGrayInterpretation() {
126

    
127
        assertFalse(colorInterpretation.isGrayInterpretation(0));
128
        assertFalse(colorInterpretation.isGrayInterpretation(1));
129
        assertFalse(colorInterpretation.isGrayInterpretation(2));
130
        assertFalse(colorInterpretation.isGrayInterpretation(3));
131

    
132
        assertFalse(colorInterpretationRGB.isGrayInterpretation(0));
133
        assertFalse(colorInterpretationRGB.isGrayInterpretation(1));
134
        assertFalse(colorInterpretationRGB.isGrayInterpretation(2));
135

    
136
        assertFalse(colorInterpretationARGB.isGrayInterpretation(0));
137
        assertFalse(colorInterpretationARGB.isGrayInterpretation(1));
138
        assertFalse(colorInterpretationARGB.isGrayInterpretation(2));
139
        assertFalse(colorInterpretationARGB.isGrayInterpretation(3));
140

    
141
        assertFalse(colorInterpretationBGR.isGrayInterpretation(0));
142
        assertFalse(colorInterpretationBGR.isGrayInterpretation(1));
143
        assertFalse(colorInterpretationBGR.isGrayInterpretation(2));
144

    
145
        assertTrue(colorInterpretationGray.isGrayInterpretation(0));
146
    }
147

    
148
    public void testIsAlphaInterpretation() {
149

    
150
        assertFalse(colorInterpretation.isAlphaInterpretation(0));
151
        assertFalse(colorInterpretation.isAlphaInterpretation(1));
152
        assertFalse(colorInterpretation.isAlphaInterpretation(2));
153
        assertTrue(colorInterpretation.isAlphaInterpretation(3));
154

    
155
        assertFalse(colorInterpretationRGB.isAlphaInterpretation(0));
156
        assertFalse(colorInterpretationRGB.isAlphaInterpretation(1));
157
        assertFalse(colorInterpretationRGB.isAlphaInterpretation(2));
158

    
159
        assertFalse(colorInterpretationARGB.isAlphaInterpretation(0));
160
        assertFalse(colorInterpretationARGB.isAlphaInterpretation(1));
161
        assertFalse(colorInterpretationARGB.isAlphaInterpretation(2));
162
        assertTrue(colorInterpretationARGB.isAlphaInterpretation(3));
163

    
164
        assertFalse(colorInterpretationBGR.isAlphaInterpretation(0));
165
        assertFalse(colorInterpretationBGR.isAlphaInterpretation(1));
166
        assertFalse(colorInterpretationBGR.isAlphaInterpretation(2));
167

    
168
        assertFalse(colorInterpretationGray.isAlphaInterpretation(0));
169
    }
170

    
171
    public void testGet() {
172
        assertEquals(ColorInterpretation.GREEN_BAND, colorInterpretation.get(0));
173
        assertEquals(ColorInterpretation.RED_BAND, colorInterpretationRGB.get(0));
174
    }
175

    
176
    public void testGetBand() {
177
        assertEquals(1, colorInterpretation.getBand(ColorInterpretation.BLUE_BAND));
178
        assertEquals(-1, colorInterpretation.getBand(ColorInterpretation.GRAY_BAND));
179
        assertEquals(2, colorInterpretationRGB.getBand(ColorInterpretation.BLUE_BAND));
180
    }
181

    
182
    public void testIsUndefined() {
183
        ColorInterpretation tmpColorInterpretation =
184
            RasterLegendLocator.getRasterLegendManager().createColorInterpretation(
185
                new String[] { ColorInterpretation.ALPHA_BAND });
186
        assertTrue(tmpColorInterpretation.isUndefined());
187

    
188
        assertFalse(colorInterpretation.isUndefined());
189
        assertFalse(colorInterpretationRGB.isUndefined());
190
        assertFalse(colorInterpretationARGB.isUndefined());
191
        assertFalse(colorInterpretationBGR.isUndefined());
192
        assertFalse(colorInterpretationGray.isUndefined());
193
    }
194

    
195
    public void testGetValues() {
196
        String[] values = colorInterpretationRGB.getValues();
197
        assertEquals(ColorInterpretation.RED_BAND, values[0]);
198
        assertEquals(ColorInterpretation.GREEN_BAND, values[1]);
199
        assertEquals(ColorInterpretation.BLUE_BAND, values[2]);
200

    
201
        values = colorInterpretationGray.getValues();
202
        assertEquals(ColorInterpretation.GRAY_BAND, values[0]);
203
    }
204

    
205
    public void testHasAlphaBand() {
206
        assertTrue(colorInterpretation.hasAlphaBand());
207
        assertFalse(colorInterpretationRGB.hasAlphaBand());
208
        assertTrue(colorInterpretationARGB.hasAlphaBand());
209
        assertFalse(colorInterpretationBGR.hasAlphaBand());
210
        assertFalse(colorInterpretationGray.hasAlphaBand());
211
    }
212

    
213
    public void testGetAlphaBand() {
214
        assertEquals(colorInterpretation.getAlphaBand(), 3);
215
        assertEquals(colorInterpretationRGB.getAlphaBand(), -1);
216
        assertEquals(colorInterpretationARGB.getAlphaBand(), 3);
217
        assertEquals(colorInterpretationBGR.getAlphaBand(), -1);
218
        assertEquals(colorInterpretationGray.getAlphaBand(), -1);
219
    }
220

    
221
    public void testCopyFrom() {
222

    
223
        colorInterpretationGray.copyFrom(colorInterpretationRGB);
224
        assertEquals(3, colorInterpretationGray.length());
225
        String[] values = colorInterpretationGray.getValues();
226
        assertEquals(ColorInterpretation.RED_BAND, values[0]);
227
        assertEquals(ColorInterpretation.GREEN_BAND, values[1]);
228
        assertEquals(ColorInterpretation.BLUE_BAND, values[2]);
229

    
230
    }
231

    
232
}