GTIF* GTIFNew(void *tif) { TIFFMethod default_methods; _GTIFSetDefaultTIFF( &default_methods ); return GTIFNewWithMethods( tif, &default_methods ); }
GTIF* GTIFNew(void *tif) { GTIF* gt=(GTIF*)0; int count,bufcount,index; GeoKey *keyptr; pinfo_t *data; KeyEntry *entptr; KeyHeader *header; gt = (GTIF*)_GTIFcalloc( sizeof(GTIF)); if (!gt) goto failure; /* install TIFF file and I/O methods */ gt->gt_tif = (tiff_t *)tif; _GTIFSetDefaultTIFF(>->gt_methods); /* since this is an array, GTIF will allocate the memory */ if (!(gt->gt_methods.get)(tif, GTIFF_GEOKEYDIRECTORY, >->gt_nshorts, &data )) { /* No ProjectionInfo, create a blank one */ data=(pinfo_t*)_GTIFcalloc((4+MAX_VALUES)*sizeof(pinfo_t)); if (!data) goto failure; header = (KeyHeader *)data; header->hdr_version = GvCurrentVersion; header->hdr_rev_major = GvCurrentRevision; header->hdr_rev_minor = GvCurrentMinorRev; gt->gt_nshorts=sizeof(KeyHeader)/sizeof(pinfo_t); } gt->gt_short = data; header = (KeyHeader *)data; if (header->hdr_version > GvCurrentVersion) goto failure; if (header->hdr_rev_major > GvCurrentRevision) { /* issue warning */ } /* If we got here, then the geokey can be parsed */ count = header->hdr_num_keys; gt->gt_num_keys = count; gt->gt_version = header->hdr_version; gt->gt_rev_major = header->hdr_rev_major; gt->gt_rev_minor = header->hdr_rev_minor; bufcount = count+MAX_KEYS; /* allow for expansion */ /* Get the PARAMS Tags, if any */ if (!(gt->gt_methods.get)(tif, GTIFF_DOUBLEPARAMS, >->gt_ndoubles, >->gt_double )) { gt->gt_double=(double*)_GTIFcalloc(MAX_VALUES*sizeof(double)); if (!gt->gt_double) goto failure; } if (!(gt->gt_methods.get)(tif, GTIFF_ASCIIPARAMS, >->gt_nascii, >->gt_ascii )) { gt->gt_ascii = (char*)_GTIFcalloc(MAX_VALUES*sizeof(char)); if (!gt->gt_ascii) goto failure; } else gt->gt_nascii--; /* last NULL doesn't count; "|" used for delimiter */ /* allocate space for GeoKey array and its index */ gt->gt_keys = (GeoKey *)_GTIFcalloc( sizeof(GeoKey)*bufcount); if (!gt->gt_keys) goto failure; gt->gt_keyindex = (int *)_GTIFcalloc( sizeof(int)*(MAX_KEYINDEX+1)); if (!gt->gt_keyindex) goto failure; /* Loop to get all GeoKeys */ entptr = ((KeyEntry *)data) + 1; keyptr = gt->gt_keys; gt->gt_keymin = MAX_KEYINDEX; gt->gt_keymax = 0; for (index=1; index<=count; index++,entptr++) { if (!ReadKey(gt, entptr, ++keyptr)) goto failure; /* Set up the index (start at 1, since 0=unset) */ gt->gt_keyindex[entptr->ent_key] = index; } return gt; failure: /* Notify of error */ if (gt) free(gt); return (GTIF *)0; }