gdaljp2metadata.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /******************************************************************************
  2. * $Id: gdaljp2metadata.h 29210 2015-05-19 19:04:28Z rouault $
  3. *
  4. * Project: GDAL
  5. * Purpose: JP2 Box Reader (and GMLJP2 Interpreter)
  6. * Author: Frank Warmerdam, warmerdam@pobox.com
  7. *
  8. ******************************************************************************
  9. * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
  10. * Copyright (c) 2010-2013, Even Rouault <even dot rouault at mines-paris dot org>
  11. *
  12. * Permission is hereby granted, free of charge, to any person obtaining a
  13. * copy of this software and associated documentation files (the "Software"),
  14. * to deal in the Software without restriction, including without limitation
  15. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  16. * and/or sell copies of the Software, and to permit persons to whom the
  17. * Software is furnished to do so, subject to the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall be included
  20. * in all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  23. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  25. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  27. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  28. * DEALINGS IN THE SOFTWARE.
  29. ****************************************************************************/
  30. #ifndef GDAL_JP2READER_H_INCLUDED
  31. #define GDAL_JP2READER_H_INCLUDED
  32. #include "cpl_conv.h"
  33. #include "cpl_vsi.h"
  34. #include "gdal.h"
  35. #include "gdal_priv.h"
  36. #include "cpl_minixml.h"
  37. /************************************************************************/
  38. /* GDALJP2Box */
  39. /************************************************************************/
  40. class CPL_DLL GDALJP2Box
  41. {
  42. VSILFILE *fpVSIL;
  43. char szBoxType[5];
  44. GIntBig nBoxOffset;
  45. GIntBig nBoxLength;
  46. GIntBig nDataOffset;
  47. GByte abyUUID[16];
  48. GByte *pabyData;
  49. public:
  50. GDALJP2Box( VSILFILE * = NULL );
  51. ~GDALJP2Box();
  52. int SetOffset( GIntBig nNewOffset );
  53. int ReadBox();
  54. int ReadFirst();
  55. int ReadNext();
  56. int ReadFirstChild( GDALJP2Box *poSuperBox );
  57. int ReadNextChild( GDALJP2Box *poSuperBox );
  58. GIntBig GetBoxOffset() const { return nBoxOffset; }
  59. GIntBig GetBoxLength() const { return nBoxLength; }
  60. GIntBig GetDataOffset() const { return nDataOffset; }
  61. GIntBig GetDataLength();
  62. const char *GetType() { return szBoxType; }
  63. GByte *ReadBoxData();
  64. int IsSuperBox();
  65. int DumpReadable( FILE *, int nIndentLevel = 0 );
  66. VSILFILE *GetFILE() { return fpVSIL; }
  67. const GByte *GetUUID() { return abyUUID; }
  68. // write support
  69. void SetType( const char * );
  70. void SetWritableData( int nLength, const GByte *pabyData );
  71. void AppendWritableData( int nLength, const void *pabyDataIn );
  72. void AppendUInt32( GUInt32 nVal );
  73. void AppendUInt16( GUInt16 nVal );
  74. void AppendUInt8( GByte nVal );
  75. const GByte*GetWritableData() { return pabyData; }
  76. // factory methods.
  77. static GDALJP2Box *CreateSuperBox( const char* pszType,
  78. int nCount, GDALJP2Box **papoBoxes );
  79. static GDALJP2Box *CreateAsocBox( int nCount, GDALJP2Box **papoBoxes );
  80. static GDALJP2Box *CreateLblBox( const char *pszLabel );
  81. static GDALJP2Box *CreateLabelledXMLAssoc( const char *pszLabel,
  82. const char *pszXML );
  83. static GDALJP2Box *CreateUUIDBox( const GByte *pabyUUID,
  84. int nDataSize, const GByte *pabyData );
  85. };
  86. /************************************************************************/
  87. /* GDALJP2Metadata */
  88. /************************************************************************/
  89. typedef struct _GDALJP2GeoTIFFBox GDALJP2GeoTIFFBox;
  90. class CPL_DLL GDALJP2Metadata
  91. {
  92. private:
  93. void CollectGMLData( GDALJP2Box * );
  94. int GMLSRSLookup( const char *pszURN );
  95. int nGeoTIFFBoxesCount;
  96. GDALJP2GeoTIFFBox *pasGeoTIFFBoxes;
  97. int nMSIGSize;
  98. GByte *pabyMSIGData;
  99. int GetGMLJP2GeoreferencingInfo( int& nEPSGCode,
  100. double adfOrigin[2],
  101. double adfXVector[2],
  102. double adfYVector[2],
  103. const char*& pszComment,
  104. CPLString& osDictBox,
  105. int& bNeedAxisFlip );
  106. static CPLXMLNode* CreateGDALMultiDomainMetadataXML(
  107. GDALDataset* poSrcDS,
  108. int bMainMDDomainOnly );
  109. public:
  110. char **papszGMLMetadata;
  111. int bHaveGeoTransform;
  112. double adfGeoTransform[6];
  113. int bPixelIsPoint;
  114. char *pszProjection;
  115. int nGCPCount;
  116. GDAL_GCP *pasGCPList;
  117. char **papszRPCMD;
  118. char **papszMetadata; /* TIFFTAG_?RESOLUTION* for now from resd box */
  119. char *pszXMPMetadata;
  120. char *pszGDALMultiDomainMetadata; /* as serialized XML */
  121. char *pszXMLIPR; /* if an IPR box with XML content has been found */
  122. public:
  123. GDALJP2Metadata();
  124. ~GDALJP2Metadata();
  125. int ReadBoxes( VSILFILE * fpVSIL );
  126. int ParseJP2GeoTIFF();
  127. int ParseMSIG();
  128. int ParseGMLCoverageDesc();
  129. int ReadAndParse( VSILFILE * fpVSIL );
  130. int ReadAndParse( const char *pszFilename );
  131. // Write oriented.
  132. void SetProjection( const char *pszWKT );
  133. void SetGeoTransform( double * );
  134. void SetGCPs( int, const GDAL_GCP * );
  135. void SetRPCMD( char** papszRPCMDIn );
  136. GDALJP2Box *CreateJP2GeoTIFF();
  137. GDALJP2Box *CreateGMLJP2( int nXSize, int nYSize );
  138. GDALJP2Box *CreateGMLJP2V2( int nXSize, int nYSize,
  139. const char* pszDefFilename,
  140. GDALDataset* poSrcDS );
  141. static GDALJP2Box* CreateGDALMultiDomainMetadataXMLBox(
  142. GDALDataset* poSrcDS,
  143. int bMainMDDomainOnly );
  144. static GDALJP2Box** CreateXMLBoxes( GDALDataset* poSrcDS,
  145. int* pnBoxes );
  146. static GDALJP2Box *CreateXMPBox ( GDALDataset* poSrcDS );
  147. static GDALJP2Box *CreateIPRBox ( GDALDataset* poSrcDS );
  148. static int IsUUID_MSI(const GByte *abyUUID);
  149. static int IsUUID_XMP(const GByte *abyUUID);
  150. };
  151. #endif /* ndef GDAL_JP2READER_H_INCLUDED */