Ejemplo n.º 1
0
/*
 * Open a TIFF file for read/writing.
 */
TIFF* VSI_TIFFOpen(const char* name, const char* mode,
                   VSILFILE* fp)
{
    int           i, a_out;
    char          access[32];
    TIFF          *tif;

    a_out = 0;
    access[0] = '\0';
    for( i = 0; mode[i] != '\0'; i++ )
    {
        if( mode[i] == 'r'
            || mode[i] == 'w'
            || mode[i] == '+'
            || mode[i] == 'a' )
        {
            access[a_out++] = mode[i];
            access[a_out] = '\0';
        }
    }

    strcat( access, "b" );

    VSIFSeekL(fp, 0, SEEK_SET);
    tif = XTIFFClientOpen(name, mode,
                          (thandle_t) fp,
                          _tiffReadProc, _tiffWriteProc,
                          _tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
                          _tiffMapProc, _tiffUnmapProc);

    return tif;
}
Ejemplo n.º 2
0
/*
 * Open a TIFF file for read/writing.
 */
TIFF* VSI_TIFFOpen(const char* name, const char* mode,
                   VSILFILE* fpL)
{
    int           i, a_out;
    char          access[32];
    TIFF          *tif;
    int           bAllocBuffer = FALSE;

    a_out = 0;
    access[0] = '\0';
    for( i = 0; mode[i] != '\0'; i++ )
    {
        if( mode[i] == 'r'
            || mode[i] == 'w'
            || mode[i] == '+'
            || mode[i] == 'a' )
        {
            access[a_out++] = mode[i];
            access[a_out] = '\0';
        }
        if( mode[i] == 'w'
            || mode[i] == '+'
            || mode[i] == 'a' )
            bAllocBuffer = TRUE;
    }

    // No need to buffer on /vsimem/
    if( STARTS_WITH(name, "/vsimem/") )
        bAllocBuffer = FALSE;

    strcat( access, "b" );

    if( VSIFSeekL(fpL, 0, SEEK_SET) < 0 )
        return NULL;

    GDALTiffHandle* psGTH = (GDALTiffHandle*) CPLMalloc(sizeof(GDALTiffHandle));
    psGTH->fpL = fpL;
    psGTH->nExpectedPos = 0;
    psGTH->bAtEndOfFile = FALSE;
    psGTH->abyWriteBuffer = (bAllocBuffer) ? (GByte*)VSIMalloc(BUFFER_SIZE) : NULL;
    psGTH->nWriteBufferSize = 0;

    tif = XTIFFClientOpen(name, mode,
                          (thandle_t) psGTH,
                          _tiffReadProc, _tiffWriteProc,
                          _tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
                          _tiffMapProc, _tiffUnmapProc);
    if( tif == NULL )
        CPLFree(psGTH);

    return tif;
}
Ejemplo n.º 3
0
/*
 * Open a TIFF file for read/writing.
 */
TIFF* VSI_TIFFOpen(const char* name, const char* mode)
{
    static const char module[] = "TIFFOpen";
    int           i, a_out;
    char          access[32];
    VSILFILE      *fp;
    TIFF          *tif;

    a_out = 0;
    access[0] = '\0';
    for( i = 0; mode[i] != '\0'; i++ )
    {
        if( mode[i] == 'r'
            || mode[i] == 'w'
            || mode[i] == '+'
            || mode[i] == 'a' )
        {
            access[a_out++] = mode[i];
            access[a_out] = '\0';
        }
    }

    strcat( access, "b" );
                    
    fp = VSIFOpenL( name, access );
    if (fp == NULL) {
        if( errno >= 0 )
            TIFFError(module,"%s: %s", name, VSIStrerror( errno ) );
        else
            TIFFError(module, "%s: Cannot open", name);
        return ((TIFF *)0);
    }

    tif = XTIFFClientOpen(name, mode,
                          (thandle_t) fp,
                          _tiffReadProc, _tiffWriteProc,
                          _tiffSeekProc, _tiffCloseProc, _tiffSizeProc,
                          _tiffMapProc, _tiffUnmapProc);

    if( tif == NULL )
        VSIFCloseL( fp );
        
    return tif;
}
Ejemplo n.º 4
0
bool	FetchTIFFCornersWithJP2K(const char * inFileName, double corners[8], int& post_pos)
{
	jas_stream_t *inStream;
	jas_image_t *image;

	if(jas_init() != 0 )
	{
		//If it failed then return error
		return -1;
	}

		//If the data stream cannot be created
	if((inStream = jas_stream_fopen(inFileName,"rb"))==false)
	{
		return false;
	}

	//Get the format ID
	int formatId;

	//If there are any errors in getting the format
	if((formatId = jas_image_getfmt(inStream)) < 0)
	{
		//It is an invalid format
		return false;
	}

	//If the image cannot be decoded
	if((image = jas_image_decode(inStream, formatId, 0)) == false)
	{
		//Return an error
		return false;
	}
	
	//If it turns out the .jp2 never had any geological data exit
	if(image->aux_buf.size == 0)
	{
		return false;
	}
	
	
	#if DUMP_GTIF
	FILE * foo = fopen("temp.tiff","wb");
	if(foo)
	{
		fwrite(image->aux_buf.buf, 1, image->aux_buf.size, foo);
		fclose(foo);
	}
	#endif
	
	//Create the handle to be used in XTIFFClientOpen
	MemJASGeoFile jasHandle(&image->aux_buf);
	//Create a TIFF handle
	TIFF * tif = XTIFFClientOpen(inFileName,"r",&jasHandle,MemJASGeoRead, MemJASGeoWrite,
	    MemJASGeoSeek, MemJASGeoClose,
	    MemJASGeoSize,
 	    MemJASGeoMapFile, MemJASGeoUnmapFile);

	int postType = dem_want_Area;
	//Pass in our TIF handle, post type, width, and height
	if(FetchTIFFCornersWithTIFF(tif,corners,postType,(image->brx_-image->tlx_),(image->bry_-image->tly_))==false)
	{
		return false;
	}
	//Shut downthe stream
	jas_stream_close(inStream);
	
	//Unintialize jasper
	jas_cleanup();
	//It all worked!
	return true;
}