Esempio n. 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);
}
Esempio n. 2
0
nitf::MemorySource::MemorySource(const void* data,
                                 size_t size,
                                 nitf::Off start,
                                 int numBytesPerPixel,
                                 int pixelSkip) throw(nitf::NITFException)
{
    setNative(nitf_MemorySource_construct(data, size, start, numBytesPerPixel, pixelSkip, &error));
    setManaged(false);
}
Esempio n. 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);
}
Esempio n. 4
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;
}
Esempio n. 5
0
/*
 * 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;
}