svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / EcwWriter.java @ 2312
History | View | Annotate | Download (20.7 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.cresques.io; |
25 |
|
26 |
import java.io.IOException; |
27 |
|
28 |
import es.gva.cit.jecwcompress.*; |
29 |
import es.gva.cit.jgdal.GdalRasterBand; |
30 |
|
31 |
import org.cresques.geo.ViewPortData; |
32 |
import org.cresques.px.PxRaster; |
33 |
|
34 |
/**
|
35 |
* Driver para la compresi?n en formato Ecw.
|
36 |
*
|
37 |
* Puede exportar un fichero desde un GeoRasterFile en cualquier formato soportado
|
38 |
* 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
|
45 |
* sirviendo y lo que le queda por servir.
|
46 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
47 |
*/
|
48 |
|
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; |
273 |
|
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);
|
312 |
|
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){ |
382 |
|
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{ |
399 |
|
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 |
|
488 |
} |
489 |
|
490 |
/**
|
491 |
* Clase que se encarga de la lectura de datos que ser?n escritos. Hereda de JniObject
|
492 |
* para asegurar para asegurar que el interfaz de la libreria tiene acceso a variables
|
493 |
* 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
|
495 |
* buffer se vacia.
|
496 |
*
|
497 |
*/
|
498 |
|
499 |
class Reader extends JniObject implements ReadCallBack { |
500 |
|
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 |
} |