--- ./bin/Makefile.in Tue Jan 4 10:57:58 2000 +++ ../libgeotiff-1.1.4/./bin/Makefile.in Fri Nov 15 13:15:43 2002 @@ -23,7 +23,7 @@ IPATH = -I. -I${GEOTIFFDIR} @TIFF_INC@ @ZIP_INC@ # -COPTS = @CFLAGS@ +COPTS = @CFLAGS@ @LDFLAGS@ $(MIPS_ABI) CFLAGS = ${COPTS} ${IPATH} # SRCS = \ @@ -53,4 +53,3 @@ clean: rm -f ${ALL} ${OBJS} core a.out newgeo.tif - --- ./Makefile.in Tue Dec 12 14:03:19 2000 +++ ../libgeotiff-1.1.4/./Makefile.in Fri Nov 15 13:15:40 2002 @@ -16,7 +16,6 @@ RANLIB = @RANLIB@ INSTALL = @INSTALL@ RM = rm -f -MAKE = make prefix = @prefix@ exec_prefix = @exec_prefix@ bindir = @bindir@ @@ -171,7 +170,7 @@ ${CC} -c ${CFLAGS} ${SRCDIR}/csv/$*.c -o ${SRCDIR}/csv/$*.o clean: - rm -f ${TARGETS} ${OBJS} ${XTIFFINC} core a.out + rm -f ${TARGETS} ${OBJS} ${XTIFFINC} core a.out libgeotiff.so so_locations dist-clean: clean (cd bin; $(MAKE) clean) --- ./README Thu Dec 28 16:52:40 2000 +++ ../libgeotiff-1.1.4/./README Fri Nov 15 13:15:43 2002 @@ -6,7 +6,7 @@ of GeoTIFF keys in new files. For more information about GeoTIFF specifications, projection codes and use, see the WWW web page at: - http://www.remotesensing.com/geotiff/geotiff.html + http://www.remotesensing.org/geotiff/geotiff.html or at: @@ -36,6 +36,14 @@ should use the "install-private" make target of libtiff instead of "install" to install some private include files required by libgeotiff. +PLEASE NOTE: Use of libgeotiff with a version of libtiff (as a shared +library for instance) other than what it was compiled for is likely to +result in crashes as libgeotiff depends on knowledge of the size and offsets +into libtiff data structures that do change from time to time. In particular +use of a libgeotiff compiled with libtiff 3.5.x include files will not +work properly with libtiff 3.4.x. + + Building LIBGEOTIFF: -------------------- @@ -88,7 +96,8 @@ o If you want to build in support for the PROJ.4 library, so that listgeo can report corner coordinates in lat/long, it may be necessary to specify the directory containing the libproj include files, and library. - (PROJ.4 can also be disabled by passing --without-proj) + (PROJ.4 can also be disabled by passing --without-proj). PROJ.4 info + can be found at http://www.remotesensing.org/proj . % rm config.status % ./configure --with-proj=/contrib/proj-4.4.1 --- ./geo_print.c Mon May 3 23:14:35 1999 +++ ../libgeotiff-1.1.4/./geo_print.c Fri Nov 15 13:16:36 2002 @@ -18,6 +18,9 @@ * 29 Sep, 1995 NDR Fixed matrix printing. * * $Log: geo_print.c,v $ + * Revision 1.4 2002/05/31 14:27:26 warmerda + * added escaping in metadata for string key values + * * Revision 1.3 1999/05/04 03:14:35 warmerda * avoid warnings * @@ -53,7 +56,6 @@ static void DefaultRead(char *string, void *aux); static int ReadKey(GTIF *gt, GTIFReadMethod scan, void *aux); static int ReadTag(GTIF *gt,GTIFReadMethod scan,void *aux); -static char message[1024]; /* * Print off the directory info, using whatever method is specified @@ -69,6 +71,7 @@ int i; int numkeys = gtif->gt_num_keys; GeoKey *key = gtif->gt_keys; + char message[1024]; if (!print) print = (GTIFPrintMethod) &DefaultPrint; if (!aux) aux=stdout; @@ -113,6 +116,7 @@ { int i,j; double *data=dptr; + char message[1024]; print(" ",aux); print(GTIFTagName(tag),aux); @@ -140,7 +144,7 @@ int vals_now,i; pinfo_t *sptr; double *dptr; - + char message[40]; print(" ",aux); print(GTIFKeyName(keyid),aux); @@ -156,12 +160,45 @@ switch (key->gk_type) { case TYPE_ASCII: - print("\"",aux); - _GTIFmemcpy(message,data,count); - message[count-1]='\0'; - print(message,aux); - print("\"\n",aux); - break; + { + int in_char, out_char; + + print("\"",aux); + + in_char = 0; + out_char = 0; + while( in_char < count-1 ) + { + char ch = ((char *) data)[in_char++]; + + if( ch == '\n' ) + { + message[out_char++] = '\\'; + message[out_char++] = 'n'; + } + else if( ch == '\\' ) + { + message[out_char++] = '\\'; + message[out_char++] = '\\'; + } + else + message[out_char++] = ch; + + /* flush message if buffer full */ + if( out_char == sizeof(message)-3 ) + { + message[out_char] = '\0'; + print(message,aux); + out_char = 0; + } + } + + message[out_char]='\0'; + print(message,aux); + + print("\"\n",aux); + } + break; case TYPE_DOUBLE: for (dptr = (double *)data; count > 0; count-= vals_now) @@ -226,6 +263,7 @@ int GTIFImport(GTIF *gtif, GTIFReadMethod scan,void *aux) { int status; + char message[1024]; if (!scan) scan = (GTIFReadMethod) &DefaultRead; if (!aux) aux=stdin; @@ -252,8 +290,8 @@ static int StringError(char *string) { - fprintf(stderr,"Parsing Error at \'%s\'\n",string); - return -1; + fprintf(stderr,"Parsing Error at \'%s\'\n",string); + return -1; } #define SKIPWHITE(vptr) \ @@ -268,6 +306,7 @@ char tagname[100]; double data[100],*dptr=data; int count,nrows,ncols,num; + char message[1024]; scan(message,aux); if (!strncmp(message,FMT_TAGEND,8)) return 0; @@ -310,9 +349,9 @@ char type[20]; double data[100]; double *dptr; - char *cdata = (char *)data; char *vptr; int num; + char message[2048]; scan(message,aux); if (!strncmp(message,FMT_KEYEND,8)) return 0; @@ -342,12 +381,44 @@ switch (ktype) { case TYPE_ASCII: - FINDCHAR(vptr,'"'); - if (!*vptr) return StringError(message); - _GTIFmemcpy(cdata,vptr+1,count); - cdata[count-1]='\0'; - GTIFKeySet(gt,key,ktype,count,cdata); - break; + { + char *cdata; + int out_char = 0; + + FINDCHAR(vptr,'"'); + if (!*vptr) return StringError(message); + + cdata = (char *) _GTIFcalloc( count+1 ); + + vptr++; + while( out_char < count-1 ) + { + if( *vptr == '\0' ) + break; + + else if( vptr[0] == '\\' && vptr[1] == 'n' ) + { + cdata[out_char++] = '\n'; + vptr += 2; + } + else if( vptr[0] == '\\' && vptr[1] == '\\' ) + { + cdata[out_char++] = '\\'; + vptr += 2; + } + else + cdata[out_char++] = *(vptr++); + } + + if( out_char < count-1 ) return StringError(message); + if( *vptr != '"' ) return StringError(message); + + cdata[count-1] = '\0'; + GTIFKeySet(gt,key,ktype,count,cdata); + + _GTIFFree( cdata ); + } + break; case TYPE_DOUBLE: outcount = count; --- ./cpl_serv.c Fri Sep 29 23:35:05 2000 +++ ../libgeotiff-1.1.4/./cpl_serv.c Fri Nov 15 13:18:41 2002 @@ -23,6 +23,15 @@ * cpl_serv.c: Various Common Portability Library derived convenience functions * * $Log: cpl_serv.c,v $ + * Revision 1.8 2001/07/09 20:14:37 warmerda + * Another problem freeing pszRLBuffer and not setting to NULL. + * + * Revision 1.7 2001/04/17 13:40:43 warmerda + * fixed freeing of line buffer in CPLReadLine(), init ptr to NULL + * + * Revision 1.6 2001/03/05 04:56:17 warmerda + * make it possible to deallocate CPLReadLine buffer + * * Revision 1.5 2000/09/30 03:35:05 warmerda * Fixed CPLReadLine() to use avoid calling VSIRealloc() on a NULL pointer. * @@ -165,6 +174,17 @@ int nLength, nReadSoFar = 0; /* -------------------------------------------------------------------- */ +/* Cleanup case. */ +/* -------------------------------------------------------------------- */ + if( fp == NULL ) + { + CPLFree( pszRLBuffer ); + pszRLBuffer = NULL; + nRLBufferSize = 0; + return NULL; + } + +/* -------------------------------------------------------------------- */ /* Loop reading chunks of the line till we get to the end of */ /* the line. */ /* -------------------------------------------------------------------- */ @@ -193,7 +213,13 @@ /* -------------------------------------------------------------------- */ if( VSIFGets( pszRLBuffer+nReadSoFar, nRLBufferSize-nReadSoFar, fp ) == NULL ) + { + CPLFree( pszRLBuffer ); + pszRLBuffer = NULL; + nRLBufferSize = 0; + return NULL; + } nReadSoFar = strlen(pszRLBuffer); --- ./geotiff_proj4.c Tue Dec 5 14:21:45 2000 +++ ../libgeotiff-1.1.4/./geotiff_proj4.c Fri Nov 15 13:18:15 2002 @@ -29,6 +29,12 @@ ****************************************************************************** * * $Log: geotiff_proj4.c,v $ + * Revision 1.18 2002/07/09 14:47:53 warmerda + * fixed translation of polar stereographic + * + * Revision 1.17 2001/11/23 19:53:56 warmerda + * free PROJ.4 definitions after use + * * Revision 1.16 2000/12/05 19:21:45 warmerda * added cassini support * @@ -239,13 +245,24 @@ /* -------------------------------------------------------------------- */ else if( psDefn->CTProjection == CT_PolarStereographic ) { - sprintf( szProjection+strlen(szProjection), - "+proj=stere +lat_0=%.9f +lon_0=%.9f +k=%.9f +x_0=%.3f +y_0=%.3f ", - psDefn->ProjParm[0], - psDefn->ProjParm[1], - psDefn->ProjParm[4], - dfFalseEasting, - dfFalseNorthing ); + if( psDefn->ProjParm[0] > 0.0 ) + sprintf( szProjection+strlen(szProjection), + "+proj=stere +lat_0=90 +lat_ts=%.9f +lon_0=%.9f " + "+k=%.9f +x_0=%.3f +y_0=%.3f ", + psDefn->ProjParm[0], + psDefn->ProjParm[1], + psDefn->ProjParm[4], + dfFalseEasting, + dfFalseNorthing ); + else + sprintf( szProjection+strlen(szProjection), + "+proj=stere +lat_0=-90 +lat_ts=%.9f +lon_0=%.9f " + "+k=%.9f +x_0=%.3f +y_0=%.3f ", + psDefn->ProjParm[0], + psDefn->ProjParm[1], + psDefn->ProjParm[4], + dfFalseEasting, + dfFalseNorthing ); } /* -------------------------------------------------------------------- */ @@ -584,6 +601,8 @@ padfY[i] = sUV.v; } + pj_free( psPJ ); + return TRUE; } @@ -641,6 +660,8 @@ padfX[i] = sUV.u * RAD_TO_DEG; padfY[i] = sUV.v * RAD_TO_DEG; } + + pj_free( psPJ ); return TRUE; } --- ./geo_trans.c Mon Aug 21 23:32:46 2000 +++ ../libgeotiff-1.1.4/./geo_trans.c Fri Nov 15 13:17:40 2002 @@ -29,6 +29,18 @@ ****************************************************************************** * * $Log: geo_trans.c,v $ + * Revision 1.9 2001/11/28 14:20:30 warmerda + * fixed transform memory leak in GTIFPCSToImage + * + * Revision 1.8 2001/04/06 16:56:22 warmerda + * added support for PCSToImage with matrix + * + * Revision 1.7 2001/03/05 03:25:23 warmerda + * restructure cleanup, and apply to GTIFPCSToImage() + * + * Revision 1.6 2001/03/04 22:37:39 warmerda + * fixed memory leak for fields fetched with gt_methods.get - Alan Gray + * * Revision 1.5 2000/08/22 03:32:46 warmerda * removed GTIFTiepointTranslate code * @@ -54,6 +66,42 @@ #include "geokeys.h" /************************************************************************/ +/* inv_geotransform() */ +/* */ +/* Invert a 6 term geotransform style matrix. */ +/************************************************************************/ + +static int inv_geotransform( double *gt_in, double *gt_out ) + +{ + double det, inv_det; + + /* we assume a 3rd row that is [0 0 1] */ + + /* Compute determinate */ + + det = gt_in[0] * gt_in[4] - gt_in[1] * gt_in[3]; + + if( fabs(det) < 0.000000000000001 ) + return 0; + + inv_det = 1.0 / det; + + /* compute adjoint, and devide by determinate */ + + gt_out[0] = gt_in[4] * inv_det; + gt_out[3] = -gt_in[3] * inv_det; + + gt_out[1] = -gt_in[1] * inv_det; + gt_out[4] = gt_in[0] * inv_det; + + gt_out[2] = ( gt_in[1] * gt_in[5] - gt_in[2] * gt_in[4]) * inv_det; + gt_out[5] = (-gt_in[0] * gt_in[5] + gt_in[2] * gt_in[3]) * inv_det; + + return 1; +} + +/************************************************************************/ /* GTIFTiepointTranslate() */ /************************************************************************/ @@ -75,6 +123,10 @@ /** * Translate a pixel/line coordinate to projection coordinates. * + * At this time this function does not support image to PCS translations for + * tiepoints-only definitions, only pixelscale and transformation matrix + * formulations. + * * @param gtif The handle from GTIFNew() indicating the target file. * @param x A pointer to the double containing the pixel offset on input, * and into which the easting/longitude will be put on completion. @@ -89,12 +141,14 @@ int GTIFImageToPCS( GTIF *gtif, double *x, double *y ) { - double *tiepoints; - int tiepoint_count, count, transform_count; - double *pixel_scale; + int res = FALSE; + int tiepoint_count, count, transform_count; tiff_t *tif=gtif->gt_tif; - double *transform; + double *tiepoints = 0; + double *pixel_scale = 0; + double *transform = 0; + if (!(gtif->gt_methods.get)(tif, GTIFF_TIEPOINTS, &tiepoint_count, &tiepoints )) tiepoint_count = 0; @@ -110,36 +164,53 @@ /* If the pixelscale count is zero, but we have tiepoints use */ /* the tiepoint based approach. */ /* -------------------------------------------------------------------- */ - if( tiepoint_count > 6 && count == 0 ) + if( tiepoint_count > 6 && count == 0 ) { - return GTIFTiepointTranslate( tiepoint_count / 6, - tiepoints, tiepoints + 3, - *x, *y, x, y ); + res = GTIFTiepointTranslate( tiepoint_count / 6, + tiepoints, tiepoints + 3, + *x, *y, x, y ); } - + /* -------------------------------------------------------------------- */ /* If we have a transformation matrix, use it. */ /* -------------------------------------------------------------------- */ - if( transform_count == 16 ) + else if( transform_count == 16 ) { - double x_in = *x, y_in = *y; + double x_in = *x, y_in = *y; *x = x_in * transform[0] + y_in * transform[1] + transform[3]; *y = x_in * transform[4] + y_in * transform[5] + transform[7]; - return TRUE; - } + res = TRUE; + } /* -------------------------------------------------------------------- */ /* For now we require one tie point, and a valid pixel scale. */ /* -------------------------------------------------------------------- */ - if( count < 3 || tiepoint_count < 6 ) - return FALSE; + else if( count < 3 || tiepoint_count < 6 ) + { + res = FALSE; + } + + else + { + *x = (*x - tiepoints[0]) * pixel_scale[0] + tiepoints[3]; + *y = (*y - tiepoints[1]) * (-1 * pixel_scale[1]) + tiepoints[4]; - *x = (*x - tiepoints[0]) * pixel_scale[0] + tiepoints[3]; - *y = (*y - tiepoints[1]) * (-1 * pixel_scale[1]) + tiepoints[4]; + res = TRUE; + } + +/* -------------------------------------------------------------------- */ +/* Cleanup */ +/* -------------------------------------------------------------------- */ + if(tiepoints) + _GTIFFree(tiepoints); + if(pixel_scale) + _GTIFFree(pixel_scale); + if(transform) + _GTIFFree(transform); - return TRUE; + return res; } /************************************************************************/ @@ -146,14 +217,37 @@ /* GTIFPCSToImage() */ /************************************************************************/ +/** + * Translate a projection coordinate to pixel/line coordinates. + * + * At this time this function does not support PCS to image translations for + * tiepoints-only based definitions, only matrix and pixelscale/tiepoints + * formulations are supposed. + * + * @param gtif The handle from GTIFNew() indicating the target file. + * @param x A pointer to the double containing the pixel offset on input, + * and into which the easting/longitude will be put on completion. + * @param y A pointer to the double containing the line offset on input, + * and into which the northing/latitude will be put on completion. + * + * @return TRUE if the transformation succeeds, or FALSE if it fails. It may + * fail if the file doesn't have properly setup transformation information, + * or it is in a form unsupported by this function. + */ + int GTIFPCSToImage( GTIF *gtif, double *x, double *y ) { - double *tiepoints; - int tiepoint_count, count; - double *pixel_scale; - tiff_t *tif=gtif->gt_tif; + double *tiepoints = NULL; + int tiepoint_count, count, transform_count = 0; + double *pixel_scale = NULL; + double *transform = NULL; + tiff_t *tif=gtif->gt_tif; + int result = FALSE; +/* -------------------------------------------------------------------- */ +/* Fetch tiepoints and pixel scale. */ +/* -------------------------------------------------------------------- */ if (!(gtif->gt_methods.get)(tif, GTIFF_TIEPOINTS, &tiepoint_count, &tiepoints )) tiepoint_count = 0; @@ -161,6 +255,10 @@ if (!(gtif->gt_methods.get)(tif, GTIFF_PIXELSCALE, &count, &pixel_scale )) count = 0; + if (!(gtif->gt_methods.get)(tif, GTIFF_TRANSMATRIX, + &transform_count, &transform )) + transform_count = 0; + /* -------------------------------------------------------------------- */ /* If the pixelscale count is zero, but we have tiepoints use */ /* the tiepoint based approach. */ @@ -167,20 +265,59 @@ /* -------------------------------------------------------------------- */ if( tiepoint_count > 6 && count == 0 ) { - return GTIFTiepointTranslate( tiepoint_count / 6, - tiepoints + 3, tiepoints, - *x, *y, x, y ); + result = GTIFTiepointTranslate( tiepoint_count / 6, + tiepoints + 3, tiepoints, + *x, *y, x, y ); + } + +/* -------------------------------------------------------------------- */ +/* Handle matrix - convert to "geotransform" format, invert and */ +/* apply. */ +/* -------------------------------------------------------------------- */ + else if( transform_count == 16 ) + { + double x_in = *x, y_in = *y; + double gt_in[6], gt_out[6]; + + gt_in[0] = transform[0]; + gt_in[1] = transform[1]; + gt_in[2] = transform[3]; + gt_in[3] = transform[4]; + gt_in[4] = transform[5]; + gt_in[5] = transform[7]; + + if( !inv_geotransform( gt_in, gt_out ) ) + result = FALSE; + else + { + *x = x_in * gt_out[0] + y_in * gt_out[1] + gt_out[2]; + *y = x_in * gt_out[3] + y_in * gt_out[4] + gt_out[5]; + + result = TRUE; + } } - + /* -------------------------------------------------------------------- */ /* For now we require one tie point, and a valid pixel scale. */ /* -------------------------------------------------------------------- */ - if( count < 3 || tiepoint_count < 6 ) - return FALSE; + else if( count >= 3 && tiepoint_count >= 6 ) + { + *x = (*x - tiepoints[3]) / pixel_scale[0] + tiepoints[0]; + *y = (*y - tiepoints[4]) / (-1 * pixel_scale[1]) + tiepoints[1]; - *x = (*x - tiepoints[3]) / pixel_scale[0] + tiepoints[0]; - *y = (*y - tiepoints[4]) / (-1 * pixel_scale[1]) + tiepoints[1]; + result = TRUE; + } + +/* -------------------------------------------------------------------- */ +/* Cleanup. */ +/* -------------------------------------------------------------------- */ + if(tiepoints) + _GTIFFree(tiepoints); + if(pixel_scale) + _GTIFFree(pixel_scale); + if(transform) + _GTIFFree(transform); - return TRUE; + return result; } --- ./configure Tue Dec 12 15:07:06 2000 +++ ../libgeotiff-1.1.4/./configure Fri Nov 15 13:15:40 2002 @@ -948,7 +948,7 @@ LD_SHARED="/bin/true" if test "$LD_SHARED" = "/bin/true" \ - -a -z "`ld -shared conftest2.o -o libconftest.so 2>&1`" ; then + -a -z "`${LD-ld} -shared conftest2.o -o libconftest.so 2>&1`" ; then if test -z "`${CC} conftest1.c libconftest.so -o conftest1 2>&1`"; then LD_LIBRARY_PATH_OLD="$LD_LIBRARY_PATH" LD_LIBRARY_PATH="`pwd`" @@ -955,7 +955,7 @@ export LD_LIBRARY_PATH if test -z "`./conftest1 2>&1`" ; then echo "checking for ld -shared ... yes" - LD_SHARED="ld -shared" + LD_SHARED="${LD-ld} -shared" fi LD_LIBRARY_PATH="$LD_LIBRARY_PATH_OLD" fi