root / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / io / EcwDriver.java @ 10960
History | View | Annotate | Download (23.4 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 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.io; |
20 |
|
21 |
import java.awt.geom.Point2D; |
22 |
import java.io.File; |
23 |
import java.util.Vector; |
24 |
|
25 |
import org.cresques.cts.ICoordTrans; |
26 |
import org.cresques.cts.IProjection; |
27 |
import org.gvsig.raster.dataset.BandList; |
28 |
import org.gvsig.raster.dataset.FileNotOpenException; |
29 |
import org.gvsig.raster.dataset.GeoInfo; |
30 |
import org.gvsig.raster.dataset.IBuffer; |
31 |
import org.gvsig.raster.dataset.InvalidSetViewException; |
32 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
33 |
import org.gvsig.raster.dataset.RasterDataset; |
34 |
import org.gvsig.raster.dataset.RasterDriverException; |
35 |
import org.gvsig.raster.dataset.properties.DatasetTransparency; |
36 |
import org.gvsig.raster.shared.Extent; |
37 |
import org.gvsig.raster.util.RasterUtilities; |
38 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
39 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
40 |
|
41 |
import com.ermapper.ecw.JNCSException; |
42 |
import com.ermapper.ecw.JNCSFile; |
43 |
import com.ermapper.ecw.JNCSFileNotOpenException; |
44 |
import com.ermapper.ecw.JNCSInvalidSetViewException; |
45 |
import com.ermapper.ecw.JNCSProgressiveUpdate; |
46 |
|
47 |
import es.gva.cit.jgdal.GdalException; |
48 |
|
49 |
|
50 |
/**
|
51 |
* Driver de Ecw
|
52 |
*
|
53 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
54 |
*/
|
55 |
public class EcwDriver extends RasterDataset implements JNCSProgressiveUpdate { |
56 |
|
57 |
private JNCSFile file = null; |
58 |
private int currentFullWidth = -1; |
59 |
private int currentFullHeight = -1; |
60 |
/**
|
61 |
* Contorno en coordenadas geogr?ficas sin rotaci?n aplicada. Esto es util para poder
|
62 |
* calcular los pixeles necesarios que se van a leer del raster.
|
63 |
*/
|
64 |
public Contour bBoxWithoutRot = new Contour(); |
65 |
/**
|
66 |
* Estado de transparencia del raster.
|
67 |
*/
|
68 |
protected DatasetTransparency fileTransparency = null; |
69 |
|
70 |
/**
|
71 |
* Extent de la ventana seleccionada
|
72 |
*/
|
73 |
private Extent view = null; |
74 |
|
75 |
static {
|
76 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
77 |
extensionPoints.add("RasterDriver", "ecw", EcwDriver.class); |
78 |
extensionPoints.add("RasterDriver", "jp2", EcwDriver.class); |
79 |
} |
80 |
|
81 |
class Contour extends Vector { |
82 |
final private static long serialVersionUID = 0; |
83 |
public double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE; |
84 |
public double maxX = -Double.MAX_VALUE, maxY = -Double.MAX_VALUE; |
85 |
public Contour() {
|
86 |
super();
|
87 |
} |
88 |
public void add(Point2D pt) { |
89 |
super.add(pt);
|
90 |
if (pt.getX() > maxX) maxX = pt.getX();
|
91 |
if (pt.getX() < minX) minX = pt.getX();
|
92 |
if (pt.getY() > maxY) maxY = pt.getY();
|
93 |
if (pt.getY() < minY) minY = pt.getY();
|
94 |
} |
95 |
} |
96 |
|
97 |
/**
|
98 |
* Constructor. Abre el dataset.
|
99 |
* @param proj Proyecci?n
|
100 |
* @param fName Nombre del fichero ecw
|
101 |
* @throws NotSupportedExtensionException
|
102 |
*/
|
103 |
public EcwDriver(IProjection proj, String fName)throws NotSupportedExtensionException { |
104 |
super(proj, fName);
|
105 |
extent = new Extent();
|
106 |
try {
|
107 |
|
108 |
if (!new File(fName).exists() && !fName.startsWith("ecwp:")) |
109 |
throw new NotSupportedExtensionException("Extension not supported"); |
110 |
|
111 |
file = new JNCSFile(fName, false); |
112 |
load(); |
113 |
//readGeoInfo(fName);
|
114 |
bandCount = file.numBands; |
115 |
getTransparencyDatasetStatus(); |
116 |
setDataType(IBuffer.TYPE_BYTE); |
117 |
} catch (Exception e) { |
118 |
throw new NotSupportedExtensionException("Extension not supported"); |
119 |
} |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Carga un ECW.
|
124 |
* @param fname
|
125 |
*/
|
126 |
public GeoInfo load() {
|
127 |
double minX;
|
128 |
double minY;
|
129 |
double maxX;
|
130 |
double maxY;
|
131 |
|
132 |
if(file.cellIncrementY > 0) |
133 |
file.cellIncrementY = -file.cellIncrementY; |
134 |
|
135 |
minX = file.originX; |
136 |
maxY = file.originY; |
137 |
maxX = file.originX + |
138 |
((double) (file.width) * file.cellIncrementX);
|
139 |
minY = file.originY + |
140 |
((double) (file.height) * file.cellIncrementY);
|
141 |
|
142 |
currentFullWidth = file.width; |
143 |
currentFullHeight = file.height; |
144 |
boundingBoxWithoutRotation(); |
145 |
|
146 |
extent = new Extent(minX, minY, maxX, maxY);
|
147 |
requestExtent = extent; |
148 |
return this; |
149 |
} |
150 |
|
151 |
/**
|
152 |
* Calcula la bounding box en la que est? metido el raster teniendo en cuenta
|
153 |
* el tama?o de pixel y la rotaci?n.
|
154 |
*/
|
155 |
private void boundingBoxWithoutRotation(){ |
156 |
double ox = file.originX;
|
157 |
double oy = file.originY;
|
158 |
double resx = file.cellIncrementX;
|
159 |
double resy = file.cellIncrementY;
|
160 |
|
161 |
bBoxWithoutRot.add(new Point2D.Double(ox, oy)); |
162 |
bBoxWithoutRot.add(new Point2D.Double(ox + resx * (file.width), oy)); |
163 |
bBoxWithoutRot.add(new Point2D.Double(ox, oy + resy * (file.height))); |
164 |
bBoxWithoutRot.add(new Point2D.Double(ox + resx * (file.width), oy + resy * (file.height))); |
165 |
} |
166 |
|
167 |
/**
|
168 |
* Cierra el fichero ECW
|
169 |
*/
|
170 |
public void close() { |
171 |
if(file != null){ |
172 |
file.close(true);
|
173 |
file = null;
|
174 |
} |
175 |
} |
176 |
|
177 |
/**
|
178 |
* Obtiene el objeto que contiene el estado de la transparencia
|
179 |
*/
|
180 |
public DatasetTransparency getTransparencyDatasetStatus() {
|
181 |
if(fileTransparency == null) |
182 |
fileTransparency = new DatasetTransparency();
|
183 |
return fileTransparency;
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* Devuelve el ancho de la imagen
|
188 |
*/
|
189 |
public int getWidth() { |
190 |
return file.width;
|
191 |
} |
192 |
|
193 |
/**
|
194 |
* Devuelve el alto de la imagen
|
195 |
*/
|
196 |
public int getHeight() { |
197 |
return file.height;
|
198 |
} |
199 |
|
200 |
/**
|
201 |
* Obtiene el extent de la ?ltima ventana seleccionada.
|
202 |
* @return Extent
|
203 |
*/
|
204 |
public Extent getView() {
|
205 |
return view;
|
206 |
} |
207 |
|
208 |
/*
|
209 |
* (non-Javadoc)
|
210 |
* @see org.gvsig.fmap.driver.RasterDataset#setView(org.gvsig.fmap.raster.Extent)
|
211 |
*/
|
212 |
public void setView(Extent e) { |
213 |
//TODO: FUNCIONALIDAD: Falta aplicar la transformaci?n a la vista en caso de que haya un fichero .rmf. Mirar EcwFile de piloto
|
214 |
view = new Extent(e);
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* Cuando se hace una petici?n de carga de buffer la extensi?n pedida puede estar ajustada a la extensi?n del raster
|
219 |
* o no estarlo. En caso de no estarlo los pixeles del buffer que caen fuera de la extensi?n del raster tendr?n valor
|
220 |
* de NoData. Esta funci?n calcula en que pixel del buffer hay que empezar a escribir en caso de que este sea mayor
|
221 |
* que los datos a leer.
|
222 |
* @param dWorldTLX Posici?n X superior izquierda en coord reales
|
223 |
* @param dWorldTLY Posici?n Y superior izquierda en coord reales
|
224 |
* @param dWorldBRX Posici?n X inferior derecha en coord reales
|
225 |
* @param dWorldBRY Posici?n Y inferior derecha en coord reales
|
226 |
* @param nWidth Ancho en pixeles del buffer
|
227 |
* @param nHeight Alto en pixeles del buffer
|
228 |
* @return desplazamiento dentro del buffer en X e Y
|
229 |
*/
|
230 |
private int[] calcStepBuffer(Extent dataExtent, int nWidth, int nHeight, int[] stpBuffer){ |
231 |
Extent imageExtent = new Extent(bBoxWithoutRot.minX, bBoxWithoutRot.minY, bBoxWithoutRot.maxX, bBoxWithoutRot.maxY);
|
232 |
Extent ajustDataExtent = RasterUtilities.calculateAdjustedView(dataExtent, imageExtent); |
233 |
if(!RasterUtilities.compareExtents(dataExtent, ajustDataExtent)){
|
234 |
Point2D p1 = worldToRaster(new Point2D.Double(ajustDataExtent.minX(), ajustDataExtent.maxY())); |
235 |
Point2D p2 = worldToRaster(new Point2D.Double(ajustDataExtent.maxX(), ajustDataExtent.minY())); |
236 |
Point2D p3 = worldToRaster(new Point2D.Double(dataExtent.minX(), dataExtent.maxY())); |
237 |
Point2D p4 = worldToRaster(new Point2D.Double(dataExtent.maxX(), dataExtent.minY())); |
238 |
//Ese es el ancho y alto q tendr?a el buffer en caso de haberse ajustado
|
239 |
int w = (int)Math.abs(Math.ceil(p2.getX()) - Math.floor(p1.getX())); |
240 |
int h = (int)Math.abs(Math.floor(p1.getY()) - Math.ceil(p2.getY())); |
241 |
|
242 |
stpBuffer[0] = (int)(p1.getX() + (-p3.getX())); |
243 |
stpBuffer[1] = (int)(p1.getY() + (-p3.getY())); |
244 |
stpBuffer[2] = stpBuffer[0] + w; |
245 |
stpBuffer[3] = stpBuffer[1] + h; |
246 |
return new int[]{w, h}; |
247 |
} |
248 |
return new int[]{nWidth, nHeight}; |
249 |
} |
250 |
|
251 |
/*
|
252 |
* (non-Javadoc)
|
253 |
* @see org.gvsig.fmap.driver.RasterDataset#worldToRaster(java.awt.geom.Point2D)
|
254 |
*/
|
255 |
public Point2D worldToRaster(Point2D pt) { |
256 |
double x = ((pt.getX() - bBoxWithoutRot.minX) * ((double) currentFullWidth)) / (double)(bBoxWithoutRot.maxX - bBoxWithoutRot.minX); |
257 |
double y = ((bBoxWithoutRot.maxY - pt.getY()) * ((double) currentFullHeight)) / (double)(bBoxWithoutRot.maxY - bBoxWithoutRot.minY); |
258 |
Point2D ptRes = new Point2D.Double(x, y); |
259 |
return ptRes;
|
260 |
} |
261 |
|
262 |
/*
|
263 |
* (non-Javadoc)
|
264 |
* @see org.gvsig.fmap.driver.RasterDataset#rasterToWorld(java.awt.geom.Point2D)
|
265 |
*/
|
266 |
public Point2D rasterToWorld(Point2D pt) { |
267 |
double x = bBoxWithoutRot.minX + ((pt.getX() * (bBoxWithoutRot.maxX - bBoxWithoutRot.minX)) / currentFullWidth);
|
268 |
double y = bBoxWithoutRot.maxY - ((pt.getY() * (bBoxWithoutRot.maxY - bBoxWithoutRot.minY)) / currentFullHeight);
|
269 |
Point2D ptRes = new Point2D.Double(x, y); |
270 |
return ptRes;
|
271 |
} |
272 |
|
273 |
/*
|
274 |
* (non-Javadoc)
|
275 |
* @see org.gvsig.fmap.driver.RasterDataset#getWindowRaster(double, double, double, double, org.gvsig.fmap.driver.BandList, org.gvsig.fmap.driver.IBuffer, boolean)
|
276 |
*/
|
277 |
public IBuffer getWindowRaster(double x, double y, double w, double h, BandList bandList, IBuffer rasterBuf, boolean adjustToExtent) { |
278 |
|
279 |
//Si cojemos pixeles completos hemos de calcular las coordenadas reales de esos pixeles completos para hacer la petici?n.
|
280 |
//Este el calculo que se hizo en RasterMultiDataset para calcular pixeles completos, convertir a pixel, redondear el primero
|
281 |
//por abajo y el ultimo por arriba
|
282 |
Point2D p1 = worldToRaster(new Point2D.Double(x, y)); |
283 |
Point2D p2 = worldToRaster(new Point2D.Double(x + w, y - h)); |
284 |
Point2D a = rasterToWorld(new Point2D.Double(Math.floor(p1.getX()), Math.floor(p1.getY()))); |
285 |
Point2D b = rasterToWorld(new Point2D.Double(Math.ceil(p2.getX()), Math.ceil(p2.getY()))); |
286 |
|
287 |
//Extent selectedExtent = new Extent(x, y, x + w, y - h);
|
288 |
Extent selectedExtent = new Extent(a.getX(), a.getY(), b.getX(), b.getY());
|
289 |
setView(selectedExtent); |
290 |
int wPx = rasterBuf.getWidth();
|
291 |
int hPx = rasterBuf.getHeight();
|
292 |
int[] stpBuffer = new int[]{0, 0 , wPx, hPx}; |
293 |
|
294 |
//TODO: FUNCIONALIDAD: Implementar adjustToExtent = false
|
295 |
/*if(!adjustToExtent){
|
296 |
int[] wh = calcStepBuffer(selectedExtent, wPx, hPx, stpBuffer);
|
297 |
if(x < 0)
|
298 |
x = 0;
|
299 |
if(y < 0)
|
300 |
y = 0;
|
301 |
readData(buf, bandList, x, y, wh[0], wh[1], wh[0], wh[1], 0, 0, stpBuffer);
|
302 |
return;
|
303 |
}*/
|
304 |
|
305 |
loadBuffer(selectedExtent, wPx, hPx, rasterBuf, bandList, stpBuffer); |
306 |
|
307 |
return rasterBuf;
|
308 |
} |
309 |
|
310 |
/*
|
311 |
* (non-Javadoc)
|
312 |
* @see org.gvsig.fmap.driver.RasterDataset#getWindowRaster(int, int, int, int, org.gvsig.fmap.driver.BandList, org.gvsig.fmap.driver.IBuffer)
|
313 |
*/
|
314 |
public IBuffer getWindowRaster(int x, int y, int w, int h, BandList bandList, IBuffer rasterBuf) { |
315 |
Point2D init = this.rasterToWorld(new Point2D.Double(x, y)); |
316 |
Point2D end = this.rasterToWorld(new Point2D.Double(x + w, y + h)); |
317 |
Extent selectedExtent = new Extent(init.getX(), init.getY(), end.getX(), end.getY());
|
318 |
setView(selectedExtent); |
319 |
int[] stpBuffer = new int[]{0, 0 , w, h}; |
320 |
|
321 |
loadBuffer(selectedExtent, w, h, rasterBuf, bandList, stpBuffer); |
322 |
return rasterBuf;
|
323 |
} |
324 |
|
325 |
/*
|
326 |
* (non-Javadoc)
|
327 |
* @see org.gvsig.fmap.driver.RasterDataset#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.driver.BandList, org.gvsig.fmap.driver.IBuffer, boolean)
|
328 |
*/
|
329 |
public IBuffer getWindowRaster(double minX, double minY, double maxX, double maxY, int bufWidth, int bufHeight, BandList bandList, IBuffer rasterBuf, boolean adjustToExtent) { |
330 |
Extent selectedExtent = new Extent(minX, maxY, maxX, minY);
|
331 |
setView(selectedExtent); |
332 |
int[] stpBuffer = new int[]{0, 0 , bufWidth, bufHeight}; |
333 |
|
334 |
//TODO: FUNCIONALIDAD: Implementar adjustToExtent = false
|
335 |
|
336 |
loadBuffer(selectedExtent, bufWidth, bufHeight, rasterBuf, bandList, stpBuffer); |
337 |
return rasterBuf;
|
338 |
} |
339 |
|
340 |
/*
|
341 |
* (non-Javadoc)
|
342 |
* @see org.gvsig.fmap.driver.RasterDataset#getWindowRaster(int, int, int, int, int, int, org.gvsig.fmap.driver.BandList, org.gvsig.fmap.driver.IBuffer)
|
343 |
*/
|
344 |
public IBuffer getWindowRaster(int x, int y, int w, int h, int bufWidth, int bufHeight, BandList bandList, IBuffer rasterBuf) { |
345 |
Point2D init = this.rasterToWorld(new Point2D.Double(x, y)); |
346 |
Point2D end = this.rasterToWorld(new Point2D.Double(x + w, y + h)); |
347 |
Extent selectedExtent = new Extent(init.getX(), init.getY(), end.getX(), end.getY());
|
348 |
setView(selectedExtent); |
349 |
int[] stpBuffer = new int[]{0, 0 , bufWidth, bufHeight}; |
350 |
|
351 |
loadBuffer(selectedExtent, bufWidth, bufHeight, rasterBuf, bandList, stpBuffer); |
352 |
return rasterBuf;
|
353 |
} |
354 |
|
355 |
/**
|
356 |
* Carga el buffer con las bandas RGB del raster con los par?metros especificados de extensi?n
|
357 |
* y tama?o de buffer. El problema de ecw es que solo podemos leer 3 bandas de una vez ya que solo disponemos
|
358 |
* de una llamada readLineRGBA. Para leer m?s bandas tendremos que hacer multiples llamadas a setView para leer
|
359 |
* 3 cada vez.
|
360 |
*
|
361 |
* Si por ejemplo tenemos un ecw de 6 bandas [0, 1, 2, 3, 4, 5] y queremos cargar un buffer con el siguiente orden
|
362 |
* [0, -, 2, -, 4, -] La variable readBandsFromECW har? la llamada a setView con los valores [0, 2, 4, 0, 0, 0]. La
|
363 |
* funci?n drawRGB ser? la encargada de hacer el switch para obtener [0, -, 2, -, 4, -].
|
364 |
*
|
365 |
* Bug#1: Si se dispone de un ecw de m?s de tres bandas podemos llamar a setView con readBandsFromECW con el orden
|
366 |
* que queramos, por ejemplo [3, 2, 5, 1, 0] pero para ecw de 3 bandas la llamada con las bandas cambiadas no
|
367 |
* hace caso. El caso de readBandsFromECW = [2, 0, 1] ser? tomado siempre como [0, 1, 2].
|
368 |
*
|
369 |
* @param selectedExtent Extensi?n seleccionada
|
370 |
* @param bufWidth Ancho de buffer
|
371 |
* @param bufHeight Alto de buffer
|
372 |
* @param rasterBuf Buffer de datos
|
373 |
*/
|
374 |
private void loadBuffer(Extent selectedExtent, int bufWidth, int bufHeight, IBuffer rasterBuf, BandList bandList, int[] stpBuffer){ |
375 |
try{
|
376 |
//Leemos el raster desde la librer?a
|
377 |
|
378 |
int[] readBandsFromECW = new int[file.numBands]; |
379 |
int[] readBands = new int[file.numBands]; |
380 |
|
381 |
|
382 |
for(int i = 0; i < readBandsFromECW.length; i ++) |
383 |
readBands[i] = -1;
|
384 |
int cont = 0; |
385 |
for(int i = 0; i < file.numBands; i++){ |
386 |
int[] bandsToDraw = bandList.getBand(i).getDataImageBandToDraw(); |
387 |
if(bandsToDraw != null){ |
388 |
for(int j = 0; j < bandsToDraw.length; j++){ |
389 |
readBandsFromECW[cont] = i; |
390 |
readBands[cont] = i; |
391 |
cont ++; |
392 |
} |
393 |
} |
394 |
|
395 |
} |
396 |
|
397 |
file.setView(file.numBands, readBandsFromECW, selectedExtent.minX(), selectedExtent.maxY(), selectedExtent.maxX(), selectedExtent.minY(), bufWidth, bufHeight); |
398 |
|
399 |
//Escribimos el raster sobre un IBuffer
|
400 |
int[] pRGBArray = new int[bufWidth]; |
401 |
drawRGB(rasterBuf, pRGBArray, readBands, bandList); |
402 |
|
403 |
}catch(JNCSInvalidSetViewException exc){
|
404 |
exc.printStackTrace(); |
405 |
}catch (JNCSFileNotOpenException e) {
|
406 |
e.printStackTrace(); |
407 |
}catch (JNCSException ex) {
|
408 |
ex.printStackTrace(); |
409 |
} |
410 |
|
411 |
} |
412 |
|
413 |
|
414 |
private void drawRGB(IBuffer rasterBuf, int[] pRGBArray, int[] readBands, BandList bandList)throws JNCSException{ |
415 |
byte data = 0; |
416 |
int bandR = readBands[0]; |
417 |
int bandG = (readBands.length > 1) ? readBands[1] : -1; |
418 |
int bandB = (readBands.length > 2) ? readBands[2] : -1; |
419 |
|
420 |
//********* caso especial que resuelve Bug#1 **********************
|
421 |
if(file.numBands == 3 && bandList.getDrawableBandsCount() < 3){ |
422 |
for(int i = 0; i < 3; i ++){ |
423 |
int[] b = bandList.getBand(i).getDataImageBandToDraw(); |
424 |
if(b != null){ |
425 |
bandG = 1; bandR = 0; bandB = 2; |
426 |
} |
427 |
} |
428 |
} |
429 |
if(file.numBands == 3 && bandR == bandG && bandG == bandB){ //caso especial que resuelve Bug#1 |
430 |
for(int i = 0; i < 3; i ++){ |
431 |
int[] b = bandList.getBand(i).getDataImageBandToDraw(); |
432 |
if(b != null){ |
433 |
if(i == 0){ |
434 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
435 |
file.readLineRGBA(pRGBArray); |
436 |
for(int col = 0; col < pRGBArray.length; col ++){ |
437 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16)); |
438 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x00ff0000) >> 16)); |
439 |
rasterBuf.setElem(line, col, bandB, (byte)((pRGBArray[col] & 0x00ff0000) >> 16)); |
440 |
} |
441 |
} |
442 |
return;
|
443 |
} |
444 |
if(i == 1){ |
445 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
446 |
file.readLineRGBA(pRGBArray); |
447 |
for(int col = 0; col < pRGBArray.length; col ++){ |
448 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x0000ff00) >> 8)); |
449 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x0000ff00) >> 8)); |
450 |
rasterBuf.setElem(line, col, bandB, (byte)((pRGBArray[col] & 0x0000ff00) >> 8)); |
451 |
} |
452 |
} |
453 |
return;
|
454 |
} |
455 |
if(i == 2){ |
456 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
457 |
file.readLineRGBA(pRGBArray); |
458 |
for(int col = 0; col < pRGBArray.length; col ++){ |
459 |
rasterBuf.setElem(line, col, bandR, (byte)(pRGBArray[col] & 0x000000ff)); |
460 |
rasterBuf.setElem(line, col, bandG, (byte)(pRGBArray[col] & 0x000000ff)); |
461 |
rasterBuf.setElem(line, col, bandB, (byte)(pRGBArray[col] & 0x000000ff)); |
462 |
} |
463 |
} |
464 |
return;
|
465 |
} |
466 |
} |
467 |
} |
468 |
|
469 |
} |
470 |
//********* END caso especial que resuelve Bug#1 **********************
|
471 |
|
472 |
if(bandR >= 0 && bandG >= 0 && bandB >= 0){ |
473 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
474 |
file.readLineRGBA(pRGBArray); |
475 |
for(int col = 0; col < pRGBArray.length; col ++){ |
476 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16)); |
477 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x0000ff00) >> 8)); |
478 |
rasterBuf.setElem(line, col, bandB, (byte)(pRGBArray[col] & 0x000000ff)); |
479 |
} |
480 |
} |
481 |
return;
|
482 |
} |
483 |
|
484 |
if(bandR >= 0 && bandG >= 0){ |
485 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
486 |
file.readLineRGBA(pRGBArray); |
487 |
for(int col = 0; col < pRGBArray.length; col ++){ |
488 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16)); |
489 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x0000ff00) >> 8)); |
490 |
} |
491 |
} |
492 |
return;
|
493 |
} |
494 |
|
495 |
if(bandR >= 0){ |
496 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
497 |
file.readLineRGBA(pRGBArray); |
498 |
for(int col = 0; col < pRGBArray.length; col ++) |
499 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16)); |
500 |
} |
501 |
return;
|
502 |
} |
503 |
|
504 |
} |
505 |
|
506 |
public void reProject(ICoordTrans rp) { |
507 |
} |
508 |
|
509 |
public void setExtentTransform(double originX, double originY, double psX, double psY) { |
510 |
} |
511 |
|
512 |
public int getBlockSize() { |
513 |
return 0; |
514 |
} |
515 |
|
516 |
/*
|
517 |
* (non-Javadoc)
|
518 |
* @see org.gvsig.raster.driver.RasterDataset#readCompletetLine(int, int)
|
519 |
*/
|
520 |
public Object readCompleteLine(int line, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
521 |
if(line < 0 || line >= file.height || band < 0 || band >= getBandCount()) |
522 |
throw new InvalidSetViewException("Request out of grid"); |
523 |
|
524 |
Point2D begin = rasterToWorld(new Point2D.Double(0, line)); |
525 |
Point2D end = rasterToWorld(new Point2D.Double(file.width, line + 1)); |
526 |
int[] readBandsFromECW = new int[file.numBands]; |
527 |
if(file.numBands <= 3) { |
528 |
for(int i = 0; i < file.numBands; i++) |
529 |
readBandsFromECW[i] = i; |
530 |
}else {
|
531 |
readBandsFromECW[0] = band;
|
532 |
} |
533 |
|
534 |
Extent e = new Extent(begin.getX(), begin.getY(), end.getX(), end.getY());
|
535 |
|
536 |
try {
|
537 |
int[] value = new int[file.width]; |
538 |
file.setView(file.numBands, readBandsFromECW, e.minX(), e.maxY(), e.maxX(), e.minY(), file.width, 1);
|
539 |
file.readLineRGBA(value); |
540 |
|
541 |
if(file.numBands <= 3) { |
542 |
switch(getDataType()) {
|
543 |
case IBuffer.TYPE_BYTE: byte[] b = new byte[file.width]; |
544 |
switch(band) {
|
545 |
case 0: for(int i = 0; i < file.width; i ++) |
546 |
b[i] = (byte)(((value[i] & 0x00ff0000) >> 16) & 0xff); |
547 |
break;
|
548 |
case 1: for(int i = 0; i < file.width; i ++) |
549 |
b[i] = (byte)(((value[i] & 0x0000ff00) >> 8) & 0xff); |
550 |
break;
|
551 |
case 2: for(int i = 0; i < file.width; i ++) |
552 |
b[i] = (byte)((value[i] & 0x000000ff) & 0xff); |
553 |
break;
|
554 |
} |
555 |
return b;
|
556 |
} |
557 |
}else {
|
558 |
switch(getDataType()) {
|
559 |
case IBuffer.TYPE_BYTE: byte[] b = new byte[file.width]; |
560 |
for(int i = 0; i < file.width; i ++) |
561 |
b[i] = (byte)(((value[i] & 0x00ff0000) >> 16) & 0xff); |
562 |
break;
|
563 |
} |
564 |
} |
565 |
//TODO: FUNCIONALIDAD: Ecw con otro tipo de dato != Byte
|
566 |
} catch (JNCSFileNotOpenException e1) {
|
567 |
throw new FileNotOpenException("Error en jecw: JNCSFileNotOpenException"); |
568 |
} catch (JNCSInvalidSetViewException e1) {
|
569 |
throw new FileNotOpenException("Error en jecw: JNCSInvalidSetViewException"); |
570 |
} catch (JNCSException e1) {
|
571 |
throw new RasterDriverException("Error la lectura de datos ecw"); |
572 |
} |
573 |
|
574 |
return null; |
575 |
} |
576 |
|
577 |
/*
|
578 |
* (non-Javadoc)
|
579 |
* @see org.gvsig.raster.driver.RasterDataset#getData(int, int, int)
|
580 |
*/
|
581 |
public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
582 |
if(x < 0 || y < 0 || x >= file.width || y >= file.height) |
583 |
throw new InvalidSetViewException("Request out of grid"); |
584 |
|
585 |
Point2D begin = rasterToWorld(new Point2D.Double(x, y)); |
586 |
Point2D end = rasterToWorld(new Point2D.Double(x + 1, y + 1)); |
587 |
int[] readBandsFromECW = new int[file.numBands]; |
588 |
if(file.numBands <= 3){ |
589 |
for(int i = 0; i < file.numBands; i++) |
590 |
readBandsFromECW[i] = i; |
591 |
}else{
|
592 |
readBandsFromECW[0] = band;
|
593 |
} |
594 |
|
595 |
Extent e = new Extent(begin.getX(), begin.getY(), end.getX(), end.getY());
|
596 |
try {
|
597 |
int[] value = new int[1]; |
598 |
file.setView(file.numBands, readBandsFromECW, e.minX(), e.maxY(), e.maxX(), e.minY(), 1, 1); |
599 |
file.readLineRGBA(value); |
600 |
if(file.numBands <= 3){ |
601 |
switch(band){
|
602 |
case 0: return new Integer((((value[0] & 0x00ff0000) >> 16) & 0xffffffff)); |
603 |
case 1: return new Integer((((value[0] & 0x0000ff00) >> 8) & 0xffffffff)); |
604 |
case 2: return new Integer((((value[0] & 0x000000ff)) & 0xffffffff)); |
605 |
} |
606 |
} |
607 |
return new Integer((((value[0] & 0x00ff0000) >> 16) & 0xffffffff)); |
608 |
} catch (JNCSFileNotOpenException e1) {
|
609 |
throw new FileNotOpenException("Error en jecw: JNCSFileNotOpenException"); |
610 |
} catch (JNCSInvalidSetViewException e1) {
|
611 |
throw new FileNotOpenException("Error en jecw: JNCSInvalidSetViewException"); |
612 |
} catch (JNCSException e1) {
|
613 |
throw new RasterDriverException("Error reading ecw data"); |
614 |
} |
615 |
} |
616 |
|
617 |
public void refreshUpdate(int arg0, int arg1, double arg2, double arg3, double arg4, double arg5) { |
618 |
} |
619 |
|
620 |
public void refreshUpdate(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5) { |
621 |
} |
622 |
|
623 |
/*
|
624 |
* (non-Javadoc)
|
625 |
* @see org.gvsig.raster.driver.GeoData#getStringProjection()
|
626 |
*/
|
627 |
public String getStringProjection() throws RasterDriverException{ |
628 |
return file.projection;
|
629 |
} |
630 |
|
631 |
} |
632 |
|
633 |
|
634 |
|