• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OSGeo / gdal / 15992523769

01 Jul 2025 07:16AM UTC coverage: 71.09% (-0.004%) from 71.094%
15992523769

Pull #12682

github

web-flow
Merge 1383a7df3 into f6ed9706f
Pull Request #12682: Bump msys2/setup-msys2 from 2.27.0 to 2.28.0

574092 of 807557 relevant lines covered (71.09%)

250020.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.83
/frmts/gtiff/libgeotiff/geo_tiffp.c
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
void _GTIFSetDefaultTIFF(TIFFMethod *method)
33,590✔
35
{
36
        if (!method) return;
33,590✔
37

38
        method->get = _GTIFGetField;
33,590✔
39
        method->set = _GTIFSetField;
33,590✔
40
        method->type = _GTIFTagType;
33,590✔
41
}
42

43
gdata_t _GTIFcalloc(gsize_t size)
214,676✔
44
{
45
    gdata_t data=(gdata_t)_TIFFmalloc((tsize_t)size);
214,676✔
46
        if (data) _TIFFmemset((tdata_t)data,0,(tsize_t)size);
214,679✔
47
        return data;
214,678✔
48
}
49

50
gdata_t _GTIFrealloc(gdata_t ptr, gsize_t size)
26,913✔
51
{
52
    return _TIFFrealloc((tdata_t)ptr, (tsize_t) size);
26,913✔
53
}
54

55
void _GTIFmemcpy(gdata_t out,gdata_t in,gsize_t size)
106,056✔
56
{
57
        _TIFFmemcpy((tdata_t)out,(tdata_t)in,(tsize_t)size);
106,056✔
58
}
106,055✔
59

60
void _GTIFFree(gdata_t data)
214,678✔
61
{
62
        if (data) _TIFFfree((tdata_t)data);
214,678✔
63
}
214,678✔
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
static int _GTIFGetField (tiff_t *tif, pinfo_t tag, int *count, void *val )
100,769✔
73
{
74
        int status;
75
        unsigned short scount=0;
100,769✔
76
        char *tmp;
77
        const gsize_t size = _gtiff_size[_GTIFTagType (tif,tag)];
100,769✔
78

79
        if (_GTIFTagType(tif,  tag) == TYPE_ASCII)
100,769✔
80
        {
81
                status = TIFFGetField((TIFF *)tif,tag,&tmp);
33,590✔
82
                if (!status) return status;
33,590✔
83
                scount = (unsigned short) (strlen(tmp)+1);
18,024✔
84
        }
85
        else status = TIFFGetField((TIFF *)tif,tag,&scount,&tmp);
67,179✔
86
        if (!status) return status;
85,201✔
87

88
        *count = scount;
44,935✔
89

90
        char *value = (char *)_GTIFcalloc( (scount+MAX_VALUES)*size);
44,935✔
91
        if (!value) return 0;
44,936✔
92

93
        _TIFFmemcpy( value, tmp,  size * scount);
44,936✔
94

95
        *(char **)val = value;
44,937✔
96
        return status;
44,937✔
97
}
98

99
/*
100
 * Set a GeoTIFF TIFF field.
101
 */
102
static int _GTIFSetField (tiff_t *tif, pinfo_t tag, int count, void *value )
8,382✔
103
{
104
        const unsigned short scount = (unsigned short) count;
8,382✔
105

106
        int status;
107
        /* libtiff ASCII uses null-delimiter */
108
        if (_GTIFTagType(tif,  tag) == TYPE_ASCII)
8,382✔
109
                status = TIFFSetField((TIFF *)tif,tag,value);
3,058✔
110
        else
111
                status = TIFFSetField((TIFF *)tif,tag,scount,value);
5,324✔
112
        return status;
8,382✔
113
}
114

115

116
/*
117
 *  This routine is supposed to return the TagType of the <tag>
118
 *  TIFF tag. Unfortunately, "libtiff" does not provide this
119
 *  service by default, so we just have to "know" what type of tags
120
 *  we've got, and how many. We only define the ones Geotiff
121
 *  uses here, and others return UNKNOWN. The "tif" parameter
122
 *  is provided for those TIFF implementations that provide
123
 *  for tag-type queries.
124
 */
125
static tagtype_t  _GTIFTagType  (tiff_t *tif, pinfo_t tag)
326,997✔
126
{
127
        (void) tif; /* dummy reference */
128

129
        tagtype_t ttype;
130
        switch (tag)
326,997✔
131
        {
132
                case GTIFF_ASCIIPARAMS:    ttype=TYPE_ASCII; break;
91,829✔
133
                case GTIFF_PIXELSCALE:
87,302✔
134
                case GTIFF_TRANSMATRIX:
135
                case GTIFF_TIEPOINTS:
136
                case GTIFF_DOUBLEPARAMS:   ttype=TYPE_DOUBLE; break;
87,302✔
137
                case GTIFF_GEOKEYDIRECTORY: ttype=TYPE_SHORT; break;
147,867✔
138
                default: ttype = TYPE_UNKNOWN;
×
139
        }
140

141
        return ttype;
326,997✔
142
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc