gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.main / src / test / java / org / gvsig / fmap / dal / coverage / datastruct / TestColorTable.java @ 162
History | View | Annotate | Download (4.31 KB)
1 | 34 | nbrodin | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
||
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | */
|
||
22 | package org.gvsig.fmap.dal.coverage.datastruct; |
||
23 | |||
24 | import java.awt.Color; |
||
25 | import java.util.ArrayList; |
||
26 | |||
27 | import org.gvsig.fmap.dal.coverage.BaseTestCase; |
||
28 | 53 | nbrodin | import org.gvsig.fmap.dal.coverage.store.props.ColorTable; |
29 | 34 | nbrodin | import org.gvsig.raster.impl.datastruct.ColorItemImpl; |
30 | 162 | nbrodin | import org.gvsig.raster.impl.store.properties.DataStoreColorTable; |
31 | 34 | nbrodin | /**
|
32 | * Test para comprobar el funcionamiento de las tablas de color.
|
||
33 | * @version 12/05/2008
|
||
34 | * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
|
||
35 | */
|
||
36 | public class TestColorTable extends BaseTestCase { |
||
37 | private String path = baseDir + "gifTransparente.gif"; |
||
38 | |||
39 | public void setUp() throws Exception { |
||
40 | try {
|
||
41 | super.doSetUp();
|
||
42 | } catch (Exception e) { |
||
43 | e.printStackTrace(); |
||
44 | } |
||
45 | System.err.println("TestColorTable running..."); |
||
46 | } |
||
47 | |||
48 | public void testStack() { |
||
49 | dataTest1(); |
||
50 | dataTest2(); |
||
51 | } |
||
52 | |||
53 | /**
|
||
54 | * Compara un array de bytes con sus respectivos valores de color
|
||
55 | * @param item
|
||
56 | * @param red
|
||
57 | * @param green
|
||
58 | * @param blue
|
||
59 | * @param alpha
|
||
60 | */
|
||
61 | private void compareColor(byte[] item, int red, int green, int blue, int alpha) { |
||
62 | assertEquals((item[0] & 0xff), red); |
||
63 | assertEquals((item[1] & 0xff), green); |
||
64 | assertEquals((item[2] & 0xff), blue); |
||
65 | assertEquals((item[3] & 0xff), alpha); |
||
66 | } |
||
67 | |||
68 | /**
|
||
69 | * Comprueba la tabla de color de una imagen existente
|
||
70 | */
|
||
71 | private void dataTest1() { |
||
72 | open(path); |
||
73 | 53 | nbrodin | ColorTable table = dataStore.getColorTable(); |
74 | 34 | nbrodin | compareColor(table.getColorTableByBand()[0], 255, 255, 255, 0); |
75 | compareColor(table.getColorTableByBand()[1], 0, 0, 0, 255); |
||
76 | compareColor(table.getColorTableByBand()[2], 0, 102, 255, 255); |
||
77 | compareColor(table.getColorTableByBand()[3], 0, 153, 255, 255); |
||
78 | compareColor(table.getColorTableByBand()[4], 0, 0, 255, 255); |
||
79 | compareColor(table.getColorTableByBand()[5], 0, 51, 255, 255); |
||
80 | compareColor(table.getColorTableByBand()[6], 55, 55, 255, 255); |
||
81 | compareColor(table.getColorTableByBand()[7], 0, 204, 255, 255); |
||
82 | compareColor(table.getColorTableByBand()[8], 191, 191, 255, 255); |
||
83 | compareColor(table.getColorTableByBand()[9], 191, 242, 255, 255); |
||
84 | compareColor(table.getColorTableByBand()[10], 223, 223, 223, 255); |
||
85 | compareColor(table.getColorTableByBand()[11], 127, 127, 127, 255); |
||
86 | compareColor(table.getColorTableByBand()[12], 63, 63, 63, 255); |
||
87 | compareColor(table.getColorTableByBand()[13], 159, 159, 159, 255); |
||
88 | compareColor(table.getColorTableByBand()[14], 31, 31, 31, 255); |
||
89 | compareColor(table.getColorTableByBand()[15], 95, 95, 95, 255); |
||
90 | compareColor(table.getColorTableByBand()[16], 191, 191, 191, 255); |
||
91 | } |
||
92 | |||
93 | /**
|
||
94 | * Comprueba una tabla de color creada a mano
|
||
95 | */
|
||
96 | 42 | nbrodin | @SuppressWarnings("unchecked") |
97 | 34 | nbrodin | private void dataTest2() { |
98 | 162 | nbrodin | ColorTable table = new DataStoreColorTable("dataTest2"); |
99 | 34 | nbrodin | ArrayList list = new ArrayList(); |
100 | ColorItem item = new ColorItemImpl();
|
||
101 | item.setValue(0.0f);
|
||
102 | item.setColor(Color.black);
|
||
103 | list.add(item); |
||
104 | item = new ColorItemImpl();
|
||
105 | item.setValue(10.0f);
|
||
106 | item.setColor(Color.white);
|
||
107 | list.add(item); |
||
108 | item = new ColorItemImpl();
|
||
109 | item.setValue(20.0f);
|
||
110 | item.setColor(Color.red);
|
||
111 | list.add(item); |
||
112 | |||
113 | table.createPaletteFromColorItems(list, false);
|
||
114 | table.setInterpolated(false);
|
||
115 | |||
116 | compareColor(table.getRGBAByBand(0.0f), 0, 0, 0, 255); |
||
117 | compareColor(table.getRGBAByBand(10.0f), 255, 255, 255, 255); |
||
118 | compareColor(table.getRGBAByBand(20.0f), 255, 0, 0, 255); |
||
119 | } |
||
120 | } |