svn-gvsig-desktop / trunk / libraries / libjni-ecw / src / main / native / jecw / ncsecwcompressclient_wrapper.cpp @ 20206
History | View | Annotate | Download (14.7 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: ncsecwcompressclient_wrapper.c 4274 2006-03-06 07:32:00Z nacho $
|
3 |
*
|
4 |
* Name: bsb_interfaz.c
|
5 |
* Project: JGDAL. Interface java to gdal (Frank Warmerdam).
|
6 |
* Purpose: Interface functions to manage bsb files. This include gdal
|
7 |
* code but it doesn't use the gdal API.
|
8 |
* Author: Nacho Brodin, brodin_ign@gva.es
|
9 |
*
|
10 |
**********************************************************************/
|
11 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
12 |
*
|
13 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
14 |
*
|
15 |
* This program is free software; you can redistribute it and/or
|
16 |
* modify it under the terms of the GNU General Public License
|
17 |
* as published by the Free Software Foundation; either version 2
|
18 |
* of the License, or (at your option) any later version.
|
19 |
*
|
20 |
* This program is distributed in the hope that it will be useful,
|
21 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
* GNU General Public License for more details.
|
24 |
*
|
25 |
* You should have received a copy of the GNU General Public License
|
26 |
* along with this program; if not, write to the Free Software
|
27 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
28 |
*
|
29 |
* For more information, contact:
|
30 |
*
|
31 |
* Generalitat Valenciana
|
32 |
* Conselleria d'Infraestructures i Transport
|
33 |
* Av. Blasco Ib??ez, 50
|
34 |
* 46010 VALENCIA
|
35 |
* SPAIN
|
36 |
*
|
37 |
* +34 963862235
|
38 |
* gvsig@gva.es
|
39 |
* www.gvsig.gva.es
|
40 |
*
|
41 |
* or
|
42 |
*
|
43 |
* IVER T.I. S.A
|
44 |
* Salamanca 50
|
45 |
* 46005 Valencia
|
46 |
* Spain
|
47 |
*
|
48 |
* +34 963163400
|
49 |
* dac@iver.es
|
50 |
*/
|
51 |
|
52 |
#include <jni.h> |
53 |
#include <string.h> |
54 |
#include <malloc.h> |
55 |
#include "NCSECWCompressClient.h" |
56 |
|
57 |
typedef struct ReadInfo { |
58 |
//NCSFileView *pNCSFileView;
|
59 |
UINT8 **ppInputBandBufferArray; |
60 |
UINT32 nPercentComplete; |
61 |
jclass clase; |
62 |
jobject *jclient; |
63 |
jobject *jreadcall; |
64 |
JNIEnv *env; |
65 |
char pErrorBuffer[1024]; |
66 |
} ReadInfo; |
67 |
|
68 |
static BOOLEAN callBackOn = TRUE;
|
69 |
|
70 |
/******************************************************************************/
|
71 |
// ReadCallback
|
72 |
/******************************************************************************/
|
73 |
|
74 |
|
75 |
static BOOLEAN ReadCallback(NCSEcwCompressClient *pClient,
|
76 |
UINT32 nNextLine, |
77 |
IEEE4 **ppOutputBandBufferArray) |
78 |
{ |
79 |
ReadInfo *pReadInfo = (ReadInfo *)pClient->pClientData; |
80 |
UINT32 nBand; |
81 |
jfieldID fid; |
82 |
jbyteArray jarray; |
83 |
JNIEnv *env=pReadInfo->env; |
84 |
int longitud;
|
85 |
jclass clase_client; |
86 |
jclass clase_readcall; |
87 |
jmethodID metodo; |
88 |
|
89 |
if(callBackOn){
|
90 |
clase_client = (env)->GetObjectClass(*(pReadInfo->jclient)); |
91 |
clase_readcall = (env)->GetObjectClass(*(pReadInfo->jreadcall)); |
92 |
|
93 |
//Ponemos el valor de la banda un n?mero de l?nea en el objeto cliente
|
94 |
|
95 |
fid = (env)->GetFieldID(clase_readcall, "nNextLine", "I"); |
96 |
(env)->SetIntField(*(pReadInfo->jreadcall), fid, nNextLine); |
97 |
|
98 |
//Ejecutamos la funci?n de java que carga el buffer
|
99 |
|
100 |
metodo = (env)->GetMethodID(clase_readcall, "loadBuffer", "()V"); |
101 |
(env)->CallVoidMethod(*(pReadInfo->jreadcall), metodo); |
102 |
|
103 |
//Obtenemos el array de bytes desde java
|
104 |
|
105 |
fid = (env)->GetFieldID(clase_client, "buffer", "[B"); |
106 |
jarray =(jbyteArray)(env)->GetObjectField(*(pReadInfo->jclient), fid); |
107 |
longitud = (env)->GetArrayLength(jarray); |
108 |
|
109 |
(env)->GetByteArrayRegion(jarray,0,longitud,(jbyte *)pReadInfo->ppInputBandBufferArray[0]); |
110 |
|
111 |
for(nBand = 0; nBand < pClient->nInputBands; nBand++) { |
112 |
UINT32 nCell; |
113 |
UINT8 *pInputValue = pReadInfo->ppInputBandBufferArray[nBand]; |
114 |
IEEE4 *pOutputValue = ppOutputBandBufferArray[nBand]; |
115 |
|
116 |
// Compression needs input to be IEEE4
|
117 |
for (nCell = 0; nCell < pClient->nInOutSizeX; nCell++) { |
118 |
*pOutputValue++ = (IEEE4)*pInputValue++; |
119 |
} |
120 |
|
121 |
} |
122 |
|
123 |
return(TRUE);
|
124 |
}else
|
125 |
return(FALSE);
|
126 |
} |
127 |
|
128 |
/******************************************************************************/
|
129 |
// StatusCallback
|
130 |
/******************************************************************************/
|
131 |
//Asigna el tanto por cien de imagen que lleva comprimido en una variable de java
|
132 |
//Ejecuta la funci?n updatePercent de java despues de actualizar la varible.
|
133 |
|
134 |
static void StatusCallback(NCSEcwCompressClient *pClient, |
135 |
UINT32 nCurrentLine) |
136 |
{ |
137 |
ReadInfo *pReadInfo = (ReadInfo *)pClient->pClientData; |
138 |
UINT32 nPercentComplete = (nCurrentLine * 100) / (pClient->nInOutSizeY - 1); |
139 |
jclass clase_client; |
140 |
jclass clase_readcall; |
141 |
JNIEnv *env=pReadInfo->env; |
142 |
jfieldID fid; |
143 |
jmethodID metodo; |
144 |
|
145 |
clase_client = (env)->GetObjectClass(*(pReadInfo->jclient)); |
146 |
clase_readcall = (env)->GetObjectClass(*(pReadInfo->jreadcall)); |
147 |
|
148 |
if (nPercentComplete != pReadInfo->nPercentComplete) {
|
149 |
fid = (env)->GetFieldID(clase_client, "porcentaje", "I"); |
150 |
(env)->SetIntField(*(pReadInfo->jclient), fid, nPercentComplete); |
151 |
metodo = (env)->GetMethodID(clase_readcall, "updatePercent", "()V"); |
152 |
(env)->CallVoidMethod(*(pReadInfo->jreadcall), metodo); |
153 |
pReadInfo->nPercentComplete = nPercentComplete; |
154 |
} |
155 |
} |
156 |
|
157 |
/******************************************************************************/
|
158 |
// NCSEcwCompressClient
|
159 |
/******************************************************************************/
|
160 |
|
161 |
JNIEXPORT jlong JNICALL Java_es_gva_cit_jecwcompress_NCSEcwCompressClient_NCSEcwCompressClientNat |
162 |
(JNIEnv *env, jobject obj){ |
163 |
|
164 |
NCSEcwCompressClient *pClient; |
165 |
jlong jresult = 0 ;
|
166 |
|
167 |
if(pClient = NCSEcwCompressAllocClient()){
|
168 |
*(NCSEcwCompressClient **)&jresult = pClient; |
169 |
return jresult;
|
170 |
}else
|
171 |
return -1; |
172 |
|
173 |
} |
174 |
|
175 |
/******************************************************************************/
|
176 |
// NCSEcwCompressOpen
|
177 |
/******************************************************************************/
|
178 |
|
179 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jecwcompress_NCSEcwCompressClient_NCSEcwCompressOpenNat |
180 |
(JNIEnv *env, jobject obj, jlong cPtr, jboolean bCalculateSizesOnly){ |
181 |
|
182 |
NCSEcwCompressClient *pClient = (NCSEcwCompressClient *) 0 ;
|
183 |
NCSError eError; |
184 |
jfieldID fid; |
185 |
jobject obj_str; |
186 |
const char *str; |
187 |
ReadInfo *compress_readInfo; |
188 |
jmethodID metodo; |
189 |
|
190 |
UINT8 *pReadBuffer,nBand; |
191 |
|
192 |
pClient = *(NCSEcwCompressClient **)&cPtr; |
193 |
if(pClient!=NULL){ |
194 |
|
195 |
//Asignamos los valores de los campos de NCSEcwCompress
|
196 |
|
197 |
jclass clase = (env)->GetObjectClass(obj); |
198 |
|
199 |
fid = (env)->GetFieldID(clase, "inputFilename", "Ljava/lang/String;"); |
200 |
obj_str = (env)->GetObjectField(obj, fid); |
201 |
if(obj_str!=NULL){ |
202 |
str = (env)->GetStringUTFChars((jstring)obj_str,0);
|
203 |
strcpy(pClient->szInputFilename,str); |
204 |
str=NULL;
|
205 |
(env)->ReleaseStringUTFChars((jstring)obj_str, str); |
206 |
//printf("inputFilename=%s\n",pClient->szInputFilename);
|
207 |
} |
208 |
|
209 |
fid = (env)->GetFieldID(clase, "outputFilename", "Ljava/lang/String;"); |
210 |
obj_str = (env)->GetObjectField(obj, fid); |
211 |
if(obj_str!=NULL){ |
212 |
str = (env)->GetStringUTFChars((jstring)obj_str,0);
|
213 |
strcpy(pClient->szOutputFilename,str); |
214 |
str=NULL;
|
215 |
(env)->ReleaseStringUTFChars((jstring)obj_str, str); |
216 |
//printf("outputFilename=%s\n",pClient->szOutputFilename);
|
217 |
} |
218 |
|
219 |
fid = (env)->GetFieldID(clase, "targetCompression", "D"); |
220 |
pClient->fTargetCompression = (IEEE4)(env)->GetDoubleField(obj, fid); |
221 |
//printf("targetCompression=%f\n",pClient->fTargetCompression);
|
222 |
|
223 |
fid = (env)->GetFieldID(clase, "eCompressFormat", "I"); |
224 |
pClient->eCompressFormat = (CompressFormat)(env)->GetIntField(obj, fid); |
225 |
//printf("eCompressFormat=%d\n",pClient->eCompressFormat);
|
226 |
|
227 |
fid = (env)->GetFieldID(clase, "eCompressHint", "I"); |
228 |
pClient->eCompressHint = (CompressHint)(env)->GetIntField(obj, fid); |
229 |
//printf("eCompressHint=%d\n",pClient->eCompressHint);
|
230 |
|
231 |
fid = (env)->GetFieldID(clase, "nBlockSizeX", "I"); |
232 |
pClient->nBlockSizeX = (env)->GetIntField(obj, fid); |
233 |
//printf("nBlockSizeX=%d\n",pClient->nBlockSizeX);
|
234 |
|
235 |
fid = (env)->GetFieldID(clase, "nBlockSizeY", "I"); |
236 |
pClient->nBlockSizeY = (env)->GetIntField(obj, fid); |
237 |
//printf("nBlockSizeY=%d\n",pClient->nBlockSizeY);
|
238 |
|
239 |
fid = (env)->GetFieldID(clase, "nInOutSizeX", "I"); |
240 |
pClient->nInOutSizeX = (env)->GetIntField(obj, fid); |
241 |
//printf("nInOutSizeX=%d\n",pClient->nInOutSizeX);
|
242 |
|
243 |
fid = (env)->GetFieldID(clase, "nInOutSizeY", "I"); |
244 |
pClient->nInOutSizeY = (env)->GetIntField(obj, fid); |
245 |
//printf("nInOutSizeY=%d\n",pClient->nInOutSizeY);
|
246 |
|
247 |
fid = (env)->GetFieldID(clase, "nInputBands", "I"); |
248 |
pClient->nInputBands = (env)->GetIntField(obj, fid); |
249 |
//printf("nInputBands=%d\n",pClient->nInputBands);
|
250 |
|
251 |
fid = (env)->GetFieldID(clase, "nOutputBands", "I"); |
252 |
pClient->nOutputBands = (env)->GetIntField(obj, fid); |
253 |
//printf("nOutputBands=%d\n",pClient->nOutputBands);
|
254 |
|
255 |
fid = (env)->GetFieldID(clase, "nInputSize", "J"); |
256 |
pClient->nInputSize = (env)->GetLongField(obj, fid); |
257 |
//printf("nInputSize=%ld\n",pClient->nInputSize);
|
258 |
|
259 |
fid = (env)->GetFieldID(clase, "fCellIncrementX", "D"); |
260 |
pClient->fCellIncrementX = (env)->GetDoubleField(obj, fid); |
261 |
//printf("fCellIncrementX=%f\n",pClient->fCellIncrementX);
|
262 |
|
263 |
fid = (env)->GetFieldID(clase, "fCellIncrementY", "D"); |
264 |
pClient->fCellIncrementY = (env)->GetDoubleField(obj, fid); |
265 |
//printf("fCellIncrementY=%f\n",pClient->fCellIncrementY);
|
266 |
|
267 |
fid = (env)->GetFieldID(clase, "fOriginX", "D"); |
268 |
pClient->fOriginX = (env)->GetDoubleField(obj, fid); |
269 |
//printf("fOriginX=%f\n",pClient->fOriginX);
|
270 |
|
271 |
fid = (env)->GetFieldID(clase, "fOriginY", "D"); |
272 |
pClient->fOriginY = (env)->GetDoubleField(obj, fid); |
273 |
//printf("fOriginY=%f\n",pClient->fOriginY);
|
274 |
|
275 |
fid = (env)->GetFieldID(clase, "eCellSizeUnits", "I"); |
276 |
pClient->fActualCompression = (IEEE4)(env)->GetIntField(obj, fid); |
277 |
//printf("eCellSizeUnits=%d\n",pClient->fActualCompression);
|
278 |
|
279 |
fid = (env)->GetFieldID(clase, "szDatum", "Ljava/lang/String;"); |
280 |
obj_str = (env)->GetObjectField(obj, fid); |
281 |
if(obj_str!=NULL){ |
282 |
str = (env)->GetStringUTFChars((jstring)obj_str,0);
|
283 |
strcpy(pClient->szDatum,str); |
284 |
str=NULL;
|
285 |
(env)->ReleaseStringUTFChars((jstring)obj_str, str); |
286 |
//printf("szDatum=%s\n",pClient->szDatum);
|
287 |
} |
288 |
|
289 |
fid = (env)->GetFieldID(clase, "szProjection", "Ljava/lang/String;"); |
290 |
obj_str = (env)->GetObjectField(obj, fid); |
291 |
if(obj_str!=NULL){ |
292 |
str = (env)->GetStringUTFChars((jstring)obj_str,0);
|
293 |
strcpy(pClient->szProjection,str); |
294 |
str=NULL;
|
295 |
(env)->ReleaseStringUTFChars((jstring)obj_str, str); |
296 |
//printf("szProjection=%s\n",pClient->szProjection);
|
297 |
} |
298 |
|
299 |
fid = (env)->GetFieldID(clase, "fActualCompression", "D"); |
300 |
pClient->fActualCompression = (IEEE4)(env)->GetDoubleField(obj, fid); |
301 |
//printf("fActualCompression=%f\n",pClient->fActualCompression);
|
302 |
|
303 |
fid = (env)->GetFieldID(clase, "fCompressionSeconds", "D"); |
304 |
pClient->fCompressionSeconds = (env)->GetDoubleField(obj, fid); |
305 |
//printf("fCompressionSeconds=%f\n",pClient->fCompressionSeconds);
|
306 |
|
307 |
fid = (env)->GetFieldID(clase, "fCompressionMBSec", "D"); |
308 |
pClient->fCompressionMBSec = (env)->GetDoubleField(obj, fid); |
309 |
//printf("fCompressionMBSec=%f\n",pClient->fCompressionMBSec);
|
310 |
|
311 |
fid = (env)->GetFieldID(clase, "nOutputSize", "J"); |
312 |
pClient->nOutputSize = (env)->GetLongField(obj, fid); |
313 |
//printf("nOutputSize=%ld\n",pClient->nOutputSize);
|
314 |
|
315 |
pClient->pReadCallback = ReadCallback; |
316 |
pClient->pStatusCallback = StatusCallback; |
317 |
|
318 |
//Inicializar el buffer que tendr? una l?nea de entrada x el n?m de bandas
|
319 |
|
320 |
metodo = (env)->GetMethodID(clase, "initialize", "()V"); |
321 |
(env)->CallIntMethod(obj,metodo); |
322 |
|
323 |
compress_readInfo = (ReadInfo *)malloc(sizeof(ReadInfo));
|
324 |
|
325 |
pReadBuffer = (UINT8 *)malloc(sizeof(UINT8) *
|
326 |
pClient->nInOutSizeX * |
327 |
pClient->nInputBands); |
328 |
compress_readInfo->ppInputBandBufferArray = (UINT8 **)malloc(sizeof(UINT8 *) *
|
329 |
pClient->nInputBands); |
330 |
for (nBand = 0; nBand < pClient->nInputBands; nBand++) { |
331 |
compress_readInfo->ppInputBandBufferArray[nBand] = pReadBuffer + |
332 |
(nBand * pClient->nInOutSizeX * sizeof(UINT8));
|
333 |
} |
334 |
|
335 |
if (compress_readInfo->ppInputBandBufferArray == NULL) return 46; |
336 |
compress_readInfo->nPercentComplete = 0;
|
337 |
|
338 |
pClient->pClientData = (void *)compress_readInfo;
|
339 |
|
340 |
eError = NCSEcwCompressOpen(pClient, ((bCalculateSizesOnly==0)? FALSE : TRUE));
|
341 |
|
342 |
return eError;
|
343 |
|
344 |
} |
345 |
return -1; |
346 |
} |
347 |
|
348 |
/******************************************************************************/
|
349 |
// NCSEcwCompress
|
350 |
/******************************************************************************/
|
351 |
|
352 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jecwcompress_NCSEcwCompressClient_NCSEcwCompressNat |
353 |
(JNIEnv *env, jobject obj, jlong cPtr, jobject obj_read){ |
354 |
|
355 |
NCSEcwCompressClient *pClient = (NCSEcwCompressClient *) 0 ;
|
356 |
ReadInfo *compress_readInfo = (ReadInfo *) 0 ;
|
357 |
NCSError eError; |
358 |
|
359 |
pClient = *(NCSEcwCompressClient **)&cPtr; |
360 |
compress_readInfo = (ReadInfo *)pClient->pClientData; |
361 |
compress_readInfo->jclient=&obj; |
362 |
compress_readInfo->jreadcall=&obj_read; |
363 |
compress_readInfo->env=env; |
364 |
|
365 |
eError = NCSEcwCompress(pClient); |
366 |
return eError;
|
367 |
} |
368 |
|
369 |
/******************************************************************************/
|
370 |
// NCSEcwCompressClose
|
371 |
/******************************************************************************/
|
372 |
|
373 |
JNIEXPORT jint JNICALL Java_es_gva_cit_jecwcompress_NCSEcwCompressClient_NCSEcwCompressCloseNat |
374 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
375 |
|
376 |
NCSEcwCompressClient *pClient = (NCSEcwCompressClient *) 0 ;
|
377 |
NCSError eError; |
378 |
|
379 |
pClient = *(NCSEcwCompressClient **)&cPtr; |
380 |
eError = NCSEcwCompressClose(pClient); |
381 |
return eError;
|
382 |
} |
383 |
|
384 |
/******************************************************************************/
|
385 |
// NCSEcwCompressCancel
|
386 |
/******************************************************************************/
|
387 |
|
388 |
JNIEXPORT void JNICALL Java_es_gva_cit_jecwcompress_NCSEcwCompressClient_NCSEcwCompressCancelNat
|
389 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
390 |
callBackOn = FALSE; |
391 |
} |
392 |
|
393 |
/******************************************************************************/
|
394 |
// finalize
|
395 |
/******************************************************************************/
|
396 |
|
397 |
JNIEXPORT void JNICALL Java_es_gva_cit_jecwcompress_NCSEcwCompressClient_finalizeNat
|
398 |
(JNIEnv *env, jobject obj, jlong cPtr){ |
399 |
|
400 |
ReadInfo *compress_readInfo = (ReadInfo *) 0 ;
|
401 |
NCSEcwCompressClient *pClient = (NCSEcwCompressClient *) 0 ;
|
402 |
int nBand;
|
403 |
|
404 |
pClient = *(NCSEcwCompressClient **)&cPtr; |
405 |
|
406 |
//Liberamos la memoria
|
407 |
|
408 |
compress_readInfo = (ReadInfo *)pClient->pClientData; |
409 |
for (nBand = 0; nBand < pClient->nInputBands; nBand++) { |
410 |
free(compress_readInfo->ppInputBandBufferArray[nBand]); |
411 |
} |
412 |
free(compress_readInfo->ppInputBandBufferArray); |
413 |
free(pClient->pClientData); |
414 |
pClient->pClientData = NULL;
|
415 |
NCSEcwCompressFreeClient(pClient); |
416 |
|
417 |
} |
418 |
|