LCOV - code coverage report
Current view: directory - frmts/gtiff/libgeotiff - geo_tiffp.c (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 45 44 97.8 %
Date: 2012-04-28 Functions: 8 8 100.0 %

       1                 : /**********************************************************************
       2                 :  *
       3                 :  *  geo_tiffp.c  Private TIFF interface module for GEOTIFF
       4                 :  *
       5                 :  *    This module implements the interface between the GEOTIFF
       6                 :  *    tag parser and the TIFF i/o module. The current setup
       7                 :  *    relies on the "libtiff" code, but if you use your own
       8                 :  *    TIFF reader software, you may replace the module implementations
       9                 :  *    here with your own calls. No "libtiff" dependencies occur
      10                 :  *    anywhere else in this code.
      11                 :  *
      12                 :  * copyright (c) 1995   Niles D. Ritter
      13                 :  *
      14                 :  * Permission granted to use this software, so long as this copyright
      15                 :  * notice accompanies any products derived therefrom.
      16                 :  *
      17                 :  **********************************************************************/
      18                 :  
      19                 : #include "geotiff.h"    /* public GTIFF interface */
      20                 : 
      21                 : #include "geo_tiffp.h"  /* Private TIFF interface */
      22                 : #include "geo_keyp.h"   /* Private GTIFF interface */
      23                 : 
      24                 : /* tiff size array global */
      25                 : gsize_t _gtiff_size[] = { 0, 1, 2, 4, 8, 1, 4, 8, 1, 2, 4, 1 };
      26                 : 
      27                 : static int        _GTIFGetField (tiff_t *tif, pinfo_t tag, int *count, void *value );
      28                 : static int        _GTIFSetField (tiff_t *tif, pinfo_t tag, int  count, void *value );
      29                 : static tagtype_t  _GTIFTagType  (tiff_t *tif, pinfo_t tag);
      30                 : 
      31                 : /*
      32                 :  * Set up default TIFF handlers. 
      33                 :  */
      34           11442 : void _GTIFSetDefaultTIFF(TIFFMethod *method)
      35                 : {
      36           11442 :   if (!method) return;
      37                 :   
      38           11442 :   method->get = _GTIFGetField;
      39           11442 :   method->set = _GTIFSetField;
      40           11442 :   method->type = _GTIFTagType;
      41                 : }
      42                 : 
      43           78342 : gdata_t _GTIFcalloc(gsize_t size)
      44                 : {
      45           78342 :     gdata_t data=(gdata_t)_TIFFmalloc((tsize_t)size);
      46           78342 :   if (data) _TIFFmemset((tdata_t)data,0,(tsize_t)size);
      47           78342 :   return data;
      48                 : }
      49                 : 
      50           11598 : gdata_t _GTIFrealloc(gdata_t ptr, gsize_t size)
      51                 : {
      52           11598 :     return( _TIFFrealloc((tdata_t)ptr, (tsize_t) size) );
      53                 : }
      54                 : 
      55           45872 : void _GTIFmemcpy(gdata_t out,gdata_t in,gsize_t size)
      56                 : {
      57           45872 :   _TIFFmemcpy((tdata_t)out,(tdata_t)in,(tsize_t)size);
      58           45872 : }
      59                 : 
      60           78344 : void _GTIFFree(gdata_t data)
      61                 : {
      62           78344 :   if (data) _TIFFfree((tdata_t)data);
      63           78344 : }
      64                 : 
      65                 : 
      66                 : 
      67                 : /* returns the value of TIFF tag <tag>, or if
      68                 :  * the value is an array, returns an allocated buffer
      69                 :  * containing the values. Allocate a copy of the actual
      70                 :  * buffer, sized up for updating.
      71                 :  */
      72           34326 : static int _GTIFGetField (tiff_t *tif, pinfo_t tag, int *count, void *val )
      73                 : {
      74                 :   int status;
      75           34326 :   unsigned short scount=0;
      76                 :   char *tmp;
      77                 :   char *value;
      78           34326 :   gsize_t size = _gtiff_size[_GTIFTagType (tif,tag)];
      79                 :   
      80           34326 :   if (_GTIFTagType(tif,  tag) == TYPE_ASCII)
      81                 :   {
      82           11442 :     status = TIFFGetField((TIFF *)tif,tag,&tmp);
      83           11442 :     if (!status) return status;
      84            7552 :     scount = (unsigned short) (strlen(tmp)+1);
      85                 :   }
      86           22884 :   else status = TIFFGetField((TIFF *)tif,tag,&scount,&tmp);
      87           30436 :   if (!status) return status;
      88                 :   
      89           19150 :   *count = scount;
      90                 : 
      91           19150 :   value = (char *)_GTIFcalloc( (scount+MAX_VALUES)*size);
      92           19150 :   if (!value) return 0;
      93                 :   
      94           19150 :   _TIFFmemcpy( value, tmp,  size * scount);
      95                 :   
      96           19150 :   *(char **)val = value;
      97           19150 :   return status;
      98                 : }
      99                 : 
     100                 : /* 
     101                 :  * Set a GeoTIFF TIFF field.
     102                 :  */
     103            5072 : static int _GTIFSetField (tiff_t *tif, pinfo_t tag, int count, void *value )
     104                 : {
     105                 :   int status;
     106            5072 :   unsigned short scount = (unsigned short) count;
     107                 : 
     108                 :   /* libtiff ASCII uses null-delimiter */
     109            5072 :   if (_GTIFTagType(tif,  tag) == TYPE_ASCII)
     110            1810 :     status = TIFFSetField((TIFF *)tif,tag,value);
     111                 :   else 
     112            3262 :     status = TIFFSetField((TIFF *)tif,tag,scount,value);
     113            5072 :   return status;
     114                 : }
     115                 : 
     116                 : 
     117                 : /*
     118                 :  *  This routine is supposed to return the TagType of the <tag>
     119                 :  *  TIFF tag. Unfortunately, "libtiff" does not provide this
     120                 :  *  service by default, so we just have to "know" what type of tags
     121                 :  *  we've got, and how many. We only define the ones Geotiff
     122                 :  *  uses here, and others return UNKNOWN. The "tif" parameter
     123                 :  *  is provided for those TIFF implementations that provide
     124                 :  *  for tag-type queries.
     125                 :  */
     126          125250 : static tagtype_t  _GTIFTagType  (tiff_t *tif, pinfo_t tag)
     127                 : {
     128                 :   tagtype_t ttype;
     129                 : 
     130                 :   (void) tif; /* dummy reference */
     131                 :   
     132          125250 :   switch (tag)
     133                 :   {
     134           34102 :     case GTIFF_ASCIIPARAMS:    ttype=TYPE_ASCII; break;
     135                 :     case GTIFF_PIXELSCALE:
     136                 :     case GTIFF_TRANSMATRIX:
     137                 :     case GTIFF_TIEPOINTS:
     138           33276 :     case GTIFF_DOUBLEPARAMS:   ttype=TYPE_DOUBLE; break;
     139           57872 :     case GTIFF_GEOKEYDIRECTORY: ttype=TYPE_SHORT; break;
     140               0 :     default: ttype = TYPE_UNKNOWN;
     141                 :   }
     142                 :   
     143          125250 :   return ttype;
     144                 : }
     145                 : 

Generated by: LCOV version 1.7