Revision 12567 trunk/libraries/libRaster/src/org/gvsig/raster/dataset/io/EcwDriver.java
EcwDriver.java | ||
---|---|---|
45 | 45 |
import com.ermapper.ecw.JNCSFileNotOpenException; |
46 | 46 |
import com.ermapper.ecw.JNCSInvalidSetViewException; |
47 | 47 |
import com.ermapper.ecw.JNCSProgressiveUpdate; |
48 |
|
|
49 |
import es.gva.cit.jgdal.GdalException; |
|
50 |
|
|
51 |
|
|
52 | 48 |
/** |
53 | 49 |
* Driver de Ecw |
54 |
*
|
|
50 |
* |
|
55 | 51 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
56 | 52 |
*/ |
57 | 53 |
public class EcwDriver extends RasterDataset implements JNCSProgressiveUpdate { |
58 |
|
|
54 |
|
|
59 | 55 |
private JNCSFile file = null; |
60 | 56 |
private int currentFullWidth = -1; |
61 | 57 |
private int currentFullHeight = -1; |
... | ... | |
68 | 64 |
* Estado de transparencia del raster. |
69 | 65 |
*/ |
70 | 66 |
protected Transparency fileTransparency = null; |
71 |
|
|
67 |
|
|
72 | 68 |
/** |
73 | 69 |
* Extent de la ventana seleccionada |
74 | 70 |
*/ |
75 |
private Extent viewRequest = null;
|
|
71 |
private Extent viewRequest = null;
|
|
76 | 72 |
private boolean readCancel = false; |
77 |
|
|
73 |
|
|
78 | 74 |
public static void register() { |
79 | 75 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
80 | 76 |
extensionPoints.add("RasterReader", "ecw", EcwDriver.class); |
81 | 77 |
extensionPoints.add("RasterReader", "jp2", EcwDriver.class); |
82 | 78 |
} |
83 |
|
|
79 |
|
|
84 | 80 |
class Contour extends Vector { |
85 | 81 |
final private static long serialVersionUID = 0; |
86 | 82 |
public double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE; |
... | ... | |
96 | 92 |
if (pt.getY() < minY) minY = pt.getY(); |
97 | 93 |
} |
98 | 94 |
} |
99 |
|
|
95 |
|
|
100 | 96 |
/** |
101 | 97 |
* Constructor. Abre el dataset. |
102 | 98 |
* @param proj Proyecci?n |
... | ... | |
106 | 102 |
public EcwDriver(IProjection proj, Object param)throws NotSupportedExtensionException { |
107 | 103 |
super(proj, ((String)param)); |
108 | 104 |
setParam(param); |
109 |
extent = new Extent();
|
|
110 |
try {
|
|
105 |
extent = new Extent();
|
|
106 |
try {
|
|
111 | 107 |
|
112 |
if (!new File(((String)param)).exists() && !((String)param).startsWith("ecwp:"))
|
|
113 |
throw new NotSupportedExtensionException("Extension not supported");
|
|
108 |
if (!new File(((String)param)).exists() && !((String)param).startsWith("ecwp:"))
|
|
109 |
throw new NotSupportedExtensionException("Extension not supported");
|
|
114 | 110 |
|
115 |
file = new JNCSFile(((String)param), false); |
|
116 |
load(); |
|
117 |
//readGeoInfo(fName); |
|
118 |
bandCount = file.numBands; |
|
119 |
getTransparencyDatasetStatus(); |
|
120 |
setDataType(IBuffer.TYPE_BYTE); |
|
121 |
|
|
122 |
super.init(); |
|
123 |
|
|
124 |
try { |
|
125 |
loadFromRmf(getRmfBlocksManager()); |
|
126 |
} catch (ParsingException e) { |
|
127 |
//No lee desde rmf |
|
128 |
} |
|
129 |
|
|
130 |
} catch (Exception e) { |
|
131 |
throw new NotSupportedExtensionException("Extension not supported"); |
|
132 |
} |
|
133 |
} |
|
111 |
file = new JNCSFile(((String)param), false); |
|
112 |
load(); |
|
113 |
//readGeoInfo(fName); |
|
114 |
bandCount = file.numBands; |
|
115 |
getTransparencyDatasetStatus(); |
|
116 |
setDataType(IBuffer.TYPE_BYTE); |
|
134 | 117 |
|
118 |
super.init(); |
|
119 |
|
|
120 |
try { |
|
121 |
loadFromRmf(getRmfBlocksManager()); |
|
122 |
} catch (ParsingException e) { |
|
123 |
//No lee desde rmf |
|
124 |
} |
|
125 |
|
|
126 |
} catch (Exception e) { |
|
127 |
throw new NotSupportedExtensionException("Extension not supported"); |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
135 | 131 |
/** |
136 |
* Carga un ECW.
|
|
137 |
* @param fname
|
|
138 |
*/
|
|
139 |
public GeoInfo load() {
|
|
140 |
double minX;
|
|
141 |
double minY;
|
|
142 |
double maxX;
|
|
143 |
double maxY;
|
|
132 |
* Carga un ECW.
|
|
133 |
* @param fname
|
|
134 |
*/
|
|
135 |
public GeoInfo load() {
|
|
136 |
double minX;
|
|
137 |
double minY;
|
|
138 |
double maxX;
|
|
139 |
double maxY;
|
|
144 | 140 |
|
145 |
if(file.cellIncrementY > 0)
|
|
146 |
file.cellIncrementY = -file.cellIncrementY;
|
|
147 |
|
|
148 |
minX = file.originX;
|
|
149 |
maxY = file.originY;
|
|
150 |
maxX = file.originX +
|
|
151 |
((double) (file.width) * file.cellIncrementX);
|
|
152 |
minY = file.originY +
|
|
153 |
((double) (file.height) * file.cellIncrementY);
|
|
154 |
|
|
155 |
currentFullWidth = file.width;
|
|
156 |
currentFullHeight = file.height;
|
|
157 |
boundingBoxWithoutRotation();
|
|
158 |
|
|
159 |
extent = new Extent(minX, minY, maxX, maxY);
|
|
160 |
requestExtent = extent;
|
|
161 |
return this;
|
|
162 |
}
|
|
163 |
|
|
164 |
/**
|
|
141 |
if(file.cellIncrementY > 0)
|
|
142 |
file.cellIncrementY = -file.cellIncrementY;
|
|
143 |
|
|
144 |
minX = file.originX;
|
|
145 |
maxY = file.originY;
|
|
146 |
maxX = file.originX +
|
|
147 |
((double) (file.width) * file.cellIncrementX);
|
|
148 |
minY = file.originY +
|
|
149 |
((double) (file.height) * file.cellIncrementY);
|
|
150 |
|
|
151 |
currentFullWidth = file.width;
|
|
152 |
currentFullHeight = file.height;
|
|
153 |
boundingBoxWithoutRotation();
|
|
154 |
|
|
155 |
extent = new Extent(minX, minY, maxX, maxY);
|
|
156 |
requestExtent = extent;
|
|
157 |
return this;
|
|
158 |
}
|
|
159 |
|
|
160 |
/**
|
|
165 | 161 |
* Calcula la bounding box en la que est? metido el raster teniendo en cuenta |
166 |
* el tama?o de pixel y la rotaci?n.
|
|
162 |
* el tama?o de pixel y la rotaci?n. |
|
167 | 163 |
*/ |
168 | 164 |
private void boundingBoxWithoutRotation() { |
169 | 165 |
double ox = file.originX; |
170 | 166 |
double oy = file.originY; |
171 | 167 |
double resx = file.cellIncrementX; |
172 | 168 |
double resy = file.cellIncrementY; |
173 |
|
|
169 |
|
|
174 | 170 |
bBoxWithoutRot.add(new Point2D.Double(ox, oy)); |
175 | 171 |
bBoxWithoutRot.add(new Point2D.Double(ox + resx * (file.width), oy)); |
176 | 172 |
bBoxWithoutRot.add(new Point2D.Double(ox, oy + resy * (file.height))); |
177 | 173 |
bBoxWithoutRot.add(new Point2D.Double(ox + resx * (file.width), oy + resy * (file.height))); |
178 | 174 |
} |
179 | 175 |
|
180 |
/**
|
|
181 |
* Cierra el fichero ECW
|
|
182 |
*/
|
|
183 |
public void close() {
|
|
184 |
if(file != null){
|
|
185 |
file.close(true);
|
|
186 |
file = null;
|
|
187 |
}
|
|
188 |
}
|
|
189 |
|
|
190 |
/**
|
|
176 |
/**
|
|
177 |
* Cierra el fichero ECW
|
|
178 |
*/
|
|
179 |
public void close() {
|
|
180 |
if(file != null){
|
|
181 |
file.close(true);
|
|
182 |
file = null;
|
|
183 |
}
|
|
184 |
}
|
|
185 |
|
|
186 |
/**
|
|
191 | 187 |
* Obtiene el objeto que contiene el estado de la transparencia |
192 | 188 |
*/ |
193 | 189 |
public Transparency getTransparencyDatasetStatus() { |
... | ... | |
195 | 191 |
fileTransparency = new Transparency(); |
196 | 192 |
return fileTransparency; |
197 | 193 |
} |
198 |
|
|
199 |
/** |
|
200 |
* Devuelve el ancho de la imagen |
|
201 |
*/ |
|
202 |
public int getWidth() { |
|
203 |
return file.width; |
|
204 |
} |
|
205 | 194 |
|
206 |
/** |
|
207 |
* Devuelve el alto de la imagen |
|
208 |
*/ |
|
209 |
public int getHeight() { |
|
210 |
return file.height; |
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
195 |
/** |
|
196 |
* Devuelve el ancho de la imagen |
|
197 |
*/ |
|
198 |
public int getWidth() { |
|
199 |
return file.width; |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* Devuelve el alto de la imagen |
|
204 |
*/ |
|
205 |
public int getHeight() { |
|
206 |
return file.height; |
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
214 | 210 |
* Obtiene el extent de la ?ltima ventana seleccionada. |
215 | 211 |
* @return Extent |
216 | 212 |
*/ |
217 | 213 |
public Extent getView() { |
218 |
return viewRequest;
|
|
219 |
}
|
|
220 |
|
|
214 |
return viewRequest;
|
|
215 |
}
|
|
216 |
|
|
221 | 217 |
/* |
222 | 218 |
* (non-Javadoc) |
223 | 219 |
* @see org.gvsig.fmap.driver.RasterDataset#setView(org.gvsig.fmap.raster.Extent) |
... | ... | |
233 | 229 |
transformTFW.transform(petInit, petInit); |
234 | 230 |
transformTFW.transform(petEnd, petEnd); |
235 | 231 |
} catch(NoninvertibleTransformException ex) { |
236 |
|
|
232 |
|
|
237 | 233 |
} |
238 | 234 |
viewRequest = new Extent(petInit.getX(), petInit.getY(), petEnd.getX(), petEnd.getY()); |
239 | 235 |
} else |
240 | 236 |
viewRequest = new Extent(e); |
241 |
}
|
|
242 |
|
|
237 |
}
|
|
238 |
|
|
243 | 239 |
/** |
244 | 240 |
* Cuando se hace una petici?n de carga de buffer la extensi?n pedida puede estar ajustada a la extensi?n del raster |
245 | 241 |
* o no estarlo. En caso de no estarlo los pixeles del buffer que caen fuera de la extensi?n del raster tendr?n valor |
... | ... | |
252 | 248 |
* @param nWidth Ancho en pixeles del buffer |
253 | 249 |
* @param nHeight Alto en pixeles del buffer |
254 | 250 |
* @return desplazamiento dentro del buffer en X e Y |
255 |
*/
|
|
251 |
*/ |
|
256 | 252 |
private int[] calcStepBuffer(Extent dataExtent, int nWidth, int nHeight, int[] stpBuffer) { |
257 |
Extent imageExtent = new Extent(bBoxWithoutRot.minX, bBoxWithoutRot.minY, bBoxWithoutRot.maxX, bBoxWithoutRot.maxY);
|
|
258 |
Extent ajustDataExtent = RasterUtilities.calculateAdjustedView(dataExtent, imageExtent);
|
|
259 |
if(!RasterUtilities.compareExtents(dataExtent, ajustDataExtent)) {
|
|
260 |
Point2D p1 = worldToRaster(new Point2D.Double(ajustDataExtent.minX(), ajustDataExtent.maxY()));
|
|
261 |
Point2D p2 = worldToRaster(new Point2D.Double(ajustDataExtent.maxX(), ajustDataExtent.minY()));
|
|
262 |
Point2D p3 = worldToRaster(new Point2D.Double(dataExtent.minX(), dataExtent.maxY()));
|
|
263 |
Point2D p4 = worldToRaster(new Point2D.Double(dataExtent.maxX(), dataExtent.minY()));
|
|
264 |
//Ese es el ancho y alto q tendr?a el buffer en caso de haberse ajustado
|
|
265 |
int w = (int)Math.abs(Math.ceil(p2.getX()) - Math.floor(p1.getX()));
|
|
266 |
int h = (int)Math.abs(Math.floor(p1.getY()) - Math.ceil(p2.getY()));
|
|
267 |
|
|
268 |
stpBuffer[0] = (int)(p1.getX() + (-p3.getX()));
|
|
269 |
stpBuffer[1] = (int)(p1.getY() + (-p3.getY()));
|
|
270 |
stpBuffer[2] = stpBuffer[0] + w;
|
|
271 |
stpBuffer[3] = stpBuffer[1] + h;
|
|
272 |
return new int[]{w, h};
|
|
273 |
}
|
|
274 |
return new int[]{nWidth, nHeight};
|
|
253 |
Extent imageExtent = new Extent(bBoxWithoutRot.minX, bBoxWithoutRot.minY, bBoxWithoutRot.maxX, bBoxWithoutRot.maxY);
|
|
254 |
Extent ajustDataExtent = RasterUtilities.calculateAdjustedView(dataExtent, imageExtent);
|
|
255 |
if(!RasterUtilities.compareExtents(dataExtent, ajustDataExtent)) {
|
|
256 |
Point2D p1 = worldToRaster(new Point2D.Double(ajustDataExtent.minX(), ajustDataExtent.maxY()));
|
|
257 |
Point2D p2 = worldToRaster(new Point2D.Double(ajustDataExtent.maxX(), ajustDataExtent.minY()));
|
|
258 |
Point2D p3 = worldToRaster(new Point2D.Double(dataExtent.minX(), dataExtent.maxY()));
|
|
259 |
Point2D p4 = worldToRaster(new Point2D.Double(dataExtent.maxX(), dataExtent.minY()));
|
|
260 |
//Ese es el ancho y alto q tendr?a el buffer en caso de haberse ajustado
|
|
261 |
int w = (int)Math.abs(Math.ceil(p2.getX()) - Math.floor(p1.getX()));
|
|
262 |
int h = (int)Math.abs(Math.floor(p1.getY()) - Math.ceil(p2.getY()));
|
|
263 |
|
|
264 |
stpBuffer[0] = (int)(p1.getX() + (-p3.getX()));
|
|
265 |
stpBuffer[1] = (int)(p1.getY() + (-p3.getY()));
|
|
266 |
stpBuffer[2] = stpBuffer[0] + w;
|
|
267 |
stpBuffer[3] = stpBuffer[1] + h;
|
|
268 |
return new int[]{w, h};
|
|
269 |
}
|
|
270 |
return new int[]{nWidth, nHeight};
|
|
275 | 271 |
} |
276 |
|
|
272 |
|
|
277 | 273 |
/* |
278 | 274 |
* (non-Javadoc) |
279 | 275 |
* @see org.gvsig.fmap.driver.RasterDataset#worldToRaster(java.awt.geom.Point2D) |
... | ... | |
284 | 280 |
Point2D ptRes = new Point2D.Double(x, y); |
285 | 281 |
return ptRes; |
286 | 282 |
} |
287 |
|
|
283 |
|
|
288 | 284 |
/* |
289 | 285 |
* (non-Javadoc) |
290 | 286 |
* @see org.gvsig.fmap.driver.RasterDataset#rasterToWorld(java.awt.geom.Point2D) |
... | ... | |
295 | 291 |
Point2D ptRes = new Point2D.Double(x, y); |
296 | 292 |
return ptRes; |
297 | 293 |
} |
298 |
|
|
294 |
|
|
299 | 295 |
/* |
300 | 296 |
* (non-Javadoc) |
301 | 297 |
* @see org.gvsig.fmap.driver.RasterDataset#getWindowRaster(double, double, double, double, org.gvsig.fmap.driver.BandList, org.gvsig.fmap.driver.IBuffer, boolean) |
302 | 298 |
*/ |
303 | 299 |
public IBuffer getWindowRaster(double x, double y, double w, double h, BandList bandList, IBuffer rasterBuf, boolean adjustToExtent) { |
304 |
|
|
300 |
|
|
305 | 301 |
//Si cojemos pixeles completos hemos de calcular las coordenadas reales de esos pixeles completos para hacer la petici?n. |
306 | 302 |
//Este el calculo que se hizo en RasterMultiDataset para calcular pixeles completos, convertir a pixel, redondear el primero |
307 | 303 |
//por abajo y el ultimo por arriba |
... | ... | |
316 | 312 |
int wPx = rasterBuf.getWidth(); |
317 | 313 |
int hPx = rasterBuf.getHeight(); |
318 | 314 |
int[] stpBuffer = new int[]{0, 0 , wPx, hPx}; |
319 |
|
|
315 |
|
|
320 | 316 |
//TODO: FUNCIONALIDAD: Implementar adjustToExtent = false |
321 | 317 |
/*if(!adjustToExtent){ |
322 |
int[] wh = calcStepBuffer(selectedExtent, wPx, hPx, stpBuffer);
|
|
323 |
if(x < 0)
|
|
324 |
x = 0;
|
|
325 |
if(y < 0)
|
|
326 |
y = 0;
|
|
327 |
readData(buf, bandList, x, y, wh[0], wh[1], wh[0], wh[1], 0, 0, stpBuffer);
|
|
328 |
return;
|
|
329 |
}*/
|
|
330 |
|
|
318 |
int[] wh = calcStepBuffer(selectedExtent, wPx, hPx, stpBuffer);
|
|
319 |
if(x < 0)
|
|
320 |
x = 0;
|
|
321 |
if(y < 0)
|
|
322 |
y = 0;
|
|
323 |
readData(buf, bandList, x, y, wh[0], wh[1], wh[0], wh[1], 0, 0, stpBuffer);
|
|
324 |
return;
|
|
325 |
}*/
|
|
326 |
|
|
331 | 327 |
loadBuffer(viewRequest, wPx, hPx, rasterBuf, bandList, stpBuffer); |
332 |
|
|
328 |
|
|
333 | 329 |
return rasterBuf; |
334 | 330 |
} |
335 | 331 |
|
... | ... | |
343 | 339 |
Extent selectedExtent = new Extent(init.getX(), init.getY(), end.getX(), end.getY()); |
344 | 340 |
setView(selectedExtent); |
345 | 341 |
int[] stpBuffer = new int[]{0, 0 , w, h}; |
346 |
|
|
342 |
|
|
347 | 343 |
loadBuffer(viewRequest, w, h, rasterBuf, bandList, stpBuffer); |
348 | 344 |
return rasterBuf; |
349 | 345 |
} |
350 |
|
|
346 |
|
|
351 | 347 |
/* |
352 | 348 |
* (non-Javadoc) |
353 | 349 |
* @see org.gvsig.fmap.driver.RasterDataset#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.driver.BandList, org.gvsig.fmap.driver.IBuffer, boolean) |
... | ... | |
356 | 352 |
Extent selectedExtent = new Extent(minX, maxY, maxX, minY); |
357 | 353 |
setView(selectedExtent); |
358 | 354 |
int[] stpBuffer = new int[]{0, 0 , bufWidth, bufHeight}; |
359 |
|
|
355 |
|
|
360 | 356 |
//TODO: FUNCIONALIDAD: Implementar adjustToExtent = false |
361 |
|
|
357 |
|
|
362 | 358 |
loadBuffer(viewRequest, bufWidth, bufHeight, rasterBuf, bandList, stpBuffer); |
363 | 359 |
return rasterBuf; |
364 | 360 |
} |
... | ... | |
373 | 369 |
Extent selectedExtent = new Extent(init.getX(), init.getY(), end.getX(), end.getY()); |
374 | 370 |
setView(selectedExtent); |
375 | 371 |
int[] stpBuffer = new int[]{0, 0 , bufWidth, bufHeight}; |
376 |
|
|
372 |
|
|
377 | 373 |
loadBuffer(viewRequest, bufWidth, bufHeight, rasterBuf, bandList, stpBuffer); |
378 | 374 |
return rasterBuf; |
379 | 375 |
} |
... | ... | |
383 | 379 |
* y tama?o de buffer. El problema de ecw es que solo podemos leer 3 bandas de una vez ya que solo disponemos |
384 | 380 |
* de una llamada readLineRGBA. Para leer m?s bandas tendremos que hacer multiples llamadas a setView para leer |
385 | 381 |
* 3 cada vez. |
386 |
*
|
|
382 |
* |
|
387 | 383 |
* Si por ejemplo tenemos un ecw de 6 bandas [0, 1, 2, 3, 4, 5] y queremos cargar un buffer con el siguiente orden |
388 | 384 |
* [0, -, 2, -, 4, -] La variable readBandsFromECW har? la llamada a setView con los valores [0, 2, 4, 0, 0, 0]. La |
389 | 385 |
* funci?n drawRGB ser? la encargada de hacer el switch para obtener [0, -, 2, -, 4, -]. |
390 |
*
|
|
386 |
* |
|
391 | 387 |
* Bug#1: Si se dispone de un ecw de m?s de tres bandas podemos llamar a setView con readBandsFromECW con el orden |
392 | 388 |
* que queramos, por ejemplo [3, 2, 5, 1, 0] pero para ecw de 3 bandas la llamada con las bandas cambiadas no |
393 |
* hace caso. El caso de readBandsFromECW = [2, 0, 1] ser? tomado siempre como [0, 1, 2].
|
|
394 |
*
|
|
389 |
* hace caso. El caso de readBandsFromECW = [2, 0, 1] ser? tomado siempre como [0, 1, 2]. |
|
390 |
* |
|
395 | 391 |
* @param selectedExtent Extensi?n seleccionada |
396 | 392 |
* @param bufWidth Ancho de buffer |
397 | 393 |
* @param bufHeight Alto de buffer |
... | ... | |
399 | 395 |
*/ |
400 | 396 |
private void loadBuffer(Extent selectedExtent, int bufWidth, int bufHeight, IBuffer rasterBuf, BandList bandList, int[] stpBuffer){ |
401 | 397 |
try{ |
402 |
//Leemos el raster desde la librer?a
|
|
403 |
|
|
398 |
//Leemos el raster desde la librer?a |
|
399 |
|
|
404 | 400 |
int[] readBandsFromECW = new int[file.numBands]; |
405 | 401 |
int[] readBands = new int[file.numBands]; |
406 |
|
|
407 |
|
|
402 |
|
|
403 |
|
|
408 | 404 |
for(int i = 0; i < readBandsFromECW.length; i ++) |
409 | 405 |
readBands[i] = -1; |
410 | 406 |
int cont = 0; |
... | ... | |
419 | 415 |
} |
420 | 416 |
|
421 | 417 |
} |
422 |
|
|
418 |
|
|
423 | 419 |
if(readCancel) { |
424 | 420 |
readCancel = false; |
425 | 421 |
return; |
426 | 422 |
} |
427 |
|
|
423 |
|
|
428 | 424 |
file.setView(file.numBands, readBandsFromECW, selectedExtent.minX(), selectedExtent.maxY(), selectedExtent.maxX(), selectedExtent.minY(), bufWidth, bufHeight); |
429 |
|
|
425 |
|
|
430 | 426 |
//Escribimos el raster sobre un IBuffer |
431 | 427 |
int[] pRGBArray = new int[bufWidth]; |
432 | 428 |
drawRGB(rasterBuf, pRGBArray, readBands, bandList); |
433 |
|
|
429 |
|
|
434 | 430 |
}catch(JNCSInvalidSetViewException exc){ |
435 | 431 |
exc.printStackTrace(); |
436 | 432 |
}catch (JNCSFileNotOpenException e) { |
... | ... | |
438 | 434 |
}catch (JNCSException ex) { |
439 | 435 |
ex.printStackTrace(); |
440 | 436 |
} |
441 |
|
|
437 |
|
|
442 | 438 |
} |
443 |
|
|
444 |
|
|
439 |
|
|
440 |
|
|
445 | 441 |
private void drawRGB(IBuffer rasterBuf, int[] pRGBArray, int[] readBands, BandList bandList)throws JNCSException{ |
446 | 442 |
int bandR = readBands[0]; |
447 | 443 |
int bandG = (readBands.length > 1) ? readBands[1] : -1; |
448 | 444 |
int bandB = (readBands.length > 2) ? readBands[2] : -1; |
449 |
|
|
445 |
|
|
450 | 446 |
//********* caso especial que resuelve Bug#1 ********************** |
451 |
if(file.numBands == 3 && bandList.getDrawableBandsCount() < 3) {
|
|
447 |
if(file.numBands == 3 && bandList.getDrawableBandsCount() < 3) { |
|
452 | 448 |
for(int i = 0; i < 3; i ++){ |
453 | 449 |
int[] b = bandList.getBand(i).getBufferBandListToDraw(); |
454 | 450 |
if(b != null){ |
... | ... | |
462 | 458 |
if(b != null){ |
463 | 459 |
if(i == 0){ |
464 | 460 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
465 |
file.readLineRGBA(pRGBArray);
|
|
466 |
for(int col = 0; col < pRGBArray.length; col ++){
|
|
467 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16));
|
|
468 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x00ff0000) >> 16));
|
|
469 |
rasterBuf.setElem(line, col, bandB, (byte)((pRGBArray[col] & 0x00ff0000) >> 16));
|
|
470 |
}
|
|
471 |
}
|
|
461 |
file.readLineRGBA(pRGBArray);
|
|
462 |
for(int col = 0; col < pRGBArray.length; col ++){
|
|
463 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16));
|
|
464 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x00ff0000) >> 16));
|
|
465 |
rasterBuf.setElem(line, col, bandB, (byte)((pRGBArray[col] & 0x00ff0000) >> 16));
|
|
466 |
}
|
|
467 |
}
|
|
472 | 468 |
return; |
473 | 469 |
} |
474 | 470 |
if(i == 1) { |
475 | 471 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
476 |
file.readLineRGBA(pRGBArray);
|
|
477 |
for(int col = 0; col < pRGBArray.length; col ++){
|
|
478 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x0000ff00) >> 8));
|
|
479 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x0000ff00) >> 8));
|
|
480 |
rasterBuf.setElem(line, col, bandB, (byte)((pRGBArray[col] & 0x0000ff00) >> 8));
|
|
481 |
}
|
|
482 |
}
|
|
472 |
file.readLineRGBA(pRGBArray);
|
|
473 |
for(int col = 0; col < pRGBArray.length; col ++){
|
|
474 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x0000ff00) >> 8));
|
|
475 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x0000ff00) >> 8));
|
|
476 |
rasterBuf.setElem(line, col, bandB, (byte)((pRGBArray[col] & 0x0000ff00) >> 8));
|
|
477 |
}
|
|
478 |
}
|
|
483 | 479 |
return; |
484 | 480 |
} |
485 | 481 |
if(i == 2) { |
486 | 482 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
487 |
file.readLineRGBA(pRGBArray);
|
|
488 |
for(int col = 0; col < pRGBArray.length; col ++){
|
|
489 |
rasterBuf.setElem(line, col, bandR, (byte)(pRGBArray[col] & 0x000000ff));
|
|
490 |
rasterBuf.setElem(line, col, bandG, (byte)(pRGBArray[col] & 0x000000ff));
|
|
491 |
rasterBuf.setElem(line, col, bandB, (byte)(pRGBArray[col] & 0x000000ff));
|
|
492 |
}
|
|
493 |
}
|
|
483 |
file.readLineRGBA(pRGBArray);
|
|
484 |
for(int col = 0; col < pRGBArray.length; col ++){
|
|
485 |
rasterBuf.setElem(line, col, bandR, (byte)(pRGBArray[col] & 0x000000ff));
|
|
486 |
rasterBuf.setElem(line, col, bandG, (byte)(pRGBArray[col] & 0x000000ff));
|
|
487 |
rasterBuf.setElem(line, col, bandB, (byte)(pRGBArray[col] & 0x000000ff));
|
|
488 |
}
|
|
489 |
}
|
|
494 | 490 |
return; |
495 | 491 |
} |
496 | 492 |
} |
... | ... | |
502 | 498 |
|
503 | 499 |
} |
504 | 500 |
//********* END caso especial que resuelve Bug#1 ********************** |
505 |
|
|
501 |
|
|
506 | 502 |
if(bandR >= 0 && bandG >= 0 && bandB >= 0) { |
507 | 503 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
508 |
file.readLineRGBA(pRGBArray);
|
|
509 |
for(int col = 0; col < pRGBArray.length; col ++){
|
|
510 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16));
|
|
511 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x0000ff00) >> 8));
|
|
512 |
rasterBuf.setElem(line, col, bandB, (byte)(pRGBArray[col] & 0x000000ff));
|
|
513 |
}
|
|
514 |
}
|
|
504 |
file.readLineRGBA(pRGBArray);
|
|
505 |
for(int col = 0; col < pRGBArray.length; col ++){
|
|
506 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16));
|
|
507 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x0000ff00) >> 8));
|
|
508 |
rasterBuf.setElem(line, col, bandB, (byte)(pRGBArray[col] & 0x000000ff));
|
|
509 |
}
|
|
510 |
}
|
|
515 | 511 |
return; |
516 | 512 |
} |
517 |
|
|
513 |
|
|
518 | 514 |
if(readCancel) { |
519 | 515 |
readCancel = false; |
520 | 516 |
return; |
521 | 517 |
} |
522 |
|
|
518 |
|
|
523 | 519 |
if(bandR >= 0 && bandG >= 0) { |
524 | 520 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
525 |
file.readLineRGBA(pRGBArray);
|
|
526 |
for(int col = 0; col < pRGBArray.length; col ++){
|
|
527 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16));
|
|
528 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x0000ff00) >> 8));
|
|
529 |
}
|
|
530 |
}
|
|
521 |
file.readLineRGBA(pRGBArray);
|
|
522 |
for(int col = 0; col < pRGBArray.length; col ++){
|
|
523 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16));
|
|
524 |
rasterBuf.setElem(line, col, bandG, (byte)((pRGBArray[col] & 0x0000ff00) >> 8));
|
|
525 |
}
|
|
526 |
}
|
|
531 | 527 |
return; |
532 | 528 |
} |
533 |
|
|
529 |
|
|
534 | 530 |
if(readCancel) { |
535 | 531 |
readCancel = false; |
536 | 532 |
return; |
537 | 533 |
} |
538 |
|
|
534 |
|
|
539 | 535 |
if(bandR >= 0){ |
540 | 536 |
for (int line = 0; line < rasterBuf.getHeight(); line++) { |
541 |
file.readLineRGBA(pRGBArray);
|
|
542 |
for(int col = 0; col < pRGBArray.length; col ++)
|
|
543 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16));
|
|
544 |
}
|
|
537 |
file.readLineRGBA(pRGBArray);
|
|
538 |
for(int col = 0; col < pRGBArray.length; col ++)
|
|
539 |
rasterBuf.setElem(line, col, bandR, (byte)((pRGBArray[col] & 0x00ff0000) >> 16));
|
|
540 |
}
|
|
545 | 541 |
return; |
546 | 542 |
} |
547 |
|
|
543 |
|
|
548 | 544 |
if(readCancel) { |
549 | 545 |
readCancel = false; |
550 | 546 |
return; |
551 | 547 |
} |
552 | 548 |
|
553 | 549 |
} |
554 |
|
|
550 |
|
|
555 | 551 |
public void reProject(ICoordTrans rp) { |
556 | 552 |
} |
557 | 553 |
|
... | ... | |
562 | 558 |
* @param originX Origen de la imagen en la coordenada X |
563 | 559 |
* @param originY Origen de la imagen en la coordenada Y |
564 | 560 |
*/ |
565 |
public void setExtentTransform(double originX, double originY, double psX, double psY) {
|
|
561 |
public void setExtentTransform(double originX, double originY, double psX, double psY) { |
|
566 | 562 |
transformRMF.setToTranslation(originX, originY); |
567 | 563 |
transformRMF.scale(psX, psY); |
568 |
|
|
564 |
|
|
569 | 565 |
transformTFW.setToTranslation(file.originX, file.originY); |
570 | 566 |
transformTFW.scale(file.cellIncrementX, file.cellIncrementY); |
571 | 567 |
} |
... | ... | |
585 | 581 |
public Object readCompleteLine(int line, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
586 | 582 |
if(line < 0 || line >= file.height || band < 0 || band >= getBandCount()) |
587 | 583 |
throw new InvalidSetViewException("Request out of grid"); |
588 |
|
|
584 |
|
|
589 | 585 |
Point2D begin = rasterToWorld(new Point2D.Double(0, line)); |
590 | 586 |
Point2D end = rasterToWorld(new Point2D.Double(file.width, line + 1)); |
591 | 587 |
int[] readBandsFromECW = new int[file.numBands]; |
... | ... | |
595 | 591 |
}else { |
596 | 592 |
readBandsFromECW[0] = band; |
597 | 593 |
} |
598 |
|
|
594 |
|
|
599 | 595 |
Extent e = new Extent(begin.getX(), begin.getY(), end.getX(), end.getY()); |
600 |
|
|
596 |
|
|
601 | 597 |
try { |
602 | 598 |
int[] value = new int[file.width]; |
603 | 599 |
file.setView(file.numBands, readBandsFromECW, e.minX(), e.maxY(), e.maxX(), e.minY(), file.width, 1); |
604 | 600 |
file.readLineRGBA(value); |
605 |
|
|
601 |
|
|
606 | 602 |
if(file.numBands <= 3) { |
607 | 603 |
switch(getDataType()) { |
608 | 604 |
case IBuffer.TYPE_BYTE: byte[] b = new byte[file.width]; |
... | ... | |
635 | 631 |
} catch (JNCSException e1) { |
636 | 632 |
throw new RasterDriverException("Error la lectura de datos ecw"); |
637 | 633 |
} |
638 |
|
|
634 |
|
|
639 | 635 |
return null; |
640 | 636 |
} |
641 |
|
|
637 |
|
|
642 | 638 |
/* |
643 | 639 |
* (non-Javadoc) |
644 | 640 |
* @see org.gvsig.raster.dataset.RasterDataset#readBlock(int, int, int) |
... | ... | |
646 | 642 |
public Object readBlock(int pos, int blockHeight) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
647 | 643 |
if(pos < 0) |
648 | 644 |
throw new InvalidSetViewException("Request out of grid"); |
649 |
|
|
645 |
|
|
650 | 646 |
if((pos + blockHeight) > file.height) |
651 | 647 |
blockHeight = Math.abs(file.height - pos); |
652 |
|
|
648 |
|
|
653 | 649 |
Point2D begin = rasterToWorld(new Point2D.Double(0, pos)); |
654 | 650 |
Point2D end = rasterToWorld(new Point2D.Double(file.width, pos + blockHeight)); |
655 | 651 |
int[] readBandsFromECW = new int[file.numBands]; |
656 |
|
|
652 |
|
|
657 | 653 |
for(int i = 0; i < file.numBands; i++) |
658 | 654 |
readBandsFromECW[i] = i; |
659 |
|
|
655 |
|
|
660 | 656 |
byte[][][] buf = new byte[file.numBands][blockHeight][file.width]; |
661 | 657 |
Extent e = new Extent(begin.getX(), begin.getY(), end.getX(), end.getY()); |
662 | 658 |
e = RasterUtilities.calculateAdjustedView(getExtent(), e); |
663 |
|
|
659 |
|
|
664 | 660 |
try { |
665 | 661 |
int[] value = new int[file.width]; |
666 | 662 |
file.setView(file.numBands, readBandsFromECW, e.minX(), e.maxY(), e.maxX(), e.minY(), file.width, blockHeight); |
667 |
|
|
663 |
|
|
668 | 664 |
if(file.numBands <= 3) { |
669 | 665 |
for (int row = 0; row < blockHeight; row++) { |
670 | 666 |
file.readLineRGBA(value); |
671 | 667 |
switch(getDataType()) { |
672 |
case IBuffer.TYPE_BYTE:
|
|
668 |
case IBuffer.TYPE_BYTE: |
|
673 | 669 |
for(int col = 0; col < file.width; col ++) { |
674 | 670 |
buf[0][row][col] = (byte)(((value[col] & 0x00ff0000) >> 16) & 0xff); |
675 | 671 |
buf[1][row][col] = (byte)(((value[col] & 0x0000ff00) >> 8) & 0xff); |
... | ... | |
678 | 674 |
break; |
679 | 675 |
} |
680 | 676 |
} |
681 |
|
|
677 |
|
|
682 | 678 |
if(readCancel) { |
683 | 679 |
readCancel = false; |
684 | 680 |
return null; |
685 | 681 |
} |
686 |
|
|
682 |
|
|
687 | 683 |
} else { |
688 | 684 |
//TODO: FUNCIONALIDAD: file.numBands > 3 |
689 | 685 |
} |
... | ... | |
696 | 692 |
} catch (JNCSException e1) { |
697 | 693 |
throw new RasterDriverException("Error la lectura de datos ecw"); |
698 | 694 |
} |
699 |
|
|
695 |
|
|
700 | 696 |
return buf; |
701 | 697 |
} |
702 |
|
|
698 |
|
|
703 | 699 |
/* |
704 | 700 |
* (non-Javadoc) |
705 | 701 |
* @see org.gvsig.raster.driver.RasterDataset#getData(int, int, int) |
... | ... | |
707 | 703 |
public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
708 | 704 |
if(x < 0 || y < 0 || x >= file.width || y >= file.height) |
709 | 705 |
throw new InvalidSetViewException("Request out of grid"); |
710 |
|
|
706 |
|
|
711 | 707 |
Point2D begin = rasterToWorld(new Point2D.Double(x, y)); |
712 | 708 |
Point2D end = rasterToWorld(new Point2D.Double(x + 1, y + 1)); |
713 | 709 |
int[] readBandsFromECW = new int[file.numBands]; |
... | ... | |
717 | 713 |
}else{ |
718 | 714 |
readBandsFromECW[0] = band; |
719 | 715 |
} |
720 |
|
|
721 |
Extent e = new Extent(begin.getX(), begin.getY(), end.getX(), end.getY());
|
|
716 |
|
|
717 |
Extent e = new Extent(begin.getX(), begin.getY(), end.getX(), end.getY()); |
|
722 | 718 |
try { |
723 | 719 |
int[] value = new int[1]; |
724 | 720 |
file.setView(file.numBands, readBandsFromECW, e.minX(), e.maxY(), e.maxX(), e.minY(), 1, 1); |
... | ... | |
739 | 735 |
throw new RasterDriverException("Error reading ecw data"); |
740 | 736 |
} |
741 | 737 |
} |
742 |
|
|
738 |
|
|
743 | 739 |
public void refreshUpdate(int arg0, int arg1, double arg2, double arg3, double arg4, double arg5) { |
744 | 740 |
} |
745 | 741 |
|
746 | 742 |
public void refreshUpdate(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5) { |
747 | 743 |
} |
748 |
|
|
744 |
|
|
749 | 745 |
/* |
750 | 746 |
* (non-Javadoc) |
751 | 747 |
* @see org.gvsig.raster.driver.GeoData#getStringProjection() |
... | ... | |
753 | 749 |
public String getStringProjection() throws RasterDriverException{ |
754 | 750 |
return file.projection; |
755 | 751 |
} |
756 |
|
|
752 |
|
|
757 | 753 |
/* |
758 | 754 |
* (non-Javadoc) |
759 | 755 |
* @see org.gvsig.raster.dataset.RasterDataset#setCanceled(boolean, int) |
760 | 756 |
*/ |
761 | 757 |
public void setCanceled(boolean value, int process) { |
762 | 758 |
super.setCanceled(value, process); |
763 |
|
|
759 |
|
|
764 | 760 |
if(process == CANCEL_READ || process == 0) |
765 | 761 |
readCancel = value; |
766 | 762 |
} |
... | ... | |
775 | 771 |
} else |
776 | 772 |
return super.isCanceled(process); |
777 | 773 |
} |
778 |
|
|
774 |
|
|
779 | 775 |
/* |
780 | 776 |
* (non-Javadoc) |
781 | 777 |
* @see org.gvsig.raster.driver.GeoData#getStringProjection() |
Also available in: Unified diff