Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/EcwWriter.java
EcwWriter.java | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 | 3 |
* |
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
... | ... | |
18 | 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
19 | 19 |
* |
20 | 20 |
* For more information, contact: |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* cresques@gmail.com |
23 | 23 |
*/ |
24 | 24 |
package org.cresques.io; |
25 | 25 |
|
26 |
import java.io.IOException; |
|
27 |
|
|
28 | 26 |
import es.gva.cit.jecwcompress.*; |
29 | 27 |
import es.gva.cit.jgdal.GdalRasterBand; |
30 | 28 |
|
31 | 29 |
import org.cresques.geo.ViewPortData; |
30 |
|
|
32 | 31 |
import org.cresques.px.PxRaster; |
33 | 32 |
|
33 |
import java.io.IOException; |
|
34 |
|
|
35 |
|
|
34 | 36 |
/** |
35 |
* Driver para la compresi?n en formato Ecw.
|
|
36 |
*
|
|
37 |
* Puede exportar un fichero desde un GeoRasterFile en cualquier formato soportado
|
|
37 |
* Driver para la compresi?n en formato Ecw. |
|
38 |
* |
|
39 |
* Puede exportar un fichero desde un GeoRasterFile en cualquier formato soportado |
|
38 | 40 |
* por los drivers de lectura a uno en formato Ecw. |
39 |
*
|
|
40 |
* Puede salvar a disco en formato Ecw obteniendo los datos que van siendo servidos
|
|
41 |
* desde el cliente. Este cliente debe implementar un IDataWriter o tener un objeto
|
|
42 |
* que lo implemente. Inicialmente le pasar? los par?metros de la imagen de salida
|
|
43 |
* y cuando el driver comience a escribir le ir? solicitando m?s a trav?s del m?todo
|
|
44 |
* readData de IDataWriter. El cliente ser? el que lleve el control de lo que va
|
|
41 |
* |
|
42 |
* Puede salvar a disco en formato Ecw obteniendo los datos que van siendo servidos |
|
43 |
* desde el cliente. Este cliente debe implementar un IDataWriter o tener un objeto |
|
44 |
* que lo implemente. Inicialmente le pasar? los par?metros de la imagen de salida |
|
45 |
* y cuando el driver comience a escribir le ir? solicitando m?s a trav?s del m?todo |
|
46 |
* readData de IDataWriter. El cliente ser? el que lleve el control de lo que va |
|
45 | 47 |
* sirviendo y lo que le queda por servir. |
46 | 48 |
* @author Nacho Brodin (brodin_ign@gva.es) |
47 | 49 |
*/ |
50 |
public class EcwWriter extends GeoRasterWriter { |
|
51 |
static { |
|
52 |
GeoRasterWriter.registerWriterExtension("ecw", EcwWriter.class); |
|
53 |
} |
|
48 | 54 |
|
49 |
public class EcwWriter extends GeoRasterWriter{ |
|
50 |
|
|
51 |
public final int windowSizeX = 386; |
|
52 |
public final int windowSizeY = 215; |
|
53 |
public final int panelSizeX = 350; |
|
54 |
public final int panelSizeY = 125; |
|
55 |
public final String panelLayout = "BorderLayout"; |
|
56 |
|
|
57 |
private NCSEcwCompressClient compressclient=null; |
|
58 |
private Reader readerObj; |
|
59 |
private double pixelSizeX; |
|
60 |
private double pixelSizeY; |
|
61 |
private double geoCoordOrigenX; |
|
62 |
private double geoCoordOrigenY; |
|
63 |
private EcwSupportOptions support = null; |
|
64 |
private boolean consulta = false; |
|
65 |
|
|
66 |
/** |
|
67 |
* @author Nacho Brodin <brodin_ign@gva.es> |
|
68 |
* |
|
69 |
* Opciones de escritura para el Ecw. Estas opciones son utilizadas para el |
|
70 |
* dialogo de propiedades de Salvar a Raster en Ecw. |
|
71 |
*/ |
|
72 |
class EcwSupportOptions extends WriterSupportOptions{ |
|
73 |
|
|
74 |
private String[] compresionListValues = {"0","20","10","1","5"}; //min, max, valor defecto, intervalo peque?o, intervalo grande; |
|
75 |
private String[] formatList = {"NONE","UINT8","YUV","MULTI","RGB"}; |
|
76 |
|
|
77 |
private int formatDefault = 4; |
|
78 |
private int compresionDefault = 10; |
|
79 |
|
|
80 |
EcwSupportOptions(){ |
|
81 |
super("Ecw"); |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* Asigna la lista de valores de compresi?n |
|
86 |
* @param compresion lista de valores |
|
87 |
*/ |
|
88 |
public void setCompressionList(String[] compresion){ |
|
89 |
this.compresionListValues = compresion; |
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* Valor de formato seleccionado en el driver. |
|
94 |
* 0-NONE, 1-UINT8, 2-YUV, 3-MULTI, 4-RGB |
|
95 |
* @param i valor de formato |
|
96 |
*/ |
|
97 |
public void setFormatDefault(int i){ |
|
98 |
this.formatDefault = i; |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* Asigna el nivel de compresi?npor defecto |
|
103 |
* @param compress Nivel de compresi?n |
|
104 |
*/ |
|
105 |
public void setCompressionDefault(int compress){ |
|
106 |
this.compresionDefault = compress; |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* Obtiene el tipo de imagen en un formato comprensible por el driver. |
|
111 |
* @return Tipo de imagen |
|
112 |
*/ |
|
113 |
public String getStringFormat(){ |
|
114 |
return "COMPRESS_"+formatList[formatDefault]; |
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* Obtiene la lista de los tipos de formato disponible |
|
119 |
* @return Lista de tipos de formato |
|
120 |
*/ |
|
121 |
public String[] getFormatList(){ |
|
122 |
return formatList; |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Obtiene el tipo de formato seleccionado en el driver |
|
127 |
* @return Tipo de formato seleccionado |
|
128 |
*/ |
|
129 |
public int getFormat(){return formatDefault;} |
|
130 |
|
|
131 |
/** |
|
132 |
* Obtiene la compresion seleccionada |
|
133 |
* @return Compresi?n seleccionada |
|
134 |
*/ |
|
135 |
public int getCompression(){return compresionDefault;} |
|
136 |
|
|
137 |
/** |
|
138 |
* Obtiene la lista de los valores para la generaci?n de la barra de |
|
139 |
* compresi?n. Son cinco valores m?nimo, m?ximo, seleccionado, |
|
140 |
* intervalo peque?o, intervalo grande. |
|
141 |
* @return lista de valores de compresi?n |
|
142 |
*/ |
|
143 |
public String[] getCompressionList(){return compresionListValues;} |
|
144 |
|
|
145 |
} |
|
146 |
|
|
147 |
static { |
|
148 |
GeoRasterWriter.registerWriterExtension("ecw", EcwWriter.class); |
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
152 |
* Constructor para la obtenci?n de par?metros del driver. |
|
153 |
* |
|
154 |
*/ |
|
155 |
public EcwWriter(){ |
|
156 |
|
|
157 |
this.support = new EcwSupportOptions(); |
|
158 |
this.driver = "ecw"; |
|
159 |
this.support.setBlockSize(64); |
|
160 |
this.support.setCompressionDefault(10); |
|
161 |
this.support.setFormatDefault(4); |
|
162 |
this.support.setWriteGeoref(true); |
|
163 |
this.ident = "Ecw"; |
|
164 |
this.consulta = true; |
|
165 |
|
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* Constructor para salvar una sola imagen completa |
|
170 |
* @param raster PxRaster de la imagen origen |
|
171 |
* @param outfilename Fichero de salida |
|
172 |
* @param infilename Fichero de entrada |
|
173 |
* @param compresion Compresi?n |
|
174 |
*/ |
|
175 |
|
|
176 |
public EcwWriter( PxRaster raster, |
|
177 |
String outfilename, |
|
178 |
String infilename, |
|
179 |
int compresion)throws EcwException, IOException { |
|
180 |
|
|
181 |
this.support = new EcwSupportOptions(); |
|
182 |
this.ident = "Ecw"; |
|
183 |
|
|
184 |
this.outfilename = outfilename; |
|
185 |
this.infilename = infilename; |
|
186 |
this.currentRaster = raster; |
|
187 |
|
|
188 |
this.support.setCompressionDefault(compresion); |
|
189 |
|
|
190 |
this.sizeWindowX = raster.getFWidth(); |
|
191 |
this.sizeWindowY = raster.getFHeight(); |
|
192 |
|
|
193 |
this.support.setBlockSize(currentRaster.getBlockSize()); |
|
194 |
|
|
195 |
nBands = currentRaster.getBandCount(); |
|
196 |
|
|
197 |
//Calculamos la georeferenciaci?n |
|
198 |
|
|
199 |
double maxX=currentRaster.getExtent().maxX(); |
|
200 |
geoCoordOrigenX=currentRaster.getExtent().minX(); |
|
201 |
geoCoordOrigenY=currentRaster.getExtent().maxY(); |
|
202 |
double minY=currentRaster.getExtent().minY(); |
|
203 |
double w=currentRaster.getFWidth(); |
|
204 |
double h=currentRaster.getFHeight(); |
|
205 |
pixelSizeX = (maxX-geoCoordOrigenX)/w; |
|
206 |
pixelSizeY = (minY-geoCoordOrigenY)/h; |
|
207 |
|
|
208 |
if(sizeWindowX<0 || sizeWindowY<0) |
|
209 |
throw new IOException("Tama?o del fichero de salida erroneo."); |
|
210 |
|
|
211 |
if(nBands == 1) |
|
212 |
this.support.setFormatDefault(CompressFormat.COMPRESS_UINT8); |
|
213 |
else if(nBands == 3) |
|
214 |
this.support.setFormatDefault(CompressFormat.COMPRESS_RGB); |
|
215 |
else |
|
216 |
this.support.setFormatDefault(CompressFormat.COMPRESS_MULTI); |
|
217 |
|
|
218 |
init(); |
|
219 |
|
|
220 |
} |
|
221 |
|
|
222 |
/** |
|
223 |
* Constructor para la lectura de datos desde el objeto cliente a partir |
|
224 |
* de un viewport dado. |
|
225 |
* @param dataWriter Objeto que sirve datos para el escritor |
|
226 |
* @param vp viewport de origen |
|
227 |
* @param outFileName Fichero de salida |
|
228 |
* @param blockSize Tama?o de bloque |
|
229 |
* @param nBands N?mero de bandas |
|
230 |
* @param compresion Compresi?n |
|
231 |
* @throws EcwException |
|
232 |
* @throws IOException |
|
233 |
*/ |
|
234 |
|
|
235 |
public EcwWriter( IDataWriter dataWriter, |
|
236 |
ViewPortData vp, |
|
237 |
String outFileName, |
|
238 |
int blockSize, |
|
239 |
int nBands, |
|
240 |
int compresion)throws EcwException, IOException { |
|
241 |
|
|
242 |
this.support = new EcwSupportOptions(); |
|
243 |
this.ident = "Ecw"; |
|
244 |
|
|
245 |
if(compresion <= 0) |
|
246 |
throw new EcwException("Tasa de compresi?n no valida."); |
|
247 |
if(nBands <= 0) |
|
248 |
throw new EcwException("N?mero de bandas erroneo."); |
|
249 |
if(vp.getWidth()<=0 || vp.getHeight()<=0) |
|
250 |
throw new EcwException("Tama?o de la imagen de salida erroneo."); |
|
251 |
|
|
252 |
this.outfilename = outFileName; |
|
253 |
this.dataWriter = dataWriter; |
|
254 |
this.support.setCompressionDefault(compresion); |
|
255 |
this.nBands = nBands; |
|
256 |
|
|
257 |
this.sizeWindowX = (int)vp.getWidth(); |
|
258 |
this.sizeWindowY = (int)vp.getHeight(); |
|
259 |
this.support.setBlockSize(blockSize); |
|
260 |
|
|
261 |
//Calculamos la georeferenciaci?n a partir del extend pasado por el cliente. |
|
262 |
|
|
263 |
|
|
264 |
double maxX = vp.getExtent().maxX(); |
|
265 |
geoCoordOrigenX = vp.getExtent().minX(); |
|
266 |
geoCoordOrigenY = vp.getExtent().maxY(); |
|
267 |
double minY = vp.getExtent().minY(); |
|
268 |
pixelSizeX = (maxX-geoCoordOrigenX)/vp.getWidth(); |
|
269 |
pixelSizeY = (minY-geoCoordOrigenY)/vp.getHeight(); |
|
270 |
|
|
271 |
if(pixelSizeX==0)pixelSizeX=1.0; |
|
272 |
if(pixelSizeY==0)pixelSizeY=1.0; |
|
55 |
public final int windowSizeX = 386; |
|
56 |
public final int windowSizeY = 215; |
|
57 |
public final int panelSizeX = 350; |
|
58 |
public final int panelSizeY = 125; |
|
59 |
public final String panelLayout = "BorderLayout"; |
|
60 |
private NCSEcwCompressClient compressclient = null; |
|
61 |
private Reader readerObj; |
|
62 |
private double pixelSizeX; |
|
63 |
private double pixelSizeY; |
|
64 |
private double geoCoordOrigenX; |
|
65 |
private double geoCoordOrigenY; |
|
66 |
private EcwSupportOptions support = null; |
|
67 |
private boolean consulta = false; |
|
273 | 68 |
|
274 |
init(); |
|
275 |
|
|
276 |
} |
|
277 |
|
|
278 |
|
|
279 |
/** |
|
280 |
* Inicializaci?n de los par?metros del compresor que ser?n obtenidos |
|
281 |
* de PxRaster. |
|
282 |
* @throws EcwException |
|
283 |
*/ |
|
284 |
|
|
285 |
private void init() throws EcwException{ |
|
286 |
|
|
287 |
if(this.support.getCompression()==0) |
|
288 |
this.support.setCompressionDefault(1); |
|
289 |
if(compressclient==null) |
|
290 |
compressclient = new NCSEcwCompressClient(); |
|
291 |
compressclient.setOutputFilename(outfilename); |
|
292 |
compressclient.setInputFilename(infilename); |
|
293 |
compressclient.setTargetCompress(this.support.getCompression()); |
|
294 |
compressclient.setInOutSizeX(sizeWindowX); |
|
295 |
compressclient.setInOutSizeY(sizeWindowY); |
|
296 |
compressclient.setInputBands(nBands); |
|
297 |
compressclient.setCompressFormat(this.support.getFormat()); |
|
298 |
|
|
299 |
//System.out.println("Origen=>"+minX + " "+maxY ); |
|
300 |
//System.out.println("Pixel Size=>"+psX+" "+psY); |
|
301 |
|
|
302 |
//compressclient.setDatum("UTM Zona 31N"); |
|
303 |
//client.setProjection("WGS84"); |
|
304 |
|
|
305 |
if(this.support.getGeoref()){ |
|
306 |
compressclient.setCellIncrementX(pixelSizeX); |
|
307 |
compressclient.setCellIncrementY(pixelSizeY); |
|
308 |
compressclient.setOriginX(geoCoordOrigenX); |
|
309 |
compressclient.setOriginY(geoCoordOrigenY); |
|
310 |
} |
|
311 |
compressclient.setCellSizeUnits(1); |
|
69 |
/** |
|
70 |
* Constructor para la obtenci?n de par?metros del driver. |
|
71 |
* |
|
72 |
*/ |
|
73 |
public EcwWriter() { |
|
74 |
this.support = new EcwSupportOptions(); |
|
75 |
this.driver = "ecw"; |
|
76 |
this.support.setBlockSize(64); |
|
77 |
this.support.setCompressionDefault(10); |
|
78 |
this.support.setFormatDefault(4); |
|
79 |
this.support.setWriteGeoref(true); |
|
80 |
this.ident = "Ecw"; |
|
81 |
this.consulta = true; |
|
82 |
} |
|
312 | 83 |
|
313 |
//System.out.println(outfilename+" "+infilename+" "+compresion+" "+sizeWindowX+" "+sizeWindowY+" "+currentRaster.getBandCount()); |
|
314 |
//System.out.println(psX+" "+psY+" "+minX+" "+maxX); |
|
315 |
|
|
316 |
if(currentRaster!=null) |
|
317 |
readerObj = new Reader( currentRaster.getGeoFile(), |
|
318 |
compressclient, |
|
319 |
ulX, |
|
320 |
ulY, |
|
321 |
sizeWindowX, |
|
322 |
sizeWindowY, |
|
323 |
this.support.getBlockSize()); |
|
324 |
else if(dataWriter!=null) |
|
325 |
readerObj = new Reader( dataWriter, |
|
326 |
compressclient, |
|
327 |
sizeWindowX, |
|
328 |
sizeWindowY, |
|
329 |
this.support.getBlockSize(), |
|
330 |
this.nBands); |
|
331 |
|
|
332 |
|
|
333 |
} |
|
334 |
|
|
335 |
/** |
|
336 |
* A partir de un elemento que contiene una propiedad y un valor |
|
337 |
* lo parsea y asigna el valor a su variable. |
|
338 |
* @param propValue elemento con la forma propiedad=valor |
|
339 |
*/ |
|
340 |
private void readProperty(String propValue){ |
|
341 |
|
|
342 |
String prop = propValue.substring(0, propValue.indexOf("=")); |
|
343 |
if(propValue.startsWith(prop)){ |
|
344 |
String value = propValue.substring(propValue.indexOf("=")+1, propValue.length()); |
|
345 |
if(value!=null && !value.equals("")){ |
|
346 |
if(prop.equals("BLOCKSIZE")) |
|
347 |
this.support.setBlockSize(Integer.parseInt(value)); |
|
348 |
if(prop.equals("FORMAT")){ |
|
349 |
int select = 0; |
|
350 |
if(value.equals("UINT8")) |
|
351 |
select = 1; |
|
352 |
if(value.equals("YUV")) |
|
353 |
select = 2; |
|
354 |
if(value.equals("MULTI")) |
|
355 |
select = 3; |
|
356 |
if(value.equals("RGB")) |
|
357 |
select = 4; |
|
358 |
this.support.setFormatDefault(select); |
|
359 |
} |
|
360 |
if(prop.equals("GEOREF")){ |
|
361 |
boolean georef = true; |
|
362 |
if(value.equals("yes")) |
|
363 |
georef = true; |
|
364 |
else |
|
365 |
georef = false; |
|
366 |
this.support.setWriteGeoref(georef); |
|
367 |
} |
|
368 |
if(prop.equals("COMPRESSION")) |
|
369 |
this.support.setCompressionDefault(Integer.parseInt(value)); |
|
370 |
} |
|
371 |
} |
|
372 |
|
|
373 |
} |
|
374 |
|
|
375 |
/** |
|
376 |
* Asigna propiedades al driver a partir de un vector de |
|
377 |
* strings donde cada elemento tiene la estructura de |
|
378 |
* propiedad=valor. |
|
379 |
* @param props Propiedades |
|
380 |
*/ |
|
381 |
public void setProps(String[] props){ |
|
84 |
/** |
|
85 |
* Constructor para salvar una sola imagen completa |
|
86 |
* @param raster PxRaster de la imagen origen |
|
87 |
* @param outfilename Fichero de salida |
|
88 |
* @param infilename Fichero de entrada |
|
89 |
* @param compresion Compresi?n |
|
90 |
*/ |
|
91 |
public EcwWriter(PxRaster raster, String outfilename, String infilename, |
|
92 |
int compresion) throws EcwException, IOException { |
|
93 |
this.support = new EcwSupportOptions(); |
|
94 |
this.ident = "Ecw"; |
|
382 | 95 |
|
383 |
for(int iProps=0;iProps<props.length;iProps++) |
|
384 |
readProperty(props[iProps]); |
|
385 |
|
|
386 |
try{ |
|
387 |
if(!consulta)init(); |
|
388 |
}catch(EcwException e){ |
|
389 |
e.printStackTrace(); |
|
390 |
} |
|
391 |
|
|
392 |
} |
|
393 |
|
|
394 |
/** |
|
395 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile. |
|
396 |
* @throws IOException |
|
397 |
*/ |
|
398 |
public void fileWrite()throws IOException{ |
|
96 |
this.outfilename = outfilename; |
|
97 |
this.infilename = infilename; |
|
98 |
this.currentRaster = raster; |
|
399 | 99 |
|
400 |
if(currentRaster==null) |
|
401 |
throw new IOException("No se ha asignado un fichero de entrada."); |
|
402 |
|
|
403 |
try{ |
|
404 |
compressclient.NCSEcwCompressOpen(false); |
|
405 |
compressclient.NCSEcwCompress(readerObj); |
|
406 |
}catch(EcwException e){ |
|
407 |
e.printStackTrace(); |
|
408 |
} |
|
409 |
} |
|
410 |
|
|
411 |
/** |
|
412 |
* Realiza la funci?n de compresi?n a partir de los datos pasados por el cliente. |
|
413 |
* @throws IOException |
|
414 |
*/ |
|
415 |
public void dataWrite()throws IOException{ |
|
416 |
|
|
417 |
if(dataWriter==null) |
|
418 |
throw new IOException("No se ha obtenido un objeto para la lectura valido."); |
|
419 |
|
|
420 |
try{ |
|
421 |
compressclient.NCSEcwCompressOpen(false); |
|
422 |
compressclient.NCSEcwCompress(readerObj); |
|
423 |
}catch(EcwException e){ |
|
424 |
e.printStackTrace(); |
|
425 |
} |
|
426 |
|
|
427 |
} |
|
428 |
|
|
429 |
/** |
|
430 |
* Cierra el compresor ecw. |
|
431 |
*/ |
|
432 |
|
|
433 |
public void writeClose(){ |
|
434 |
|
|
435 |
try{ |
|
436 |
compressclient.NCSEcwCompressClose(); |
|
437 |
}catch(EcwException e){ |
|
438 |
e.printStackTrace(); |
|
439 |
} |
|
440 |
|
|
441 |
} |
|
442 |
|
|
443 |
/** |
|
444 |
* Devuelve la configuraci?n de la ventana de dialogo |
|
445 |
* para las propiedades del driver de escritura de Ecw. |
|
446 |
* @return XML de configuraci?n del dialogo. |
|
447 |
*/ |
|
448 |
public String getXMLPropertiesDialog(){ |
|
449 |
|
|
450 |
StringBuffer options = null; |
|
451 |
options = new StringBuffer(); |
|
452 |
options.append("<window sizex=\""+this.windowSizeX+"\" sizey=\""+this.windowSizeY+"\">"); |
|
453 |
options.append("<panel sizex=\""+this.panelSizeX+"\" sizey=\""+this.panelSizeY+"\" layout=\""+this.panelLayout+"\" border=\"yes\">"); |
|
454 |
|
|
455 |
options.append("<panel layout=\"FlowLayout\" position=\"North\" align=\"left\">"); |
|
456 |
options.append("<label>Tama?o bloque:</label>"); |
|
457 |
options.append("<combo ident=\"BLOCKSIZE\" selected=\""+this.support.getBlockSize() +"\">"); |
|
458 |
for(int i=0;i<this.support.getBlockSizeList().length;i++) |
|
459 |
options.append("<elem>"+this.support.getBlockSizeList()[i]+"</elem>"); |
|
460 |
options.append("</combo>"); |
|
461 |
options.append("<label>Formato:</label>"); |
|
462 |
String sel = null; |
|
463 |
if(this.support.getGeoref()) |
|
464 |
sel = new String("yes"); |
|
465 |
else |
|
466 |
sel = new String("no"); |
|
467 |
options.append("<check ident=\"GEOREF\" selected=\""+sel +"\" text=\"Georef Si/No\">"); |
|
468 |
options.append("</check>"); |
|
469 |
options.append("</panel>"); |
|
470 |
|
|
471 |
options.append("<panel layout=\"FlowLayout\" position=\"South\">"); |
|
472 |
options.append("<slider ident=\"COMPRESSION\" name=\"Nivel de Compresi?n\" sizex=\"350\" sizey=\"20\">"); |
|
473 |
options.append("<min>"+this.support.getCompressionList()[0]+"</min>"); |
|
474 |
options.append("<max>"+this.support.getCompressionList()[1]+"</max>"); |
|
475 |
options.append("<value>"+this.support.compresionDefault+"</value>"); |
|
476 |
options.append("<minorspacing>"+this.support.getCompressionList()[3]+"</minorspacing>"); |
|
477 |
options.append("<majorspacing>"+this.support.getCompressionList()[4]+"</majorspacing>"); |
|
478 |
options.append("</slider>"); |
|
479 |
options.append("</panel>"); |
|
480 |
|
|
481 |
options.append("</panel>"); |
|
482 |
options.append("</window>"); |
|
483 |
|
|
484 |
return options.toString(); |
|
485 |
|
|
486 |
} |
|
487 |
|
|
100 |
this.support.setCompressionDefault(compresion); |
|
101 |
|
|
102 |
this.sizeWindowX = raster.getFWidth(); |
|
103 |
this.sizeWindowY = raster.getFHeight(); |
|
104 |
|
|
105 |
this.support.setBlockSize(currentRaster.getBlockSize()); |
|
106 |
|
|
107 |
nBands = currentRaster.getBandCount(); |
|
108 |
|
|
109 |
//Calculamos la georeferenciaci?n |
|
110 |
double maxX = currentRaster.getExtent().maxX(); |
|
111 |
geoCoordOrigenX = currentRaster.getExtent().minX(); |
|
112 |
geoCoordOrigenY = currentRaster.getExtent().maxY(); |
|
113 |
|
|
114 |
double minY = currentRaster.getExtent().minY(); |
|
115 |
double w = currentRaster.getFWidth(); |
|
116 |
double h = currentRaster.getFHeight(); |
|
117 |
pixelSizeX = (maxX - geoCoordOrigenX) / w; |
|
118 |
pixelSizeY = (minY - geoCoordOrigenY) / h; |
|
119 |
|
|
120 |
if ((sizeWindowX < 0) || (sizeWindowY < 0)) { |
|
121 |
throw new IOException("Tama?o del fichero de salida erroneo."); |
|
122 |
} |
|
123 |
|
|
124 |
if (nBands == 1) { |
|
125 |
this.support.setFormatDefault(CompressFormat.COMPRESS_UINT8); |
|
126 |
} else if (nBands == 3) { |
|
127 |
this.support.setFormatDefault(CompressFormat.COMPRESS_RGB); |
|
128 |
} else { |
|
129 |
this.support.setFormatDefault(CompressFormat.COMPRESS_MULTI); |
|
130 |
} |
|
131 |
|
|
132 |
init(); |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* Constructor para la lectura de datos desde el objeto cliente a partir |
|
137 |
* de un viewport dado. |
|
138 |
* @param dataWriter Objeto que sirve datos para el escritor |
|
139 |
* @param vp viewport de origen |
|
140 |
* @param outFileName Fichero de salida |
|
141 |
* @param blockSize Tama?o de bloque |
|
142 |
* @param nBands N?mero de bandas |
|
143 |
* @param compresion Compresi?n |
|
144 |
* @throws EcwException |
|
145 |
* @throws IOException |
|
146 |
*/ |
|
147 |
public EcwWriter(IDataWriter dataWriter, ViewPortData vp, |
|
148 |
String outFileName, int blockSize, int nBands, |
|
149 |
int compresion) throws EcwException, IOException { |
|
150 |
this.support = new EcwSupportOptions(); |
|
151 |
this.ident = "Ecw"; |
|
152 |
|
|
153 |
if (compresion <= 0) { |
|
154 |
throw new EcwException("Tasa de compresi?n no valida."); |
|
155 |
} |
|
156 |
|
|
157 |
if (nBands <= 0) { |
|
158 |
throw new EcwException("N?mero de bandas erroneo."); |
|
159 |
} |
|
160 |
|
|
161 |
if ((vp.getWidth() <= 0) || (vp.getHeight() <= 0)) { |
|
162 |
throw new EcwException("Tama?o de la imagen de salida erroneo."); |
|
163 |
} |
|
164 |
|
|
165 |
this.outfilename = outFileName; |
|
166 |
this.dataWriter = dataWriter; |
|
167 |
this.support.setCompressionDefault(compresion); |
|
168 |
this.nBands = nBands; |
|
169 |
|
|
170 |
this.sizeWindowX = (int) vp.getWidth(); |
|
171 |
this.sizeWindowY = (int) vp.getHeight(); |
|
172 |
this.support.setBlockSize(blockSize); |
|
173 |
|
|
174 |
//Calculamos la georeferenciaci?n a partir del extend pasado por el cliente. |
|
175 |
double maxX = vp.getExtent().maxX(); |
|
176 |
geoCoordOrigenX = vp.getExtent().minX(); |
|
177 |
geoCoordOrigenY = vp.getExtent().maxY(); |
|
178 |
|
|
179 |
double minY = vp.getExtent().minY(); |
|
180 |
pixelSizeX = (maxX - geoCoordOrigenX) / vp.getWidth(); |
|
181 |
pixelSizeY = (minY - geoCoordOrigenY) / vp.getHeight(); |
|
182 |
|
|
183 |
if (pixelSizeX == 0) { |
|
184 |
pixelSizeX = 1.0; |
|
185 |
} |
|
186 |
|
|
187 |
if (pixelSizeY == 0) { |
|
188 |
pixelSizeY = 1.0; |
|
189 |
} |
|
190 |
|
|
191 |
init(); |
|
192 |
} |
|
193 |
|
|
194 |
/** |
|
195 |
* Inicializaci?n de los par?metros del compresor que ser?n obtenidos |
|
196 |
* de PxRaster. |
|
197 |
* @throws EcwException |
|
198 |
*/ |
|
199 |
private void init() throws EcwException { |
|
200 |
if (this.support.getCompression() == 0) { |
|
201 |
this.support.setCompressionDefault(1); |
|
202 |
} |
|
203 |
|
|
204 |
if (compressclient == null) { |
|
205 |
compressclient = new NCSEcwCompressClient(); |
|
206 |
} |
|
207 |
|
|
208 |
compressclient.setOutputFilename(outfilename); |
|
209 |
compressclient.setInputFilename(infilename); |
|
210 |
compressclient.setTargetCompress(this.support.getCompression()); |
|
211 |
compressclient.setInOutSizeX(sizeWindowX); |
|
212 |
compressclient.setInOutSizeY(sizeWindowY); |
|
213 |
compressclient.setInputBands(nBands); |
|
214 |
compressclient.setCompressFormat(this.support.getFormat()); |
|
215 |
|
|
216 |
//System.out.println("Origen=>"+minX + " "+maxY ); |
|
217 |
//System.out.println("Pixel Size=>"+psX+" "+psY); |
|
218 |
//compressclient.setDatum("UTM Zona 31N"); |
|
219 |
//client.setProjection("WGS84"); |
|
220 |
if (this.support.getGeoref()) { |
|
221 |
compressclient.setCellIncrementX(pixelSizeX); |
|
222 |
compressclient.setCellIncrementY(pixelSizeY); |
|
223 |
compressclient.setOriginX(geoCoordOrigenX); |
|
224 |
compressclient.setOriginY(geoCoordOrigenY); |
|
225 |
} |
|
226 |
|
|
227 |
compressclient.setCellSizeUnits(1); |
|
228 |
|
|
229 |
//System.out.println(outfilename+" "+infilename+" "+compresion+" "+sizeWindowX+" "+sizeWindowY+" "+currentRaster.getBandCount()); |
|
230 |
//System.out.println(psX+" "+psY+" "+minX+" "+maxX); |
|
231 |
if (currentRaster != null) { |
|
232 |
readerObj = new Reader(currentRaster.getGeoFile(), compressclient, |
|
233 |
ulX, ulY, sizeWindowX, sizeWindowY, |
|
234 |
this.support.getBlockSize()); |
|
235 |
} else if (dataWriter != null) { |
|
236 |
readerObj = new Reader(dataWriter, compressclient, sizeWindowX, |
|
237 |
sizeWindowY, this.support.getBlockSize(), |
|
238 |
this.nBands); |
|
239 |
} |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* A partir de un elemento que contiene una propiedad y un valor |
|
244 |
* lo parsea y asigna el valor a su variable. |
|
245 |
* @param propValue elemento con la forma propiedad=valor |
|
246 |
*/ |
|
247 |
private void readProperty(String propValue) { |
|
248 |
String prop = propValue.substring(0, propValue.indexOf("=")); |
|
249 |
|
|
250 |
if (propValue.startsWith(prop)) { |
|
251 |
String value = propValue.substring(propValue.indexOf("=") + 1, |
|
252 |
propValue.length()); |
|
253 |
|
|
254 |
if ((value != null) && !value.equals("")) { |
|
255 |
if (prop.equals("BLOCKSIZE")) { |
|
256 |
this.support.setBlockSize(Integer.parseInt(value)); |
|
257 |
} |
|
258 |
|
|
259 |
if (prop.equals("FORMAT")) { |
|
260 |
int select = 0; |
|
261 |
|
|
262 |
if (value.equals("UINT8")) { |
|
263 |
select = 1; |
|
264 |
} |
|
265 |
|
|
266 |
if (value.equals("YUV")) { |
|
267 |
select = 2; |
|
268 |
} |
|
269 |
|
|
270 |
if (value.equals("MULTI")) { |
|
271 |
select = 3; |
|
272 |
} |
|
273 |
|
|
274 |
if (value.equals("RGB")) { |
|
275 |
select = 4; |
|
276 |
} |
|
277 |
|
|
278 |
this.support.setFormatDefault(select); |
|
279 |
} |
|
280 |
|
|
281 |
if (prop.equals("GEOREF")) { |
|
282 |
boolean georef = true; |
|
283 |
|
|
284 |
if (value.equals("yes")) { |
|
285 |
georef = true; |
|
286 |
} else { |
|
287 |
georef = false; |
|
288 |
} |
|
289 |
|
|
290 |
this.support.setWriteGeoref(georef); |
|
291 |
} |
|
292 |
|
|
293 |
if (prop.equals("COMPRESSION")) { |
|
294 |
this.support.setCompressionDefault(Integer.parseInt(value)); |
|
295 |
} |
|
296 |
} |
|
297 |
} |
|
298 |
} |
|
299 |
|
|
300 |
/** |
|
301 |
* Asigna propiedades al driver a partir de un vector de |
|
302 |
* strings donde cada elemento tiene la estructura de |
|
303 |
* propiedad=valor. |
|
304 |
* @param props Propiedades |
|
305 |
*/ |
|
306 |
public void setProps(String[] props) { |
|
307 |
for (int iProps = 0; iProps < props.length; iProps++) |
|
308 |
readProperty(props[iProps]); |
|
309 |
|
|
310 |
try { |
|
311 |
if (!consulta) { |
|
312 |
init(); |
|
313 |
} |
|
314 |
} catch (EcwException e) { |
|
315 |
e.printStackTrace(); |
|
316 |
} |
|
317 |
} |
|
318 |
|
|
319 |
/** |
|
320 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile. |
|
321 |
* @throws IOException |
|
322 |
*/ |
|
323 |
public void fileWrite() throws IOException { |
|
324 |
if (currentRaster == null) { |
|
325 |
throw new IOException("No se ha asignado un fichero de entrada."); |
|
326 |
} |
|
327 |
|
|
328 |
try { |
|
329 |
compressclient.NCSEcwCompressOpen(false); |
|
330 |
compressclient.NCSEcwCompress(readerObj); |
|
331 |
} catch (EcwException e) { |
|
332 |
e.printStackTrace(); |
|
333 |
} |
|
334 |
} |
|
335 |
|
|
336 |
/** |
|
337 |
* Realiza la funci?n de compresi?n a partir de los datos pasados por el cliente. |
|
338 |
* @throws IOException |
|
339 |
*/ |
|
340 |
public void dataWrite() throws IOException { |
|
341 |
if (dataWriter == null) { |
|
342 |
throw new IOException("No se ha obtenido un objeto para la lectura valido."); |
|
343 |
} |
|
344 |
|
|
345 |
try { |
|
346 |
compressclient.NCSEcwCompressOpen(false); |
|
347 |
compressclient.NCSEcwCompress(readerObj); |
|
348 |
} catch (EcwException e) { |
|
349 |
e.printStackTrace(); |
|
350 |
} |
|
351 |
} |
|
352 |
|
|
353 |
/** |
|
354 |
* Cierra el compresor ecw. |
|
355 |
*/ |
|
356 |
public void writeClose() { |
|
357 |
try { |
|
358 |
compressclient.NCSEcwCompressClose(); |
|
359 |
} catch (EcwException e) { |
|
360 |
e.printStackTrace(); |
|
361 |
} |
|
362 |
} |
|
363 |
|
|
364 |
/** |
|
365 |
* Devuelve la configuraci?n de la ventana de dialogo |
|
366 |
* para las propiedades del driver de escritura de Ecw. |
|
367 |
* @return XML de configuraci?n del dialogo. |
|
368 |
*/ |
|
369 |
public String getXMLPropertiesDialog() { |
|
370 |
StringBuffer options = null; |
|
371 |
options = new StringBuffer(); |
|
372 |
options.append("<window sizex=\"" + this.windowSizeX + "\" sizey=\"" + |
|
373 |
this.windowSizeY + "\">"); |
|
374 |
options.append("<panel sizex=\"" + this.panelSizeX + "\" sizey=\"" + |
|
375 |
this.panelSizeY + "\" layout=\"" + this.panelLayout + |
|
376 |
"\" border=\"yes\">"); |
|
377 |
|
|
378 |
options.append("<panel layout=\"FlowLayout\" position=\"North\" align=\"left\">"); |
|
379 |
options.append("<label>Tama?o bloque:</label>"); |
|
380 |
options.append("<combo ident=\"BLOCKSIZE\" selected=\"" + |
|
381 |
this.support.getBlockSize() + "\">"); |
|
382 |
|
|
383 |
for (int i = 0; i < this.support.getBlockSizeList().length; i++) |
|
384 |
options.append("<elem>" + this.support.getBlockSizeList()[i] + |
|
385 |
"</elem>"); |
|
386 |
|
|
387 |
options.append("</combo>"); |
|
388 |
options.append("<label>Formato:</label>"); |
|
389 |
|
|
390 |
String sel = null; |
|
391 |
|
|
392 |
if (this.support.getGeoref()) { |
|
393 |
sel = new String("yes"); |
|
394 |
} else { |
|
395 |
sel = new String("no"); |
|
396 |
} |
|
397 |
|
|
398 |
options.append("<check ident=\"GEOREF\" selected=\"" + sel + |
|
399 |
"\" text=\"Georef Si/No\">"); |
|
400 |
options.append("</check>"); |
|
401 |
options.append("</panel>"); |
|
402 |
|
|
403 |
options.append("<panel layout=\"FlowLayout\" position=\"South\">"); |
|
404 |
options.append("<slider ident=\"COMPRESSION\" name=\"Nivel de Compresi?n\" sizex=\"350\" sizey=\"20\">"); |
|
405 |
options.append("<min>" + this.support.getCompressionList()[0] + |
|
406 |
"</min>"); |
|
407 |
options.append("<max>" + this.support.getCompressionList()[1] + |
|
408 |
"</max>"); |
|
409 |
options.append("<value>" + this.support.compresionDefault + "</value>"); |
|
410 |
options.append("<minorspacing>" + this.support.getCompressionList()[3] + |
|
411 |
"</minorspacing>"); |
|
412 |
options.append("<majorspacing>" + this.support.getCompressionList()[4] + |
|
413 |
"</majorspacing>"); |
|
414 |
options.append("</slider>"); |
|
415 |
options.append("</panel>"); |
|
416 |
|
|
417 |
options.append("</panel>"); |
|
418 |
options.append("</window>"); |
|
419 |
|
|
420 |
return options.toString(); |
|
421 |
} |
|
422 |
|
|
423 |
/** |
|
424 |
* @author Nacho Brodin <brodin_ign@gva.es> |
|
425 |
* |
|
426 |
* Opciones de escritura para el Ecw. Estas opciones son utilizadas para el |
|
427 |
* dialogo de propiedades de Salvar a Raster en Ecw. |
|
428 |
*/ |
|
429 |
class EcwSupportOptions extends WriterSupportOptions { |
|
430 |
private String[] compresionListValues = { "0", "20", "10", "1", "5" }; //min, max, valor defecto, intervalo peque?o, intervalo grande; |
|
431 |
private String[] formatList = { "NONE", "UINT8", "YUV", "MULTI", "RGB" }; |
|
432 |
private int formatDefault = 4; |
|
433 |
private int compresionDefault = 10; |
|
434 |
|
|
435 |
EcwSupportOptions() { |
|
436 |
super("Ecw"); |
|
437 |
} |
|
438 |
|
|
439 |
/** |
|
440 |
* Asigna la lista de valores de compresi?n |
|
441 |
* @param compresion lista de valores |
|
442 |
*/ |
|
443 |
public void setCompressionList(String[] compresion) { |
|
444 |
this.compresionListValues = compresion; |
|
445 |
} |
|
446 |
|
|
447 |
/** |
|
448 |
* Valor de formato seleccionado en el driver. |
|
449 |
* 0-NONE, 1-UINT8, 2-YUV, 3-MULTI, 4-RGB |
|
450 |
* @param i valor de formato |
|
451 |
*/ |
|
452 |
public void setFormatDefault(int i) { |
|
453 |
this.formatDefault = i; |
|
454 |
} |
|
455 |
|
|
456 |
/** |
|
457 |
* Asigna el nivel de compresi?npor defecto |
|
458 |
* @param compress Nivel de compresi?n |
|
459 |
*/ |
|
460 |
public void setCompressionDefault(int compress) { |
|
461 |
this.compresionDefault = compress; |
|
462 |
} |
|
463 |
|
|
464 |
/** |
|
465 |
* Obtiene el tipo de imagen en un formato comprensible por el driver. |
|
466 |
* @return Tipo de imagen |
|
467 |
*/ |
|
468 |
public String getStringFormat() { |
|
469 |
return "COMPRESS_" + formatList[formatDefault]; |
|
470 |
} |
|
471 |
|
|
472 |
/** |
|
473 |
* Obtiene la lista de los tipos de formato disponible |
|
474 |
* @return Lista de tipos de formato |
|
475 |
*/ |
|
476 |
public String[] getFormatList() { |
|
477 |
return formatList; |
|
478 |
} |
|
479 |
|
|
480 |
/** |
|
481 |
* Obtiene el tipo de formato seleccionado en el driver |
|
482 |
* @return Tipo de formato seleccionado |
|
483 |
*/ |
|
484 |
public int getFormat() { |
|
485 |
return formatDefault; |
|
486 |
} |
|
487 |
|
|
488 |
/** |
|
489 |
* Obtiene la compresion seleccionada |
|
490 |
* @return Compresi?n seleccionada |
|
491 |
*/ |
|
492 |
public int getCompression() { |
|
493 |
return compresionDefault; |
|
494 |
} |
|
495 |
|
|
496 |
/** |
|
497 |
* Obtiene la lista de los valores para la generaci?n de la barra de |
|
498 |
* compresi?n. Son cinco valores m?nimo, m?ximo, seleccionado, |
|
499 |
* intervalo peque?o, intervalo grande. |
|
500 |
* @return lista de valores de compresi?n |
|
501 |
*/ |
|
502 |
public String[] getCompressionList() { |
|
503 |
return compresionListValues; |
|
504 |
} |
|
505 |
} |
|
488 | 506 |
} |
489 | 507 |
|
508 |
|
|
490 | 509 |
/** |
491 | 510 |
* Clase que se encarga de la lectura de datos que ser?n escritos. Hereda de JniObject |
492 | 511 |
* para asegurar para asegurar que el interfaz de la libreria tiene acceso a variables |
493 | 512 |
* necesarias para la petici?n de datos cuando vacia el buffer. Implementa ReadCallBack |
494 |
* para obligar escribir el m?todo loadBuffer encargado de servir los datos cuando el
|
|
513 |
* para obligar escribir el m?todo loadBuffer encargado de servir los datos cuando el |
|
495 | 514 |
* buffer se vacia. |
496 | 515 |
* |
497 | 516 |
*/ |
498 |
|
|
499 | 517 |
class Reader extends JniObject implements ReadCallBack { |
518 |
private NCSEcwCompressClient compressclient = null; |
|
519 |
private int width; |
|
520 |
private int height; |
|
521 |
private int ulX; |
|
522 |
private int ulY; |
|
523 |
private GeoRasterFile grf = null; |
|
524 |
private IDataWriter dataWriter = null; |
|
525 |
private GdalRasterBand rband = null; |
|
526 |
private int blockSizeRead = 1; //Alto del bloque leido de la imagen origen |
|
527 |
private int countLine = 1; //Contador de l?neas procesadas en cada lectura de bloque |
|
528 |
byte[][] buf = null; |
|
529 |
byte[] bufband1 = null; |
|
530 |
byte[] bufband2 = null; |
|
531 |
byte[] bufband3 = null; |
|
532 |
byte[] bufband4 = null; |
|
533 |
byte[] bufband5 = null; |
|
534 |
byte[] bufband6 = null; |
|
535 |
int[] dataBuffer = null; |
|
536 |
private int lineasBloqueFinal = 0; //N?mero de l?neas leidas del bloque final |
|
537 |
private int nBlocks = 0; //N?mero de bloques completos |
|
538 |
private int countBlock = 1; //Contador de bloques completos procesados |
|
539 |
private int nBands = 0; |
|
500 | 540 |
|
501 |
private NCSEcwCompressClient compressclient=null; |
|
502 |
private int width, height; |
|
503 |
private int ulX, ulY; |
|
504 |
private GeoRasterFile grf=null; |
|
505 |
private IDataWriter dataWriter=null; |
|
506 |
private GdalRasterBand rband=null; |
|
507 |
private int blockSizeRead=1; //Alto del bloque leido de la imagen origen |
|
508 |
private int countLine=1; //Contador de l?neas procesadas en cada lectura de bloque |
|
509 |
byte[][] buf=null; |
|
510 |
byte[] bufband1=null; |
|
511 |
byte[] bufband2=null; |
|
512 |
byte[] bufband3=null; |
|
513 |
byte[] bufband4=null; |
|
514 |
byte[] bufband5=null; |
|
515 |
byte[] bufband6=null; |
|
516 |
int[] dataBuffer=null; |
|
517 |
private int lineasBloqueFinal=0; //N?mero de l?neas leidas del bloque final |
|
518 |
private int nBlocks=0; //N?mero de bloques completos |
|
519 |
private int countBlock=1; //Contador de bloques completos procesados |
|
520 |
private int nBands=0; |
|
521 |
|
|
522 |
/** |
|
523 |
* Constructor para la escritura de un fichero desde un GeoRasterFile |
|
524 |
* @param grf GeorasterFile del fichero de origen |
|
525 |
* @param compressclient Objeto que representa al compresor ecw |
|
526 |
* @param ulx Coordenada X de la esquina superior izquierda |
|
527 |
* @param uly Coordenada Y de la esquina superior izquierda |
|
528 |
* @param width Ancho de la imagen |
|
529 |
* @param height Alto de la imagen |
|
530 |
* @param blockSizeRead Altura del bloque en la lectura |
|
531 |
*/ |
|
532 |
public Reader( GeoRasterFile grf, |
|
533 |
NCSEcwCompressClient compressclient, |
|
534 |
int ulx, |
|
535 |
int uly, |
|
536 |
int width, |
|
537 |
int height, |
|
538 |
int blockSizeRead){ |
|
539 |
this.compressclient = compressclient; |
|
540 |
this.width = width; |
|
541 |
this.height = height; |
|
542 |
this.ulX = ulx; |
|
543 |
this.ulY = uly; |
|
544 |
this.grf = grf; |
|
545 |
this.nBands = grf.bandCount; |
|
546 |
|
|
547 |
if(blockSizeRead!=0) |
|
548 |
this.blockSizeRead = blockSizeRead; |
|
549 |
|
|
550 |
nBlocks = (int)(height/this.blockSizeRead); |
|
551 |
lineasBloqueFinal = height-(nBlocks*this.blockSizeRead); |
|
552 |
|
|
553 |
if(blockSizeRead>64) |
|
554 |
this.blockSizeRead=64; |
|
555 |
} |
|
556 |
|
|
557 |
/** |
|
558 |
* Constructor para que los datos sean servidos desde el cliente a trav?s de un |
|
559 |
* IDataWriter. |
|
560 |
* @param dataWriter Objeto servidor de datos del driver |
|
561 |
* @param compressclient Objeto que representa al compresor ecw |
|
562 |
* @param width Ancho de la imagen |
|
563 |
* @param height Alto de la imagen |
|
564 |
* @param blockSizeRead Altura del bloque en la lectura |
|
565 |
* @param nBands N?mero de bandas |
|
566 |
*/ |
|
567 |
public Reader( IDataWriter dataWriter, |
|
568 |
NCSEcwCompressClient compressclient, |
|
569 |
int width, |
|
570 |
int height, |
|
571 |
int blockSizeRead, |
|
572 |
int nBands){ |
|
573 |
this.compressclient = compressclient; |
|
574 |
this.width = width; |
|
575 |
this.height = height; |
|
576 |
this.dataWriter = dataWriter; |
|
577 |
this.nBands = nBands; |
|
578 |
|
|
579 |
if(blockSizeRead!=0) |
|
580 |
this.blockSizeRead = blockSizeRead; |
|
581 |
|
|
582 |
nBlocks = (int)(height/this.blockSizeRead); |
|
583 |
lineasBloqueFinal = height-(nBlocks*this.blockSizeRead); |
|
584 |
|
|
585 |
//System.out.println("NBLOQUES="+nBlocks+" lineas ultimo="+lineasBloqueFinal); |
|
586 |
|
|
587 |
if(blockSizeRead>64) |
|
588 |
this.blockSizeRead=64; |
|
589 |
} |
|
590 |
|
|
591 |
/** |
|
592 |
* Lectura de bandas desde un GeoRasterFile |
|
593 |
* @param ulX Coordenada X de la esquina superior izquierda |
|
594 |
* @param ulY Coordenada Y de la esquina superior izquierda |
|
595 |
* @param width Ancho de la imagen |
|
596 |
* @param lineasLeidas N?mero de l?neas a leer del origen |
|
597 |
*/ |
|
598 |
|
|
599 |
private void readBandsGRFile(int ulX, int ulY, int width, int lineasLeidas){ |
|
600 |
if(nBands>=1) |
|
601 |
bufband1 = grf.getWindow(ulX, ulY, width, lineasLeidas, 1); |
|
602 |
if(nBands>=2) |
|
603 |
bufband2 = grf.getWindow(ulX, ulY, width, lineasLeidas, 2); |
|
604 |
if(nBands>=3) |
|
605 |
bufband3 = grf.getWindow(ulX, ulY, width, lineasLeidas, 3); |
|
606 |
if(nBands>=4) |
|
607 |
bufband4 = grf.getWindow(ulX, ulY, width, lineasLeidas, 4); |
|
608 |
if(nBands>=5) |
|
609 |
bufband5 = grf.getWindow(ulX, ulY, width, lineasLeidas, 5); |
|
610 |
if(nBands>=6) |
|
611 |
bufband6 = grf.getWindow(ulX, ulY, width, lineasLeidas, 6); |
|
612 |
} |
|
613 |
|
|
614 |
/** |
|
615 |
* Lectura de bandas llamando al objeto cliente para que nos cargue el buffer |
|
616 |
* @param width Ancho de la imagen |
|
617 |
* @param height Alto de la imagen |
|
618 |
*/ |
|
619 |
|
|
620 |
private void readBands(int width, int height){ |
|
621 |
dataBuffer = dataWriter.readData(width, height, 0); |
|
622 |
} |
|
623 |
|
|
624 |
/** |
|
625 |
* M?todo obligado por el interfaz y que es llamado desde C cuando el |
|
626 |
* compresor necesita que le sirvan m?s datos. |
|
627 |
*/ |
|
628 |
|
|
629 |
public void loadBuffer(){ |
|
630 |
int lineasLeidas=0; |
|
631 |
|
|
632 |
//si se leen bloques completos lineasLeidas es == al tama?o de bloque sino |
|
633 |
//es que es el ?ltimo con lo que ser? del tama?o del bloque final |
|
634 |
|
|
635 |
if(countBlock<=nBlocks)lineasLeidas=blockSizeRead; |
|
636 |
else lineasLeidas=lineasBloqueFinal; |
|
637 |
|
|
638 |
//Leemos un bloque nuevo cuando se han procesado todas las l?neas del anterior |
|
639 |
|
|
640 |
if(nNextLine%blockSizeRead==0){ |
|
641 |
if(grf!=null) |
|
642 |
readBandsGRFile(ulX, ulY+nNextLine, width, lineasLeidas); |
|
643 |
else if(dataWriter!=null) |
|
644 |
readBands(width, lineasLeidas); |
|
645 |
|
|
646 |
countLine = 0; |
|
647 |
countBlock++; |
|
648 |
} |
|
649 |
|
|
650 |
|
|
651 |
for(int iBand=0;iBand<this.nBands;iBand++){ |
|
652 |
for(int pos=0; pos<width; pos++){ |
|
653 |
if(grf!=null){ |
|
654 |
if(iBand==0) |
|
655 |
compressclient.buffer[pos+(width*iBand)]=bufband1[pos+(width*countLine)]; |
|
656 |
if(iBand==1) |
|
657 |
compressclient.buffer[pos+(width*iBand)]=bufband2[pos+(width*countLine)]; |
|
658 |
if(iBand==2) |
|
659 |
compressclient.buffer[pos+(width*iBand)]=bufband3[pos+(width*countLine)]; |
|
660 |
if(iBand==3) |
|
661 |
compressclient.buffer[pos+(width*iBand)]=bufband4[pos+(width*countLine)]; |
|
662 |
if(iBand==4) |
|
663 |
compressclient.buffer[pos+(width*iBand)]=bufband5[pos+(width*countLine)]; |
|
664 |
if(iBand==5) |
|
665 |
compressclient.buffer[pos+(width*iBand)]=bufband6[pos+(width*countLine)]; |
|
666 |
}else{ |
|
667 |
if(iBand==0) |
|
668 |
compressclient.buffer[pos+(width*iBand)] = (byte)((dataBuffer[pos+(width*countLine)] & 0xff0000)>>16); |
|
669 |
if(iBand==1) |
|
670 |
compressclient.buffer[pos+(width*iBand)] = (byte)((dataBuffer[pos+(width*countLine)] & 0xff00)>>8); |
|
671 |
if(iBand==2) |
|
672 |
compressclient.buffer[pos+(width*iBand)] = (byte)(dataBuffer[pos+(width*countLine)] & 0xff); |
|
673 |
} |
|
674 |
if(pos==width-1 && iBand==this.nBands-1){ |
|
675 |
countLine++; |
|
676 |
} |
|
677 |
} |
|
678 |
} |
|
679 |
} |
|
680 |
|
|
681 |
/** |
|
682 |
* M?todo obligado por el interfaz y que es llamado desde C cuando el |
|
683 |
* compresor actualiza el porcentaje de compresi?n |
|
684 |
*/ |
|
685 |
public void updatePercent(){ |
|
686 |
System.out.println(compressclient.getPercent()+"%"); |
|
687 |
} |
|
688 |
|
|
689 |
} |
|
541 |
/** |
|
542 |
* Constructor para la escritura de un fichero desde un GeoRasterFile |
|
543 |
* @param grf GeorasterFile del fichero de origen |
|
544 |
* @param compressclient Objeto que representa al compresor ecw |
|
545 |
* @param ulx Coordenada X de la esquina superior izquierda |
|
546 |
* @param uly Coordenada Y de la esquina superior izquierda |
|
547 |
* @param width Ancho de la imagen |
|
548 |
* @param height Alto de la imagen |
|
549 |
* @param blockSizeRead Altura del bloque en la lectura |
|
550 |
*/ |
|
551 |
public Reader(GeoRasterFile grf, NCSEcwCompressClient compressclient, |
|
552 |
int ulx, int uly, int width, int height, int blockSizeRead) { |
|
553 |
this.compressclient = compressclient; |
|
554 |
this.width = width; |
|
555 |
this.height = height; |
|
556 |
this.ulX = ulx; |
|
557 |
this.ulY = uly; |
|
558 |
this.grf = grf; |
|
559 |
this.nBands = grf.bandCount; |
|
560 |
|
|
561 |
if (blockSizeRead != 0) { |
|
562 |
this.blockSizeRead = blockSizeRead; |
|
563 |
} |
|
564 |
|
|
565 |
nBlocks = (int) (height / this.blockSizeRead); |
|
566 |
lineasBloqueFinal = height - (nBlocks * this.blockSizeRead); |
|
567 |
|
|
568 |
if (blockSizeRead > 64) { |
|
569 |
this.blockSizeRead = 64; |
|
570 |
} |
|
571 |
} |
|
572 |
|
|
573 |
/** |
|
574 |
* Constructor para que los datos sean servidos desde el cliente a trav?s de un |
|
575 |
* IDataWriter. |
|
576 |
* @param dataWriter Objeto servidor de datos del driver |
|
577 |
* @param compressclient Objeto que representa al compresor ecw |
|
578 |
* @param width Ancho de la imagen |
|
579 |
* @param height Alto de la imagen |
|
580 |
* @param blockSizeRead Altura del bloque en la lectura |
|
581 |
* @param nBands N?mero de bandas |
|
582 |
*/ |
|
583 |
public Reader(IDataWriter dataWriter, NCSEcwCompressClient compressclient, |
|
584 |
int width, int height, int blockSizeRead, int nBands) { |
|
585 |
this.compressclient = compressclient; |
|
586 |
this.width = width; |
|
587 |
this.height = height; |
|
588 |
this.dataWriter = dataWriter; |
|
589 |
this.nBands = nBands; |
|
590 |
|
|
591 |
if (blockSizeRead != 0) { |
|
592 |
this.blockSizeRead = blockSizeRead; |
|
593 |
} |
|
594 |
|
|
595 |
nBlocks = (int) (height / this.blockSizeRead); |
|
596 |
lineasBloqueFinal = height - (nBlocks * this.blockSizeRead); |
|
597 |
|
|
598 |
//System.out.println("NBLOQUES="+nBlocks+" lineas ultimo="+lineasBloqueFinal); |
|
599 |
if (blockSizeRead > 64) { |
|
600 |
this.blockSizeRead = 64; |
|
601 |
} |
|
602 |
} |
|
603 |
|
|
604 |
/** |
|
605 |
* Lectura de bandas desde un GeoRasterFile |
|
606 |
* @param ulX Coordenada X de la esquina superior izquierda |
|
607 |
* @param ulY Coordenada Y de la esquina superior izquierda |
|
608 |
* @param width Ancho de la imagen |
|
609 |
* @param lineasLeidas N?mero de l?neas a leer del origen |
|
610 |
*/ |
|
611 |
private void readBandsGRFile(int ulX, int ulY, int width, int lineasLeidas) { |
|
612 |
if (nBands >= 1) { |
|
613 |
bufband1 = grf.getWindow(ulX, ulY, width, lineasLeidas, 1); |
|
614 |
} |
|
615 |
|
|
616 |
if (nBands >= 2) { |
|
617 |
bufband2 = grf.getWindow(ulX, ulY, width, lineasLeidas, 2); |
|
618 |
} |
|
619 |
|
|
620 |
if (nBands >= 3) { |
|
621 |
bufband3 = grf.getWindow(ulX, ulY, width, lineasLeidas, 3); |
|
622 |
} |
|
623 |
|
|
624 |
if (nBands >= 4) { |
|
625 |
bufband4 = grf.getWindow(ulX, ulY, width, lineasLeidas, 4); |
|
626 |
} |
|
627 |
|
|
628 |
if (nBands >= 5) { |
|
629 |
bufband5 = grf.getWindow(ulX, ulY, width, lineasLeidas, 5); |
|
630 |
} |
|
631 |
|
|
632 |
if (nBands >= 6) { |
|
633 |
bufband6 = grf.getWindow(ulX, ulY, width, lineasLeidas, 6); |
|
634 |
} |
|
635 |
} |
|
636 |
|
|
637 |
/** |
|
638 |
* Lectura de bandas llamando al objeto cliente para que nos cargue el buffer |
|
639 |
* @param width Ancho de la imagen |
|
640 |
* @param height Alto de la imagen |
|
641 |
*/ |
|
642 |
private void readBands(int width, int height) { |
|
643 |
dataBuffer = dataWriter.readData(width, height, 0); |
|
644 |
} |
|
645 |
|
|
646 |
/** |
|
647 |
* M?todo obligado por el interfaz y que es llamado desde C cuando el |
|
648 |
* compresor necesita que le sirvan m?s datos. |
|
649 |
*/ |
|
650 |
public void loadBuffer() { |
|
651 |
int lineasLeidas = 0; |
|
652 |
|
|
653 |
//si se leen bloques completos lineasLeidas es == al tama?o de bloque sino |
|
654 |
//es que es el ?ltimo con lo que ser? del tama?o del bloque final |
|
655 |
if (countBlock <= nBlocks) { |
|
656 |
lineasLeidas = blockSizeRead; |
|
657 |
} else { |
|
658 |
lineasLeidas = lineasBloqueFinal; |
|
659 |
} |
|
660 |
|
|
661 |
//Leemos un bloque nuevo cuando se han procesado todas las l?neas del anterior |
|
662 |
if ((nNextLine % blockSizeRead) == 0) { |
|
663 |
if (grf != null) { |
|
664 |
readBandsGRFile(ulX, ulY + nNextLine, width, lineasLeidas); |
|
665 |
} else if (dataWriter != null) { |
|
666 |
readBands(width, lineasLeidas); |
|
667 |
} |
|
668 |
|
|
669 |
countLine = 0; |
|
670 |
countBlock++; |
|
671 |
} |
|
672 |
|
|
673 |
for (int iBand = 0; iBand < this.nBands; iBand++) { |
|
674 |
for (int pos = 0; pos < width; pos++) { |
|
675 |
if (grf != null) { |
|
676 |
if (iBand == 0) { |
|
677 |
compressclient.buffer[pos + (width * iBand)] = bufband1[pos + |
|
678 |
(width * countLine)]; |
|
679 |
} |
|
680 |
|
|
681 |
if (iBand == 1) { |
|
682 |
compressclient.buffer[pos + (width * iBand)] = bufband2[pos + |
|
683 |
(width * countLine)]; |
|
684 |
} |
|
685 |
|
|
686 |
if (iBand == 2) { |
|
687 |
compressclient.buffer[pos + (width * iBand)] = bufband3[pos + |
|
688 |
(width * countLine)]; |
|
689 |
} |
|
690 |
|
|
691 |
if (iBand == 3) { |
|
692 |
compressclient.buffer[pos + (width * iBand)] = bufband4[pos + |
|
693 |
(width * countLine)]; |
|
694 |
} |
|
695 |
|
|
696 |
if (iBand == 4) { |
|
697 |
compressclient.buffer[pos + (width * iBand)] = bufband5[pos + |
|
698 |
(width * countLine)]; |
|
699 |
} |
|
700 |
|
|
701 |
if (iBand == 5) { |
|
702 |
compressclient.buffer[pos + (width * iBand)] = bufband6[pos + |
|
703 |
(width * countLine)]; |
|
704 |
} |
|
705 |
} else { |
|
706 |
if (iBand == 0) { |
|
707 |
compressclient.buffer[pos + (width * iBand)] = (byte) ((dataBuffer[pos + |
|
708 |
(width * countLine)] & |
|
709 |
0xff0000) >> 16); |
|
710 |
} |
|
711 |
|
|
712 |
if (iBand == 1) { |
|
713 |
compressclient.buffer[pos + (width * iBand)] = (byte) ((dataBuffer[pos + |
|
714 |
(width * countLine)] & |
|
715 |
0xff00) >> 8); |
|
716 |
} |
|
717 |
|
|
718 |
if (iBand == 2) { |
|
719 |
compressclient.buffer[pos + (width * iBand)] = (byte) (dataBuffer[pos + |
|
720 |
(width * countLine)] & |
|
721 |
0xff); |
|
722 |
} |
|
723 |
} |
|
724 |
|
|
725 |
if ((pos == (width - 1)) && (iBand == (this.nBands - 1))) { |
|
726 |
countLine++; |
|
727 |
} |
|
728 |
} |
|
729 |
} |
|
730 |
} |
|
731 |
|
|
732 |
/** |
|
733 |
* M?todo obligado por el interfaz y que es llamado desde C cuando el |
|
734 |
* compresor actualiza el porcentaje de compresi?n |
|
735 |
*/ |
|
736 |
public void updatePercent() { |
|
737 |
System.out.println(compressclient.getPercent() + "%"); |
|
738 |
} |
|
739 |
} |
Also available in: Unified diff