svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / io / ErmapperWriter.java @ 11960
History | View | Annotate | Download (23.1 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.raster.dataset.io; |
20 |
|
21 |
import java.io.IOException; |
22 |
|
23 |
import org.cresques.io.GeoRasterFile; |
24 |
import org.gvsig.raster.dataset.GeoRasterWriter; |
25 |
import org.gvsig.raster.dataset.IBuffer; |
26 |
import org.gvsig.raster.dataset.IDataWriter; |
27 |
import org.gvsig.raster.dataset.Params; |
28 |
import org.gvsig.raster.dataset.Params.Param; |
29 |
import org.gvsig.raster.shared.Extent; |
30 |
import org.gvsig.raster.util.RasterUtilities; |
31 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
32 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
33 |
|
34 |
import es.gva.cit.jecwcompress.EcwException; |
35 |
import es.gva.cit.jecwcompress.JniObject; |
36 |
import es.gva.cit.jecwcompress.NCSEcwCompressClient; |
37 |
import es.gva.cit.jecwcompress.ReadCallBack; |
38 |
import es.gva.cit.jgdal.GdalRasterBand; |
39 |
|
40 |
|
41 |
/**
|
42 |
* Driver para la compresi?n en formato Ecw.
|
43 |
*
|
44 |
* Puede exportar un fichero desde un GeoRasterFile en cualquier formato soportado
|
45 |
* por los drivers de lectura a uno en formato Ecw.
|
46 |
*
|
47 |
* Puede salvar a disco en formato Ecw obteniendo los datos que van siendo servidos
|
48 |
* desde el cliente. Este cliente debe implementar un IDataWriter o tener un objeto
|
49 |
* que lo implemente. Inicialmente le pasar? los par?metros de la imagen de salida
|
50 |
* y cuando el driver comience a escribir le ir? solicitando m?s a trav?s del m?todo
|
51 |
* readData de IDataWriter. El cliente ser? el que lleve el control de lo que va
|
52 |
* sirviendo y lo que le queda por servir.
|
53 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
54 |
*/
|
55 |
public class ErmapperWriter extends GeoRasterWriter { |
56 |
|
57 |
static {
|
58 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
59 |
String os = System.getProperties().getProperty("os.version"); |
60 |
if (os.startsWith("2.4")){ |
61 |
extensionPoints.add("RasterWriter", "ecw", ErmapperWriter.class); |
62 |
typeList.put("ecw", "Ecw"); |
63 |
} |
64 |
extensionPoints.add("RasterWriter", "jp2", ErmapperWriter.class); |
65 |
typeList.put("jp2", "Jpeg2000"); |
66 |
} |
67 |
|
68 |
public final int windowSizeX = 386; |
69 |
public final int windowSizeY = 220; |
70 |
public final int panelSizeX = 358; |
71 |
public final int panelSizeY = 125; |
72 |
public final String panelLayout = "BorderLayout"; |
73 |
private NCSEcwCompressClient compressclient = null; |
74 |
private Reader readerObj; |
75 |
private double pixelSizeX; |
76 |
private double pixelSizeY; |
77 |
private double geoCoordOrigenX; |
78 |
private double geoCoordOrigenY; |
79 |
private boolean consulta = false; |
80 |
|
81 |
/**
|
82 |
* Carga los par?metros de este driver.
|
83 |
*/
|
84 |
public void loadParams() { |
85 |
super.loadParams();
|
86 |
|
87 |
driverParams.setParam( "compression",
|
88 |
"10",
|
89 |
Params.SLIDER, |
90 |
new String[]{ "0", "20", "10", "1", "5" }); //min, max, valor defecto, intervalo peque?o, intervalo grande; |
91 |
|
92 |
driverParams.setParam( "format",
|
93 |
"RGB",
|
94 |
Params.CHOICE, |
95 |
new String[]{ "NONE", "UINT8", "YUV", "MULTI", "RGB"}); |
96 |
} |
97 |
|
98 |
/**
|
99 |
* Constructor para la obtenci?n de par?metros del driver.
|
100 |
*/
|
101 |
public ErmapperWriter(String fileName) { |
102 |
ident = RasterUtilities.getExtensionFromFileName(fileName); |
103 |
driver = (String)typeList.get(ident);
|
104 |
|
105 |
loadParams(); |
106 |
|
107 |
consulta = true;
|
108 |
} |
109 |
|
110 |
/**
|
111 |
* Constructor para la lectura de datos desde el objeto cliente a partir
|
112 |
* de un viewport dado.
|
113 |
* @param dataWriter Objeto que sirve datos para el escritor
|
114 |
* @param vp viewport de origen
|
115 |
* @param outFileName Fichero de salida
|
116 |
* @param blockSize Tama?o de bloque
|
117 |
* @param nBands N?mero de bandas
|
118 |
* @param compresion Compresi?n
|
119 |
* @throws EcwException
|
120 |
* @throws IOException
|
121 |
*/
|
122 |
public ErmapperWriter( IDataWriter dataWriter,
|
123 |
String outFileName,
|
124 |
Integer nBands,
|
125 |
Extent ex, |
126 |
Integer outSizeX,
|
127 |
Integer outSizeY,
|
128 |
Integer dataType,
|
129 |
Params params) throws EcwException, IOException { |
130 |
ident = RasterUtilities.getExtensionFromFileName(outFileName); |
131 |
driver = (String)typeList.get(ident);
|
132 |
this.dataType = dataType.intValue();
|
133 |
|
134 |
if (nBands.intValue() <= 0) |
135 |
throw new EcwException("N?mero de bandas erroneo."); |
136 |
|
137 |
if ((ex.width() <= 0) || (ex.height() <= 0)) { |
138 |
throw new EcwException("Tama?o de la imagen de salida erroneo."); |
139 |
} |
140 |
|
141 |
this.outFileName = outFileName;
|
142 |
this.dataWriter = dataWriter;
|
143 |
|
144 |
this.nBands = nBands.intValue();
|
145 |
|
146 |
this.sizeWindowX = outSizeX.intValue();
|
147 |
this.sizeWindowY = outSizeY.intValue();
|
148 |
|
149 |
//Calculamos la georeferenciaci?n a partir del extend pasado por el cliente.
|
150 |
double maxX = ex.maxX();
|
151 |
geoCoordOrigenX = ex.minX(); |
152 |
geoCoordOrigenY = ex.maxY(); |
153 |
|
154 |
double minY = ex.minY();
|
155 |
pixelSizeX = (maxX - geoCoordOrigenX) / outSizeX.intValue(); |
156 |
pixelSizeY = (minY - geoCoordOrigenY) / outSizeY.intValue(); |
157 |
|
158 |
if (pixelSizeX == 0) |
159 |
pixelSizeX = 1.0;
|
160 |
|
161 |
if (pixelSizeY == 0) |
162 |
pixelSizeY = 1.0;
|
163 |
|
164 |
if(params == null) |
165 |
loadParams(); |
166 |
else
|
167 |
driverParams = params; |
168 |
|
169 |
init(); |
170 |
} |
171 |
|
172 |
/**
|
173 |
* Inicializaci?n de los par?metros del compresor que ser?n obtenidos
|
174 |
* de PxRaster.
|
175 |
* @throws EcwException
|
176 |
*/
|
177 |
private void init() throws EcwException { |
178 |
percent = 0;
|
179 |
int comp = new Integer(((Param)driverParams.getParamById("compression")).defaultValue).intValue(); |
180 |
String format = ((Param)driverParams.getParamById("format")).defaultValue; |
181 |
if ( comp == 0 ) |
182 |
driverParams.changeParamValue("compression", "1"); |
183 |
|
184 |
if (compressclient == null) |
185 |
compressclient = new NCSEcwCompressClient();
|
186 |
|
187 |
compressclient.setOutputFilename(outFileName); |
188 |
compressclient.setInputFilename(inFileName); |
189 |
compressclient.setTargetCompress(comp); |
190 |
compressclient.setInOutSizeX(sizeWindowX); |
191 |
compressclient.setInOutSizeY(sizeWindowY); |
192 |
compressclient.setInputBands(nBands); |
193 |
compressclient.setCompressFormat(convertFormatToInt(format)); |
194 |
|
195 |
boolean georef = new Boolean(((Param)driverParams.getParamById("georef")).defaultValue).booleanValue(); |
196 |
if (georef) {
|
197 |
compressclient.setCellIncrementX(pixelSizeX); |
198 |
compressclient.setCellIncrementY(pixelSizeY); |
199 |
compressclient.setOriginX(geoCoordOrigenX); |
200 |
compressclient.setOriginY(geoCoordOrigenY); |
201 |
} |
202 |
|
203 |
compressclient.setCellSizeUnits(1);
|
204 |
|
205 |
int blocksize = new Integer(((Param)driverParams.getParamById("blocksize")).defaultValue).intValue(); |
206 |
if (dataWriter != null) { |
207 |
readerObj = new Reader(dataWriter, compressclient, sizeWindowX, |
208 |
sizeWindowY, blocksize, nBands, this, dataType);
|
209 |
} |
210 |
} |
211 |
|
212 |
/**
|
213 |
* Convierte la cadena que representa el formato en un valor n?merico
|
214 |
* que entiende el driver.
|
215 |
* @param format Cadena que representa el formato
|
216 |
* @return Entero que representa a la cadena
|
217 |
*/
|
218 |
private int convertFormatToInt(String format) { |
219 |
if(format.compareTo("NONE") == 0) |
220 |
return 0; |
221 |
if(format.compareTo("UINT8") == 0) |
222 |
return 1; |
223 |
if(format.compareTo("YUV") == 0) |
224 |
return 2; |
225 |
if(format.compareTo("MULTI") == 0) |
226 |
return 3; |
227 |
if(format.compareTo("RGB") == 0) |
228 |
return 4; |
229 |
return -1; |
230 |
} |
231 |
/**
|
232 |
* A partir de un elemento que contiene una propiedad y un valor
|
233 |
* lo parsea y asigna el valor a su variable.
|
234 |
* @param propValue elemento con la forma propiedad=valor
|
235 |
*/
|
236 |
private void readProperty(String propValue) { |
237 |
String prop = propValue.substring(0, propValue.indexOf("=")); |
238 |
|
239 |
if (propValue.startsWith(prop)) {
|
240 |
String value = propValue.substring(propValue.indexOf("=") + 1, propValue.length()); |
241 |
|
242 |
if ((value != null) && !value.equals("")) { |
243 |
if (prop.equals("BLOCKSIZE")) |
244 |
driverParams.changeParamValue("blocksize", value);
|
245 |
if (prop.equals("FORMAT")) |
246 |
driverParams.changeParamValue("format", value);
|
247 |
if (prop.equals("COMPRESSION")) |
248 |
driverParams.changeParamValue("compression", value);
|
249 |
} |
250 |
} |
251 |
} |
252 |
|
253 |
/**
|
254 |
* Asigna propiedades al driver a partir de un vector de
|
255 |
* strings donde cada elemento tiene la estructura de
|
256 |
* propiedad=valor.
|
257 |
* @param props Propiedades
|
258 |
*/
|
259 |
public void setProps(String[] props) { |
260 |
for (int iProps = 0; iProps < props.length; iProps++) |
261 |
readProperty(props[iProps]); |
262 |
|
263 |
loadParams(); |
264 |
|
265 |
try {
|
266 |
if (!consulta) {
|
267 |
init(); |
268 |
} |
269 |
} catch (EcwException e) {
|
270 |
e.printStackTrace(); |
271 |
} |
272 |
} |
273 |
|
274 |
/**
|
275 |
* Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
|
276 |
* @throws IOException
|
277 |
*/
|
278 |
public void fileWrite() throws IOException { |
279 |
/* try {
|
280 |
compressclient.NCSEcwCompressOpen(false);
|
281 |
compressclient.NCSEcwCompress(readerObj);
|
282 |
} catch (EcwException e) {
|
283 |
e.printStackTrace();
|
284 |
}*/
|
285 |
//TODO: FUNCIONALIDAD: Compresi?n a partir de un dataset. De momento no es necesario y es posible que nunca lo sea.
|
286 |
} |
287 |
|
288 |
/**
|
289 |
* Realiza la funci?n de compresi?n a partir de los datos pasados por el cliente.
|
290 |
* @throws IOException
|
291 |
*/
|
292 |
public void dataWrite() throws IOException { |
293 |
if (dataWriter == null) { |
294 |
throw new IOException("No se ha obtenido un objeto para la lectura valido."); |
295 |
} |
296 |
|
297 |
try {
|
298 |
compressclient.NCSEcwCompressOpen(false);
|
299 |
compressclient.NCSEcwCompress(readerObj); |
300 |
} catch (EcwException e) {
|
301 |
e.printStackTrace(); |
302 |
} |
303 |
} |
304 |
|
305 |
/**
|
306 |
* Cierra el compresor ecw.
|
307 |
*/
|
308 |
public void writeClose() { |
309 |
try {
|
310 |
compressclient.NCSEcwCompressClose(); |
311 |
} catch (EcwException e) {
|
312 |
e.printStackTrace(); |
313 |
} |
314 |
} |
315 |
|
316 |
/**
|
317 |
* Cancela el compresor ecw.
|
318 |
*/
|
319 |
public void writeCancel() { |
320 |
try {
|
321 |
if(readerObj != null) |
322 |
readerObj.setWrite(false);
|
323 |
compressclient.NCSEcwCompressCancel(); |
324 |
} catch (EcwException e) {
|
325 |
e.printStackTrace(); |
326 |
} |
327 |
} |
328 |
|
329 |
/*
|
330 |
* (non-Javadoc)
|
331 |
* @see org.gvsig.raster.dataset.GeoRasterWriter#getDriverExtensionsByDataType(java.lang.String)
|
332 |
*/
|
333 |
public String[] getDriverExtensionsByDataType(int dataType) { |
334 |
switch(dataType) {
|
335 |
case IBuffer.TYPE_BYTE: return new String[]{"jp2"}; |
336 |
case IBuffer.TYPE_SHORT:
|
337 |
case IBuffer.TYPE_INT:
|
338 |
case IBuffer.TYPE_FLOAT:
|
339 |
case IBuffer.TYPE_DOUBLE:
|
340 |
} |
341 |
return null; |
342 |
} |
343 |
|
344 |
} |
345 |
|
346 |
|
347 |
/**
|
348 |
* Clase que se encarga de la lectura de datos que ser?n escritos. Hereda de JniObject
|
349 |
* para asegurar para asegurar que el interfaz de la libreria tiene acceso a variables
|
350 |
* necesarias para la petici?n de datos cuando vacia el buffer. Implementa ReadCallBack
|
351 |
* para obligar escribir el m?todo loadBuffer encargado de servir los datos cuando el
|
352 |
* buffer se vacia.
|
353 |
*
|
354 |
*/
|
355 |
class Reader extends JniObject implements ReadCallBack { |
356 |
private NCSEcwCompressClient compressclient = null; |
357 |
private int width; |
358 |
private int height; |
359 |
private int ulX; |
360 |
private int ulY; |
361 |
private GeoRasterFile grf = null; |
362 |
private IDataWriter dataWriter = null; |
363 |
private GdalRasterBand rband = null; |
364 |
private GeoRasterWriter writer = null; |
365 |
private int blockSizeRead = 1; //Alto del bloque leido de la imagen origen |
366 |
private int countLine = 1; //Contador de l?neas procesadas en cada lectura de bloque |
367 |
byte[][] buf = null; |
368 |
byte[] bufband1 = null; |
369 |
byte[] bufband2 = null; |
370 |
byte[] bufband3 = null; |
371 |
byte[] bufband4 = null; |
372 |
byte[] bufband5 = null; |
373 |
byte[] bufband6 = null; |
374 |
int[] dataBuffer = null; |
375 |
byte[][] byteBuffer = null; |
376 |
private int lineasBloqueFinal = 0; //N?mero de l?neas leidas del bloque final |
377 |
private int nBlocks = 0; //N?mero de bloques completos |
378 |
private int countBlock = 1; //Contador de bloques completos procesados |
379 |
private int nBands = 0; |
380 |
private boolean write = true; //Cuando est? a true se puede escribir en la imagen de salida. Si est? a false el proceso es interrumpido |
381 |
private int dataType = IBuffer.TYPE_BYTE; |
382 |
|
383 |
/**
|
384 |
* Constructor para la escritura de un fichero desde un GeoRasterFile
|
385 |
* @param grf GeorasterFile del fichero de origen
|
386 |
* @param compressclient Objeto que representa al compresor ecw
|
387 |
* @param ulx Coordenada X de la esquina superior izquierda
|
388 |
* @param uly Coordenada Y de la esquina superior izquierda
|
389 |
* @param width Ancho de la imagen
|
390 |
* @param height Alto de la imagen
|
391 |
* @param blockSizeRead Altura del bloque en la lectura
|
392 |
*/
|
393 |
public Reader(GeoRasterFile grf, NCSEcwCompressClient compressclient, |
394 |
int ulx, int uly, int width, int height, int blockSizeRead, int dataType) { |
395 |
this.compressclient = compressclient;
|
396 |
this.width = width;
|
397 |
this.height = height;
|
398 |
this.ulX = ulx;
|
399 |
this.ulY = uly;
|
400 |
this.grf = grf;
|
401 |
this.nBands = grf.getBandCount();
|
402 |
this.dataType = dataType;
|
403 |
|
404 |
if (blockSizeRead != 0) { |
405 |
this.blockSizeRead = blockSizeRead;
|
406 |
} |
407 |
|
408 |
nBlocks = (int) (height / this.blockSizeRead); |
409 |
lineasBloqueFinal = height - (nBlocks * this.blockSizeRead);
|
410 |
|
411 |
} |
412 |
|
413 |
/**
|
414 |
* Constructor para que los datos sean servidos desde el cliente a trav?s de un
|
415 |
* IDataWriter.
|
416 |
* @param dataWriter Objeto servidor de datos del driver
|
417 |
* @param compressclient Objeto que representa al compresor ecw
|
418 |
* @param width Ancho de la imagen
|
419 |
* @param height Alto de la imagen
|
420 |
* @param blockSizeRead Altura del bloque en la lectura
|
421 |
* @param nBands N?mero de bandas
|
422 |
*/
|
423 |
public Reader(IDataWriter dataWriter, NCSEcwCompressClient compressclient, |
424 |
int width, int height, int blockSizeRead, int nBands, |
425 |
GeoRasterWriter writer, int dataType) {
|
426 |
this.compressclient = compressclient;
|
427 |
this.width = width;
|
428 |
this.height = height;
|
429 |
this.dataWriter = dataWriter;
|
430 |
this.nBands = nBands;
|
431 |
this.writer = writer;
|
432 |
this.dataType = dataType;
|
433 |
|
434 |
if (blockSizeRead != 0) { |
435 |
this.blockSizeRead = blockSizeRead;
|
436 |
} |
437 |
|
438 |
nBlocks = (int) (height / this.blockSizeRead); |
439 |
lineasBloqueFinal = height - (nBlocks * this.blockSizeRead);
|
440 |
} |
441 |
|
442 |
/**
|
443 |
* Lectura de bandas desde un GeoRasterFile
|
444 |
* @param ulX Coordenada X de la esquina superior izquierda
|
445 |
* @param ulY Coordenada Y de la esquina superior izquierda
|
446 |
* @param width Ancho de la imagen
|
447 |
* @param lineasLeidas N?mero de l?neas a leer del origen
|
448 |
*/
|
449 |
private void readBandsGRFile(int ulX, int ulY, int width, int lineasLeidas) { |
450 |
if (nBands >= 1) |
451 |
bufband1 = grf.getWindow(ulX, ulY, width, lineasLeidas, 1);
|
452 |
|
453 |
if (nBands >= 2) |
454 |
bufband2 = grf.getWindow(ulX, ulY, width, lineasLeidas, 2);
|
455 |
|
456 |
if (nBands >= 3) |
457 |
bufband3 = grf.getWindow(ulX, ulY, width, lineasLeidas, 3);
|
458 |
|
459 |
if (nBands >= 4) |
460 |
bufband4 = grf.getWindow(ulX, ulY, width, lineasLeidas, 4);
|
461 |
|
462 |
if (nBands >= 5) |
463 |
bufband5 = grf.getWindow(ulX, ulY, width, lineasLeidas, 5);
|
464 |
|
465 |
if (nBands >= 6) |
466 |
bufband6 = grf.getWindow(ulX, ulY, width, lineasLeidas, 6);
|
467 |
} |
468 |
|
469 |
/**
|
470 |
* Lectura de bandas llamando al objeto cliente para que nos cargue el buffer
|
471 |
* @param width Ancho de la imagen
|
472 |
* @param height Alto de la imagen
|
473 |
*/
|
474 |
private void readBands(int width, int height) { |
475 |
if(dataType == IBuffer.TYPE_IMAGE)
|
476 |
dataBuffer = dataWriter.readARGBData(width, height, 0);
|
477 |
if(dataType == IBuffer.TYPE_BYTE) {
|
478 |
byte[][] b = dataWriter.readByteData(width, height); |
479 |
|
480 |
} |
481 |
} |
482 |
|
483 |
/**
|
484 |
* M?todo obligado por el interfaz y que es llamado desde C cuando el
|
485 |
* compresor necesita que le sirvan m?s datos.
|
486 |
*/
|
487 |
public void loadBuffer() { |
488 |
int lineasLeidas = 0; |
489 |
|
490 |
//si se leen bloques completos lineasLeidas es == al tama?o de bloque sino
|
491 |
//es que es el ?ltimo con lo que ser? del tama?o del bloque final
|
492 |
if (countBlock <= nBlocks)
|
493 |
lineasLeidas = blockSizeRead; |
494 |
else
|
495 |
lineasLeidas = lineasBloqueFinal; |
496 |
|
497 |
//Leemos un bloque nuevo cuando se han procesado todas las l?neas del anterior
|
498 |
if ((nNextLine % blockSizeRead) == 0) { |
499 |
if (grf != null) |
500 |
readBandsGRFile(ulX, ulY + nNextLine, width, lineasLeidas); |
501 |
else if (dataWriter != null) { |
502 |
if(dataType == IBuffer.TYPE_IMAGE)
|
503 |
dataBuffer = dataWriter.readARGBData(width, lineasLeidas, 0);
|
504 |
if(dataType == IBuffer.TYPE_BYTE)
|
505 |
byteBuffer = dataWriter.readByteData(width, lineasLeidas); |
506 |
} |
507 |
|
508 |
countLine = 0;
|
509 |
countBlock++; |
510 |
} |
511 |
|
512 |
if(dataType == IBuffer.TYPE_IMAGE)
|
513 |
loadBufferFromImageDataType(dataBuffer); |
514 |
if(dataType == IBuffer.TYPE_BYTE)
|
515 |
loadBufferFromByteDataType(byteBuffer); |
516 |
|
517 |
/* for (int iBand = 0; iBand < this.nBands; iBand++) {
|
518 |
for (int pos = 0; pos < width; pos++) {
|
519 |
if (grf != null && write) {
|
520 |
if (iBand == 0)
|
521 |
compressclient.buffer[pos + (width * iBand)] =
|
522 |
bufband1[pos + (width * countLine)];
|
523 |
|
524 |
if (iBand == 1)
|
525 |
compressclient.buffer[pos + (width * iBand)] =
|
526 |
bufband2[pos + (width * countLine)];
|
527 |
|
528 |
if (iBand == 2)
|
529 |
compressclient.buffer[pos + (width * iBand)] =
|
530 |
bufband3[pos + (width * countLine)];
|
531 |
|
532 |
if (iBand == 3)
|
533 |
compressclient.buffer[pos + (width * iBand)] =
|
534 |
bufband4[pos + (width * countLine)];
|
535 |
|
536 |
if (iBand == 4)
|
537 |
compressclient.buffer[pos + (width * iBand)] =
|
538 |
bufband5[pos + (width * countLine)];
|
539 |
|
540 |
if (iBand == 5)
|
541 |
compressclient.buffer[pos + (width * iBand)] =
|
542 |
bufband6[pos + (width * countLine)];
|
543 |
|
544 |
} else {
|
545 |
if (iBand == 0)
|
546 |
compressclient.buffer[pos + (width * iBand)] =
|
547 |
(byte) ((dataBuffer[pos + (width * countLine)] & 0xff0000) >> 16);
|
548 |
|
549 |
|
550 |
if (iBand == 1)
|
551 |
compressclient.buffer[pos + (width * iBand)] =
|
552 |
(byte) ((dataBuffer[pos + (width * countLine)] & 0xff00) >> 8);
|
553 |
|
554 |
|
555 |
if (iBand == 2)
|
556 |
compressclient.buffer[pos + (width * iBand)] =
|
557 |
(byte) (dataBuffer[pos + (width * countLine)] & 0xff);
|
558 |
|
559 |
}
|
560 |
|
561 |
if ((pos == (width - 1)) && (iBand == (this.nBands - 1))) {
|
562 |
countLine++;
|
563 |
}
|
564 |
}
|
565 |
}*/
|
566 |
} |
567 |
|
568 |
/**
|
569 |
* Carga el buffer de datos desde elementos de tipo entero con contenido ARGB
|
570 |
* @param data Array de datos enteros
|
571 |
*/
|
572 |
private void loadBufferFromImageDataType(int[] data) { |
573 |
for (int iBand = 0; iBand < this.nBands; iBand++) { |
574 |
for (int pos = 0; pos < width; pos++) { |
575 |
switch(iBand) {
|
576 |
case 0: |
577 |
compressclient.buffer[pos + (width * iBand)] = |
578 |
(byte) ((data[pos + (width * countLine)] & 0xff0000) >> 16); |
579 |
break;
|
580 |
case 1: |
581 |
compressclient.buffer[pos + (width * iBand)] = |
582 |
(byte) ((data[pos + (width * countLine)] & 0xff00) >> 8); |
583 |
break;
|
584 |
case 2: |
585 |
compressclient.buffer[pos + (width * iBand)] = |
586 |
(byte) (data[pos + (width * countLine)] & 0xff); |
587 |
break;
|
588 |
} |
589 |
if ((pos == (width - 1)) && (iBand == (this.nBands - 1))) |
590 |
countLine++; |
591 |
} |
592 |
} |
593 |
} |
594 |
|
595 |
/**
|
596 |
* Carga el buffer de datos a comprimir desde un buffer byte[][] donde la primera dimensi?n
|
597 |
* es el n?mero de bandas y la segunda los elementos en lista (Ancho X Alto)
|
598 |
* @param b Buffer de datos de tipo byte[][]
|
599 |
*/
|
600 |
private void loadBufferFromByteDataType(byte[][] b) { |
601 |
for (int iBand = 0; iBand < this.nBands; iBand++) { |
602 |
for (int pos = 0; pos < width; pos++) { |
603 |
compressclient.buffer[pos + (width * iBand)] = b[iBand][pos + (width * countLine)]; |
604 |
if ((pos == (width - 1)) && (iBand == (this.nBands - 1))) |
605 |
countLine++; |
606 |
} |
607 |
} |
608 |
} |
609 |
|
610 |
/**
|
611 |
* M?todo obligado por el interfaz y que es llamado desde C cuando el
|
612 |
* compresor actualiza el porcentaje de compresi?n
|
613 |
*/
|
614 |
public void updatePercent() { |
615 |
writer.setPercent(compressclient.getPercent()); |
616 |
//System.out.println(compressclient.getPercent() + "%");
|
617 |
} |
618 |
|
619 |
/**
|
620 |
* Obtiene el valor a la variable write que estar? a true cuando se est? escribiendo
|
621 |
* o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
|
622 |
* pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
|
623 |
* de salida.
|
624 |
* @return True si puede escribirse y false si no puede
|
625 |
*/
|
626 |
public boolean isWrite() { |
627 |
return write;
|
628 |
} |
629 |
|
630 |
/**
|
631 |
* Asigna el valor a la variable write que estar? a true cuando se est? escribiendo
|
632 |
* o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
|
633 |
* pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
|
634 |
* de salida.
|
635 |
* @param write Variable booleana. True si puede escribirse y false si no puede
|
636 |
*/
|
637 |
public void setWrite(boolean write) { |
638 |
this.write = write;
|
639 |
} |
640 |
|
641 |
} |