示例#1
0
/*
 * 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);
}
示例#2
0
int main(int argc, char **argv)
{
    nitf_Reader* reader;                /* The reader object */
    nitf_Writer* writer;                /* The writer object */
    nitf_Record* record;                /* a record object */
    nitf_Record* record2;
    nitf_ListIterator iter;             /* current pos iterator */
    nitf_ListIterator end;              /* end of list iterator */
    nitf_ImageSegment* segment;         /* the image segment */

    NITF_BOOL success;                  /* status bool */

    nitf_IOHandle input_io;             /* input IOHandle */
    nitf_IOHandle output_io;            /* output IOHandle */
    nitf_Error error;                   /* error object */

    /*  Check argv and make sure we are happy  */
    if (argc != 3)
    {
        printf("Usage: %s <input-file> <output-file> \n", argv[0]);
        exit(EXIT_FAILURE);
    }

    input_io = nitf_IOHandle_create(argv[1],
                                    NITF_ACCESS_READONLY,
                                    NITF_OPEN_EXISTING, &error);
    if ( NITF_INVALID_HANDLE(input_io))
    {
        goto CATCH_ERROR;
    }

    output_io = nitf_IOHandle_create(argv[2],
                                     NITF_ACCESS_WRITEONLY,
                                     NITF_CREATE | NITF_TRUNCATE,
                                     &error);

    if ( NITF_INVALID_HANDLE(output_io))
    {
        goto CATCH_ERROR;
    }

    reader = nitf_Reader_construct(&error);
    if (!reader)
    {
        goto CATCH_ERROR;
    }

    writer = nitf_Writer_construct(&error);
    if (!writer)
    {
        goto CATCH_ERROR;
    }

    record = nitf_Record_construct(&error);
    if (!record)
    {
        goto CATCH_ERROR;
    }

    assert(nitf_Reader_read(reader, input_io, record, &error));
    showFileHeader(record->header);

    /*  Write to the file  */
    success = nitf_Writer_writeHeader(writer, record->header, output_io, &error);
    if (!success) goto CATCH_ERROR;


    /*  ------ IMAGES ------  */
    iter = nitf_List_begin(record->images);
    end  = nitf_List_end(record->images);
    while (nitf_ListIterator_notEqualTo(&iter, &end))
    {
        /*  Cast it to an imageSegment...  */
        segment = (nitf_ImageSegment*)nitf_ListIterator_get(&iter);

        /* write the image subheader */
        if (!nitf_Writer_writeImageSubheader(writer,
                                             segment->subheader,
                                             record->header->NITF_FVER->raw,
                                             output_io,
                                             &error))
        {
            goto CATCH_ERROR;
        }

        /* Now, write the image */
        if (!writeImage(segment, input_io, output_io))
        {
            goto CATCH_ERROR;
        }

        nitf_ListIterator_increment(&iter);
    }

    nitf_IOHandle_close(input_io);
    nitf_IOHandle_close(output_io);
    nitf_Record_destruct(&record);
    nitf_Writer_destruct(&writer);

    /*  Open the file we just wrote to, and dump it to screen */
    input_io = nitf_IOHandle_create(argv[2],
                                    NITF_ACCESS_READONLY,
                                    NITF_OPEN_EXISTING,
                                    &error);
    if (NITF_INVALID_HANDLE(input_io))
    {
        goto CATCH_ERROR;
    }

    record2 = nitf_Record_construct(&error);
    if (!record2)
    {
        goto CATCH_ERROR;
    }

    assert(nitf_Reader_readHeader(reader, input_io, record2, &error));
    showFileHeader(record2->header);

    nitf_IOHandle_close(input_io);
    nitf_Record_destruct(&record2);
    nitf_Reader_destruct(&reader);

    return 0;

CATCH_ERROR:
    if (input_io) nitf_IOHandle_close(input_io);
    if (output_io) nitf_IOHandle_close(output_io);
    if (record2) nitf_Record_destruct(&record2);
    if (reader) nitf_Reader_destruct(&reader);
    if (record) nitf_Record_destruct(&record);
    if (writer) nitf_Writer_destruct(&writer);
    nitf_Error_print(&error, stdout, "Exiting...");
    exit(EXIT_FAILURE);
}