~ubuntu-branches/debian/sid/gdal/sid

« back to all changes in this revision

Viewing changes to gcore/gdaljp2metadata.cpp

  • Committer: Package Import Robot
  • Author(s): Francesco Paolo Lovergine
  • Date: 2012-05-07 15:04:42 UTC
  • mfrom: (5.5.16 experimental)
  • Revision ID: package-import@ubuntu.com-20120507150442-2eks97loeh6rq005
Tags: 1.9.0-1
* Ready for sid, starting transition.
* All symfiles updated to latest builds.
* Added dh_numpy call in debian/rules to depend on numpy ABI.
* Policy bumped to 3.9.3, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: gdaljp2metadata.cpp 17636 2009-09-12 23:19:18Z warmerdam $
 
2
 * $Id: gdaljp2metadata.cpp 22678 2011-07-09 19:47:12Z rouault $
3
3
 *
4
4
 * Project:  GDAL 
5
5
 * Purpose:  GDALJP2Metadata - Read GeoTIFF and/or GML georef info.
33
33
#include "ogr_spatialref.h"
34
34
#include "ogr_geometry.h"
35
35
#include "ogr_api.h"
 
36
#include "gt_wkt_srs_for_gdal.h"
36
37
 
37
 
CPL_CVSID("$Id: gdaljp2metadata.cpp 17636 2009-09-12 23:19:18Z warmerdam $");
 
38
CPL_CVSID("$Id: gdaljp2metadata.cpp 22678 2011-07-09 19:47:12Z rouault $");
38
39
 
39
40
static const unsigned char msi_uuid2[16] =
40
41
{0xb1,0x4b,0xf8,0xbd,0x08,0x3d,0x4b,0x43,
44
45
{ 0x96,0xA9,0xF1,0xF1,0xDC,0x98,0x40,0x2D,
45
46
  0xA7,0xAE,0xD6,0x8E,0x34,0x45,0x18,0x09 };
46
47
 
47
 
CPL_C_START
48
 
CPLErr CPL_DLL GTIFMemBufFromWkt( const char *pszWKT, 
49
 
                                  const double *padfGeoTransform,
50
 
                                  int nGCPCount, const GDAL_GCP *pasGCPList,
51
 
                                  int *pnSize, unsigned char **ppabyBuffer );
52
 
CPLErr CPL_DLL GTIFWktFromMemBuf( int nSize, unsigned char *pabyBuffer, 
53
 
                          char **ppszWKT, double *padfGeoTransform,
54
 
                          int *pnGCPCount, GDAL_GCP **ppasGCPList );
55
 
CPL_C_END
 
48
static const unsigned char xmp_uuid[16] =
 
49
{ 0xBE,0x7A,0xCF,0xCB,0x97,0xA9,0x42,0xE8,
 
50
  0x9C,0x71,0x99,0x94,0x91,0xE3,0xAF,0xAC};
56
51
 
57
52
/************************************************************************/
58
53
/*                          GDALJP2Metadata()                           */
67
62
    pasGCPList = NULL;
68
63
 
69
64
    papszGMLMetadata = NULL;
 
65
    papszMetadata = NULL;
70
66
 
71
67
    nGeoTIFFSize = 0;
72
68
    pabyGeoTIFFData = NULL;
74
70
    nMSIGSize = 0;
75
71
    pabyMSIGData = NULL;
76
72
 
 
73
    pszXMPMetadata = NULL;
 
74
 
77
75
    bHaveGeoTransform = FALSE;
78
76
    adfGeoTransform[0] = 0.0;
79
77
    adfGeoTransform[1] = 1.0;
100
98
    CPLFree( pabyGeoTIFFData );
101
99
    CPLFree( pabyMSIGData );
102
100
    CSLDestroy( papszGMLMetadata );
 
101
    CSLDestroy( papszMetadata );
 
102
    CPLFree( pszXMPMetadata );
103
103
}
104
104
 
105
105
/************************************************************************/
113
113
int GDALJP2Metadata::ReadAndParse( const char *pszFilename )
114
114
 
115
115
{
116
 
    FILE *fpLL;
 
116
    VSILFILE *fpLL;
117
117
        
118
118
    fpLL = VSIFOpenL( pszFilename, "rb" );
119
119
        
204
204
/*                             ReadBoxes()                              */
205
205
/************************************************************************/
206
206
 
207
 
int GDALJP2Metadata::ReadBoxes( FILE *fpVSIL )
 
207
int GDALJP2Metadata::ReadBoxes( VSILFILE *fpVSIL )
208
208
 
209
209
{
210
210
    GDALJP2Box oBox( fpVSIL );
220
220
        if( EQUAL(oBox.GetType(),"uuid") 
221
221
            && memcmp( oBox.GetUUID(), msi_uuid2, 16 ) == 0 )
222
222
        {
223
 
            nGeoTIFFSize = (int) oBox.GetDataLength();
 
223
            nGeoTIFFSize = (int) oBox.GetDataLength();
224
224
            pabyGeoTIFFData = oBox.ReadBoxData();
225
225
        }
226
226
 
230
230
        if( EQUAL(oBox.GetType(),"uuid") 
231
231
            && memcmp( oBox.GetUUID(), msig_uuid, 16 ) == 0 )
232
232
        {
233
 
            nMSIGSize = (int) oBox.GetDataLength();
 
233
            nMSIGSize = (int) oBox.GetDataLength();
234
234
            pabyMSIGData = oBox.ReadBoxData();
235
235
 
236
236
            if( nMSIGSize < 70 
243
243
        }
244
244
 
245
245
/* -------------------------------------------------------------------- */
 
246
/*      Collect XMP box.                                                */
 
247
/* -------------------------------------------------------------------- */
 
248
        if( EQUAL(oBox.GetType(),"uuid")
 
249
            && memcmp( oBox.GetUUID(), xmp_uuid, 16 ) == 0 &&
 
250
            pszXMPMetadata == NULL )
 
251
        {
 
252
            pszXMPMetadata = (char*) oBox.ReadBoxData();
 
253
        }
 
254
 
 
255
/* -------------------------------------------------------------------- */
246
256
/*      Process asoc box looking for Labelled GML data.                 */
247
257
/* -------------------------------------------------------------------- */
248
258
        if( EQUAL(oBox.GetType(),"asoc") )
276
286
            CPLFree( pszXML );
277
287
        }
278
288
 
 
289
/* -------------------------------------------------------------------- */
 
290
/*      Check for a resd box in jp2h.                                   */
 
291
/* -------------------------------------------------------------------- */
 
292
        if( EQUAL(oBox.GetType(),"jp2h") )
 
293
        {
 
294
            GDALJP2Box oSubBox( fpVSIL );
 
295
 
 
296
            for( oSubBox.ReadFirstChild( &oBox );
 
297
                 strlen(oSubBox.GetType()) > 0;
 
298
                 oSubBox.ReadNextChild( &oBox ) )
 
299
            {
 
300
                if( EQUAL(oSubBox.GetType(),"res ") )
 
301
                {
 
302
                    GDALJP2Box oResBox( fpVSIL );
 
303
 
 
304
                    oResBox.ReadFirstChild( &oSubBox );
 
305
                    
 
306
                    // we will use either the resd or resc box, which ever
 
307
                    // happens to be first.  Should we prefer resd?
 
308
                    if( oResBox.GetDataLength() == 10 )
 
309
                    {
 
310
                        unsigned char *pabyResData = oResBox.ReadBoxData();
 
311
                        int nVertNum, nVertDen, nVertExp;
 
312
                        int nHorzNum, nHorzDen, nHorzExp;
 
313
                        
 
314
                        nVertNum = pabyResData[0] * 256 + pabyResData[1];
 
315
                        nVertDen = pabyResData[2] * 256 + pabyResData[3];
 
316
                        nHorzNum = pabyResData[4] * 256 + pabyResData[5];
 
317
                        nHorzDen = pabyResData[6] * 256 + pabyResData[7];
 
318
                        nVertExp = pabyResData[8];
 
319
                        nHorzExp = pabyResData[9];
 
320
                        
 
321
                        // compute in pixels/cm 
 
322
                        double dfVertRes = 
 
323
                            (nVertNum/(double)nVertDen) * pow(10.0,nVertExp)/100;
 
324
                        double dfHorzRes = 
 
325
                            (nHorzNum/(double)nHorzDen) * pow(10.0,nHorzExp)/100;
 
326
                        CPLString osFormatter;
 
327
 
 
328
                        papszMetadata = CSLSetNameValue( 
 
329
                            papszMetadata, 
 
330
                            "TIFFTAG_XRESOLUTION",
 
331
                            osFormatter.Printf("%g",dfHorzRes) );
 
332
                        
 
333
                        papszMetadata = CSLSetNameValue( 
 
334
                            papszMetadata, 
 
335
                            "TIFFTAG_YRESOLUTION",
 
336
                            osFormatter.Printf("%g",dfVertRes) );
 
337
                        papszMetadata = CSLSetNameValue( 
 
338
                            papszMetadata, 
 
339
                            "TIFFTAG_RESOLUTIONUNIT", 
 
340
                            "3 (pixels/cm)" );
 
341
                        
 
342
                        CPLFree( pabyResData );
 
343
                    }
 
344
                }
 
345
            }
 
346
        }
 
347
 
279
348
        oBox.ReadNext();
280
349
    }
281
350
    
810
879
/* -------------------------------------------------------------------- */
811
880
    if( CPLGetConfigOption( "GMLJP2OVERRIDE", NULL ) != NULL )
812
881
    {
813
 
        FILE *fp = VSIFOpenL( CPLGetConfigOption( "GMLJP2OVERRIDE",""), "r" );
 
882
        VSILFILE *fp = VSIFOpenL( CPLGetConfigOption( "GMLJP2OVERRIDE",""), "r" );
814
883
        char *pszGML = NULL;
815
884
 
816
885
        if( fp == NULL )
936
1005
"<gml:FeatureCollection\n"
937
1006
"   xmlns:gml=\"http://www.opengis.net/gml\"\n"
938
1007
"   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
939
 
"   xsi:schemaLocation=\"http://www.opengeospatial.net/gml http://schemas.opengis.net/gml/3.1.1/profiles/gmlJP2Profile/1.0.0/gmlJP2Profile.xsd\">\n"
 
1008
"   xsi:schemaLocation=\"http://www.opengis.net/gml http://schemas.opengis.net/gml/3.1.1/profiles/gmlJP2Profile/1.0.0/gmlJP2Profile.xsd\">\n"
940
1009
"  <gml:boundedBy>\n"
941
1010
"    <gml:Null>withheld</gml:Null>\n"
942
1011
"  </gml:boundedBy>\n"