#!/usr/local/bin/perl use warnings; use strict; my $img = shift || die "Usage: perl inline.pl [tiff]\n"; my $gtif = 0; if ( ! $gtif ) { die "Couldn't use $img\n" unless use_tiff( $img ); tiff_cleanup(); } else { die "Couldn't use $img\n" unless use_gtif( $img ); gtif_cleanup(); } #--------------------------------------------------------------------------------------------------- use Inline C => Config => LIBS => '-lm -ltiff -L/usr/local/lib -lgeotiff', # LIBS => '-lm -ltiff', # Works with $gtif = 0 INC => '-I/usr/local/include' ; use Inline C => <<'END_OF_C_CODE'; #include #include #include #include "geotiff.h" #include "xtiffio.h" #define DEBUG 1 TIFF *IMAGE; // TIFF image handle GTIF *GEO_IMAGE; // GeoTIFF image handle void check_image(TIFF *image) { // Check that it is of a type that we support - if not throw errors uint16 bps, spp; if ( (TIFFGetField(image, TIFFTAG_BITSPERSAMPLE, &bps) == 0) || (bps != 8) ) throw_error("Either undefined or unsupported number of bits per sample.\n"); if ( (TIFFGetField(image, TIFFTAG_SAMPLESPERPIXEL, &spp) == 0) || (spp != 1) ) throw_error("Either undefined or unsupported number of samples per pixel.\n"); if ( TIFFIsTiled(image) == 0 ) throw_error("Image must be tiled.\n"); } int use_tiff( const char *image_file ) { if ( DEBUG == 1 ) printf( "TIFF file: %s\n", image_file ); // Open the TIFF image if ( (IMAGE = TIFFOpen(image_file, "r")) == NULL ) { throw_error("Could not open incoming image.\n"); } check_image(IMAGE); return 1; } int use_gtif( const char *image_file ) { if ( DEBUG == 1 ) printf( "GTIF file: %s\n", image_file ); // Open the TIFF image if ( (IMAGE = XTIFFOpen(image_file, "r")) == NULL ) { throw_error("Could not open incoming image.\n"); } check_image(IMAGE); // Open the geotiff information handle on image if ( (GEO_IMAGE = GTIFNew(IMAGE)) == NULL ) throw_error("Could not read geotiff data on image.\n"); return 1; } void tiff_cleanup() { TIFFClose(IMAGE); } void gtif_cleanup() { GTIFFree(GEO_IMAGE); XTIFFClose(IMAGE); } void throw_error(char * msg) { fprintf(stderr,msg); exit(42); } END_OF_C_CODE