Exemple #1
0
NITF_BOOL makeImageSource(imgInfo *img, nitf_Writer *writer, nitf_Error *error)
{
    nitf_ImageSource *source;     /* Image source for image writer */
    nitf_BandSource *bandSource;  /* Current band source */
    int i;

    img->imgWriter = nitf_Writer_newImageWriter(writer, img->index, error);
    source = nitf_ImageSource_construct(error);
    if (source == NULL)
        return(NITF_FAILURE);

    for (i = 0;i < img->nBands;i++)
    {
        bandSource = nitf_MemorySource_construct((char *) (img->buffers[i]),
                     img->imgSize, (nitf_Off) 0, 0, 0, error);
        if (!bandSource)
            return(NITF_FAILURE);

        if (!nitf_ImageSource_addBand(source, bandSource, error))
            return(NITF_FAILURE);
    }

    img->imgSource = source;

    if (!nitf_ImageWriter_attachSource(img->imgWriter, source, error))
        return(NITF_FAILURE);

    nitf_ImageIO_setPadPixel(img->imgWriter->imageBlocker,
                             img->padValue, img->bytes);

    return(NITF_SUCCESS);
}
Exemple #2
0
/*
 * Class:     nitf_ImageSource
 * Method:    addBand
 * Signature: (Lnitf/BandSource;)Z
 */
JNIEXPORT jboolean JNICALL Java_nitf_ImageSource_addBand
    (JNIEnv * env, jobject self, jobject jBandSource)
{
    nitf_ImageSource *source = _GetObj(env, self);
    nitf_BandSource *bandSource;
    nitf_Error error;
    jclass bandSourceClass = (*env)->FindClass(env, "nitf/BandSource");
    jmethodID methodID =
        (*env)->GetMethodID(env, bandSourceClass, "getAddress", "()J");

    bandSource = (nitf_BandSource *) (*env)->CallLongMethod(
            env, jBandSource, methodID);

    if (!bandSource)
    {
        return JNI_FALSE;
    }

    if (!nitf_ImageSource_addBand(source, bandSource, &error))
    {
        _ThrowNITFException(env, error.message);
        return JNI_FALSE;
    }

    /* Now, tell Java not to manage it anymore */
    _ManageObject(env, (jlong)bandSource, JNI_FALSE);

    return JNI_TRUE;
}
Exemple #3
0
nitf_ImageSource *makeImageSource(
    test_nitf_ImageIOConstructArgs *args, char ***data)
{
    nitf_ImageSource *imgSource;  /* The result */
    nitf_Uint32 nBands;           /* Number of bands */
    nitf_Off bandSize;               /* Size of individual bands */
    nitf_Error error;             /* Error object argument */
    nitf_Uint32 i;

    bandSize = (args->nRows) * (args->nColumns) * (NITF_NBPP_TO_BYTES(args->nBits));

    imgSource = nitf_ImageSource_construct(&error);
    if (imgSource == NULL)
    {
        nitf_Error_print(&error, stderr, "Error setting up image source ");
        exit(EXIT_FAILURE);
    }

    nBands = args->nBands;
    if (nBands == 0)
        nBands = args->nMultiBands;

    for (i = 0;i < nBands;i++)
    {
        nitf_DataSource * bandSrc;   /* Current band data source */

        bandSrc = nitf_MemorySource_construct(
                      &(data[i][0][0]), bandSize, 0, 0, 0, &error);
        if (bandSrc == NULL)
        {
            nitf_Error_print(&error, stderr, "Error setting up band source ");
            exit(EXIT_FAILURE);
        }

        if (!nitf_ImageSource_addBand(imgSource, bandSrc, &error))
        {
            nitf_Error_print(&error, stderr, "Error setting up band source ");
            exit(EXIT_FAILURE);
        }

    }
    return(imgSource);
}
Exemple #4
0
nitf_ImageSource *setupBands(int nbands, int imageNum,
                             const char *inRootFile)
{
    nitf_Error error;
    int i;
    nitf_BandSource *bandSource;
    nitf_ImageSource *iSource = nitf_ImageSource_construct(&error);
    if (!iSource)
        goto CATCH_ERROR;
    for (i = 0; i < nbands; i++)
    {
        char *inFile = makeBandName(inRootFile, "img", imageNum, i);

        nitf_IOHandle sourceHandle =
            nitf_IOHandle_create(inFile, NITF_ACCESS_READONLY,
                                 NITF_OPEN_EXISTING, &error);
        if (NITF_INVALID_HANDLE(sourceHandle))
            goto CATCH_ERROR;
 
        freeBandName(&inFile);

        bandSource = nitf_FileSource_construct(sourceHandle,
                                               0, 0 /*gets ignored */ , 0,
                                               &error);
        freeBandName(&inFile);

        if (!bandSource)
        {
            goto CATCH_ERROR;
        }
        if (!nitf_ImageSource_addBand(iSource, bandSource, &error))
        {
            goto CATCH_ERROR;
        }
    }
    return iSource;

CATCH_ERROR:
    nitf_Error_print(&error, stderr, "While constructing image source");
    exit(EXIT_FAILURE);
}
Exemple #5
0
NITF_BOOL writeImage(nitf_ImageSegment* segment, nitf_IOHandle input_io, nitf_IOHandle output_io)
{
    nitf_Error error;
    nitf_Off offset;
    int ret;

    nitf_ImageIO* ioClone;

    nitf_Uint8** buffer;
    nitf_Uint32 nBits, nBands, xBands, nRows, nColumns;
    nitf_SubWindow *subimage;
    size_t subimageSize;
    nitf_Uint32 band;
    nitf_Uint32 *bandList;
    NITF_BOOL success;
    int padded;

    nitf_ImageSource *imgSrc;  /* Image source object */
    nitf_BandSource *bandSrc;   /* Current band source object */


    /* clone the imageIO */
    ioClone = nitf_ImageIO_clone(segment->imageIO, &error);
    if (!ioClone)
    {
        nitf_Error_print(&error, stderr, "Clone failed");
        goto CATCH_ERROR;
    }

    /* get IO offset, and set the offset for the ImageIO */
    offset = nitf_IOHandle_tell(output_io, &error);
    if (!NITF_IO_SUCCESS(offset)) goto CATCH_ERROR;

    if (!nitf_ImageIO_setFileOffset(segment->imageIO, offset, &error))
    {
        goto CATCH_ERROR;
    }

    /*   Read image */

    GET_UINT32(segment->subheader->numBitsPerPixel, &nBits, &error);
    GET_UINT32(segment->subheader->numImageBands, &nBands, &error);
    GET_UINT32(segment->subheader->numMultispectralImageBands, &xBands, &error);
    nBands += xBands;
    GET_UINT32(segment->subheader->numRows, &nRows, &error);
    GET_UINT32(segment->subheader->numCols, &nColumns, &error);
    subimageSize = nRows * nColumns * NITF_NBPP_TO_BYTES(nBits);


    /* Allcoate buffers */
    buffer = (nitf_Uint8 **)malloc(8 * nBands);
    assert(buffer);

    for (band = 0; band < nBands; band++)
    {
        buffer[band] = (nitf_Uint8*)malloc(subimageSize);
        assert(buffer[band]);
    }

    /*  Set-up band array and subimage */

    bandList = (nitf_Uint32 *)malloc(sizeof(nitf_Uint32 *) * nBands);

    subimage = nitf_SubWindow_construct(&error);
    assert(subimage);

    subimage->startCol = 0;
    subimage->startRow = 0;
    subimage->numRows = nRows;
    subimage->numCols = nColumns;

    for (band = 0; band < nBands; band++)
    {
        bandList[band] = band;
    }
    subimage->bandList = bandList;
    subimage->numBands = nBands;

    /*  Read data */

    if (!nitf_ImageIO_read(ioClone,
                           input_io, subimage, buffer, &padded, &error) )
    {
        nitf_Error_print(&error, stderr, "Read failed");
        return(0);
    }
    free(bandList);

    /* Setup for image source */

    imgSrc = nitf_ImageSource_construct(&error);
    if (imgSrc == NULL)
        return(0);
    for (band = 0; band < nBands; band++)
    {
        bandSrc = nitf_MemorySource_construct(buffer[band], (size_t) subimageSize,
                                              (nitf_Off) 0, NITF_NBPP_TO_BYTES(nBits), 0, &error);
        if (bandSrc == NULL)
            return(0);

        if (!nitf_ImageSource_addBand(imgSrc, bandSrc, &error))
            return(0);
    }

    /* Do write */

    ret = doWrite(segment, imgSrc, output_io, ioClone);

    if (ioClone) nitf_ImageIO_destruct(&ioClone);
    nitf_ImageSource_destruct(&imgSrc);

    /* OK return */
    return ret;

CATCH_ERROR:
    if (ioClone) nitf_ImageIO_destruct(&ioClone);
    printf("ERROR processing\n");
    return 0;
}