gvsig-raster / org.gvsig.raster.lizardtech / trunk / org.gvsig.raster.lizardtech / org.gvsig.raster.lizardtech.io / src / main / java / org / gvsig / raster / lizardtech / io / LizardTechProvider.java @ 1054
History | View | Annotate | Download (26.4 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.raster.lizardtech.io; |
23 |
|
24 |
import java.awt.geom.AffineTransform; |
25 |
import java.awt.geom.Point2D; |
26 |
import java.awt.image.BufferedImage; |
27 |
|
28 |
import org.gvsig.fmap.dal.DALFileLocator; |
29 |
import org.gvsig.fmap.dal.DALLocator; |
30 |
import org.gvsig.fmap.dal.DataStore; |
31 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
32 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
33 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
34 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
35 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
36 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
37 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
38 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
39 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
40 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
41 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
42 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
43 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
44 |
import org.gvsig.metadata.MetadataLocator; |
45 |
import org.gvsig.raster.cache.tile.provider.TileListener; |
46 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
47 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
48 |
import org.gvsig.raster.impl.process.RasterTask; |
49 |
import org.gvsig.raster.impl.process.RasterTaskQueue; |
50 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
51 |
import org.gvsig.raster.impl.provider.RasterProvider; |
52 |
import org.gvsig.raster.impl.provider.tile.FileTileServer; |
53 |
import org.gvsig.raster.impl.store.AbstractRasterDataParameters; |
54 |
import org.gvsig.raster.impl.store.DefaultStoreFactory; |
55 |
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation; |
56 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency; |
57 |
import org.gvsig.tools.ToolsLocator; |
58 |
import org.gvsig.tools.task.TaskStatus; |
59 |
|
60 |
import es.gva.cit.jmrsid.MrSIDException; |
61 |
/**
|
62 |
* Clase encargada del acceso a los datos y repintado de imagenes MrSID. Estos
|
63 |
* son registrados con la extensi?n sid
|
64 |
*
|
65 |
* @version 15/05/2008
|
66 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
67 |
*/
|
68 |
public class LizardTechProvider extends DefaultRasterProvider { |
69 |
public static String NAME = "LizardTech Store"; |
70 |
public static String DESCRIPTION = "LizardTech Raster file"; |
71 |
public static final String METADATA_DEFINITION_NAME = "LizardTechStore"; |
72 |
protected LizardTechNative file = null; |
73 |
private Extent viewRequest = null; |
74 |
private DataStoreColorInterpretation colorInterpr = null; |
75 |
protected DataStoreTransparency fileTransparency = null; |
76 |
private boolean open = false; |
77 |
protected static String[] formatList = null; |
78 |
|
79 |
public static void register() { |
80 |
RasterLocator.getManager().registerFileProvidersTiled(LizardTechProvider.class); |
81 |
registerFormats(); |
82 |
|
83 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
84 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
85 |
dataman.registerStoreProvider(NAME, |
86 |
LizardTechProvider.class, LizardTechDataParameters.class); |
87 |
} |
88 |
|
89 |
if(DALFileLocator.getFilesystemServerExplorerManager() != null) |
90 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
91 |
NAME, DESCRIPTION, |
92 |
LizardTechFilesystemServerExplorer.class); |
93 |
|
94 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
95 |
} |
96 |
|
97 |
private static void registerFormats() { |
98 |
formatList = new String[] {"sid"}; |
99 |
for (int i = 0; i < formatList.length; i++) |
100 |
RasterLocator.getManager().addFormat(formatList[i], LizardTechProvider.class); |
101 |
} |
102 |
|
103 |
/*
|
104 |
* (non-Javadoc)
|
105 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getFormatList()
|
106 |
*/
|
107 |
public String[] getFormatList() { |
108 |
return formatList;
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* Returns true if the extension is supported and false if doesn't
|
113 |
* @param ext
|
114 |
* @return
|
115 |
*/
|
116 |
public boolean isExtensionSupported(String ext) { |
117 |
if(ext.indexOf(".") != -1) |
118 |
ext = ext.substring(ext.lastIndexOf(".") + 1, ext.length()); |
119 |
for (int i = 0; i < formatList.length; i++) { |
120 |
if(formatList[i].compareTo(ext) == 0) |
121 |
return true; |
122 |
} |
123 |
return false; |
124 |
} |
125 |
|
126 |
/**
|
127 |
* Mandatory constructor to instantiate an empty provider
|
128 |
*/
|
129 |
public LizardTechProvider() {
|
130 |
} |
131 |
|
132 |
/**
|
133 |
* Constructor. Abre el dataset.
|
134 |
* @param proj Proyecci?n
|
135 |
* @param fName Nombre del fichero ecw
|
136 |
* @throws NotSupportedExtensionException
|
137 |
*/
|
138 |
public LizardTechProvider(String params) throws NotSupportedExtensionException { |
139 |
super(params);
|
140 |
if(params instanceof String) { |
141 |
LizardTechDataParameters p = new LizardTechDataParameters();
|
142 |
p.setURI((String)params);
|
143 |
super.init(p, null, ToolsLocator.getDynObjectManager() |
144 |
.createDynObject( |
145 |
MetadataLocator.getMetadataManager().getDefinition( |
146 |
DataStore.METADATA_DEFINITION_NAME))); |
147 |
init(p, null);
|
148 |
} |
149 |
} |
150 |
|
151 |
public LizardTechProvider(LizardTechDataParameters params,
|
152 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
|
153 |
super(params, storeServices, ToolsLocator.getDynObjectManager()
|
154 |
.createDynObject( |
155 |
MetadataLocator.getMetadataManager().getDefinition( |
156 |
DataStore.METADATA_DEFINITION_NAME))); |
157 |
init(params, storeServices); |
158 |
} |
159 |
|
160 |
/**
|
161 |
* Contructor. Abre el fichero mrsid
|
162 |
* @param proj Proyecci?n
|
163 |
* @param fName Nombre del fichero mrsid
|
164 |
*/
|
165 |
public void init(AbstractRasterDataParameters params, |
166 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
|
167 |
setParam(storeServices, params); |
168 |
try {
|
169 |
file = new LizardTechNative(params.getURI());
|
170 |
load(); |
171 |
bandCount = file.nbands; |
172 |
int[] dt = new int[bandCount]; |
173 |
for (int i = 0; i < dt.length; i++) |
174 |
dt[i] = Buffer.TYPE_BYTE;
|
175 |
setDataType(dt); |
176 |
super.init();
|
177 |
|
178 |
try {
|
179 |
loadFromRmf(getRmfBlocksManager()); |
180 |
} catch (ParsingException e) {
|
181 |
// No lee desde rmf
|
182 |
} |
183 |
} catch (Exception e) { |
184 |
System.out.println("Error en constructor de MrSID"); |
185 |
e.printStackTrace(); |
186 |
file = null;
|
187 |
} |
188 |
open = true;
|
189 |
} |
190 |
|
191 |
/*
|
192 |
* (non-Javadoc)
|
193 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#load()
|
194 |
*/
|
195 |
public RasterProvider load() {
|
196 |
ownTransformation = file.getOwnTransformation(); |
197 |
externalTransformation = (AffineTransform) ownTransformation.clone();
|
198 |
return this; |
199 |
} |
200 |
|
201 |
/*
|
202 |
* (non-Javadoc)
|
203 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isOpen()
|
204 |
*/
|
205 |
public boolean isOpen() { |
206 |
return open;
|
207 |
} |
208 |
|
209 |
/*
|
210 |
* (non-Javadoc)
|
211 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#close()
|
212 |
*/
|
213 |
public void close() { |
214 |
if (file != null) { |
215 |
file.close(); |
216 |
file = null;
|
217 |
} |
218 |
open = false;
|
219 |
} |
220 |
|
221 |
/*
|
222 |
* (non-Javadoc)
|
223 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setView(org.gvsig.fmap.dal.coverage.datastruct.Extent)
|
224 |
*/
|
225 |
public void setView(Extent e) { |
226 |
viewRequest = new ExtentImpl(e);
|
227 |
} |
228 |
|
229 |
/*
|
230 |
* (non-Javadoc)
|
231 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getView()
|
232 |
*/
|
233 |
public Extent getView() {
|
234 |
return viewRequest;
|
235 |
} |
236 |
|
237 |
/*
|
238 |
* (non-Javadoc)
|
239 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWidth()
|
240 |
*/
|
241 |
public double getWidth() { |
242 |
return file.width;
|
243 |
} |
244 |
|
245 |
/*
|
246 |
* (non-Javadoc)
|
247 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getHeight()
|
248 |
*/
|
249 |
public double getHeight() { |
250 |
return file.height;
|
251 |
} |
252 |
|
253 |
/**
|
254 |
* Asigna al objeto Image los valores con los dato de la imagen contenidos en
|
255 |
* el vector de enteros.
|
256 |
* @param image imagen con los datos actuales
|
257 |
* @param startX inicio de la posici?n en X dentro de la imagen
|
258 |
* @param startY inicio de la posici?n en X dentro de la imagen
|
259 |
* @param w Ancho de la imagen
|
260 |
* @param h Alto de la imagen
|
261 |
* @param rgbArray vector que contiene la banda que se va a sustituir
|
262 |
* @param offset desplazamiento
|
263 |
* @param scansize tama?o de imagen recorrida por cada p
|
264 |
*/
|
265 |
protected void setRGBLine(BufferedImage image, int startX, int startY, int w, int h, |
266 |
int[] rgbArray, int offset, int scansize) { |
267 |
image.setRGB(startX, startY, w, h, rgbArray, offset, scansize); |
268 |
} |
269 |
|
270 |
/*
|
271 |
* (non-Javadoc)
|
272 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getData(int, int, int)
|
273 |
*/
|
274 |
public Object getData(int x, int y, int band) throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
275 |
if (file != null) { |
276 |
if (x < 0 || y < 0 || x >= file.width || y >= file.height) |
277 |
throw new InvalidSetViewException("Request out of grid"); |
278 |
Object[] data = file.getData(x, y); |
279 |
return data[band];
|
280 |
} |
281 |
throw new FileNotOpenException("MrSIDNative not exist"); |
282 |
} |
283 |
|
284 |
/*
|
285 |
* (non-Javadoc)
|
286 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getBlockSize()
|
287 |
*/
|
288 |
public int getBlockSize() { |
289 |
return file.blocksize;
|
290 |
} |
291 |
|
292 |
/**
|
293 |
* Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el
|
294 |
* driver el que colocar? el valor de esta variable cada vez que dibuja.
|
295 |
* @return true si se ha supersampleado y false si no se ha hecho.
|
296 |
*/
|
297 |
public boolean isSupersampling() { |
298 |
return file.isSupersampling;
|
299 |
} |
300 |
|
301 |
/*
|
302 |
* (non-Javadoc)
|
303 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.raster.cache.tile.provider.TileListener)
|
304 |
*/
|
305 |
public void getWindow(Extent ex, int bufWidth, int bufHeight, |
306 |
BandList bandList, TileListener listener, TaskStatus status)throws ProcessInterruptedException, RasterDriverException {
|
307 |
|
308 |
} |
309 |
|
310 |
/*
|
311 |
* (non-Javadoc)
|
312 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
|
313 |
*/
|
314 |
public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf, TaskStatus status) |
315 |
throws ProcessInterruptedException, RasterDriverException {
|
316 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
|
317 |
|
318 |
// TODO: FUNCIONALIDAD: Hacer caso del bandList
|
319 |
int width = rasterBuf.getWidth();
|
320 |
int height = rasterBuf.getHeight();
|
321 |
|
322 |
// Impedimos que los valores de ancho y alto de la im?gen sean menores que 1
|
323 |
if (width <= 0) |
324 |
width = 1;
|
325 |
|
326 |
if (height <= 0) |
327 |
height = 1;
|
328 |
|
329 |
setView(ex); |
330 |
file.setView(viewRequest.getULX(), viewRequest.getULY(), viewRequest.getLRX(), viewRequest.getLRY(), width, height); |
331 |
|
332 |
int[] pRGBArray = new int[width * height]; |
333 |
|
334 |
try {
|
335 |
file.readScene(pRGBArray, task); |
336 |
loadBuffer(rasterBuf.getHeight(), rasterBuf.getWidth(), bandList, rasterBuf, pRGBArray); |
337 |
} catch (MrSIDException e) {
|
338 |
throw new RasterDriverException("Error reading data"); |
339 |
} |
340 |
return rasterBuf;
|
341 |
} |
342 |
|
343 |
/*
|
344 |
* (non-Javadoc)
|
345 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
|
346 |
*/
|
347 |
public Buffer getWindow(double ulx, double uly, double w, double h, |
348 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
349 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
|
350 |
|
351 |
// El incremento o decremento de las X e Y depende de los signos de rotaci?n
|
352 |
// y escala en la matriz de transformaci?n. Por esto
|
353 |
// tenemos que averiguar si lrx es x + w o x -w, asi como si lry es y + h o
|
354 |
// y - h
|
355 |
Extent ext = getExtent(); |
356 |
Point2D pInit = rasterToWorld(new Point2D.Double(0, 0)); |
357 |
Point2D pEnd = rasterToWorld(new Point2D.Double(getWidth(), getHeight())); |
358 |
double wRaster = Math.abs(pEnd.getX() - pInit.getX()); |
359 |
double hRaster = Math.abs(pEnd.getY() - pInit.getY()); |
360 |
double lrx = (((ext.getULX() - wRaster) > ext.maxX()) || ((ext.getULX() - wRaster) < ext.minX())) ? (ulx + w) : (ulx - w);
|
361 |
double lry = (((ext.getULY() - hRaster) > ext.maxY()) || ((ext.getULY() - hRaster) < ext.minY())) ? (uly + h) : (uly - h);
|
362 |
|
363 |
// TODO: FUNCIONALIDAD: Hacer caso del bandList
|
364 |
int width = rasterBuf.getWidth();
|
365 |
int height = rasterBuf.getHeight();
|
366 |
|
367 |
// Impedimos que los valores de ancho y alto de la im?gen sean menores que 1
|
368 |
if (width <= 0) |
369 |
width = 1;
|
370 |
|
371 |
if (height <= 0) |
372 |
height = 1;
|
373 |
|
374 |
setView(new ExtentImpl(ulx, uly, lrx, lry));
|
375 |
file.setView(viewRequest.minX(), viewRequest.maxY(), viewRequest.maxX(), viewRequest.minY(), width, height); |
376 |
|
377 |
int[] pRGBArray = new int[width * height]; |
378 |
|
379 |
try {
|
380 |
file.readScene(pRGBArray, task); |
381 |
loadBuffer(rasterBuf.getHeight(), rasterBuf.getWidth(), bandList, rasterBuf, pRGBArray); |
382 |
} catch (MrSIDException e) {
|
383 |
throw new RasterDriverException("Error reading data"); |
384 |
} |
385 |
return rasterBuf;
|
386 |
} |
387 |
|
388 |
/*
|
389 |
* (non-Javadoc)
|
390 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
|
391 |
*/
|
392 |
public Buffer getWindow(Extent extent, int bufWidth, int bufHeight, |
393 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
394 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
|
395 |
|
396 |
// Impedimos que los valores de ancho y alto de la im?gen sean menores que 1
|
397 |
if (bufWidth <= 0) |
398 |
bufWidth = 1;
|
399 |
|
400 |
if (bufHeight <= 0) |
401 |
bufHeight = 1;
|
402 |
|
403 |
setView(extent); |
404 |
file.setView(viewRequest.getULX(), viewRequest.getULY(), viewRequest.getLRX(), viewRequest.getLRY(), bufWidth, bufHeight); |
405 |
|
406 |
int[] pRGBArray = new int[bufWidth * bufHeight]; |
407 |
|
408 |
try {
|
409 |
file.readScene(pRGBArray, task); |
410 |
loadBuffer(rasterBuf.getHeight(), rasterBuf.getWidth(), bandList, rasterBuf, pRGBArray); |
411 |
} catch (MrSIDException e) {
|
412 |
throw new RasterDriverException("Error reading data"); |
413 |
} |
414 |
return rasterBuf;
|
415 |
} |
416 |
|
417 |
// private void loadCachedBuffer( Buffer buf,
|
418 |
// Extent inputWindow,
|
419 |
// RasterTask task,
|
420 |
// int[] pRGBArray,
|
421 |
// BandList bandList) throws ProcessInterruptedException, MrSIDException {
|
422 |
// if(buf.isCached()) {
|
423 |
// Point2D blockHeightWC = rasterToWorld(new Point2D.Double(buf.getBlockHeight(), buf.getBlockHeight()));
|
424 |
// int nBlocks = (int)(inputWindow.height() / blockHeightWC.getX());
|
425 |
// double lastblockWC = inputWindow.height() - (nBlocks * blockHeightWC.getX());
|
426 |
// int lastBlock = buf.getHeight() - (nBlocks * buf.getBlockHeight());
|
427 |
// if(lastblockWC > 0)
|
428 |
// nBlocks ++;
|
429 |
// double init = inputWindow.getULY();
|
430 |
// Extent ext = null;
|
431 |
// for (int i = 0; i < nBlocks; i++) {
|
432 |
// if(lastblockWC > 0 && i == (nBlocks - 1)) {
|
433 |
// ext = RasterLocator.getManager().getDataStructFactory().createExtent(
|
434 |
// inputWindow.getULX(),
|
435 |
// init,
|
436 |
// inputWindow.getLRX(),
|
437 |
// lastblockWC);
|
438 |
// file.setView(ext.getULX(), ext.getULY(), ext.getLRX(), ext.getLRY(), buf.getWidth(), buf.getBlockHeight());
|
439 |
// file.readScene(pRGBArray, task);
|
440 |
// loadPartialBuffer(new int[]{0, i * buf.getBlockHeight(), buf.getWidth(), buf.getHeight() },
|
441 |
// bandList,
|
442 |
// buf,
|
443 |
// pRGBArray,
|
444 |
// buf.getWidth());
|
445 |
// } else {
|
446 |
// ext = RasterLocator.getManager().getDataStructFactory().createExtent(
|
447 |
// inputWindow.getULX(),
|
448 |
// init,
|
449 |
// inputWindow.getLRX(),
|
450 |
// init - blockHeightWC.getX());
|
451 |
// file.setView(ext.getULX(), ext.getULY(), ext.getLRX(), ext.getLRY(), buf.getWidth(), lastBlock);
|
452 |
// file.readScene(pRGBArray, task);
|
453 |
// loadPartialBuffer(new int[]{0, i * buf.getBlockHeight(), buf.getWidth(), i * buf.getBlockHeight() + buf.getBlockHeight() },
|
454 |
// bandList,
|
455 |
// buf,
|
456 |
// pRGBArray,
|
457 |
// buf.getWidth());
|
458 |
// init += buf.getBlockHeight();
|
459 |
// }
|
460 |
// }
|
461 |
// } else {
|
462 |
// file.setView(inputWindow.getULX(), inputWindow.getULY(), inputWindow.getLRX(), inputWindow.getLRY(), buf.getWidth(), buf.getHeight());
|
463 |
// file.readScene(pRGBArray, task);
|
464 |
// loadBuffer(buf.getWidth(), buf.getHeight(), bandList, buf, pRGBArray);
|
465 |
// }
|
466 |
// }
|
467 |
//
|
468 |
// private void loadPartialBuffer(int[] stepBuffer,
|
469 |
// BandList bandList,
|
470 |
// Buffer rasterBuf,
|
471 |
// int[] pRGBArray,
|
472 |
// int bufWidth) throws ProcessInterruptedException {
|
473 |
// RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
|
474 |
// int[] drawableBandsR = bandList.getBufferBandToDraw(getURIOfFirstProvider(), 0);
|
475 |
// int[] drawableBandsG = bandList.getBufferBandToDraw(getURIOfFirstProvider(), 1);
|
476 |
// int[] drawableBandsB = bandList.getBufferBandToDraw(getURIOfFirstProvider(), 2);
|
477 |
// int element = 0;
|
478 |
// int rowSrc = 0;
|
479 |
//
|
480 |
// for (int row = stepBuffer[1]; row < stepBuffer[3]; row++) {
|
481 |
// int colSrc = 0;
|
482 |
// for (int col = stepBuffer[0]; col < stepBuffer[2]; col++) {
|
483 |
// element = pRGBArray[(rowSrc * bufWidth) + colSrc];
|
484 |
// if(drawableBandsR != null) {
|
485 |
// for (int i = 0; i < drawableBandsR.length; i++) {
|
486 |
// if(drawableBandsR[i] >= 0 && drawableBandsR[i] < rasterBuf.getBandCount())
|
487 |
// rasterBuf.setElem(row, col, drawableBandsR[i], (byte) ((element & 0x00ff0000) >> 16));
|
488 |
// }
|
489 |
// }
|
490 |
// if(drawableBandsG != null) {
|
491 |
// for (int i = 0; i < drawableBandsG.length; i++) {
|
492 |
// if(drawableBandsG[i] >= 0 && drawableBandsG[i] < rasterBuf.getBandCount())
|
493 |
// rasterBuf.setElem(row, col, drawableBandsG[i], (byte) ((element & 0x0000ff00) >> 8));
|
494 |
// }
|
495 |
// }
|
496 |
// if(drawableBandsB != null) {
|
497 |
// for (int i = 0; i < drawableBandsB.length; i++) {
|
498 |
// if(drawableBandsB[i] >= 0 && drawableBandsB[i] < rasterBuf.getBandCount())
|
499 |
// rasterBuf.setElem(row, col, drawableBandsB[i], (byte) (element & 0x000000ff));
|
500 |
// }
|
501 |
// }
|
502 |
// colSrc ++;
|
503 |
// }
|
504 |
// if (task.getEvent() != null)
|
505 |
// task.manageEvent(task.getEvent());
|
506 |
// rowSrc ++;
|
507 |
// }
|
508 |
// }
|
509 |
|
510 |
private void loadBuffer(int h, int w, BandList bandList, Buffer rasterBuf, int[] pRGBArray) throws ProcessInterruptedException { |
511 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
|
512 |
int[] drawableBandsR = bandList.getBufferBandToDraw(getURIOfFirstProvider(), 0); |
513 |
int[] drawableBandsG = bandList.getBufferBandToDraw(getURIOfFirstProvider(), 1); |
514 |
int[] drawableBandsB = bandList.getBufferBandToDraw(getURIOfFirstProvider(), 2); |
515 |
int element = 0; |
516 |
|
517 |
for (int row = 0; row < h; row++) { |
518 |
for (int col = 0; col < w; col++) { |
519 |
element = pRGBArray[(row * w) + col]; |
520 |
if(drawableBandsR != null) { |
521 |
for (int i = 0; i < drawableBandsR.length; i++) { |
522 |
if(drawableBandsR[i] >= 0 && drawableBandsR[i] < rasterBuf.getBandCount()) |
523 |
rasterBuf.setElem(row, col, drawableBandsR[i], (byte) ((element & 0x00ff0000) >> 16)); |
524 |
} |
525 |
} |
526 |
if(drawableBandsG != null) { |
527 |
for (int i = 0; i < drawableBandsG.length; i++) { |
528 |
if(drawableBandsG[i] >= 0 && drawableBandsG[i] < rasterBuf.getBandCount()) |
529 |
rasterBuf.setElem(row, col, drawableBandsG[i], (byte) ((element & 0x0000ff00) >> 8)); |
530 |
} |
531 |
} |
532 |
if(drawableBandsB != null) { |
533 |
for (int i = 0; i < drawableBandsB.length; i++) { |
534 |
if(drawableBandsB[i] >= 0 && drawableBandsB[i] < rasterBuf.getBandCount()) |
535 |
rasterBuf.setElem(row, col, drawableBandsB[i], (byte) (element & 0x000000ff)); |
536 |
} |
537 |
} |
538 |
} |
539 |
if (task.getEvent() != null) |
540 |
task.manageEvent(task.getEvent()); |
541 |
} |
542 |
} |
543 |
|
544 |
/*
|
545 |
* (non-Javadoc)
|
546 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, int, int, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
|
547 |
*/
|
548 |
public Buffer getWindow(int x, int y, int w, int h, |
549 |
BandList bandList, Buffer rasterBuf, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
550 |
try {
|
551 |
file.readWindow(rasterBuf, bandList, x, y, w, h, rasterBuf.getWidth(), rasterBuf.getHeight()); |
552 |
} catch (MrSIDException e) {
|
553 |
throw new RasterDriverException("Error reading data"); |
554 |
} |
555 |
return rasterBuf;
|
556 |
} |
557 |
|
558 |
/*
|
559 |
* (non-Javadoc)
|
560 |
* @see org.gvsig.raster.impl.provider.RasterProvider#readBlock(int, int, double)
|
561 |
*/
|
562 |
public Object readBlock(int pos, int blockHeight, double scale) throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException { |
563 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
|
564 |
|
565 |
if (pos < 0) |
566 |
throw new InvalidSetViewException("Request out of grid"); |
567 |
|
568 |
if ((pos + blockHeight) > file.height)
|
569 |
blockHeight = Math.abs(file.height - pos);
|
570 |
|
571 |
Point2D begin = rasterToWorld(new Point2D.Double(0, pos)); |
572 |
Point2D end = rasterToWorld(new Point2D.Double(file.width, pos + blockHeight)); |
573 |
|
574 |
int w = file.width;
|
575 |
|
576 |
file.setView(begin.getX(), begin.getY(), end.getX(), end.getY(), w, blockHeight); |
577 |
|
578 |
int[] pRGBArray = new int[file.width * blockHeight]; |
579 |
try {
|
580 |
file.readScene(pRGBArray, task); |
581 |
byte[][][] buf = new byte[3][blockHeight][w]; |
582 |
for (int row = 0; row < blockHeight; row++) { |
583 |
for (int col = 0; col < w; col++) { |
584 |
buf[0][row][col] = (byte) ((pRGBArray[(row * w) + col] & 0x00ff0000) >> 16); |
585 |
buf[1][row][col] = (byte) ((pRGBArray[(row * w) + col] & 0x0000ff00) >> 8); |
586 |
buf[2][row][col] = (byte) (pRGBArray[(row * w) + col] & 0x000000ff); |
587 |
} |
588 |
if (task.getEvent() != null) |
589 |
task.manageEvent(task.getEvent()); |
590 |
} |
591 |
return buf;
|
592 |
} catch (MrSIDException e) {
|
593 |
throw new RasterDriverException("Error reading data"); |
594 |
} |
595 |
} |
596 |
|
597 |
/**
|
598 |
* Read a line from the file
|
599 |
* @param line
|
600 |
* @param band
|
601 |
* @return
|
602 |
* @throws InvalidSetViewException
|
603 |
* @throws FileNotOpenException
|
604 |
* @throws RasterDriverException
|
605 |
* @Deprecated This operation is deprecated because is not useful and in the future
|
606 |
* it will not be maintained. The abstract operation has dissapear
|
607 |
*/
|
608 |
public Object readCompleteLine(int line, int band) |
609 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
|
610 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
|
611 |
|
612 |
if (line > this.getHeight() || band > this.getBandCount()) |
613 |
throw new InvalidSetViewException("Request out of grid"); |
614 |
|
615 |
try {
|
616 |
Extent extent = getExtent(); |
617 |
Point2D pt = rasterToWorld(new Point2D.Double(extent.minX(), line)); |
618 |
file.setView(extent.minX(), pt.getY(), extent.maxX(), pt.getY(), (int)getWidth(), 1); |
619 |
int[] pRGBArray = new int[(int)getWidth()]; |
620 |
file.readScene(pRGBArray, task); |
621 |
return pRGBArray;
|
622 |
} catch (MrSIDException e) {
|
623 |
throw new RasterDriverException("Error reading data from MrSID library"); |
624 |
} catch (ProcessInterruptedException e) {
|
625 |
// El proceso que debe ser interrumpido es el que llama a readLine.
|
626 |
} |
627 |
return null; |
628 |
} |
629 |
|
630 |
/*
|
631 |
* (non-Javadoc)
|
632 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getTransparency()
|
633 |
*/
|
634 |
public DataStoreTransparency getTransparency() {
|
635 |
if (fileTransparency == null) |
636 |
fileTransparency = new DataStoreTransparency();
|
637 |
return fileTransparency;
|
638 |
} |
639 |
|
640 |
/*
|
641 |
* (non-Javadoc)
|
642 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getColorInterpretation()
|
643 |
*/
|
644 |
public DataStoreColorInterpretation getColorInterpretation() {
|
645 |
if (colorInterpr == null) { |
646 |
colorInterpr = new DataStoreColorInterpretation();
|
647 |
colorInterpr.initColorInterpretation(getBandCount()); |
648 |
if (getBandCount() == 1) |
649 |
colorInterpr.setColorInterpValue(0, DataStoreColorInterpretation.GRAY_BAND);
|
650 |
if (getBandCount() >= 3) { |
651 |
colorInterpr.setColorInterpValue(0, DataStoreColorInterpretation.RED_BAND);
|
652 |
colorInterpr.setColorInterpValue(1, DataStoreColorInterpretation.GREEN_BAND);
|
653 |
colorInterpr.setColorInterpValue(2, DataStoreColorInterpretation.BLUE_BAND);
|
654 |
} |
655 |
} |
656 |
return colorInterpr;
|
657 |
} |
658 |
|
659 |
/*
|
660 |
* (non-Javadoc)
|
661 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWktProjection()
|
662 |
*/
|
663 |
public String getWktProjection() { |
664 |
// System.err.println("======>" + file);
|
665 |
return null; |
666 |
} |
667 |
|
668 |
/*
|
669 |
* (non-Javadoc)
|
670 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setAffineTransform(java.awt.geom.AffineTransform)
|
671 |
*/
|
672 |
public void setAffineTransform(AffineTransform t) { |
673 |
super.setAffineTransform(t);
|
674 |
file.setExternalTransform(t); |
675 |
} |
676 |
|
677 |
/*
|
678 |
* (non-Javadoc)
|
679 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getOverviewCount(int)
|
680 |
*/
|
681 |
public int getOverviewCount(int band) throws BandAccessException, RasterDriverException { |
682 |
if (band >= getBandCount())
|
683 |
throw new BandAccessException("Wrong band"); |
684 |
try {
|
685 |
return file.getNumLevels();
|
686 |
} catch (MrSIDException e) {
|
687 |
throw new RasterDriverException(""); |
688 |
} |
689 |
} |
690 |
|
691 |
/*
|
692 |
* (non-Javadoc)
|
693 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getOverviewWidth(int, int)
|
694 |
*/
|
695 |
public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException { |
696 |
if (band >= getBandCount())
|
697 |
throw new BandAccessException("Wrong band"); |
698 |
return 0; |
699 |
} |
700 |
|
701 |
/*
|
702 |
* (non-Javadoc)
|
703 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getOverviewHeight(int, int)
|
704 |
*/
|
705 |
public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException { |
706 |
if (band >= getBandCount())
|
707 |
throw new BandAccessException("Wrong band"); |
708 |
return 0; |
709 |
} |
710 |
|
711 |
/*
|
712 |
* (non-Javadoc)
|
713 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#isOverviewsSupported()
|
714 |
*/
|
715 |
public boolean isOverviewsSupported() { |
716 |
// No podemos escribir por lo que no podemos informar de que soporta overviews aunque el formato si lo haga.
|
717 |
return false; |
718 |
} |
719 |
|
720 |
/*
|
721 |
* (non-Javadoc)
|
722 |
* @see org.gvsig.fmap.dal.spi.DataStoreProvider#getName()
|
723 |
*/
|
724 |
public String getName() { |
725 |
return NAME;
|
726 |
} |
727 |
|
728 |
/*
|
729 |
* (non-Javadoc)
|
730 |
* @see org.gvsig.raster.impl.provider.RasterProvider#setStatus(org.gvsig.raster.impl.provider.RasterProvider)
|
731 |
*/
|
732 |
public void setStatus(RasterProvider provider) { |
733 |
if(provider instanceof LizardTechProvider) { |
734 |
//Not implemented yet
|
735 |
} |
736 |
} |
737 |
|
738 |
/*
|
739 |
* (non-Javadoc)
|
740 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getTileServer()
|
741 |
*/
|
742 |
public TileServer getTileServer() {
|
743 |
if(tileServer == null) |
744 |
tileServer = new FileTileServer(this); |
745 |
return tileServer;
|
746 |
} |
747 |
|
748 |
} |