/* * Class: nitf_BandInfo * Method: setLookupTable * Signature: (Lnitf/LookupTable;)V */ JNIEXPORT void JNICALL Java_nitf_BandInfo_setLookupTable (JNIEnv * env, jobject self, jobject lookupTable) { nitf_BandInfo *info = _GetObj(env, self); jclass lutClass; /* the class for the LUT */ jmethodID methodID; nitf_LookupTable *lut = NULL; /* the LUT */ nitf_Error error; /* temp error object */ /* get the class, method, and C object */ lutClass = (*env)->GetObjectClass(env, lookupTable); methodID = (*env)->GetMethodID(env, lutClass, "getAddress", "()J"); lut = (nitf_LookupTable *) (*env)->CallLongMethod(env, lookupTable, methodID); /* if alreay has a LUT, release it to Java */ if (info->lut) { _ManageObject(env, (jlong)info->lut, JNI_TRUE); } /* set the lut */ info->lut = lut; /* set the tables and entries field in the BandInfo object */ nitf_Field_setUint32(info->numLUTs, lut->tables, &error); nitf_Field_setUint32(info->bandEntriesPerLUT, lut->entries, &error); /* tell Java not to manage it */ _ManageObject(env, (jlong)info->lut, JNI_FALSE); return; }
NITFAPI(NITF_BOOL) nitf_BandInfo_init(nitf_BandInfo * bandInfo, const char *representation, const char *subcategory, const char *imageFilterCondition, const char *imageFilterCode, nitf_Uint32 numLUTs, nitf_Uint32 bandEntriesPerLUT, nitf_LookupTable * lut, nitf_Error * error) { if (!nitf_Field_setString (bandInfo->NITF_IREPBAND, representation, error)) return (NITF_FAILURE); if (!nitf_Field_setString(bandInfo->NITF_ISUBCAT, subcategory, error)) return (NITF_FAILURE); if (!nitf_Field_setString (bandInfo->NITF_IFC, imageFilterCondition, error)) return (NITF_FAILURE); if (!nitf_Field_setString (bandInfo->NITF_IMFLT, imageFilterCode, error)) return (NITF_FAILURE); if (!nitf_Field_setUint32(bandInfo->NITF_NLUTS, numLUTs, error)) return (NITF_FAILURE); if (!nitf_Field_setUint32 (bandInfo->NITF_NELUT, bandEntriesPerLUT, error)) return (NITF_FAILURE); bandInfo->lut = lut; return (NITF_SUCCESS); }
void setupImageSubheader( test_nitf_ImageIOConstructArgs *args, nitf_Record *record, nitf_ImageSegment *seg) { nitf_ImageSubheader *subheader; /* Subheader from segment */ nitf_Uint32 nBands; /* Number of bands */ nitf_BandInfo **bands; /* BandInfo array */ nitf_Error errorObj; /* Error object argument */ nitf_Uint32 i; subheader = seg->subheader; nitf_Field_setUint32(subheader->numRows, args->nRows, &errorObj); nitf_Field_setUint32(subheader->numCols, args->nColumns, &errorObj); nitf_Field_setUint32(subheader->numImageBands, args->nBands, &errorObj); nitf_Field_setUint32(subheader->numMultispectralImageBands, args->nMultiBands, &errorObj); nitf_Field_setUint32(subheader->numBlocksPerRow, args->nBlksPerRow, &errorObj); nitf_Field_setUint32(subheader->numBlocksPerCol, args->nBlksPerColumn, &errorObj); nitf_Field_setUint32(subheader->numPixelsPerVertBlock, args->nRowsPerBlk, &errorObj); nitf_Field_setUint32(subheader->numPixelsPerHorizBlock, args->nColumnsPerBlk, &errorObj); nitf_Field_setString(subheader->imageMode, args->mode, &errorObj); nitf_Field_setString(subheader->imageCompression, args->compression, &errorObj); nBands = args->nBands; if (nBands == 0) nBands = args->nMultiBands; bands = (nitf_BandInfo **) NITF_MALLOC(sizeof(nitf_BandInfo *)); if (bands == NULL) { nitf_Error_init(&errorObj, NITF_STRERROR(NITF_ERRNO), NITF_CTXT, NITF_ERR_MEMORY); nitf_Error_print(&errorObj, stderr, "Error setting up band source "); exit(EXIT_FAILURE); } for (i = 0;i < nBands;i++) { bands[i] = nitf_BandInfo_construct(&errorObj); if (bands[i] == NULL) { nitf_Error_print(&errorObj, stderr, "Error setting up band source "); exit(EXIT_FAILURE); } if (!nitf_BandInfo_init(bands[i], "M", /* The band representation, Nth band */ " ", /* The band subcategory */ "N", /* The band filter condition */ " ", /* The band standard image filter code */ 0, /* The number of look-up tables */ 0, /* The number of entries/LUT */ NULL, /* The look-up tables */ &errorObj)) { nitf_Error_print(&errorObj, stderr, "Error setting up band source "); exit(EXIT_FAILURE); } } if (!nitf_ImageSubheader_setPixelInformation(subheader, args->pixelType, /* Pixel value type */ args->nBits, /* Number of bits/pixel*/ args->nBitsActual, /* Actual number of bits/pixel */ args->justify, /* Pixel justification */ "MONO", /* Image representation */ "SAR", /* Image category */ nBands, /* Number of bands */ bands, /* Band information object list */ &errorObj )) { nitf_Error_print(&errorObj, stderr, "Error setting up band source "); exit(EXIT_FAILURE); } return; }
void set(nitf::Uint32 data) throw(nitf::NITFException) { NITF_BOOL x = nitf_Field_setUint32(getNativeOrThrow(), data, &error); if (!x) throw nitf::NITFException(&error); }
void set(nitf::Uint16 data) { if (!nitf_Field_setUint32(getNativeOrThrow(), nitf::Uint32(data), &error)) throw nitf::NITFException(&error); }
int main(int argc, char *argv[]) { nitf_FileHeader *fhdr; /* File header supplying fields */ nitf_ImageSubheader *subhdr; /* Subheader supplying fields */ nitf_Uint32 valueU32Before; /* Value buffer */ nitf_Uint32 valueU32After; /* Value buffer */ nitf_Uint64 valueU64Before; /* Value buffer */ nitf_Uint64 valueU64After; /* Value buffer */ char *valueStrBefore; /* Value buffer */ /* Value buffer */ static char valueStrAfter[STR_LEN + 2]; nitf_Uint32 valueStrLen; /* Value buffer */ static nitf_Error errorObj; /* Error object for messages */ nitf_Error *error; /* Pointer to the error object */ error = &errorObj; fhdr = nitf_FileHeader_construct(error); if (fhdr == NULL) { nitf_Error_print(error, stdout, "Error creating image subheader"); exit(EXIT_FAILURE); } subhdr = nitf_ImageSubheader_construct(error); if (subhdr == NULL) { nitf_Error_print(error, stdout, "Error creating image subheader"); exit(EXIT_FAILURE); } /* Set some fields (should work) */ valueU32Before = 12345; if (nitf_Field_setUint32(subhdr->NITF_XBANDS, valueU32Before, error)) fprintf(stdout, "Set of XBANDS via nitf_Field_setUint32 worked as expected\n"); else nitf_Error_print(error, stdout, "Unexpected error setting XBANDS via nitf_Field_setUint32"); nitf_Field_get(subhdr->NITF_XBANDS, (NITF_DATA *) & valueU32After, NITF_CONV_UINT, NITF_INT32_SZ, error); fprintf(stdout, "Set of XBANDS via nitf_Field_setUint32 original %d readback %d\n", valueU32Before, valueU32After); valueU32Before = 1234; if (nitf_Field_setUint32(subhdr->NITF_COMRAT, valueU32Before, error)) fprintf(stdout, "Set of COMRAT via nitf_Field_setUint32 worked as expected\n"); else nitf_Error_print(error, stdout, "Unexpected error setting COMRAT via nitf_Field_setUint32"); nitf_Field_get(subhdr->NITF_COMRAT, (NITF_DATA *) & valueU32After, NITF_CONV_UINT, NITF_INT32_SZ, error); fprintf(stdout, "Set of COMRAT via nitf_Field_setUint32 original %d readback %d\n", valueU32Before, valueU32After); valueU64Before = 11234567890ll; if (nitf_Field_setUint64(fhdr->NITF_FL, valueU64Before, error)) fprintf(stdout, "Set of FL via nitf_Field_setUint64 worked as expected\n"); else nitf_Error_print(error, stdout, "Unexpected error setting FL via nitf_Field_setUint64"); nitf_Field_get(fhdr->NITF_FL, (NITF_DATA *) & valueU64After, NITF_CONV_UINT, NITF_INT64_SZ, error); fprintf(stdout, "Set of FL via nitf_Field_setUint64 original %llu readback %llu\n", valueU64Before, valueU64After); valueStrBefore = "TestStr"; if (nitf_Field_setString(subhdr->NITF_IID2, valueStrBefore, error)) fprintf(stdout, "Set of IID2 via nitf_Field_setString worked as expected\n"); else nitf_Error_print(error, stdout, "Unexpected error setting IID2 via nitf_Field_setString"); nitf_Field_get(subhdr->NITF_IID2, (NITF_DATA *) valueStrAfter, NITF_CONV_STRING, STR_LEN, error); fprintf(stdout, "Set of IID2 via nitf_Field_setString original %s readback %s\n", valueStrBefore, valueStrAfter); valueStrBefore = "1234"; if (nitf_Field_setString(subhdr->NITF_NCOLS, valueStrBefore, error)) fprintf(stdout, "Set of NCOLS via nitf_Field_setString worked as expected\n"); else nitf_Error_print(error, stdout, "Unexpected error setting NCOLS via nitf_Field_setString"); nitf_Field_get(subhdr->NITF_NCOLS, (NITF_DATA *) valueStrAfter, NITF_CONV_STRING, STR_LEN, error); fprintf(stdout, "Set of NCOLS via nitf_Field_setString original %s readback %s\n", valueStrBefore, valueStrAfter); /* Set some fields (should fail) */ valueU32Before = 123; if (nitf_Field_setUint32(fhdr->NITF_FBKGC, valueU32Before, error)) fprintf(stdout, "Set of FBKGC via nitf_Field_setUnit32 worked expected error\n"); else nitf_Error_print(error, stdout, "Expected error setting FBKGC via nitf_Field_setUint32"); valueStrBefore = "123"; if (nitf_Field_setString(fhdr->NITF_FBKGC, valueStrBefore, error)) fprintf(stdout, "Set of FBKGC via nitf_Field_setString worked expected error\n"); else nitf_Error_print(error, stdout, "Expected error setting FBKGC via nitf_Field_setString"); valueStrBefore = "12g"; if (nitf_Field_setString(subhdr->NITF_NCOLS, valueStrBefore, error)) fprintf(stdout, "Set of NCOLS via nitf_Field_setString worked expected error\n"); else nitf_Error_print(error, stdout, "Expected error setting NCOLS via nitf_Field_setString"); valueU32Before = 3; if (nitf_Field_setUint32(subhdr->NITF_NBANDS, valueU32Before, error)) fprintf(stdout, "Set of NBANDS via nitf_Field_setUint32 worked expected error\n"); else nitf_Error_print(error, stdout, "Expected error setting NBANDS via nitf_Field_setUint32"); return 0; }