Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / dataset / io / ErmapperWriter.java @ 12567

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.extensionPoints.ExtensionPoints;
34
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton;
35

    
36
import es.gva.cit.jecwcompress.EcwException;
37
import es.gva.cit.jecwcompress.JniObject;
38
import es.gva.cit.jecwcompress.NCSEcwCompressClient;
39
import es.gva.cit.jecwcompress.ReadCallBack;
40
import es.gva.cit.jgdal.GdalRasterBand;
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
        public static void register() {
58
                ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
59
                WriteFileFormatFeatures features = null;
60

    
61
                String os = System.getProperties().getProperty("os.version");
62
                if (os.startsWith("2.4")){
63
                        extensionPoints.add("RasterWriter", "ecw", ErmapperWriter.class);
64
                        features = new WriteFileFormatFeatures("Ecw", "ecw", -1, null, ErmapperWriter.class);
65
                        fileFeature.put("ecw", features);
66
                }
67
                extensionPoints.add("RasterWriter", "jp2", ErmapperWriter.class);
68
                features = new WriteFileFormatFeatures("Jpeg2000", "jp2", -1, null, ErmapperWriter.class);
69
                fileFeature.put("jp2", features);
70
        }
71

    
72
        public final int                                 windowSizeX = 386;
73
        public final int                                 windowSizeY = 220;
74
        public final int                                 panelSizeX = 358;
75
        public final int                                 panelSizeY = 125;
76
        public final String                         panelLayout = "BorderLayout";
77
        private NCSEcwCompressClient         compressclient = null;
78
        private Reader                                         readerObj;
79
        private double                                         pixelSizeX;
80
        private double                                         pixelSizeY;
81
        private double                                         geoCoordOrigenX;
82
        private double                                         geoCoordOrigenY;
83
        private boolean                                 consulta = false;
84

    
85
        /**
86
         * Carga los par?metros de este driver.
87
         */
88
        public void loadParams() {
89
                WriteFileFormatFeatures wfff = new WriteFileFormatFeatures();
90
                wfff.loadParams();
91
                driverParams = wfff.getParams();
92

    
93
                driverParams.setParam(        "compression",
94
                                "10",
95
                                Params.SLIDER,
96
                                new String[]{ "0", "20", "10", "1", "5" }); //min, max, valor defecto, intervalo peque?o, intervalo grande;
97

    
98
                driverParams.setParam(        "format",
99
                                "RGB",
100
                                Params.CHOICE,
101
                                new String[]{ "NONE", "UINT8", "YUV", "MULTI", "RGB"});
102
        }
103

    
104
        /**
105
         * Constructor para la obtenci?n de par?metros del driver.
106
         */
107
        public ErmapperWriter(String fileName) {
108
                ident = RasterUtilities.getExtensionFromFileName(fileName);
109
                driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName();
110

    
111
                loadParams();
112

    
113
                consulta = true;
114
        }
115

    
116
        /**
117
         * Constructor para la lectura de datos desde el objeto cliente a partir
118
         * de un viewport dado.
119
         * @param dataWriter        Objeto que sirve datos para el escritor
120
         * @param vp        viewport de origen
121
         * @param outFileName        Fichero de salida
122
         * @param blockSize        Tama?o de bloque
123
         * @param nBands        N?mero de bandas
124
         * @param compresion        Compresi?n
125
         * @throws EcwException
126
         * @throws IOException
127
         */
128
        public ErmapperWriter(        IDataWriter dataWriter,
129
                        String outFileName,
130
                        Integer nBands,
131
                        Extent ex,
132
                        Integer outSizeX,
133
                        Integer outSizeY,
134
                        Integer dataType,
135
                        Params params,
136
                        IProjection proj) throws EcwException, IOException {
137
                this.proj = proj;
138
                ident = RasterUtilities.getExtensionFromFileName(outFileName);
139
                driver = ((WriteFileFormatFeatures)fileFeature.get(ident)).getDriverName();
140
                this.dataType = dataType.intValue();
141

    
142
                if (nBands.intValue() <= 0)
143
                        throw new EcwException("N?mero de bandas erroneo.");
144

    
145
                if ((ex.width() <= 0) || (ex.height() <= 0)) {
146
                        throw new EcwException("Tama?o de la imagen de salida erroneo.");
147
                }
148

    
149
                this.outFileName = outFileName;
150
                this.dataWriter = dataWriter;
151

    
152
                this.nBands = nBands.intValue();
153

    
154
                this.sizeWindowX = outSizeX.intValue();
155
                this.sizeWindowY = outSizeY.intValue();
156

    
157
                //Calculamos la georeferenciaci?n a partir del extend pasado por el cliente.
158
                double maxX = ex.maxX();
159
                geoCoordOrigenX = ex.minX();
160
                geoCoordOrigenY = ex.maxY();
161

    
162
                double minY = ex.minY();
163
                pixelSizeX = (maxX - geoCoordOrigenX) / outSizeX.intValue();
164
                pixelSizeY = (minY - geoCoordOrigenY) / outSizeY.intValue();
165

    
166
                if (pixelSizeX == 0)
167
                        pixelSizeX = 1.0;
168

    
169
                if (pixelSizeY == 0)
170
                        pixelSizeY = 1.0;
171

    
172
                if(params == null)
173
                        loadParams();
174
                else
175
                        driverParams = params;
176

    
177
                init();
178
        }
179

    
180
        /**
181
         * Inicializaci?n de los par?metros del compresor que ser?n obtenidos
182
         * de PxRaster.
183
         * @throws EcwException
184
         */
185
        private void init() throws EcwException {
186
                percent = 0;
187
                int comp = new Integer((String) ((Param)driverParams.getParamById("compression")).defaultValue).intValue();
188
                String format = (String) ((Param)driverParams.getParamById("format")).defaultValue;
189
                if ( comp == 0 )
190
                        driverParams.changeParamValue("compression", "1");
191

    
192
                if (compressclient == null)
193
                        compressclient = new NCSEcwCompressClient();
194

    
195
                compressclient.setOutputFilename(outFileName);
196
                compressclient.setInputFilename(inFileName);
197
                compressclient.setTargetCompress(comp);
198
                compressclient.setInOutSizeX(sizeWindowX);
199
                compressclient.setInOutSizeY(sizeWindowY);
200
                compressclient.setInputBands(nBands);
201
                compressclient.setCompressFormat(convertFormatToInt(format));
202

    
203
                /* boolean georef = new Boolean(((Param)driverParams.getParamById("georef")).defaultValue).booleanValue();
204
                                if (georef) {*/
205
                compressclient.setCellIncrementX(pixelSizeX);
206
                compressclient.setCellIncrementY(pixelSizeY);
207
                compressclient.setOriginX(geoCoordOrigenX);
208
                compressclient.setOriginY(geoCoordOrigenY);
209
                //}
210

    
211
                compressclient.setCellSizeUnits(1);
212

    
213
                int blocksize = new Integer((String) ((Param)driverParams.getParamById("blocksize")).defaultValue).intValue();
214
                if (dataWriter != null) {
215
                        readerObj = new Reader(dataWriter, compressclient, sizeWindowX,
216
                                        sizeWindowY, blocksize, nBands, this, dataType);
217
                }
218
        }
219

    
220
        /**
221
         * Convierte la cadena que representa el formato en un valor n?merico
222
         * que entiende el driver.
223
         * @param format Cadena que representa el formato
224
         * @return Entero que representa a la cadena
225
         */
226
        private int convertFormatToInt(String format) {
227
                if(format.compareTo("NONE") == 0)
228
                        return 0;
229
                if(format.compareTo("UINT8") == 0)
230
                        return 1;
231
                if(format.compareTo("YUV") == 0)
232
                        return 2;
233
                if(format.compareTo("MULTI") == 0)
234
                        return 3;
235
                if(format.compareTo("RGB") == 0)
236
                        return 4;
237
                return -1;
238
        }
239
        /**
240
         * A partir de un elemento que contiene una propiedad y un valor
241
         * lo parsea y asigna el valor a su variable.
242
         * @param propValue        elemento con la forma propiedad=valor
243
         */
244
        private void readProperty(String propValue) {
245
                String prop = propValue.substring(0, propValue.indexOf("="));
246

    
247
                if (propValue.startsWith(prop)) {
248
                        String value = propValue.substring(propValue.indexOf("=") + 1, propValue.length());
249

    
250
                        if ((value != null) && !value.equals("")) {
251
                                if (prop.equals("BLOCKSIZE"))
252
                                        driverParams.changeParamValue("blocksize", value);
253
                                if (prop.equals("FORMAT"))
254
                                        driverParams.changeParamValue("format", value);
255
                                if (prop.equals("COMPRESSION"))
256
                                        driverParams.changeParamValue("compression", value);
257
                        }
258
                }
259
        }
260

    
261
        /**
262
         * Asigna propiedades al driver a partir de un vector de
263
         * strings donde cada elemento tiene la estructura de
264
         * propiedad=valor.
265
         * @param props        Propiedades
266
         */
267
        public void setProps(String[] props) {
268
                for (int iProps = 0; iProps < props.length; iProps++)
269
                        readProperty(props[iProps]);
270

    
271
                loadParams();
272

    
273
                try {
274
                        if (!consulta) {
275
                                init();
276
                        }
277
                } catch (EcwException e) {
278
                        e.printStackTrace();
279
                }
280
        }
281

    
282
        /**
283
         * Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
284
         * @throws IOException
285
         */
286
        public void fileWrite() throws IOException {
287
                /* try {
288
                                                compressclient.NCSEcwCompressOpen(false);
289
                                                compressclient.NCSEcwCompress(readerObj);
290
                                } catch (EcwException e) {
291
                                                e.printStackTrace();
292
                                }*/
293
                //TODO: FUNCIONALIDAD: Compresi?n a partir de un dataset. De momento no es necesario y es posible que nunca lo sea.
294
        }
295

    
296
        /**
297
         * Realiza la funci?n de compresi?n a partir de los datos pasados por el cliente.
298
         * @throws IOException
299
         */
300
        public void dataWrite() throws IOException {
301
                if (dataWriter == null) {
302
                        throw new IOException("No se ha obtenido un objeto para la lectura valido.");
303
                }
304

    
305
                try {
306
                        compressclient.NCSEcwCompressOpen(false);
307
                        compressclient.NCSEcwCompress(readerObj);
308
                } catch (EcwException e) {
309
                        e.printStackTrace();
310
                }
311
        }
312

    
313
        /**
314
         * Cierra el compresor ecw.
315
         */
316
        public void writeClose() {
317
                try {
318
                        compressclient.NCSEcwCompressClose();
319
                } catch (EcwException e) {
320
                        e.printStackTrace();
321
                }
322
        }
323

    
324
        /**
325
         * Cancela el compresor ecw.
326
         */
327
        public void writeCancel() {
328
                try {
329
                        if(readerObj != null)
330
                                readerObj.setWrite(false);
331
                        compressclient.NCSEcwCompressCancel();
332
                } catch (EcwException e) {
333
                        e.printStackTrace();
334
                }
335
        }
336

    
337
        /*
338
         * (non-Javadoc)
339
         * @see org.gvsig.raster.dataset.GeoRasterWriter#setWkt(java.lang.String)
340
         */
341
        public void setWkt(String wkt) {
342
                //TODO: FUNCIONALIDAD: La asignaci?n de proyecci?n en Ecw falla haciendo petar la aplicaci?n.
343
                /*if(compressclient != null && wkt != null && wkt.compareTo("unknown") != 0) {
344
                        WktUtils wktutil = new WktUtils(wkt);
345
                        compressclient.setProjection("EPSG:" + wktutil.getEPSG());
346
                }*/
347
        }
348

    
349
}
350

    
351

    
352
/**
353
 * Clase que se encarga de la lectura de datos que ser?n escritos. Hereda de JniObject
354
 * para asegurar  para asegurar que el interfaz de la libreria tiene acceso a variables
355
 * necesarias para la petici?n de datos cuando vacia el buffer. Implementa ReadCallBack
356
 * para obligar escribir el m?todo loadBuffer encargado de servir los datos cuando el
357
 * buffer se vacia.
358
 *
359
 */
360
class Reader extends JniObject implements ReadCallBack {
361
        private NCSEcwCompressClient        compressclient = null;
362
        private int                                         width;
363
        private int                                         height;
364
        private int                                         ulX;
365
        private int                                         ulY;
366
        private GeoRasterFile                         grf = null;
367
        private IDataWriter                         dataWriter = null;
368
        private GdalRasterBand                         rband = null;
369
        private GeoRasterWriter                        writer = null;
370
        private int                                         blockSizeRead = 1; //Alto del bloque leido de la imagen origen
371
        private int                                         countLine = 1; //Contador de l?neas procesadas en cada lectura de bloque
372
        byte[][]                                                 buf = null;
373
        byte[]                                                         bufband1 = null;
374
        byte[]                                                         bufband2 = null;
375
        byte[]                                                         bufband3 = null;
376
        byte[]                                                         bufband4 = null;
377
        byte[]                                                         bufband5 = null;
378
        byte[]                                                         bufband6 = null;
379
        int[]                                                         dataBuffer = null;
380
        byte[][]                                                 byteBuffer = null;
381
        private int                                         lineasBloqueFinal = 0; //N?mero de l?neas leidas del bloque final
382
        private int                                         nBlocks = 0; //N?mero de bloques completos
383
        private int                                         countBlock = 1; //Contador de bloques completos procesados
384
        private int                                         nBands = 0;
385
        private        boolean                                        write = true; //Cuando est? a true se puede escribir en la imagen de salida. Si est? a false el proceso es interrumpido
386
        private int                                                dataType = IBuffer.TYPE_BYTE;
387

    
388
        /**
389
         * Constructor para la escritura de un fichero desde un GeoRasterFile
390
         * @param grf        GeorasterFile del fichero de origen
391
         * @param compressclient        Objeto que representa al compresor ecw
392
         * @param ulx        Coordenada X de la esquina superior izquierda
393
         * @param uly        Coordenada Y de la esquina superior izquierda
394
         * @param width        Ancho de la imagen
395
         * @param height        Alto de la imagen
396
         * @param blockSizeRead        Altura del bloque en la lectura
397
         */
398
        public Reader(GeoRasterFile grf, NCSEcwCompressClient compressclient,
399
                        int ulx, int uly, int width, int height, int blockSizeRead, int dataType) {
400
                this.compressclient = compressclient;
401
                this.width = width;
402
                this.height = height;
403
                this.ulX = ulx;
404
                this.ulY = uly;
405
                this.grf = grf;
406
                this.nBands = grf.getBandCount();
407
                this.dataType = dataType;
408

    
409
                if (blockSizeRead != 0) {
410
                        this.blockSizeRead = blockSizeRead;
411
                }
412

    
413
                nBlocks = (int) (height / this.blockSizeRead);
414
                lineasBloqueFinal = height - (nBlocks * this.blockSizeRead);
415

    
416
        }
417

    
418
        /**
419
         * Constructor para que los datos sean servidos desde el cliente a trav?s de un
420
         * IDataWriter.
421
         * @param dataWriter        Objeto servidor de datos del driver
422
         * @param compressclient        Objeto que representa al compresor ecw
423
         * @param width        Ancho de la imagen
424
         * @param height        Alto de la imagen
425
         * @param blockSizeRead        Altura del bloque en la lectura
426
         * @param nBands        N?mero de bandas
427
         */
428
        public Reader(IDataWriter dataWriter, NCSEcwCompressClient compressclient,
429
                        int width, int height, int blockSizeRead, int nBands,
430
                        GeoRasterWriter writer, int dataType) {
431
                this.compressclient = compressclient;
432
                this.width = width;
433
                this.height = height;
434
                this.dataWriter = dataWriter;
435
                this.nBands = nBands;
436
                this.writer = writer;
437
                this.dataType = dataType;
438

    
439
                if (blockSizeRead != 0) {
440
                        this.blockSizeRead = blockSizeRead;
441
                }
442

    
443
                nBlocks = (int) (height / this.blockSizeRead);
444
                lineasBloqueFinal = height - (nBlocks * this.blockSizeRead);
445
        }
446

    
447
        /**
448
         * Lectura de bandas desde un GeoRasterFile
449
         * @param ulX        Coordenada X de la esquina superior izquierda
450
         * @param ulY        Coordenada Y de la esquina superior izquierda
451
         * @param width        Ancho de la imagen
452
         * @param lineasLeidas        N?mero de l?neas a leer del origen
453
         */
454
        private void readBandsGRFile(int ulX, int ulY, int width, int lineasLeidas) {
455
                if (nBands >= 1)
456
                        bufband1 = grf.getWindow(ulX, ulY, width, lineasLeidas, 1);
457

    
458
                if (nBands >= 2)
459
                        bufband2 = grf.getWindow(ulX, ulY, width, lineasLeidas, 2);
460

    
461
                if (nBands >= 3)
462
                        bufband3 = grf.getWindow(ulX, ulY, width, lineasLeidas, 3);
463

    
464
                if (nBands >= 4)
465
                        bufband4 = grf.getWindow(ulX, ulY, width, lineasLeidas, 4);
466

    
467
                if (nBands >= 5)
468
                        bufband5 = grf.getWindow(ulX, ulY, width, lineasLeidas, 5);
469

    
470
                if (nBands >= 6)
471
                        bufband6 = grf.getWindow(ulX, ulY, width, lineasLeidas, 6);
472
        }
473

    
474
        /**
475
         * Lectura de bandas llamando al objeto cliente para que nos cargue el buffer
476
         * @param width        Ancho de la imagen
477
         * @param height        Alto de la imagen
478
         */
479
        private void readBands(int width, int height) {
480
                if(dataType == IBuffer.TYPE_IMAGE)
481
                        dataBuffer = dataWriter.readARGBData(width, height, 0);
482
                if(dataType == IBuffer.TYPE_BYTE) {
483
                        byte[][] b = dataWriter.readByteData(width, height);
484

    
485
                }
486
        }
487

    
488
        /**
489
         * M?todo obligado por el interfaz y que es llamado desde C cuando el
490
         * compresor necesita que le sirvan m?s datos.
491
         */
492
        public void loadBuffer() {
493
                int lineasLeidas = 0;
494

    
495
                //si se leen bloques completos lineasLeidas es == al tama?o de bloque sino
496
                //es que es el ?ltimo con lo que ser? del tama?o del bloque final
497
                if (countBlock <= nBlocks)
498
                        lineasLeidas = blockSizeRead;
499
                else
500
                        lineasLeidas = lineasBloqueFinal;
501

    
502
                //Leemos un bloque nuevo cuando se han procesado todas las l?neas del anterior
503
                if ((nNextLine % blockSizeRead) == 0) {
504
                        if (grf != null)
505
                                readBandsGRFile(ulX, ulY + nNextLine, width, lineasLeidas);
506
                        else if (dataWriter != null) {
507
                                if(dataType == IBuffer.TYPE_IMAGE)
508
                                        dataBuffer = dataWriter.readARGBData(width, lineasLeidas, 0);
509
                                if(dataType == IBuffer.TYPE_BYTE)
510
                                        byteBuffer = dataWriter.readByteData(width, lineasLeidas);
511
                        }
512

    
513
                        countLine = 0;
514
                        countBlock++;
515
                }
516

    
517
                if(dataType == IBuffer.TYPE_IMAGE)
518
                        loadBufferFromImageDataType(dataBuffer);
519
                if(dataType == IBuffer.TYPE_BYTE)
520
                        loadBufferFromByteDataType(byteBuffer);
521

    
522
                /* for (int iBand = 0; iBand < this.nBands; iBand++) {
523
                                                for (int pos = 0; pos < width; pos++) {
524
                                                                if (grf != null && write) {
525
                                                                                if (iBand == 0)
526
                                                                                                compressclient.buffer[pos + (width * iBand)] =
527
                                                                                                        bufband1[pos + (width * countLine)];
528

529
                                                                                if (iBand == 1)
530
                                                                                                compressclient.buffer[pos + (width * iBand)] =
531
                                                                                                        bufband2[pos + (width * countLine)];
532

533
                                                                                if (iBand == 2)
534
                                                                                                compressclient.buffer[pos + (width * iBand)] =
535
                                                                                                        bufband3[pos + (width * countLine)];
536

537
                                                                                if (iBand == 3)
538
                                                                                                compressclient.buffer[pos + (width * iBand)] =
539
                                                                                                        bufband4[pos + (width * countLine)];
540

541
                                                                                if (iBand == 4)
542
                                                                                                compressclient.buffer[pos + (width * iBand)] =
543
                                                                                                        bufband5[pos + (width * countLine)];
544

545
                                                                                if (iBand == 5)
546
                                                                                                compressclient.buffer[pos + (width * iBand)] =
547
                                                                                                        bufband6[pos + (width * countLine)];
548

549
                                                                } else {
550
                                                                                if (iBand == 0)
551
                                                                                                compressclient.buffer[pos + (width * iBand)] =
552
                                                                                                        (byte) ((dataBuffer[pos + (width * countLine)] & 0xff0000) >> 16);
553

554

555
                                                                                if (iBand == 1)
556
                                                                                                compressclient.buffer[pos + (width * iBand)] =
557
                                                                                                        (byte) ((dataBuffer[pos + (width * countLine)] & 0xff00) >> 8);
558

559

560
                                                                                if (iBand == 2)
561
                                                                                                compressclient.buffer[pos + (width * iBand)] =
562
                                                                                                        (byte) (dataBuffer[pos + (width * countLine)] & 0xff);
563

564
                                                                }
565

566
                                                                if ((pos == (width - 1)) && (iBand == (this.nBands - 1))) {
567
                                                                                countLine++;
568
                                                                }
569
                                                }
570
                                }*/
571
        }
572

    
573
        /**
574
         * Carga el buffer de datos desde elementos de tipo entero con contenido ARGB
575
         * @param data Array de datos enteros
576
         */
577
        private void loadBufferFromImageDataType(int[] data) {
578
                for (int iBand = 0; iBand < this.nBands; iBand++) {
579
                        for (int pos = 0; pos < width; pos++) {
580
                                switch(iBand) {
581
                                case 0:
582
                                        compressclient.buffer[pos + (width * iBand)] =
583
                                                (byte) ((data[pos + (width * countLine)] & 0xff0000) >> 16);
584
                                        break;
585
                                case 1:
586
                                        compressclient.buffer[pos + (width * iBand)] =
587
                                                (byte) ((data[pos + (width * countLine)] & 0xff00) >> 8);
588
                                        break;
589
                                case 2:
590
                                        compressclient.buffer[pos + (width * iBand)] =
591
                                                (byte) (data[pos + (width * countLine)] & 0xff);
592
                                        break;
593
                                }
594
                                if ((pos == (width - 1)) && (iBand == (this.nBands - 1)))
595
                                        countLine++;
596
                        }
597
                }
598
        }
599

    
600
        /**
601
         * Carga el buffer de datos a comprimir desde un buffer byte[][] donde la primera dimensi?n
602
         * es el n?mero de bandas y la segunda los elementos en lista (Ancho X Alto)
603
         * @param b Buffer de datos de tipo byte[][]
604
         */
605
        private void loadBufferFromByteDataType(byte[][] b) {
606
                for (int iBand = 0; iBand < this.nBands; iBand++) {
607
                        for (int pos = 0; pos < width; pos++) {
608
                                compressclient.buffer[pos + (width * iBand)] = b[iBand][pos + (width * countLine)];
609
                                if ((pos == (width - 1)) && (iBand == (this.nBands - 1)))
610
                                        countLine++;
611
                        }
612
                }
613
        }
614

    
615
        /**
616
         * M?todo obligado por el interfaz y que es llamado desde C cuando el
617
         * compresor actualiza el porcentaje de compresi?n
618
         */
619
        public void updatePercent() {
620
                writer.setPercent(compressclient.getPercent());
621
                //System.out.println(compressclient.getPercent() + "%");
622
        }
623

    
624
        /**
625
         * Obtiene el valor a la variable write que estar? a true cuando se est? escribiendo
626
         *  o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
627
         * pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
628
         * de salida.
629
         * @return True si puede escribirse y false si no puede
630
         */
631
        public boolean isWrite() {
632
                return write;
633
        }
634

    
635
        /**
636
         * Asigna el valor a la variable write que estar? a true cuando se est? escribiendo
637
         *  o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
638
         * pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
639
         * de salida.
640
         * @param write Variable booleana. True si puede escribirse y false si no puede
641
         */
642
        public void setWrite(boolean write) {
643
                this.write = write;
644
        }
645

    
646
}