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