Statistics
| Revision:

root / trunk / libraries / libjni-ecwcompress / src / es / gva / cit / jecwcompress / NCSEcwCompressClient.java @ 17862

History | View | Annotate | Download (10.5 KB)

1
/**********************************************************************
2
 * $Id: NCSEcwCompressClient.java 17862 2008-01-09 15:07:14Z nbrodin $
3
 *
4
 * Name:     NCSEcwCompressClient.java
5
 * Project:  
6
 * Purpose:  
7
 * Author:   Nacho Brodin, brodin_ign@gva.es
8
 *
9
 **********************************************************************/
10
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
11
*
12
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
13
*
14
* This program is free software; you can redistribute it and/or
15
* modify it under the terms of the GNU General Public License
16
* as published by the Free Software Foundation; either version 2
17
* of the License, or (at your option) any later version.
18
*
19
* This program is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
* GNU General Public License for more details.
23
*
24
* You should have received a copy of the GNU General Public License
25
* along with this program; if not, write to the Free Software
26
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
27
*
28
* For more information, contact:
29
*
30
*  Generalitat Valenciana
31
*   Conselleria d'Infraestructures i Transport
32
*   Av. Blasco Ib??ez, 50
33
*   46010 VALENCIA
34
*   SPAIN
35
*
36
*      +34 963862235
37
*   gvsig@gva.es
38
*      www.gvsig.gva.es
39
*
40
*    or
41
*
42
*   IVER T.I. S.A
43
*   Salamanca 50
44
*   46005 Valencia
45
*   Spain
46
*
47
*   +34 963163400
48
*   dac@iver.es
49
*/
50

    
51
package es.gva.cit.jecwcompress;
52

    
53
/**
54
 * Esta clase contiene las funciones para b?sicas para la compresi?n de Ecw. Para su uso 
55
 * debe seguirse la secuencia de operaciones l?gica:
56
 * <UL>
57
 * <LI>Creaci?n de objeto de esta clase NCSEcwCompressClient</LI> 
58
 * <LI>Asignaci?n de par?metros de compresi?n con las operaciones set</LI>
59
 * <LI>Crear una clase servidora de datos que implemente el interfaz ReadCallBack 
60
 * y herede de JniObject</LI>
61
 * <LI>Hacer un open con NCSEcwCompressOpen</LI> 
62
 * <LI>ejecutar el compresor con NCSEcwCompress y cerrar con NCSEcwCompressClose</LI>
63
 * </UL>
64
 * 
65
 * @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
66
 * @version 0.0
67
 * @link http://www.gvsig.gva.es
68
 */
69
public class NCSEcwCompressClient extends JNIBase{
70

    
71
        private native long NCSEcwCompressClientNat();
72
        private native int NCSEcwCompressOpenNat(long cPtr, boolean bCalculateSizesOnly);
73
        private native int NCSEcwCompressNat(long cPtr,ReadCallBack read);
74
        private native int NCSEcwCompressCloseNat(long cPtr);
75
        private native void NCSEcwCompressCancelNat(long cPtr);
76
        private native void finalizeNat(long cPtr);
77
                
78
        private String                                inputFilename=null;                        
79
        private        String                                 outputFilename=null;        
80
        private double                                 targetCompression=0.0;
81
        private int                                        eCompressFormat=0;
82
        private int                                        eCompressHint=0;
83
        private int                                        nBlockSizeX=0;
84
        private int                                        nBlockSizeY=0;
85
        private int                                        nInOutSizeX=0;
86
        private int                                        nInOutSizeY=0;
87
        private int                                        nInputBands=0;
88
        private int                                        nOutputBands=0;
89
        private long                                nInputSize=0;
90
        private double                                fCellIncrementX=0.0;
91
        private double                                fCellIncrementY=0.0;
92
        private double                                fOriginX=0.0;
93
        private double                                fOriginY=0.0;
94
        private int                                        eCellSizeUnits=0;
95
        private String                                 szDatum=null;
96
        private String                                 szProjection=null;
97
        private double                                fActualCompression=0.0;        
98
        private double                                fCompressionSeconds=0.0;
99
        private double                                fCompressionMBSec=0.0;
100
        private long                                nOutputSize=0;
101
        
102
        public byte[]                                buffer;
103
        private long                                readInfo;
104
        private int                                        porcentaje;
105
        
106
        /**
107
         * Esta funci?n es llamada desde C para inicializar el buffer que contendr? 1 linea de datos
108
         */
109
        private void initialize() {
110
                buffer = new byte[nInOutSizeX*nInputBands];
111
        }
112
        
113
        /**
114
         * Esta funci?n es llamada desde C para asignar la direcci?n de memoria de la estructura readInfo
115
         */
116
        private void setReadInfo(long ptr) {
117
                readInfo = ptr;
118
        }
119
        
120
        /**
121
         * Esta funci?n es llamada desde C para recuperar la direcci?n de memoria de readInfo
122
         */
123
        private long getReadInfo() {
124
                return readInfo;
125
        }
126
        
127
        /**
128
         * Devuelve la cantidad de imagen comprimida en tanto por cien.
129
         */
130
        public int getPercent() {
131
                return porcentaje;
132
        }
133
        
134
        /**
135
         * Contructor
136
         * @throws EcwException Se produce cuando la llamada nativa devuelve un c?digo de error
137
         */
138
        public NCSEcwCompressClient()throws EcwException {
139
                
140
                cPtr = NCSEcwCompressClientNat();
141
                
142
                if(cPtr == 0)
143
                    throw new EcwException("Error en la creaci?n del objeto NCSEcwCompressClient");
144
        }
145
        
146
        /**
147
         * Inicializa el compresor
148
         * @throws EcwException Se produce cuando la llamada nativa devuelve un c?digo de error
149
         */
150
        public void NCSEcwCompressOpen(boolean bCalculateSizesOnly)throws EcwException {
151
                
152
                if(cPtr == 0)
153
                        throw new EcwException("Error en NCSEcwCompressOpen(). No hay una referencia v?lida al objeto NCSEcwCompressClient.");
154
                
155
                int error = NCSEcwCompressOpenNat(cPtr, bCalculateSizesOnly);
156
                
157
                if(error == -1)
158
                        throw new EcwException("Error en NCSEcwCompressOpen(). No se ha podido obtener un objeto NCSEcwCompress valido");
159
                else if(error != 0)
160
                        throw new EcwException("Error en NCSEcwCompressOpen(). La llamada nativa ha devuelto un error "+NCSError.ErrorToString(error));
161
                            
162
        }
163
        
164
        /**
165
         * Realiza la funci?n de compresi?n
166
         * @throws EcwException Se produce cuando la llamada nativa devuelve un c?digo de error
167
         */
168
        public void NCSEcwCompress(ReadCallBack read)throws EcwException {
169
                
170
                if(cPtr == 0)
171
                        throw new EcwException("Error en NCSEcwCompress(). No hay una referencia v?lida al objeto NCSEcwCompressClient.");
172
                
173
                if(read == null)
174
                        throw new EcwException("Error en NCSEcwCompress(). El par?metro ReadCallBack no puede ser nulo.");
175
                
176
                int error = NCSEcwCompressNat(cPtr, read);
177
                
178
                if(error == -1)
179
                        throw new EcwException("Error en NCSEcwCompress(). No se ha podido obtener un objeto NCSEcwCompress valido");
180
                else if(error != 0)
181
                        throw new EcwException("Error en NCSEcwCompress(). La llamada nativa ha devuelto un error "+NCSError.ErrorToString(error));
182
        }
183
        
184
        /**
185
         * Cierra el compresor
186
         * @throws EcwException Se produce cuando la llamada nativa devuelve un c?digo de error
187
         */
188
        public void NCSEcwCompressClose()throws EcwException {
189
                
190
                if(cPtr == 0)
191
                        throw new EcwException("Error en NCSEcwCompress(). No hay una referencia v?lida al objeto NCSEcwCompressClient.");
192
                
193
                int error = NCSEcwCompressCloseNat(cPtr);
194
                
195
                if(error == -1)
196
                        throw new EcwException("Error en NCSEcwCompress(). No se ha podido obtener un objeto NCSEcwCompress valido");
197
                else if(error != 0)
198
                        throw new EcwException("Error en NCSEcwCompress(). La llamada nativa ha devuelto un error "+NCSError.ErrorToString(error));
199
        }
200
        
201
        /**
202
         * Cancela la compresi?n
203
         * @throws EcwException Se produce cuando la llamada nativa devuelve un c?digo de error
204
         */
205
        public void NCSEcwCompressCancel()throws EcwException {
206
                
207
                if(cPtr == 0)
208
                        throw new EcwException("Error en NCSEcwCompress(). No hay una referencia v?lida al objeto NCSEcwCompressClient.");
209
                
210
                NCSEcwCompressCancelNat(cPtr);
211
        }
212
        
213
        /**
214
         * @throws EcwException Se produce cuando la llamada nativa devuelve un c?digo de error
215
         */
216
        public void finalize()throws EcwException {
217
                
218
                if(cPtr == 0)
219
                        throw new EcwException("Error en finalize(). No hay una referencia v?lida al objeto NCSEcwCompressClient y no se ha podido liberar la memoria.");
220
                
221
                //TODO: Temporalmente deshabilitado.
222
                //finalizeNat(cPtr);
223
        }
224
        
225
        /**
226
         * Asigna el nombre del fichero de entrada
227
         * @param filename        Nombre del fichero
228
         */
229
        public void setInputFilename(String filename){inputFilename=filename;};
230
        
231
        /**
232
         * Asigna el nombre del fichero de salida
233
         * @param filename        Nombre del fichero
234
         */
235
        public void setOutputFilename(String filename){outputFilename=filename;};
236
        
237
        /**
238
         * Asigna el nivel de compresi?n
239
         * @param compress nivel de compresi?n
240
         */
241
        public void setTargetCompress(double compress){targetCompression=compress;};
242
        
243
        /**
244
         * Asigna el formato de compresi?n.
245
         * @param format        formato de compresi?n. Los valores que puede tomar son:
246
         * <UL>
247
         * <LI>COMPRESS_NONE        = NCSCS_NONE</LI>
248
         * <LI>COMPRESS_UINT8        = NCSCS_GREYSCALE</LI>
249
         * <LI>COMPRESS_YUV                = NCSCS_YUV</LI>
250
         * <LI>COMPRESS_MULTI        = NCSCS_MULTIBAND</LI>
251
         * <LI>COMPRESS_RGB                = NCSCS_sRGB</LI>
252
         * </UL>
253
         */
254
        public void setCompressFormat(int format){eCompressFormat=format;};
255
        
256
        /**
257
         * Asigna el Compress Hint. 
258
         * @param Compress hint. Los valores que puede tomar son:
259
         * <UL>
260
         * <LI>COMPRESS_HINT_NONE        = 0</LI>
261
         * <LI>COMPRESS_HINT_FAST        = 1</LI>
262
         * </LI>COMPRESS_HINT_BEST        = 2</LI>
263
         * <LI>COMPRESS_HINT_INTERNET = 3</LI>
264
         * </UL>
265
         */
266
        public void setCompressHint(int hint){eCompressHint=hint;};
267
        
268
        /**
269
         * Asigna el tama?o de bloque en x
270
         * @param n        tama?o de bloque en x
271
         */
272
        public void setBlockSizeX(int n){nBlockSizeX=n;};
273
        
274
        /**
275
         * Asigna el tama?o de bloque en y
276
         * @param n        tama?o de bloque en y
277
         */
278
        public void setBlockSizeY(int n){nBlockSizeY=n;};
279
        
280
        /**
281
         * Asigna el tama?o de la imagen de salida en x
282
         * @param n        tama?o de imagen de salida en x
283
         */
284
        public void setInOutSizeX(int n){nInOutSizeX=n;};
285
        
286
        /**
287
         * Asigna el tama?o de la imagen de salida en y
288
         * @param n        tama?o de imagen de salida en y
289
         */
290
        public void setInOutSizeY(int n){nInOutSizeY=n;};
291
        
292
        /**
293
         * Asigna el n?mero de bandas de entrada
294
         * @param n        N?mero de bandas de entrada
295
         */
296
        public void setInputBands(int n){nInputBands=n;};
297
        
298
        /**
299
         * Asigna el n?mero de bandas de salida
300
         * @param n        N?mero de bandas de salida
301
         */
302
        public void setOutputBands(int n){nOutputBands=n;};
303
        
304
        public void setInputSize(long nis){nInputSize=nis;};
305
        public void setCellIncrementX(double x){fCellIncrementX=x;};
306
        public void setCellIncrementY(double y){fCellIncrementY=y;};
307
        public void setOriginX(double x){fOriginX=x;};
308
        public void setOriginY(double y){fOriginY=y;};
309

    
310
        /**
311
         * Asigna el tama?o de celda
312
         * @param cellu        tama?o de celda. Puede tomar un valor entre los siguientes:
313
         * <UL>
314
         * <LI>ECW_CELL_UNITS_INVALID        =        0</LI>
315
         * <LI>ECW_CELL_UNITS_METERS        =        1</LI>
316
         * <LI>ECW_CELL_UNITS_DEGREES        =        2</LI>
317
         * <LI>ECW_CELL_UNITS_FEET                =        3</LI>
318
         * <LI>ECW_CELL_UNITS_UNKNOWN        =        4</LI>
319
         * </UL>
320
         */
321
        public void setCellSizeUnits(int cellu){eCellSizeUnits=cellu;};
322
        
323
        /**
324
         * Asigna el datum
325
         * @param dat        datum
326
         */
327
        public void setDatum(String dat){szDatum=dat;};
328
        
329
        /**
330
         * Asigna la proyecci?n
331
         * @param proj        Proyecci?n
332
         */
333
        public void setProjection(String proj){szProjection=proj;};
334
        
335
        public void setActualCompression(double comp){fActualCompression=comp;};
336
        public void setCompressionSeconds(double comp){fCompressionSeconds=comp;};
337
        public void setCompressionMBSec(double comp){fCompressionMBSec=comp;};
338
        public void setOutputSize(long n){nOutputSize=n;};
339
}
340