gvsig-raster / org.gvsig.raster.ermapper / trunk / org.gvsig.raster.ermapper / org.gvsig.raster.ermapper.jni / src / main / native / jecw / ecw_jni.c @ 2449
History | View | Annotate | Download (27.6 KB)
1 | 2449 | nbrodin | /**********************************************************
|
---|---|---|---|
2 | ** Copyright 1998 Earth Resource Mapping Ltd.
|
||
3 | ** This document contains proprietary source code of
|
||
4 | ** Earth Resource Mapping Ltd, and can only be used under
|
||
5 | ** one of the three licenses as described in the
|
||
6 | ** license.txt file supplied with this distribution.
|
||
7 | ** See separate license.txt file for license details
|
||
8 | ** and conditions.
|
||
9 | **
|
||
10 | ** This software is covered by US patent #6,442,298,
|
||
11 | ** #6,102,897 and #6,633,688. Rights to use these patents
|
||
12 | ** is included in the license agreements.
|
||
13 | **
|
||
14 | ** FILE: ecw_jni.c
|
||
15 | ** CREATED: 4 Jan 2000
|
||
16 | ** AUTHOR: Mark Sheridan
|
||
17 | ** PURPOSE: Java wrappers for JNI usage of the ECW library in Java.
|
||
18 | ** EDITS:
|
||
19 | **
|
||
20 | ** [01] 01Nov00 mjs Rewrote to be JVM 1.1 compliant.
|
||
21 | ** [02] 08Mar04 mjs Removed old 1.1 spec stuff, now needs a 1.2 compatible virtual machine.
|
||
22 | ** [03] 01Oct05 nbt ECWOpenArray function to support name parameter in char array
|
||
23 | **
|
||
24 | *******************************************************/
|
||
25 | |||
26 | #include <stdio.h> |
||
27 | #include "NCSErrors.h" |
||
28 | #include "NCSECWClient.h" |
||
29 | #include "NCSMalloc.h" |
||
30 | #include "NCSUtil.h" |
||
31 | #include "NCSBuildNumber.h" |
||
32 | #include "JNCSFile.h" |
||
33 | #include "NCSDynamicLib.h" |
||
34 | |||
35 | //#ifndef JNI_VERSION_1_2
|
||
36 | //#error You must compile this class against a 1.2 virtual machine specification
|
||
37 | //#endif
|
||
38 | |||
39 | static JavaVM *pJavaVirtualMachineInst = NULL; |
||
40 | struct NCSJNIFieldIDs *pGlobalJNCSFieldIDs = NULL; |
||
41 | |||
42 | typedef struct NCSJNIFieldIDs { |
||
43 | jfieldID jIDNativeDataPointer; |
||
44 | jfieldID jIDWidth; |
||
45 | jfieldID jIDHeight; |
||
46 | jfieldID jIDNumberOfBands; |
||
47 | jfieldID jIDCompressionRate; |
||
48 | jfieldID jIDCellIncrementX; |
||
49 | jfieldID jIDCellIncrementY; |
||
50 | jfieldID jIDCellSizeUnits; |
||
51 | jfieldID jIDOriginX; |
||
52 | jfieldID jIDOriginY; |
||
53 | jfieldID jIDDatum; |
||
54 | jfieldID jIDProjection; |
||
55 | jfieldID jIDFilename; |
||
56 | jfieldID jIDIsOpen; |
||
57 | jmethodID jIDRefreshUpdateMethod; |
||
58 | jfieldID jIDFileType; |
||
59 | jfieldID jIDFileMimeType; |
||
60 | } NCSJNIFieldIDs; |
||
61 | |||
62 | // This is the object specific data structure, its cached.
|
||
63 | typedef struct NCSJNIInfo { |
||
64 | //jobject ECWFile;
|
||
65 | NCSFileView *pFileView; |
||
66 | } NCSJNIInfo; |
||
67 | |||
68 | void NCSJNIThrowException(JNIEnv *pEnv, const char *pSignature, const char *pMessage) |
||
69 | { |
||
70 | jclass jExceptionClass = NULL;
|
||
71 | |||
72 | if ((*pEnv)->ExceptionCheck(pEnv)) {
|
||
73 | (*pEnv)->ExceptionDescribe(pEnv); |
||
74 | (*pEnv)->ExceptionClear(pEnv); |
||
75 | } |
||
76 | |||
77 | jExceptionClass = (*pEnv)->FindClass(pEnv, pSignature); |
||
78 | |||
79 | if (jExceptionClass != NULL) { |
||
80 | (*pEnv)->ThrowNew(pEnv, jExceptionClass, pMessage); |
||
81 | } |
||
82 | (*pEnv)->DeleteLocalRef(pEnv, jExceptionClass); |
||
83 | } |
||
84 | |||
85 | NCSError NCSCreateJNIInfoStruct(JNIEnv *pEnv, jobject ECWFile, NCSFileView *pNCSFileView, NCSJNIInfo **pReturn) |
||
86 | { |
||
87 | NCSJNIInfo *pJNIInfo; |
||
88 | //char *pErrorString = NULL;
|
||
89 | |||
90 | pJNIInfo = (NCSJNIInfo *)NCSMalloc(sizeof(NCSJNIInfo), TRUE);
|
||
91 | if (pJNIInfo != NULL) |
||
92 | { |
||
93 | pJNIInfo->pFileView = pNCSFileView; |
||
94 | //pJNIInfo->ECWFile = (void *)(*pEnv)->NewGlobalRef(pEnv, ECWFile);
|
||
95 | *pReturn = pJNIInfo; |
||
96 | } |
||
97 | else
|
||
98 | { |
||
99 | return NCS_COULDNT_ALLOC_MEMORY;
|
||
100 | } |
||
101 | return NCS_SUCCESS;
|
||
102 | } |
||
103 | |||
104 | /*
|
||
105 | * Class: None
|
||
106 | * Method: JNI_OnLoad
|
||
107 | * Signature: ()Z
|
||
108 | */
|
||
109 | |||
110 | JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *pJVM, void *reserved)
|
||
111 | { |
||
112 | JNIEnv *pEnv; |
||
113 | |||
114 | if ((*pJVM)->GetEnv(pJVM, (void **)&pEnv, JNI_VERSION_1_2)) { |
||
115 | NCSJNIThrowException(pEnv, "java/lang/Exception", "JNCS classes require a version 1.2 or higher virtual machine."); |
||
116 | return JNI_ERR;
|
||
117 | } |
||
118 | else {
|
||
119 | pJavaVirtualMachineInst = pJVM; |
||
120 | #ifndef WIN32
|
||
121 | NCSecwInit(); |
||
122 | #endif
|
||
123 | } |
||
124 | return JNI_VERSION_1_2;
|
||
125 | } |
||
126 | |||
127 | |||
128 | /*
|
||
129 | * Class: None
|
||
130 | * Method: JNI_OnUnload
|
||
131 | * Signature: ()Z
|
||
132 | */
|
||
133 | JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *pJVM, void *reserved) |
||
134 | { |
||
135 | #ifndef WIN32
|
||
136 | NCSecwShutdown(); |
||
137 | #endif
|
||
138 | NCSFree((void *)pGlobalJNCSFieldIDs);
|
||
139 | return;
|
||
140 | } |
||
141 | |||
142 | /*
|
||
143 | * Class: com_ermapper_ecw_JNCSFile
|
||
144 | * Method: NCSJNIInit
|
||
145 | * Signature: ()I
|
||
146 | */
|
||
147 | JNIEXPORT jint JNICALL Java_com_ermapper_ecw_JNCSFile_NCSJNIInit |
||
148 | (JNIEnv *pEnv, jclass ECWFileClass) |
||
149 | { |
||
150 | NCSJNIFieldIDs *pJNIInfo = NULL;
|
||
151 | char *pErrorString = NULL; |
||
152 | |||
153 | if (!pGlobalJNCSFieldIDs) {
|
||
154 | |||
155 | pJNIInfo = (NCSJNIFieldIDs *)NCSMalloc(sizeof(NCSJNIFieldIDs), TRUE);
|
||
156 | |||
157 | // Get all the field ids of the ECWFile object
|
||
158 | pJNIInfo->jIDNativeDataPointer = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "nativeDataPointer", "J" ); |
||
159 | pJNIInfo->jIDWidth = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "width", "I" ); |
||
160 | pJNIInfo->jIDHeight = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "height", "I" ); |
||
161 | pJNIInfo->jIDNumberOfBands = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "numBands", "I" ); |
||
162 | pJNIInfo->jIDCompressionRate = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "compressionRate", "D" ); |
||
163 | pJNIInfo->jIDCellIncrementX = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "cellIncrementX", "D" ); |
||
164 | pJNIInfo->jIDCellIncrementY = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "cellIncrementY", "D" ); |
||
165 | pJNIInfo->jIDCellSizeUnits = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "cellSizeUnits", "I" ); |
||
166 | pJNIInfo->jIDOriginX = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "originX", "D" ); |
||
167 | pJNIInfo->jIDOriginY = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "originY", "D" ); |
||
168 | pJNIInfo->jIDDatum = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "datum", "Ljava/lang/String;" ); |
||
169 | pJNIInfo->jIDProjection = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "projection", "Ljava/lang/String;" ); |
||
170 | pJNIInfo->jIDFilename = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "fileName", "Ljava/lang/String;" ); |
||
171 | pJNIInfo->jIDIsOpen = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "bIsOpen", "Z" ); |
||
172 | pJNIInfo->jIDRefreshUpdateMethod= (*pEnv)->GetMethodID(pEnv, ECWFileClass, "refreshUpdate", "(IIDDDD)V"); |
||
173 | |||
174 | //pJNIInfo->jIDFileType = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "fileType", "I" );
|
||
175 | //pJNIInfo->jIDFileMimeType = (*pEnv)->GetFieldID(pEnv, ECWFileClass, "mimeType", "Ljava/lang/String;" );
|
||
176 | |||
177 | |||
178 | // Do some error checking
|
||
179 | if (!pJNIInfo->jIDNativeDataPointer)
|
||
180 | pErrorString = "Could not determine fieldID for 'nativeDataPointer' in ECWFile object.";
|
||
181 | if (!pJNIInfo->jIDWidth)
|
||
182 | pErrorString = "Could not determine fieldID for 'width' in ECWFile object.";
|
||
183 | if (!pJNIInfo->jIDHeight)
|
||
184 | pErrorString = "Could not determine fieldID for 'height' in ECWFile object.";
|
||
185 | if (!pJNIInfo->jIDNumberOfBands)
|
||
186 | pErrorString = "Could not determine fieldID for 'numBands' in ECWFile object.";
|
||
187 | if (!pJNIInfo->jIDCompressionRate)
|
||
188 | pErrorString = "Could not determine fieldID for 'compressionRate' in ECWFile object.";
|
||
189 | if (!pJNIInfo->jIDCellIncrementX)
|
||
190 | pErrorString = "Could not determine fieldID for 'cellIncrementX' in ECWFile object.";
|
||
191 | if (!pJNIInfo->jIDCellIncrementY)
|
||
192 | pErrorString = "Could not determine fieldID for 'cellIncrementY' in ECWFile object.";
|
||
193 | if (!pJNIInfo->jIDCellSizeUnits)
|
||
194 | pErrorString = "Could not determine fieldID for 'cellSizeUnits' in ECWFile object.";
|
||
195 | if (!pJNIInfo->jIDOriginX)
|
||
196 | pErrorString = "Could not determine fieldID for 'originX' in ECWFile object.";
|
||
197 | if (!pJNIInfo->jIDOriginY)
|
||
198 | pErrorString = "Could not determine fieldID for 'originY' in ECWFile object.";
|
||
199 | if (!pJNIInfo->jIDDatum)
|
||
200 | pErrorString = "Could not determine fieldID for 'datum' in ECWFile object.";
|
||
201 | if (!pJNIInfo->jIDProjection)
|
||
202 | pErrorString = "Could not determine fieldID for 'projection' in ECWFile object.";
|
||
203 | if (!pJNIInfo->jIDFilename)
|
||
204 | pErrorString = "Could not determine fieldID for 'fileName' in ECWFile object.";
|
||
205 | if (!pJNIInfo->jIDIsOpen)
|
||
206 | pErrorString = "Could not determine fieldID for 'bIsOpen' in ECWFile object.";
|
||
207 | /*if (!pJNIInfo->jIDFileType)
|
||
208 | pErrorString = "Could not determine fieldID for 'fileType' in ECWFile object.";
|
||
209 | if (!pJNIInfo->jIDFileMimeType)
|
||
210 | pErrorString = "Could not determine fieldID for 'mimeType' in ECWFile object.";*/
|
||
211 | |||
212 | if (pErrorString) {
|
||
213 | #ifdef WIN32
|
||
214 | MessageBox(NULL, OS_STRING(pErrorString), TEXT("JNCSClass Library (JNI)"), MB_OK); |
||
215 | #else
|
||
216 | fprintf(stderr, "JNCSClass Library (JNI) : %s\n", pErrorString);
|
||
217 | #endif
|
||
218 | NCSFormatErrorText(NCS_JNI_ERROR, pErrorString); |
||
219 | return NCS_JNI_ERROR;
|
||
220 | } |
||
221 | else {
|
||
222 | pGlobalJNCSFieldIDs = pJNIInfo; |
||
223 | return NCS_SUCCESS;
|
||
224 | } |
||
225 | } |
||
226 | else {
|
||
227 | return NCS_SUCCESS;
|
||
228 | } |
||
229 | } |
||
230 | |||
231 | /*
|
||
232 | * There is so much that can go wrong in this call, that is why there is so much error checking.
|
||
233 | *
|
||
234 | * Class: None
|
||
235 | * Method: NCSJNIRefreshCallback
|
||
236 | * Signature:
|
||
237 | */
|
||
238 | NCSEcwReadStatus NCSJNIRefreshCallback(NCSFileView *pNCSFileView) |
||
239 | { |
||
240 | NCSFileViewSetInfo *pViewInfo; |
||
241 | NCSJNIInfo *pJNIInfo; |
||
242 | jint nError; |
||
243 | JNIEnv *pEnv; |
||
244 | jclass EcwObjectClass = NULL;
|
||
245 | jobject pECWFile = NULL;
|
||
246 | |||
247 | NCScbmGetViewInfo(pNCSFileView, &pViewInfo); |
||
248 | |||
249 | // Must attach to the vm thread before calling any java methods.
|
||
250 | nError = (*pJavaVirtualMachineInst)->AttachCurrentThread(pJavaVirtualMachineInst, (void **)&pEnv, NULL); |
||
251 | |||
252 | if (nError != 0) { |
||
253 | char Message[] = "The ECW JNI interface could not attach to the current thread in\n" |
||
254 | "the Java virtual machine. Please refer to the Image Web Server\n"
|
||
255 | "Java SDK documentation for more information about JVM threads.\n\n"
|
||
256 | "Progressive imagery will not be available.";
|
||
257 | #ifdef WIN32
|
||
258 | MessageBox(GetActiveWindow(), OS_STRING(Message), TEXT("JNCSFile VM Error"), MB_OK);
|
||
259 | #else
|
||
260 | fprintf(stderr, "JNCSFile VM Error : %s\n", Message);
|
||
261 | #endif
|
||
262 | return NCSECW_READ_FAILED;
|
||
263 | } |
||
264 | |||
265 | // Make sure we got a view info struct.
|
||
266 | if (!pViewInfo) {
|
||
267 | NCSJNIThrowException(pEnv, "java/lang/Exception", "ECW JNI component could not obtain the NCSViewInfo pointer from the NCSFileView. No refreshUpdate() will occur."); |
||
268 | (*pJavaVirtualMachineInst)->DetachCurrentThread(pJavaVirtualMachineInst); |
||
269 | return NCSECW_READ_FAILED;
|
||
270 | } |
||
271 | |||
272 | // The file is the global reference stashed in the client data pointer.
|
||
273 | pECWFile = (jobject)pViewInfo->pClientData; |
||
274 | |||
275 | // Check to make sure that the ECW object has not been free'd or garbaged collected. This is only valid for JNI 1.2
|
||
276 | if ((*pEnv)->IsSameObject(pEnv, pECWFile/*pViewInfo->pClientData*/, NULL) == JNI_TRUE) { |
||
277 | (*pJavaVirtualMachineInst)->DetachCurrentThread(pJavaVirtualMachineInst); |
||
278 | return NCSECW_READ_FAILED;
|
||
279 | } |
||
280 | |||
281 | // Use the valid reference to the object, to obtain the data pointer.
|
||
282 | pJNIInfo = (NCSJNIInfo *)(*pEnv)->GetLongField(pEnv, pViewInfo->pClientData, pGlobalJNCSFieldIDs->jIDNativeDataPointer); |
||
283 | |||
284 | if (!pJNIInfo) {
|
||
285 | NCSJNIThrowException(pEnv, "java/lang/Exception", "The ECW JNI component could not obtain the client data pointer from the NCSViewInfo struct. No refreshUpdate() will occur."); |
||
286 | (*pJavaVirtualMachineInst)->DetachCurrentThread(pJavaVirtualMachineInst); |
||
287 | return NCSECW_READ_FAILED;
|
||
288 | } |
||
289 | |||
290 | EcwObjectClass = (*pEnv)->GetObjectClass(pEnv, pECWFile/*pJNIInfo->ECWFile*/);
|
||
291 | if (EcwObjectClass == NULL) { |
||
292 | NCSJNIThrowException(pEnv, "java/lang/Exception", "The ECW JNI component could not determine the class signature of the ECW object."); |
||
293 | (*pJavaVirtualMachineInst)->DetachCurrentThread(pJavaVirtualMachineInst); |
||
294 | return NCSECW_READ_FAILED;
|
||
295 | } |
||
296 | |||
297 | (*pEnv)->DeleteLocalRef(pEnv, EcwObjectClass); |
||
298 | |||
299 | //Call the "refreshUpdate" method on this object, if it implements the JNCSProgressiveUpdate interface.
|
||
300 | if (pGlobalJNCSFieldIDs->jIDRefreshUpdateMethod) {
|
||
301 | (*pEnv)->CallVoidMethod(pEnv, \ |
||
302 | pECWFile, \ |
||
303 | pGlobalJNCSFieldIDs->jIDRefreshUpdateMethod, \ |
||
304 | pViewInfo->nSizeX, pViewInfo->nSizeY, \ |
||
305 | pViewInfo->fTopX, pViewInfo->fLeftY, \ |
||
306 | pViewInfo->fBottomX, pViewInfo->fRightY); |
||
307 | } |
||
308 | else {
|
||
309 | NCSJNIThrowException(pEnv, "java/lang/ClassNotFoundException", "'refreshUpdate' method not found. Derived classes must implement the interface 'JNCSProgressiveUpdate' to use progressive imagery."); |
||
310 | (*pJavaVirtualMachineInst)->DetachCurrentThread(pJavaVirtualMachineInst); |
||
311 | return NCSECW_READ_FAILED;
|
||
312 | } |
||
313 | |||
314 | (*pJavaVirtualMachineInst)->DetachCurrentThread(pJavaVirtualMachineInst); |
||
315 | |||
316 | return NCSECW_READ_OK;
|
||
317 | } |
||
318 | |||
319 | |||
320 | /**
|
||
321 | *
|
||
322 | */
|
||
323 | int openFile(JNIEnv *pEnv, jobject *JNCSFile, jstring Filename, char *pFilename, jboolean bProgressive, NCSFileViewSetInfo *pNCSFileViewSetInfo, NCSFileView *pNCSFileView){ |
||
324 | NCSError nError; |
||
325 | |||
326 | if (bProgressive) {
|
||
327 | nError = NCScbmOpenFileView((char *)pFilename, &pNCSFileView, NCSJNIRefreshCallback);
|
||
328 | } |
||
329 | else {
|
||
330 | nError = NCScbmOpenFileView((char *)pFilename, &pNCSFileView, NULL); |
||
331 | } |
||
332 | |||
333 | |||
334 | if (NCS_FAILED(nError)) {
|
||
335 | // Return the short filename, since people dont like diplaying the full ecwp url
|
||
336 | char *pProtocol, *pHost, *pECWFilename, *pShortFileName;
|
||
337 | int nProtocolLength, nHostLength, nFilenameLength;
|
||
338 | |||
339 | NCSecwNetBreakdownUrl((char *)pFilename, &pProtocol, &nProtocolLength,
|
||
340 | &pHost, &nHostLength, |
||
341 | &pECWFilename, &nFilenameLength); |
||
342 | |||
343 | if (pECWFilename && nFilenameLength > 0 && (strstr(pECWFilename, "/") || strstr(pECWFilename, "\\"))) |
||
344 | { |
||
345 | int len = strlen(pECWFilename), index = 0; |
||
346 | for (index=len; index > 0; index--) |
||
347 | { |
||
348 | pShortFileName = &pECWFilename[index]; |
||
349 | if (pECWFilename[index] == '\\' || pECWFilename[index] == '/') |
||
350 | { |
||
351 | pShortFileName ++; |
||
352 | break;
|
||
353 | } |
||
354 | } |
||
355 | } |
||
356 | else
|
||
357 | { |
||
358 | pShortFileName = (char *)pFilename;
|
||
359 | } |
||
360 | |||
361 | NCSFormatErrorText(NCS_FILE_OPEN_FAILED, pShortFileName, NCSGetLastErrorText(nError)); |
||
362 | return NCS_FILE_OPEN_FAILED;
|
||
363 | } |
||
364 | else {
|
||
365 | NCSJNIInfo *pJNIInfo = NULL;
|
||
366 | char *pMimeType = NULL; |
||
367 | NCSFileViewFileInfo *pNCSFileInfo = NULL;
|
||
368 | |||
369 | nError = NCSCreateJNIInfoStruct(pEnv, (*JNCSFile), pNCSFileView, &pJNIInfo); |
||
370 | NCScbmGetViewFileInfo(pNCSFileView, &pNCSFileInfo); |
||
371 | |||
372 | // Set the properties in the actual Java object
|
||
373 | (*pEnv)->SetIntField(pEnv, (*JNCSFile), pGlobalJNCSFieldIDs->jIDWidth, (jint)pNCSFileInfo->nSizeX ); |
||
374 | (*pEnv)->SetIntField(pEnv, (*JNCSFile), pGlobalJNCSFieldIDs->jIDHeight, (jint)pNCSFileInfo->nSizeY ); |
||
375 | (*pEnv)->SetIntField(pEnv, (*JNCSFile), pGlobalJNCSFieldIDs->jIDNumberOfBands, (jint)pNCSFileInfo->nBands); |
||
376 | (*pEnv)->SetDoubleField(pEnv, (*JNCSFile), pGlobalJNCSFieldIDs->jIDCompressionRate, (jdouble)pNCSFileInfo->nCompressionRate ); |
||
377 | (*pEnv)->SetDoubleField(pEnv, (*JNCSFile), pGlobalJNCSFieldIDs->jIDCellIncrementX, (jdouble)pNCSFileInfo->fCellIncrementX ); |
||
378 | (*pEnv)->SetDoubleField(pEnv, (*JNCSFile), pGlobalJNCSFieldIDs->jIDCellIncrementY, (jdouble)pNCSFileInfo->fCellIncrementY ); |
||
379 | (*pEnv)->SetIntField(pEnv, (*JNCSFile), pGlobalJNCSFieldIDs->jIDCellSizeUnits, (jint)pNCSFileInfo->eCellSizeUnits); |
||
380 | (*pEnv)->SetDoubleField(pEnv, (*JNCSFile), pGlobalJNCSFieldIDs->jIDOriginX, (jdouble)pNCSFileInfo->fOriginX ); |
||
381 | (*pEnv)->SetDoubleField(pEnv, (*JNCSFile), pGlobalJNCSFieldIDs->jIDOriginY, (jdouble)pNCSFileInfo->fOriginY ); |
||
382 | (*pEnv)->SetObjectField(pEnv, (*JNCSFile), pGlobalJNCSFieldIDs->jIDDatum, (*pEnv)->NewStringUTF(pEnv, pNCSFileInfo->szDatum)); |
||
383 | (*pEnv)->SetObjectField(pEnv, (*JNCSFile), pGlobalJNCSFieldIDs->jIDProjection, (*pEnv)->NewStringUTF(pEnv, pNCSFileInfo->szProjection)); |
||
384 | (*pEnv)->SetObjectField(pEnv, (*JNCSFile), pGlobalJNCSFieldIDs->jIDFilename, Filename); |
||
385 | (*pEnv)->SetBooleanField(pEnv, (*JNCSFile), pGlobalJNCSFieldIDs->jIDIsOpen, JNI_TRUE); |
||
386 | (*pEnv)->SetLongField(pEnv, (*JNCSFile), pGlobalJNCSFieldIDs->jIDNativeDataPointer, (jlong)pJNIInfo); |
||
387 | } |
||
388 | return NCS_SUCCESS;
|
||
389 | } |
||
390 | |||
391 | /*
|
||
392 | * Class: com_ermapper_ecw_JNCSFile
|
||
393 | * Method: ECWOpen
|
||
394 | * Signature: (Ljava/lang/String;Z)I
|
||
395 | */
|
||
396 | |||
397 | JNIEXPORT jint JNICALL Java_com_ermapper_ecw_JNCSFile_ECWOpen |
||
398 | (JNIEnv *pEnv, jobject JNCSFile, jstring Filename, jboolean bProgressive){ |
||
399 | const char *pFilename = (*pEnv)->GetStringUTFChars(pEnv, Filename, (jboolean *)NULL); |
||
400 | NCSFileView *pNCSFileView = NULL;
|
||
401 | NCSFileViewSetInfo *pNCSFileViewSetInfo = NULL;
|
||
402 | int ret;
|
||
403 | |||
404 | ret = openFile(pEnv, &JNCSFile, Filename, (char *)pFilename, bProgressive, pNCSFileViewSetInfo, pNCSFileView);
|
||
405 | |||
406 | (*pEnv)->ReleaseStringUTFChars(pEnv, Filename, (const char *)pFilename); |
||
407 | |||
408 | NCScbmGetViewInfo(pNCSFileView, &pNCSFileViewSetInfo); |
||
409 | |||
410 | pNCSFileViewSetInfo->pClientData = (void *)(*pEnv)->NewGlobalRef(pEnv, JNCSFile);
|
||
411 | |||
412 | return ret;
|
||
413 | } |
||
414 | |||
415 | |||
416 | /*
|
||
417 | * Class: com_ermapper_ecw_JNCSFile
|
||
418 | * Method: ECWOpen
|
||
419 | * Signature: (Ljava/lang/String;Z)I
|
||
420 | */
|
||
421 | |||
422 | JNIEXPORT jint JNICALL Java_com_ermapper_ecw_JNCSFile_ECWOpenArray |
||
423 | (JNIEnv *pEnv, jobject JNCSFile, jstring Filename, jboolean bProgressive, jbyteArray pszF){ |
||
424 | |||
425 | NCSFileView *pNCSFileView = NULL;
|
||
426 | NCSFileViewSetInfo *pNCSFileViewSetInfo = NULL;
|
||
427 | int ret;
|
||
428 | jbyte *pFilename; |
||
429 | int longitud = 0; |
||
430 | NCSError nError; |
||
431 | jbyte *aux = NULL;
|
||
432 | FILE *fich; |
||
433 | |||
434 | longitud = (*pEnv)->GetArrayLength(pEnv, pszF); |
||
435 | pFilename = (*pEnv)->GetByteArrayElements(pEnv, pszF, 0);
|
||
436 | |||
437 | aux = (jbyte *)malloc(sizeof(jbyte) * (longitud + 1)); |
||
438 | memcpy(aux, pFilename, longitud); |
||
439 | (*pEnv)->ReleaseByteArrayElements(pEnv, pszF, (jbyte *)pFilename, 0);
|
||
440 | pFilename = aux; |
||
441 | |||
442 | pFilename[longitud] = '\0';
|
||
443 | |||
444 | fich = fopen((char *)pFilename, "r"); |
||
445 | if(fich)
|
||
446 | fclose(fich); |
||
447 | else
|
||
448 | return -1; |
||
449 | |||
450 | if (bProgressive) {
|
||
451 | nError = NCScbmOpenFileView((char *)pFilename, &pNCSFileView, NCSJNIRefreshCallback);
|
||
452 | }else {
|
||
453 | nError = NCScbmOpenFileView((char *)pFilename, &pNCSFileView, NULL); |
||
454 | } |
||
455 | |||
456 | |||
457 | if (NCS_FAILED(nError)) {
|
||
458 | // Return the short filename, since people dont like diplaying the full ecwp url
|
||
459 | char *pProtocol, *pHost, *pECWFilename, *pShortFileName;
|
||
460 | int nProtocolLength, nHostLength, nFilenameLength;
|
||
461 | |||
462 | NCSecwNetBreakdownUrl((char *)pFilename, &pProtocol, &nProtocolLength,
|
||
463 | &pHost, &nHostLength, |
||
464 | &pECWFilename, &nFilenameLength); |
||
465 | |||
466 | if (pECWFilename && nFilenameLength > 0 && (strstr(pECWFilename, "/") || strstr(pECWFilename, "\\"))) |
||
467 | { |
||
468 | int len = strlen(pECWFilename), index = 0; |
||
469 | for (index=len; index > 0; index--) |
||
470 | { |
||
471 | pShortFileName = &pECWFilename[index]; |
||
472 | if (pECWFilename[index] == '\\' || pECWFilename[index] == '/') |
||
473 | { |
||
474 | pShortFileName ++; |
||
475 | break;
|
||
476 | } |
||
477 | } |
||
478 | } |
||
479 | else
|
||
480 | { |
||
481 | pShortFileName = (char *)pFilename;
|
||
482 | } |
||
483 | |||
484 | NCSFormatErrorText(NCS_FILE_OPEN_FAILED, pShortFileName, NCSGetLastErrorText(nError)); |
||
485 | return NCS_FILE_OPEN_FAILED;
|
||
486 | } |
||
487 | else {
|
||
488 | NCSJNIInfo *pJNIInfo = NULL;
|
||
489 | char *pMimeType = NULL; |
||
490 | NCSFileViewFileInfo *pNCSFileInfo = NULL;
|
||
491 | |||
492 | nError = NCSCreateJNIInfoStruct(pEnv, JNCSFile, pNCSFileView, &pJNIInfo); |
||
493 | NCScbmGetViewFileInfo(pNCSFileView, &pNCSFileInfo); |
||
494 | |||
495 | // Set the properties in the actual Java object
|
||
496 | (*pEnv)->SetIntField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDWidth, (jint)pNCSFileInfo->nSizeX ); |
||
497 | (*pEnv)->SetIntField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDHeight, (jint)pNCSFileInfo->nSizeY ); |
||
498 | (*pEnv)->SetIntField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDNumberOfBands, (jint)pNCSFileInfo->nBands); |
||
499 | (*pEnv)->SetDoubleField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDCompressionRate, (jdouble)pNCSFileInfo->nCompressionRate ); |
||
500 | (*pEnv)->SetDoubleField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDCellIncrementX, (jdouble)pNCSFileInfo->fCellIncrementX ); |
||
501 | (*pEnv)->SetDoubleField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDCellIncrementY, (jdouble)pNCSFileInfo->fCellIncrementY ); |
||
502 | (*pEnv)->SetIntField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDCellSizeUnits, (jint)pNCSFileInfo->eCellSizeUnits); |
||
503 | (*pEnv)->SetDoubleField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDOriginX, (jdouble)pNCSFileInfo->fOriginX ); |
||
504 | (*pEnv)->SetDoubleField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDOriginY, (jdouble)pNCSFileInfo->fOriginY ); |
||
505 | (*pEnv)->SetObjectField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDDatum, (*pEnv)->NewStringUTF(pEnv, pNCSFileInfo->szDatum)); |
||
506 | (*pEnv)->SetObjectField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDProjection, (*pEnv)->NewStringUTF(pEnv, pNCSFileInfo->szProjection)); |
||
507 | (*pEnv)->SetObjectField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDFilename, Filename); |
||
508 | (*pEnv)->SetBooleanField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDIsOpen, JNI_TRUE); |
||
509 | (*pEnv)->SetLongField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDNativeDataPointer, (jlong)pJNIInfo); |
||
510 | |||
511 | } |
||
512 | |||
513 | |||
514 | //ret = openFile(pEnv, &JNCSFile, Filename, (char *)pszFilename, bProgressive, pNCSFileViewSetInfo, pNCSFileView);
|
||
515 | |||
516 | NCScbmGetViewInfo(pNCSFileView, &pNCSFileViewSetInfo); |
||
517 | |||
518 | pNCSFileViewSetInfo->pClientData = (void *)(*pEnv)->NewGlobalRef(pEnv, JNCSFile);
|
||
519 | |||
520 | free(pFilename); |
||
521 | return NCS_SUCCESS;
|
||
522 | } |
||
523 | |||
524 | |||
525 | /*
|
||
526 | * Class: com_ermapper_ecw_JNCSFile
|
||
527 | * Method: ECWClose
|
||
528 | * Signature: (Z)V
|
||
529 | */
|
||
530 | JNIEXPORT void JNICALL Java_com_ermapper_ecw_JNCSFile_ECWClose
|
||
531 | (JNIEnv *pEnv , jobject JNCSFile, jboolean bFreeCache) |
||
532 | { |
||
533 | NCSError nError; |
||
534 | NCSJNIInfo *pJNIInfo = NULL;
|
||
535 | |||
536 | pJNIInfo = (NCSJNIInfo *)(*pEnv)->GetLongField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDNativeDataPointer); |
||
537 | |||
538 | if (pJNIInfo != NULL) { |
||
539 | NCSFileViewSetInfo *pViewInfo; |
||
540 | |||
541 | NCScbmGetViewInfo(pJNIInfo->pFileView, &pViewInfo); |
||
542 | |||
543 | // Clear the Java object members.
|
||
544 | (*pEnv)->SetIntField (pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDWidth, (jint)0 );
|
||
545 | (*pEnv)->SetIntField (pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDHeight, (jint)0 );
|
||
546 | (*pEnv)->SetIntField (pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDNumberOfBands, (jint)0);
|
||
547 | (*pEnv)->SetDoubleField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDCompressionRate, (jdouble)0.0 ); |
||
548 | (*pEnv)->SetDoubleField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDCellIncrementX, (jdouble)0.0 ); |
||
549 | (*pEnv)->SetDoubleField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDCellIncrementY, (jdouble)0.0 ); |
||
550 | (*pEnv)->SetIntField (pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDCellSizeUnits, (jint)0 );
|
||
551 | (*pEnv)->SetDoubleField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDOriginX, (jdouble)0.0 ); |
||
552 | (*pEnv)->SetDoubleField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDOriginY, (jdouble)0.0 ); |
||
553 | (*pEnv)->SetObjectField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDDatum, (*pEnv)->NewStringUTF(pEnv, ""));
|
||
554 | (*pEnv)->SetObjectField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDProjection, (*pEnv)->NewStringUTF(pEnv, ""));
|
||
555 | (*pEnv)->SetObjectField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDFilename, NULL);
|
||
556 | (*pEnv)->SetBooleanField(pEnv,JNCSFile, pGlobalJNCSFieldIDs->jIDIsOpen, JNI_FALSE); |
||
557 | (*pEnv)->SetLongField (pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDNativeDataPointer, (jlong)0);
|
||
558 | |||
559 | (*pEnv)->SetIntField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDFileType, (jint)0 );
|
||
560 | (*pEnv)->SetObjectField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDFileMimeType, NULL );
|
||
561 | |||
562 | // Clean up any global refs
|
||
563 | //(*pEnv)->DeleteGlobalRef(pEnv, pJNIInfo->ECWFile);
|
||
564 | (*pEnv)->DeleteGlobalRef(pEnv, pViewInfo->pClientData); |
||
565 | |||
566 | nError = NCScbmCloseFileViewEx(pJNIInfo->pFileView, bFreeCache); |
||
567 | |||
568 | pJNIInfo->pFileView = NULL;
|
||
569 | NCSFree(pJNIInfo); |
||
570 | } |
||
571 | return;
|
||
572 | } |
||
573 | |||
574 | /*
|
||
575 | * Class: com_ermapper_ecw_JNCSFile
|
||
576 | * Method: ECWSetView
|
||
577 | * Signature: (I[IIIIIDDDDII)I
|
||
578 | */
|
||
579 | JNIEXPORT jint JNICALL Java_com_ermapper_ecw_JNCSFile_ECWSetView |
||
580 | (JNIEnv *pEnv, jobject ECWFile, jint nBands, jintArray nBandList, jint nDatasetTLX, jint nDatasetTLY, jint nDatasetBRX, jint nDatasetBRY, jdouble dWorldTLX, jdouble dWorldTLY, jdouble dWorldBRX, jdouble dWorldBRY, jint nWidth, jint nHeight) |
||
581 | { |
||
582 | NCSError nError = NCS_SUCCESS; |
||
583 | NCSJNIInfo *pJNIInfo = NULL;
|
||
584 | |||
585 | // Sanity check
|
||
586 | if ((*pEnv)->IsInstanceOf(pEnv, ECWFile, (*pEnv)->FindClass(pEnv, "com/ermapper/ecw/JNCSFile")) == JNI_FALSE) |
||
587 | { |
||
588 | #ifdef WIN32
|
||
589 | MessageBox(NULL, OS_STRING("ECWSetView() error : object is not a JNCSFile instance"), TEXT("JNCSClass Library (JNI)"), MB_OK); |
||
590 | #endif //WIN32 |
||
591 | return NCS_JNI_ERROR;
|
||
592 | } |
||
593 | |||
594 | pJNIInfo = (NCSJNIInfo *)(*pEnv)->GetLongField(pEnv, ECWFile, pGlobalJNCSFieldIDs->jIDNativeDataPointer); |
||
595 | |||
596 | if (pJNIInfo) {
|
||
597 | |||
598 | jint *pBandBuffer = (jint *)NCSMalloc(sizeof(UINT32)*nBands+1, TRUE); |
||
599 | (*pEnv)->GetIntArrayRegion(pEnv, nBandList, 0, nBands, pBandBuffer);
|
||
600 | |||
601 | nError = NCScbmSetFileViewEx( pJNIInfo->pFileView, |
||
602 | nBands, |
||
603 | (UINT32*)pBandBuffer, |
||
604 | nDatasetTLX, nDatasetTLY, nDatasetBRX, nDatasetBRY, |
||
605 | nWidth, |
||
606 | nHeight, |
||
607 | dWorldTLX, |
||
608 | dWorldTLY, |
||
609 | dWorldBRX, |
||
610 | dWorldBRY); |
||
611 | NCSFree(pBandBuffer); |
||
612 | |||
613 | } else {
|
||
614 | NCSFormatErrorText(NCS_JNI_ERROR, "method SetView() could not get native data from JNCSFile object.");
|
||
615 | nError = NCS_JNI_ERROR; |
||
616 | } |
||
617 | |||
618 | return nError;
|
||
619 | } |
||
620 | |||
621 | |||
622 | /*
|
||
623 | * Class: com_ermapper_ecw_JNCSFile
|
||
624 | * Method: ECWReadImageRGBA
|
||
625 | * Signature: ([I)I
|
||
626 | */
|
||
627 | JNIEXPORT jint JNICALL Java_com_ermapper_ecw_JNCSFile_ECWReadImageRGBA |
||
628 | (JNIEnv *pEnv, jobject JNCSFile, jintArray pRGBArray, jint width, jint height) |
||
629 | { |
||
630 | jboolean bIsCopy; |
||
631 | NCSEcwReadStatus eStatus; |
||
632 | NCSJNIInfo *pJNIInfo = NULL;
|
||
633 | NCSError nError = NCS_SUCCESS; |
||
634 | jint *pRGBAPixels; |
||
635 | jint *pRGBLineArrayPtr = NULL;
|
||
636 | int nIndex;
|
||
637 | |||
638 | pJNIInfo = (NCSJNIInfo *)(*pEnv)->GetLongField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDNativeDataPointer); |
||
639 | |||
640 | if (!pJNIInfo) {
|
||
641 | NCSFormatErrorText(NCS_JNI_ERROR, "method readLineRGB() could not get native data from JNCSFile object.");
|
||
642 | nError = NCS_JNI_ERROR; |
||
643 | } |
||
644 | else {
|
||
645 | // Lock the primitive array and get a pointer to the memory.
|
||
646 | pRGBAPixels = (jint *)(*pEnv)->GetPrimitiveArrayCritical(pEnv, pRGBArray, &bIsCopy); |
||
647 | |||
648 | if (pRGBAPixels) {
|
||
649 | |||
650 | pRGBLineArrayPtr = pRGBAPixels; |
||
651 | for (nIndex = 0; nIndex < height; nIndex ++) { |
||
652 | #if defined(NCSBO_LSBFIRST)
|
||
653 | eStatus = NCScbmReadViewLineBGRA( pJNIInfo->pFileView, (UINT32 *)pRGBLineArrayPtr); |
||
654 | #elif defined(NCSBO_MSBFIRST)
|
||
655 | eStatus = NCScbmReadViewLineBGRA( pJNIInfo->pFileView, (UINT32 *)pRGBLineArrayPtr); |
||
656 | //eStatus = NCScbmReadViewLineRGBA( pJNIInfo->pFileView, (UINT32 *)pRGBLineArrayPtr);
|
||
657 | #endif
|
||
658 | pRGBLineArrayPtr += width; |
||
659 | |||
660 | if (eStatus == NCSECW_READ_CANCELLED) {
|
||
661 | nError = NCS_SUCCESS; |
||
662 | break;
|
||
663 | } |
||
664 | if (eStatus == NCSECW_READ_FAILED) {
|
||
665 | NCSFormatErrorText(NCS_JNI_ERROR, "method readLineRGB() failed (internal error).");
|
||
666 | nError = NCS_JNI_ERROR; |
||
667 | break;
|
||
668 | } |
||
669 | #ifndef WIN32
|
||
670 | NCSThreadYield(); |
||
671 | #endif
|
||
672 | } |
||
673 | } |
||
674 | else {
|
||
675 | NCSFormatErrorText(NCS_JNI_ERROR, "method readLineRGB() could not allocate memory for RGB Array.");
|
||
676 | nError = NCS_JNI_ERROR; |
||
677 | } |
||
678 | // Copy the array back to the object and free the memory
|
||
679 | (*pEnv)->ReleasePrimitiveArrayCritical(pEnv, pRGBArray, pRGBAPixels, 0);
|
||
680 | } |
||
681 | return nError;
|
||
682 | } |
||
683 | |||
684 | |||
685 | /*
|
||
686 | * Class: com_ermapper_ecw_JNCSFile
|
||
687 | * Method: ECWReadLineRGB
|
||
688 | * Signature: ([I)I
|
||
689 | */
|
||
690 | |||
691 | JNIEXPORT jint JNICALL Java_com_ermapper_ecw_JNCSFile_ECWReadLineRGBA |
||
692 | (JNIEnv *pEnv, jobject JNCSFile, jintArray pRGBArray) |
||
693 | { |
||
694 | jboolean bIsCopy; |
||
695 | NCSEcwReadStatus eStatus; |
||
696 | NCSJNIInfo *pJNIInfo = NULL;
|
||
697 | NCSError nError = NCS_SUCCESS; |
||
698 | jint *pRGBAPixels; |
||
699 | |||
700 | pJNIInfo = (NCSJNIInfo *)(*pEnv)->GetLongField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDNativeDataPointer); |
||
701 | |||
702 | if (!pJNIInfo) {
|
||
703 | NCSFormatErrorText(NCS_JNI_ERROR, "method readLineRGB() could not get native data from JNCSFile object.");
|
||
704 | nError = NCS_JNI_ERROR; |
||
705 | } |
||
706 | else {
|
||
707 | // Lock the primitive array and get a pointer to the memory.
|
||
708 | pRGBAPixels = (jint *)(*pEnv)->GetPrimitiveArrayCritical(pEnv, pRGBArray, &bIsCopy); |
||
709 | |||
710 | if (pRGBAPixels) {
|
||
711 | // Read into a RGBA Java scaneline (which is byte reversed, so go the BGRA here (???)
|
||
712 | eStatus = NCScbmReadViewLineBGRA( pJNIInfo->pFileView, (UINT32 *)pRGBAPixels); |
||
713 | |||
714 | if (eStatus == NCSECW_READ_FAILED) {
|
||
715 | NCSFormatErrorText(NCS_JNI_ERROR, "method readLineRGB() failed (internal error).");
|
||
716 | nError = NCS_JNI_ERROR; |
||
717 | } |
||
718 | } |
||
719 | else {
|
||
720 | NCSFormatErrorText(NCS_JNI_ERROR, "method readLineRGB() could not allocate memory for RGB Array.");
|
||
721 | nError = NCS_JNI_ERROR; |
||
722 | } |
||
723 | // Copy the array back to the object and free the memory
|
||
724 | (*pEnv)->ReleasePrimitiveArrayCritical(pEnv, pRGBArray, pRGBAPixels, 0);
|
||
725 | } |
||
726 | return nError;
|
||
727 | } |
||
728 | |||
729 | /*
|
||
730 | * Class: com_ermapper_ecw_JNCSFile
|
||
731 | * Method: ECWGetErrorString
|
||
732 | * Signature: (I)Ljava/lang/String;
|
||
733 | */
|
||
734 | JNIEXPORT jstring JNICALL Java_com_ermapper_ecw_JNCSFile_ECWGetErrorString |
||
735 | (JNIEnv *pEnv, jobject JNCSFile, jint nErrorNumber) |
||
736 | { |
||
737 | //return (*pEnv)->NewStringUTF(pEnv, NCSGetLastErrorText(nErrorNumber));
|
||
738 | |||
739 | return (*pEnv)->NewStringUTF(pEnv, "...."); |
||
740 | } |
||
741 | |||
742 | |||
743 | /*
|
||
744 | * Class: com_ermapper_ecw_JNCSFile
|
||
745 | * Method: ECWGetLibVersion
|
||
746 | * Signature: ()Ljava/lang/String;
|
||
747 | */
|
||
748 | JNIEXPORT jstring JNICALL Java_com_ermapper_ecw_JNCSFile_ECWGetLibVersion |
||
749 | (JNIEnv *pEnv, jclass clazz) |
||
750 | { |
||
751 | return (*pEnv)->NewStringUTF(pEnv, NCS_VERSION_STRING_NO_NULL);
|
||
752 | } |
||
753 | |||
754 | /*
|
||
755 | * Class: com_ermapper_ecw_JNCSFile
|
||
756 | * Method: ECWGetPercentComplete
|
||
757 | * Signature: ()I
|
||
758 | */
|
||
759 | |||
760 | JNIEXPORT jshort JNICALL Java_com_ermapper_ecw_JNCSFile_ECWGetPercentComplete |
||
761 | (JNIEnv *pEnv, jobject JNCSFile) |
||
762 | |||
763 | { |
||
764 | NCSFileViewSetInfo *pViewInfo = NULL;
|
||
765 | NCSJNIInfo *pJNIInfo = NULL;
|
||
766 | |||
767 | pJNIInfo = (NCSJNIInfo *)(*pEnv)->GetLongField(pEnv, JNCSFile, pGlobalJNCSFieldIDs->jIDNativeDataPointer); |
||
768 | |||
769 | if (!pJNIInfo)
|
||
770 | return 0; |
||
771 | |||
772 | if (pJNIInfo->pFileView) {
|
||
773 | NCScbmGetViewInfo(pJNIInfo->pFileView, &pViewInfo); |
||
774 | if (pViewInfo) {
|
||
775 | return (jshort)((pViewInfo->nBlocksAvailable / (double)pViewInfo->nBlocksInView) * 100); |
||
776 | } |
||
777 | } |
||
778 | else {
|
||
779 | return 0; |
||
780 | } |
||
781 | |||
782 | return 0; |
||
783 | } |