Revision 4182 org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/jgdal/GdalColorTable.java
GdalColorTable.java | ||
---|---|---|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department |
4 | 4 |
* of the Valencian Government (CIT) |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
9 | 9 |
* of the License, or (at your option) any later version. |
10 |
*
|
|
10 |
* |
|
11 | 11 |
* This program is distributed in the hope that it will be useful, |
12 | 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | 14 |
* GNU General Public License for more details. |
15 |
*
|
|
15 |
* |
|
16 | 16 |
* You should have received a copy of the GNU General Public License |
17 | 17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
19 | 19 |
* MA 02110-1301, USA. |
20 |
*
|
|
20 |
* |
|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.jgdal; |
23 | 23 |
|
... | ... | |
25 | 25 |
|
26 | 26 |
import org.gdal.gdal.ColorTable; |
27 | 27 |
|
28 |
public class GdalColorTable extends ColorTable { |
|
29 |
|
|
30 |
// private native int getColorEntryCountNat(long cPtr); |
|
31 |
// private native short[] getColorEntryAsRGBNat(long cPtr, int pos); |
|
32 |
|
|
33 |
|
|
34 |
/** |
|
35 |
* Constructor de ColorTable pasandole como par?metro la referencia al objeto |
|
36 |
* GdalColorTable en C |
|
37 |
* |
|
38 |
* @param cPtr direcci?n de memoria del objeto |
|
39 |
*/ |
|
40 |
|
|
41 |
public GdalColorTable(long cPtr){ |
|
42 |
super(cPtr, true); |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* Obtiene |
|
47 |
* @return |
|
48 |
* @throws GdalException |
|
49 |
*/ |
|
28 |
public class GdalColorTable { |
|
29 |
|
|
30 |
|
|
31 |
private ColorTable ct; |
|
32 |
|
|
33 |
/** |
|
34 |
* |
|
35 |
*/ |
|
36 |
public GdalColorTable(ColorTable ct) { |
|
37 |
this.ct = ct; |
|
38 |
} |
|
39 |
|
|
50 | 40 |
public int getColorEntryCount() throws GdalException{ |
51 |
// if (cPtr == 0) |
|
52 |
// throw new GdalException("No se ha podido acceder al archivo."); |
|
53 |
return this.GetCount(); |
|
41 |
return this.ct.GetCount(); |
|
54 | 42 |
} |
55 |
|
|
56 |
public static long getCPtr(ColorTable obj) { |
|
57 |
return ColorTable.getCPtr(obj); |
|
58 |
} |
|
59 |
|
|
60 |
/** |
|
61 |
* Obtiene la entrada de la tabla de color de la posici?n pasada por par?metro |
|
62 |
* y la devuelve en forma de objeto GdalColorEntry. |
|
63 |
* @param pos Posici?n de la entrada de la tabla |
|
64 |
* @return Objeto GdalColorEntry correspondiente a pos |
|
65 |
* @throws GdalException |
|
66 |
*/ |
|
43 |
|
|
67 | 44 |
public GdalColorEntry getColorEntryAsRGB(int pos) throws GdalException{ |
68 |
// if (cPtr == 0) |
|
69 |
// throw new GdalException("No se ha podido acceder al archivo."); |
|
70 |
|
|
45 |
|
|
71 | 46 |
if ((pos < 0) || (pos >= getColorEntryCount())) |
72 | 47 |
throw new GdalException("Entrada de la tabla de color fuera de rango"); |
73 |
|
|
48 |
|
|
74 | 49 |
GdalColorEntry entry = new GdalColorEntry(); |
75 |
Color values = this.GetColorEntry(pos); |
|
50 |
Color values = this.ct.GetColorEntry(pos); |
|
51 |
if(values == null) |
|
52 |
throw new GdalException("Error en getColorEntryAsRGB(). Posici?n de la tabla de color inexistente."); |
|
76 | 53 |
entry.c1 = (short) values.getRed(); |
77 | 54 |
entry.c2 = (short) values.getGreen(); |
78 | 55 |
entry.c3 = (short) values.getBlue(); |
79 | 56 |
entry.c4 = (short) values.getAlpha(); |
80 |
if(values == null) |
|
81 |
throw new GdalException("Error en getColorEntryAsRGB(). Posici?n de la tabla de color inexistente."); |
|
82 | 57 |
return entry; |
83 | 58 |
} |
59 |
|
|
84 | 60 |
} |
Also available in: Unified diff