/* * Class: nitf_PixelSkipDownSampler * Method: construct * Signature: (II)V */ JNIEXPORT void JNICALL Java_nitf_PixelSkipDownSampler_construct (JNIEnv *env, jobject self, jint rowSkip, jint colSkip) { nitf_Error error; jmethodID methodID; nitf_DownSampler *downSampler; jclass downSamplerClass = (*env)->FindClass(env, "nitf/DownSampler"); jmethodID downSamplerMethodID = (*env)->GetStaticMethodID(env, downSamplerClass, "register", "(Lnitf/DownSampler;)V"); if (rowSkip <= 0) rowSkip = 1; if (colSkip <= 0) colSkip = 1; downSampler = nitf_PixelSkip_construct(rowSkip, colSkip, &error); if (!downSampler) { _ThrowNITFException(env, error.message); return; } _SetObj(env, self, downSampler); /* now, we must also register this type */ (*env)->CallStaticVoidMethod(env, downSamplerClass, downSamplerMethodID, self); return; }
/* * Class: nitf_LookupTable * Method: construct * Signature: (II[B)V */ JNIEXPORT void JNICALL Java_nitf_LookupTable_construct (JNIEnv * env, jobject self, jint numTables, jint numEntries, jbyteArray lutData) { nitf_LookupTable *lut = NULL; nitf_Error error; char *dataBuf = NULL; /* construct the LUT */ lut = nitf_LookupTable_construct((nitf_Uint32) numTables, (nitf_Uint32) numEntries, &error); if (!lut) { /* throw an error */ _ThrowNITFException(env, error.message); return; } dataBuf = (char *) (*env)->GetByteArrayElements(env, lutData, 0); if (!dataBuf) { _ThrowNITFException(env, "Out of memory!"); return; } /* initialize the data */ nitf_LookupTable_init(lut, (nitf_Uint32) numTables, (nitf_Uint32) numEntries, (NITF_DATA *) dataBuf, &error); (*env)->ReleaseByteArrayElements(env, lutData, dataBuf, 0); _SetObj(env, self, lut); }
/* * Class: nitf_ImageSource * Method: construct * Signature: ()V */ JNIEXPORT void JNICALL Java_nitf_ImageSource_construct (JNIEnv * env, jobject self) { nitf_ImageSource *source; nitf_Error error; source = nitf_ImageSource_construct(&error); _SetObj(env, self, source); }
JNIEXPORT void JNICALL Java_cgm_MetafileReader_construct (JNIEnv *env, jobject self) { cgm_MetafileReader *reader = NULL; nitf_Error error; reader = cgm_MetafileReader_construct(&error); if (!reader) _ThrowNITFException(env, "Unable to create new MetafileReader"); _SetObj(env, self, reader); }
JNIEXPORT jboolean JNICALL Java_nitf_TRE_00024TREIterator_hasNext (JNIEnv *env, jobject self) { nitf_TREEnumerator *enumerator = _GetObj(env, self); jboolean rv = JNI_FALSE; if (enumerator) { rv = enumerator->hasNext(&enumerator) ? JNI_TRUE : JNI_FALSE; _SetObj(env, self, enumerator); } return rv; }
JNIEXPORT void JNICALL Java_nitf_TRE_00024TREIterator_construct (JNIEnv *env, jobject self, jobject jTREObject) { jclass treClass; jmethodID treMethodId; nitf_TRE *tre = NULL; nitf_TREEnumerator *enumerator = NULL; nitf_Error error; treClass = (*env)->GetObjectClass(env, jTREObject); treMethodId = (*env)->GetMethodID(env, treClass, "getAddress", "()J"); tre = (nitf_TRE*)(*env)->CallLongMethod(env, jTREObject, treMethodId); enumerator = nitf_TRE_begin(tre, &error); _SetObj(env, self, enumerator); }
/* * Class: nitf_Record * Method: construct * Signature: (Lnitf/Version;)V */ JNIEXPORT void JNICALL Java_nitf_Record_construct (JNIEnv * env, jobject self, jobject version) { nitf_Record *record; nitf_Error error; nitf_Version nitfVersion = _GetNITFVersion(env, version); record = nitf_Record_construct(nitfVersion, &error); if (!record) { /* throw an error */ _ThrowNITFException(env, error.message); } _SetObj(env, self, record); }
JNIEXPORT void JNICALL Java_nitf_BandSource_construct (JNIEnv * env, jobject self) { /* make the interface */ static nitf_IDataSource iBandSource = { &BandSource_read, &BandSource_destruct, &BandSource_getSize, &BandSource_setSize }; /* the return bandSource */ nitf_BandSource *bandSource = NULL; BandSourceImpl *impl; /* gets malloc'd for this object */ nitf_Error error; jclass bandSourceClass = (*env)->FindClass(env, "nitf/BandSource"); jmethodID methodID = (*env)->GetStaticMethodID(env, bandSourceClass, "register", "(Lnitf/BandSource;)V"); /* construct the persisent one */ impl = (BandSourceImpl *) NITF_MALLOC(sizeof(BandSourceImpl)); if (!impl) { _ThrowNITFException(env, "Out of memory"); return; } /**************************************************************/ /* THIS IS VERY IMPORTANT... WE MUST MAKE A STRONG GLOBAL REF */ /**************************************************************/ impl->self = (*env)->NewGlobalRef(env, self); bandSource = (nitf_BandSource *) NITF_MALLOC(sizeof(nitf_BandSource)); if (!bandSource) { _ThrowNITFException(env, "Out of Memory"); return; } bandSource->data = impl; bandSource->iface = &iBandSource; _SetObj(env, self, bandSource); /* now, we must also register this type */ (*env)->CallStaticVoidMethod(env, bandSourceClass, methodID, self); }
/* * Class: nitf_SubWindow * Method: construct * Signature: ()V */ JNIEXPORT void JNICALL Java_nitf_SubWindow_construct (JNIEnv * env, jobject self) { nitf_SubWindow *subWindow; nitf_Error error; subWindow = nitf_SubWindow_construct(&error); if (!subWindow) { /* throw an error */ _ThrowNITFException(env, error.message); } else { _SetObj(env, self, subWindow); } }
JNIEXPORT void JNICALL Java_nitf_WriteHandler_construct (JNIEnv *env, jobject self) { /* make the interface */ static nitf_IWriteHandler iWriteHandler = { &WriteHandler_write, &WriteHandler_destruct }; nitf_WriteHandler *writeHandler = NULL; WriteHandlerImpl *impl = NULL; nitf_Error error; /* construct the persisent one */ impl = (WriteHandlerImpl *) NITF_MALLOC(sizeof(WriteHandlerImpl)); if (!impl) { _ThrowNITFException(env, "Out of memory"); return; } /**************************************************************/ /* THIS IS VERY IMPORTANT... WE MUST MAKE A STRONG GLOBAL REF */ /**************************************************************/ impl->self = (*env)->NewGlobalRef(env, self); writeHandler = (nitf_WriteHandler *) NITF_MALLOC(sizeof(nitf_WriteHandler)); if (!writeHandler) { _ThrowNITFException(env, "Out of Memory"); return; } writeHandler->data = impl; writeHandler->iface = &iWriteHandler; _SetObj(env, self, writeHandler); }
/* * Class: nitf_MemorySource * Method: construct * Signature: ([BIII)V */ JNIEXPORT void JNICALL Java_nitf_MemorySource_construct (JNIEnv * env, jobject self, jbyteArray data, jint size, jint start, jint numBytesPerPixel, jint pixelSkip) { nitf_Error error; char *buf, *copyBuf; jboolean isCopy; nitf_BandSource *memorySource; jclass bandSourceClass = (*env)->FindClass(env, "nitf/BandSource"); jmethodID methodID = (*env)->GetStaticMethodID(env, bandSourceClass, "register", "(Lnitf/BandSource;)V"); if (!data) { _ThrowNITFException(env, "ERROR, data array is null"); return; } /* get the data */ buf = (char *) (*env)->GetByteArrayElements(env, data, &isCopy); if (!buf) { _ThrowNITFException(env, "ERROR getting data from array"); return; } if (isCopy == JNI_TRUE) { /* this will almost always be true - most JVMs always copy... */ copyBuf = buf; } else { /* we must copy ourselves */ copyBuf = (char*)NITF_MALLOC(size); if (!copyBuf) { _ThrowNITFException(env, "Out of memory"); return; } memcpy(copyBuf, buf, size); } memorySource = nitf_MemorySource_construct(copyBuf, size, start, numBytesPerPixel, pixelSkip, &error); if (!memorySource) { _ThrowNITFException(env, error.message); return; } _SetObj(env, self, memorySource); /* now, we must also register this type */ (*env)->CallStaticVoidMethod(env, bandSourceClass, methodID, self); if (isCopy != JNI_TRUE) { /* if the JVM did not make a copy, we need to tell it we're done with it */ (*env)->ReleaseByteArrayElements(env, data, buf, JNI_ABORT); } return; }