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