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