예제 #1
0
NITFPRIV(NITF_BOOL) FileSource_contigRead(FileSourceImpl * fileSource,
        char *buf,
        nitf_Off size, nitf_Error * error)
{
    if (!NITF_IO_SUCCESS(nitf_IOInterface_read(fileSource->io, buf, size,
                                               error)))
        return NITF_FAILURE;
    fileSource->mark += size;
    return NITF_SUCCESS;
}
예제 #2
0
NITFPRIV(NITF_BOOL) IOSource_contigRead(IOSourceImpl * source,
                                        char *buf,
                                        nitf_Off size,
                                        nitf_Error * error)
{
    if (!NITF_IO_SUCCESS(nitf_IOInterface_read(source->io,
                                               buf,
                                               (size_t)size,
                                               error)))
        return NITF_FAILURE;
    source->mark += size;
    return NITF_SUCCESS;

}
예제 #3
0
/*
 *  The idea here is we will speed it up by creating a temporary buffer
 *  for reading from the io interface.  Even with the allocation, this should
 *  be much faster than seeking every time.
 *
 *  The basic idea is that we allocate the temporary buffer to the request
 *  size * the skip factor.  It should be noted that the tradeoff here is that,
 *  for very large read values, this may be really undesirable, especially for
 *  large skip factors.
 *
 *  If this proves to be a problem, I will revert it back to a seek/read paradigm
 *  -DP
 */
NITFPRIV(NITF_BOOL) IOSource_offsetRead(IOSourceImpl * source,
        void* buf,
        nitf_Off size, nitf_Error * error)
{

    /* we do not multiply the pixelSkip by numBytesPerPixel, b/c this
     * read method takes in size as number of bytes, not number of pixels */

    /* TODO - this *could* be smaller, but this should be ok for now */
    nitf_Off tsize = size * (source->pixelSkip + 1);

    nitf_Uint8* tbuf;
    nitf_Uint8* bufPtr = (nitf_Uint8*)buf;
    nitf_Off lmark = 0;
    int i = 0;
    int j = 0;
    if (tsize + source->mark > source->size)
        tsize = source->size - source->mark;

    tbuf = (nitf_Uint8 *) NITF_MALLOC((size_t)tsize);
    if (!tbuf)
    {
        nitf_Error_init(error,
                        NITF_STRERROR(NITF_ERRNO),
                        NITF_CTXT, NITF_ERR_MEMORY);
        return NITF_FAILURE;
    }

    if (!nitf_IOInterface_read(source->io, tbuf, (size_t)tsize, error))
    {
        NITF_FREE(tbuf);
        return NITF_FAILURE;
    }
    /*  Downsize for buf */
    while (i < size)
    {
        for (j = 0; j < source->numBytesPerPixel; ++j, ++i, ++lmark)
        {
            bufPtr[i] = tbuf[lmark];
        }
        lmark += (source->pixelSkip * source->numBytesPerPixel);
    }
    source->mark += lmark;
    NITF_FREE(tbuf);
    return NITF_SUCCESS;
}
예제 #4
0
파일: TREUtils.c 프로젝트: aivaras16/nitro
NITFAPI(NITF_BOOL) nitf_TREUtils_readField(nitf_IOInterface* io,
                                           char *field,
                                           int length, nitf_Error * error)
{
    NITF_BOOL status;

    /* Make sure the field is nulled out  */
    memset(field, 0, length);

    /* Read from the IO handle */
    status = nitf_IOInterface_read(io, field, length, error);
    if (!status)
    {
        nitf_Error_init(error,
                "Unable to read from IO object",
                NITF_CTXT, NITF_ERR_READING_FROM_FILE);
    }
    return status;
}
예제 #5
0
/*
 *  The idea here is we will speed it up by creating a temporary buffer
 *  for reading from the io handle.  Even with the allocation, this should
 *  be much faster than seeking every time.
 *
 *  The basic idea is that we allocate the temporary buffer to the request
 *  size * the skip factor.  It should be noted that the tradeoff here is that,
 *  for very large read values, this may be really undesirable, especially for
 *  large skip factors.
 *
 *  If this proves to be a problem, I will revert it back to a seek/read paradigm
 *  -DP
 */
NITFPRIV(NITF_BOOL) FileSource_offsetRead(FileSourceImpl * fileSource,
        char *buf,
        nitf_Off size, nitf_Error * error)
{

    nitf_Off tsize = size * (fileSource->byteSkip + 1);

    char *tbuf;
    nitf_Off lmark = 0;
    int i = 0;
    if (tsize + fileSource->mark > fileSource->size)
        tsize = fileSource->size - fileSource->mark;

    tbuf = (char *) NITF_MALLOC(tsize);
    if (!tbuf)
    {
        nitf_Error_init(error,
                        NITF_STRERROR(NITF_ERRNO),
                        NITF_CTXT, NITF_ERR_MEMORY);
        return NITF_FAILURE;
    }

    if (!nitf_IOInterface_read(fileSource->io, tbuf, tsize, error))
    {
        NITF_FREE(tbuf);
        return NITF_FAILURE;
    }
    /*  Downsize for buf */
    while (i < size)
    {
        buf[i++] = *(tbuf + lmark++);
        lmark += (fileSource->byteSkip);
    }
    fileSource->mark += lmark;
    NITF_FREE(tbuf);
    return NITF_SUCCESS;
}