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