gvsig-raster / org.gvsig.raster.gdal / tags / pre-remove-jgdal / org.gvsig.raster.gdal / org.gvsig.raster.gdal.io / src / main / java / org / gvsig / jgdal / GdalColorTable.java @ 3497
History | View | Annotate | Download (2.53 KB)
1 |
/* 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.jgdal; |
23 |
|
24 |
import java.awt.Color; |
25 |
|
26 |
import org.gdal.gdal.ColorTable; |
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 |
*/
|
50 |
public int getColorEntryCount() throws GdalException{ |
51 |
// if (cPtr == 0)
|
52 |
// throw new GdalException("No se ha podido acceder al archivo.");
|
53 |
return this.GetCount(); |
54 |
} |
55 |
|
56 |
/**
|
57 |
* Obtiene la entrada de la tabla de color de la posici?n pasada por par?metro
|
58 |
* y la devuelve en forma de objeto GdalColorEntry.
|
59 |
* @param pos Posici?n de la entrada de la tabla
|
60 |
* @return Objeto GdalColorEntry correspondiente a pos
|
61 |
* @throws GdalException
|
62 |
*/
|
63 |
public GdalColorEntry getColorEntryAsRGB(int pos) throws GdalException{ |
64 |
// if (cPtr == 0)
|
65 |
// throw new GdalException("No se ha podido acceder al archivo.");
|
66 |
|
67 |
if ((pos < 0) || (pos >= getColorEntryCount())) |
68 |
throw new GdalException("Entrada de la tabla de color fuera de rango"); |
69 |
|
70 |
GdalColorEntry entry = new GdalColorEntry();
|
71 |
Color values = this.GetColorEntry(pos); |
72 |
entry.c1 = (short) values.getRed();
|
73 |
entry.c2 = (short) values.getGreen();
|
74 |
entry.c3 = (short) values.getBlue();
|
75 |
entry.c4 = (short) values.getAlpha();
|
76 |
if(values == null) |
77 |
throw new GdalException("Error en getColorEntryAsRGB(). Posici?n de la tabla de color inexistente."); |
78 |
return entry;
|
79 |
} |
80 |
} |