Beispiel #1
0
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);
}
Beispiel #2
0
 void set(const std::string& data) throw(nitf::NITFException)
 {
     const NITF_BOOL x =
             nitf_Field_setString(getNativeOrThrow(), data.c_str(), &error);
     if (!x)
         throw nitf::NITFException(&error);
 }
Beispiel #3
0
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;
}
Beispiel #4
0
 void set(const char * data) throw(nitf::NITFException)
 {
     NITF_BOOL x = nitf_Field_setString(getNativeOrThrow(), (char*)data, &error);
     if (!x)
         throw nitf::NITFException(&error);
 }
Beispiel #5
0
NITFAPI(NITF_BOOL) nitf_TREUtils_fillData(nitf_TRE * tre,
        const nitf_TREDescription* descrip,
        nitf_Error * error)
{
    nitf_TRECursor cursor;

    /* set the description so the cursor can use it */
    ((nitf_TREPrivateData*)tre->priv)->description =
        (nitf_TREDescription*)descrip;

    /* loop over the description, and add blank fields for the
     * "normal" fields... any special case fields (loops, conditions)
     * won't be added here
     */
    cursor = nitf_TRECursor_begin(tre);
    while (!nitf_TRECursor_isDone(&cursor))
    {
        if (nitf_TRECursor_iterate(&cursor, error))
        {
            nitf_Pair* pair = nitf_HashTable_find(
                    ((nitf_TREPrivateData*)tre->priv)->hash, cursor.tag_str);

            if (!pair || !pair->data)
            {
                nitf_Field* field = NULL;
                int fieldLength = cursor.length;

                /* If it is a GOBBLE length, there isn't really a standard
                 * on how long it can be... therefore we'll just throw in
                 * a field of size 1, just to have something...
                 */
                if (fieldLength == NITF_TRE_GOBBLE)
                {
                    fieldLength = 1;
                }

                field = nitf_Field_construct(fieldLength,
                        cursor.desc_ptr->data_type,
                        error);

                /* set the field to be resizable later on */
                if (cursor.length == NITF_TRE_GOBBLE)
                    field->resizable = 1;

                /* special case if BINARY... must set Raw Data */
                if (cursor.desc_ptr->data_type == NITF_BINARY)
                {
                    char* tempBuf = (char *) NITF_MALLOC(fieldLength);
                    if (!tempBuf)
                    {
                        nitf_Field_destruct(&field);
                        nitf_Error_init(error, NITF_STRERROR(NITF_ERRNO),
                                NITF_CTXT, NITF_ERR_MEMORY);
                        goto CATCH_ERROR;
                    }

                    memset(tempBuf, 0, fieldLength);
                    nitf_Field_setRawData(field, (NITF_DATA *) tempBuf,
                            fieldLength, error);
                }
                else if (cursor.desc_ptr->data_type == NITF_BCS_N)
                {
                    /* this will get zero/blank filled by the function */
                    nitf_Field_setString(field, "0", error);
                }
                else
                {
                    /* this will get zero/blank filled by the function */
                    nitf_Field_setString(field, " ", error);
                }

                /* add to hash if there wasn't an entry yet */
                if (!pair)
                {
                    nitf_HashTable_insert(
                            ((nitf_TREPrivateData*)tre->priv)->hash,
                            cursor.tag_str, field, error);
                }
                /* otherwise, just set the data pointer */
                else
                {
                    pair->data = (NITF_DATA *) field;
                }
            }
        }
    }
    nitf_TRECursor_cleanup(&cursor);

    /* no problems */
    /*    return tre->descrip; */
    return NITF_SUCCESS;

  CATCH_ERROR:
    return NITF_FAILURE;
}
Beispiel #6
0
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;

}