Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libRaster / src-test / org / gvsig / raster / datastruct / TestColorTable.java @ 30754

History | View | Annotate | Download (3.99 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.datastruct;
20

    
21
import java.awt.Color;
22
import java.util.ArrayList;
23

    
24
import org.gvsig.raster.BaseTestCase;
25
/**
26
 * Test para comprobar el funcionamiento de las tablas de color.
27
 * @version 12/05/2008
28
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
29
 */
30
public class TestColorTable extends BaseTestCase {
31
        private String baseDir = "./test-images/";
32
        private String path = baseDir + "gifTransparente.gif";
33

    
34
        protected void doSetUp() throws Exception {
35
                super.doSetUp();
36
                System.err.println("TestColorTable running...");
37
        }
38

    
39
        public void testStack() {
40
                dataTest1();
41
                dataTest2();
42
        }
43

    
44
        /**
45
         * Compara un array de bytes con sus respectivos valores de color
46
         * @param item
47
         * @param red
48
         * @param green
49
         * @param blue
50
         * @param alpha
51
         */
52
        private void compareColor(byte[] item, int red, int green, int blue, int alpha) {
53
                assertEquals((item[0] & 0xff), red);
54
                assertEquals((item[1] & 0xff), green);
55
                assertEquals((item[2] & 0xff), blue);
56
                assertEquals((item[3] & 0xff), alpha);
57
        }
58

    
59
        /**
60
         * Comprueba la tabla de color de una imagen existente
61
         */
62
        private void dataTest1() {
63
                open(path);
64
                ColorTable table = dataset.getColorTables()[0];
65
                compareColor(table.getColorTableByBand()[0],  255, 255, 255,   0);
66
                compareColor(table.getColorTableByBand()[1],    0,   0,   0, 255);
67
                compareColor(table.getColorTableByBand()[2],    0, 102, 255, 255);
68
                compareColor(table.getColorTableByBand()[3],    0, 153, 255, 255);
69
                compareColor(table.getColorTableByBand()[4],    0,   0, 255, 255);
70
                compareColor(table.getColorTableByBand()[5],    0,  51, 255, 255);
71
                compareColor(table.getColorTableByBand()[6],   55,  55, 255, 255);
72
                compareColor(table.getColorTableByBand()[7],    0, 204, 255, 255);
73
                compareColor(table.getColorTableByBand()[8],  191, 191, 255, 255);
74
                compareColor(table.getColorTableByBand()[9],  191, 242, 255, 255);
75
                compareColor(table.getColorTableByBand()[10], 223, 223, 223, 255);
76
                compareColor(table.getColorTableByBand()[11], 127, 127, 127, 255);
77
                compareColor(table.getColorTableByBand()[12],  63,  63,  63, 255);
78
                compareColor(table.getColorTableByBand()[13], 159, 159, 159, 255);
79
                compareColor(table.getColorTableByBand()[14],  31,  31,  31, 255);
80
                compareColor(table.getColorTableByBand()[15],  95,  95,  95, 255);
81
                compareColor(table.getColorTableByBand()[16], 191, 191, 191, 255);
82
        }
83

    
84
        /**
85
         * Comprueba una tabla de color creada a mano
86
         */
87
        private void dataTest2() {
88
                ColorTable table = new ColorTable("dataTest2");
89
                ArrayList list = new ArrayList();
90
                ColorItem item = new ColorItem();
91
                item.setValue(0.0f);
92
                item.setColor(Color.black);
93
                list.add(item);
94
                item = new ColorItem();
95
                item.setValue(10.0f);
96
                item.setColor(Color.white);
97
                list.add(item);
98
                item = new ColorItem();
99
                item.setValue(20.0f);
100
                item.setColor(Color.red);
101
                list.add(item);
102

    
103
                table.createPaletteFromColorItems(list, false);
104
                table.setInterpolated(false);
105

    
106
                compareColor(table.getRGBAByBand(0.0f),    0,   0,   0, 255);
107
                compareColor(table.getRGBAByBand(10.0f), 255, 255, 255, 255);
108
                compareColor(table.getRGBAByBand(20.0f), 255,   0,   0, 255);
109
        }
110
}