root / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / properties / DatasetPalette.java @ 11196
History | View | Annotate | Download (7.47 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 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.dataset.properties; |
20 |
|
21 |
import org.gvsig.raster.dataset.IBuffer; |
22 |
|
23 |
import es.gva.cit.jgdal.GdalColorEntry; |
24 |
import es.gva.cit.jgdal.GdalColorTable; |
25 |
import es.gva.cit.jgdal.GdalException; |
26 |
|
27 |
/**
|
28 |
* Paleta para raster. Esta consta de los valores RGB de la paleta que son almacenados en un vector de
|
29 |
* enteros donde cada elemento entero contiene en su interior el RGB completo y del vector de rangos.
|
30 |
* Dependiendo de si el tipo de rango es entero o decimal este estar? almacenado en un vector de rangos
|
31 |
* entero (intRange) o enun vector de rangos double (doubleRange). El tipo de dato del rango quedar?
|
32 |
* almacenado en la variable type.
|
33 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
34 |
*/
|
35 |
public class DatasetPalette{ |
36 |
/**
|
37 |
* Tipo de dato de la paleta
|
38 |
* <UL>
|
39 |
* <LI>TYPE_INT = Valido para byte, short e int</LI>
|
40 |
* <LI>TYPE_DOUBLE = Valido para float y double</LI>
|
41 |
* </UL>
|
42 |
*/
|
43 |
protected int type = IBuffer.TYPE_UNDEFINED; |
44 |
/**
|
45 |
* Lista de rangos para paletas enteras
|
46 |
*/
|
47 |
protected int[] intRange = null; |
48 |
/**
|
49 |
* Lista de rangos para paletas decimales
|
50 |
*/
|
51 |
protected double[] doubleRange = null; |
52 |
/**
|
53 |
* Lista de valores RGB
|
54 |
*/
|
55 |
protected int[] palette = null; |
56 |
/**
|
57 |
* Nombre de la clase asociada a la entrada
|
58 |
*/
|
59 |
protected String[] nameClass = null; |
60 |
/**
|
61 |
* Nombre de la paleta
|
62 |
*/
|
63 |
protected String name = null; |
64 |
/**
|
65 |
* Ruta del fichero a la cual se asocia la paleta. Las bandas de un GeoRasterMultiFile
|
66 |
* han de saber a que paleta van asociadas.
|
67 |
*/
|
68 |
protected String filePath = null; |
69 |
|
70 |
public DatasetPalette(){}
|
71 |
|
72 |
/**
|
73 |
* Constructor. Asigna el nombre de la paleta.
|
74 |
* @param name
|
75 |
*/
|
76 |
public DatasetPalette(String name){ |
77 |
this.name = name;
|
78 |
} |
79 |
|
80 |
/**
|
81 |
* Asigna el nombre de la paleta
|
82 |
* @param Nombre de la paleta
|
83 |
*/
|
84 |
public void addName(String name){ |
85 |
this.name = name;
|
86 |
} |
87 |
|
88 |
/**
|
89 |
* Obtiene el nombre de la paleta
|
90 |
* @return Nombre de la paleta
|
91 |
*/
|
92 |
public String getName(){ |
93 |
return name;
|
94 |
} |
95 |
|
96 |
/*
|
97 |
* TODO: RENDIMIENTO: Incluir una heuristica que dado un valor se compare con el
|
98 |
* valor de la mitad de la tabla y si es menor se empieza a recorrer desde el principio
|
99 |
* sino se empieza a recorrer desde la mitad de la tabla hasta abajo. Esto hace
|
100 |
* que se reduzca la tabla a la mitad de valores haciendo solo una comparaci?n.
|
101 |
*/
|
102 |
/**
|
103 |
* Obtiene el valor RGB para un clave entera pasada por par?metro
|
104 |
* @param value clave de la cual se quiere obtener el valor RGB de la paleta
|
105 |
* @return valor RGB
|
106 |
*/
|
107 |
public int getRGB(int value){ |
108 |
int init = 1; |
109 |
for(int i = init; i <= intRange.length; i++){ |
110 |
if(i < intRange.length){
|
111 |
if(value > intRange[i])
|
112 |
return palette[i - 1]; |
113 |
}else{
|
114 |
return palette[i - 1]; |
115 |
} |
116 |
} |
117 |
return 0; |
118 |
} |
119 |
|
120 |
/**
|
121 |
* Obtiene el valor RGB para un clave decimal pasada por par?metro
|
122 |
* @param value clave de la cual se quiere obtener el valor RGB de la paleta
|
123 |
* @return valor RGB
|
124 |
*/
|
125 |
public int getRGB(double value){ |
126 |
int init = 1; |
127 |
for(int i = init; i <= doubleRange.length; i++) |
128 |
if(i < doubleRange.length){
|
129 |
if(value > doubleRange[i])
|
130 |
return palette[i - 1]; |
131 |
}else{
|
132 |
return palette[i - 1]; |
133 |
} |
134 |
return 0; |
135 |
} |
136 |
|
137 |
/**
|
138 |
* Crea una paleta a partir de un objeto GdalColorTable. Esto es necesario para los ficheros
|
139 |
* que tienen un paleta asignada, como los gif, y que son tratados por Gdal. Se pasa la tabla
|
140 |
* de color le?da desde gdal y se crea directamente un objeto Palette.
|
141 |
* @param table
|
142 |
*/
|
143 |
public void createPaletteFromGdalColorTable(GdalColorTable table){ |
144 |
try{
|
145 |
type = IBuffer.TYPE_BYTE; |
146 |
nameClass = new String[table.getColorEntryCount()]; |
147 |
palette = new int[table.getColorEntryCount()]; |
148 |
intRange = new int[table.getColorEntryCount()]; |
149 |
|
150 |
int cont = table.getColorEntryCount() - 1; |
151 |
for(int iEntry = 0; iEntry < table.getColorEntryCount(); iEntry++){ |
152 |
GdalColorEntry entry = table.getColorEntryAsRGB(iEntry); |
153 |
nameClass[cont] = "";
|
154 |
palette[cont] = 0x00000000;
|
155 |
palette[cont] |= ((entry.c4 & 0x000000ff) << 24); |
156 |
palette[cont] |= ((entry.c1 & 0x000000ff) << 16); |
157 |
palette[cont] |= ((entry.c2 & 0x000000ff) << 8); |
158 |
palette[cont] |= (entry.c3 & 0x000000ff);
|
159 |
intRange[cont] = iEntry; |
160 |
cont --; |
161 |
} |
162 |
}catch(GdalException ex){
|
163 |
//No se crea la paleta
|
164 |
} |
165 |
} |
166 |
|
167 |
/**
|
168 |
* Carga una paleta desde el fichero .rmf asociado a la imagen
|
169 |
* @param file nombre del fichero de imagen
|
170 |
*/
|
171 |
public void loadPaletteFromRMF(String file){ |
172 |
//TODO: FUNCIONALIDAD: Implemetar cargar paleta desde .rmf
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* Salva una paleta desde al fichero .rmf asociado a la imagen
|
177 |
* @param file nombre del fichero de imagen
|
178 |
*/
|
179 |
public void savePaletteToRMF(String file){ |
180 |
//TODO: FUNCIONALIDAD: Implemetar salvar paleta a .rmf
|
181 |
} |
182 |
|
183 |
/**
|
184 |
* Obtiene la paleta
|
185 |
* @return Paleta
|
186 |
*/
|
187 |
public int[] getPalette() { |
188 |
return palette;
|
189 |
} |
190 |
|
191 |
/**
|
192 |
* Asigna una paleta
|
193 |
* @param palette Paleta
|
194 |
*/
|
195 |
public void setPalette(int[] palette) { |
196 |
this.palette = palette;
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* Obtiene el tipo del rango de la paleta que corresponde con los tipos de rasterBuf
|
201 |
* @return Tipo de rango, entero o double
|
202 |
*/
|
203 |
public int getType() { |
204 |
return type;
|
205 |
} |
206 |
|
207 |
/**
|
208 |
* Asigna el tipo del rango de la paleta que corresponde con los tipos de rasterBuf
|
209 |
* @param Tipo de rango, entero o double
|
210 |
*/
|
211 |
public void setType(int type) { |
212 |
this.type = type;
|
213 |
} |
214 |
|
215 |
/**
|
216 |
* Asigna los rangos si el tipo es decimal
|
217 |
* @param rangos
|
218 |
*/
|
219 |
public void setDoubleRange(double[] value) { |
220 |
doubleRange = value; |
221 |
} |
222 |
|
223 |
/**
|
224 |
* Asigna los rangos si el tipo es entero
|
225 |
* @param values
|
226 |
*/
|
227 |
public void setIntRange(int[] values) { |
228 |
intRange = values; |
229 |
} |
230 |
|
231 |
/**
|
232 |
* Obtiene los rangos si el tipo es decimal
|
233 |
* @return rangos
|
234 |
*/
|
235 |
public double[] getDoubleRange() { |
236 |
return doubleRange;
|
237 |
} |
238 |
|
239 |
/**
|
240 |
* Obtiene los rangos si el tipo es entero
|
241 |
* @return rangos
|
242 |
*/
|
243 |
public int[] getIntRange() { |
244 |
return intRange;
|
245 |
} |
246 |
|
247 |
|
248 |
/**
|
249 |
* Obtiene los nombres de las clases de la paleta
|
250 |
* @return Array de cadenas. Cada una corresponde con un nombre de clase
|
251 |
* que corresponde a cada rango de tipos.
|
252 |
*/
|
253 |
public String[] getNameClass() { |
254 |
return nameClass;
|
255 |
} |
256 |
|
257 |
/**
|
258 |
* Asigna los nombres de las clases de la paleta
|
259 |
* @param names Array de cadenas. Cada una corresponde con un nombre de clase
|
260 |
* que corresponde a cada rango de tipos.
|
261 |
*/
|
262 |
public void setNameClass(String[] names) { |
263 |
nameClass = names; |
264 |
} |
265 |
|
266 |
/**
|
267 |
* Obtiene la ruta del fichero al que va asociada la paleta.
|
268 |
* @return Ruta del fichero al que va asociada la paleta.
|
269 |
*/
|
270 |
public String getFilePath() { |
271 |
return filePath;
|
272 |
} |
273 |
|
274 |
/**
|
275 |
* Asigna la ruta del fichero al que va asociada la paleta.
|
276 |
* @param Ruta del fichero al que va asociada la paleta.
|
277 |
*/
|
278 |
public void setFilePath(String filePath) { |
279 |
this.filePath = filePath;
|
280 |
} |
281 |
|
282 |
|
283 |
} |