GDAL
gdaljp2metadata.h
1 /******************************************************************************
2  * $Id$
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 spatialys.com>
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 
31 #ifndef GDAL_JP2READER_H_INCLUDED
32 #define GDAL_JP2READER_H_INCLUDED
33 
34 #ifndef DOXYGEN_SKIP
35 
36 #include "cpl_conv.h"
37 #include "cpl_minixml.h"
38 #include "cpl_vsi.h"
39 #include "gdal.h"
40 #include "gdal_priv.h"
41 
42 /************************************************************************/
43 /* GDALJP2Box */
44 /************************************************************************/
45 
46 class CPL_DLL GDALJP2Box
47 {
48 
49  VSILFILE *fpVSIL = nullptr;
50 
51  char szBoxType[5] {0, 0, 0, 0, 0};
52 
53  GIntBig nBoxOffset = -1;
54  GIntBig nBoxLength = 0;
55 
56  GIntBig nDataOffset = -1;
57 
58  GByte abyUUID[16] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
59 
60  GByte *pabyData = nullptr;
61 
62  bool m_bAllowGetFileSize = true;
63 
64  CPL_DISALLOW_COPY_ASSIGN(GDALJP2Box)
65 
66 public:
67  explicit GDALJP2Box( VSILFILE * = nullptr );
68  ~GDALJP2Box();
69 
70  void SetAllowGetFileSize(bool b) { m_bAllowGetFileSize = b; }
71 
72  int SetOffset( GIntBig nNewOffset );
73  int ReadBox();
74 
75  int ReadFirst();
76  int ReadNext();
77 
78  int ReadFirstChild( GDALJP2Box *poSuperBox );
79  int ReadNextChild( GDALJP2Box *poSuperBox );
80 
81  GIntBig GetBoxOffset() const { return nBoxOffset; }
82  GIntBig GetBoxLength() const { return nBoxLength; }
83 
84  GIntBig GetDataOffset() const { return nDataOffset; }
85  GIntBig GetDataLength() const;
86 
87  const char *GetType() { return szBoxType; }
88 
89  GByte *ReadBoxData();
90 
91  int IsSuperBox();
92 
93  int DumpReadable( FILE *, int nIndentLevel = 0 );
94 
95  VSILFILE *GetFILE() { return fpVSIL; }
96 
97  const GByte *GetUUID() { return abyUUID; }
98 
99  // write support
100  void SetType( const char * );
101  void SetWritableData( int nLength, const GByte *pabyData );
102  void AppendWritableData( int nLength, const void *pabyDataIn );
103  void AppendUInt32( GUInt32 nVal );
104  void AppendUInt16( GUInt16 nVal );
105  void AppendUInt8( GByte nVal );
106  const GByte*GetWritableData() const { return pabyData; }
107  GByte *GetWritableBoxData() const;
108 
109  // factory methods.
110  static GDALJP2Box *CreateSuperBox( const char* pszType,
111  int nCount,
112  const GDALJP2Box * const *papoBoxes );
113  static GDALJP2Box *CreateAsocBox( int nCount,
114  const GDALJP2Box * const *papoBoxes );
115  static GDALJP2Box *CreateLblBox( const char *pszLabel );
116  static GDALJP2Box *CreateLabelledXMLAssoc( const char *pszLabel,
117  const char *pszXML );
118  static GDALJP2Box *CreateUUIDBox( const GByte *pabyUUID,
119  int nDataSize, const GByte *pabyData );
120 
121  // JUMBF boxes (ISO/IEC 19566-5:2019)
122  static GDALJP2Box *CreateJUMBFDescriptionBox( const GByte *pabyUUIDType,
123  const char* pszLabel );
124  static GDALJP2Box *CreateJUMBFBox( const GDALJP2Box* poJUMBFDescriptionBox,
125  int nCount,
126  const GDALJP2Box * const *papoBoxes );
127 };
128 
129 /************************************************************************/
130 /* GDALJP2Metadata */
131 /************************************************************************/
132 
133 typedef struct _GDALJP2GeoTIFFBox GDALJP2GeoTIFFBox;
134 
135 class CPL_DLL GDALJP2Metadata
136 
137 {
138 private:
139  void CollectGMLData( GDALJP2Box * );
140  int GMLSRSLookup( const char *pszURN );
141 
142  int nGeoTIFFBoxesCount;
143  GDALJP2GeoTIFFBox *pasGeoTIFFBoxes;
144 
145  int nMSIGSize;
146  GByte *pabyMSIGData;
147 
148  int GetGMLJP2GeoreferencingInfo( int& nEPSGCode,
149  double adfOrigin[2],
150  double adfXVector[2],
151  double adfYVector[2],
152  const char*& pszComment,
153  CPLString& osDictBox,
154  int& bNeedAxisFlip );
155  static CPLXMLNode* CreateGDALMultiDomainMetadataXML(
156  GDALDataset* poSrcDS,
157  int bMainMDDomainOnly );
158 
159  CPL_DISALLOW_COPY_ASSIGN(GDALJP2Metadata)
160 
161 public:
162  char **papszGMLMetadata;
163 
164  bool bHaveGeoTransform;
165  double adfGeoTransform[6];
166  bool bPixelIsPoint;
167 
168  OGRSpatialReference m_oSRS{};
169 
170  int nGCPCount;
171  GDAL_GCP *pasGCPList;
172 
173  char **papszRPCMD;
174 
175  char **papszMetadata; /* TIFFTAG_?RESOLUTION* for now from resd box */
176  char *pszXMPMetadata;
177  char *pszGDALMultiDomainMetadata; /* as serialized XML */
178  char *pszXMLIPR; /* if an IPR box with XML content has been found */
179 
180  void ReadBox( VSILFILE *fpVSIL, GDALJP2Box& oBox, int& iBox );
181 
182 public:
183  GDALJP2Metadata();
184  ~GDALJP2Metadata();
185 
186  int ReadBoxes( VSILFILE * fpVSIL );
187 
188  int ParseJP2GeoTIFF();
189  int ParseMSIG();
190  int ParseGMLCoverageDesc();
191 
192  int ReadAndParse( VSILFILE * fpVSIL,
193  int nGEOJP2Index = 0, int nGMLJP2Index = 1,
194  int nMSIGIndex = 2, int *pnIndexUsed = nullptr );
195  int ReadAndParse( const char *pszFilename, int nGEOJP2Index = 0,
196  int nGMLJP2Index = 1, int nMSIGIndex = 2,
197  int nWorldFileIndex = 3, int *pnIndexUsed = nullptr );
198 
199  // Write oriented.
200  void SetSpatialRef( const OGRSpatialReference *poSRS );
201  void SetGeoTransform( double * );
202  void SetGCPs( int, const GDAL_GCP * );
203  void SetRPCMD( char** papszRPCMDIn );
204 
205  GDALJP2Box *CreateJP2GeoTIFF();
206  GDALJP2Box *CreateGMLJP2( int nXSize, int nYSize );
207  GDALJP2Box *CreateGMLJP2V2( int nXSize, int nYSize,
208  const char* pszDefFilename,
209  GDALDataset* poSrcDS );
210 
211  static GDALJP2Box* CreateGDALMultiDomainMetadataXMLBox(
212  GDALDataset* poSrcDS,
213  int bMainMDDomainOnly );
214  static GDALJP2Box** CreateXMLBoxes( GDALDataset* poSrcDS,
215  int* pnBoxes );
216  static GDALJP2Box *CreateXMPBox ( GDALDataset* poSrcDS );
217  static GDALJP2Box *CreateIPRBox ( GDALDataset* poSrcDS );
218  static int IsUUID_MSI(const GByte *abyUUID);
219  static int IsUUID_XMP(const GByte *abyUUID);
220 };
221 
222 CPLXMLNode* GDALGetJPEG2000Structure(const char* pszFilename,
223  VSILFILE* fp,
224  CSLConstList papszOptions);
225 
226 const char CPL_DLL *GDALGetJPEG2000Reversibility(const char* pszFilename,
227  VSILFILE* fp);
228 #endif /* #ifndef DOXYGEN_SKIP */
229 
230 #endif /* ndef GDAL_JP2READER_H_INCLUDED */
GByte
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:203
gdal.h
GDALGetJPEG2000Structure
CPLXMLNode * GDALGetJPEG2000Structure(const char *pszFilename, CSLConstList papszOptions)
Dump the structure of a JPEG2000 file as a XML tree.
Definition: gdaljp2structure.cpp:2205
cpl_minixml.h
cpl_vsi.h
OGRSpatialReference
This class represents an OpenGIS Spatial Reference System, and contains methods for converting betwee...
Definition: ogr_spatialref.h:157
CPLString
Convenient string class based on std::string.
Definition: cpl_string.h:320
CPLXMLNode
Document node structure.
Definition: cpl_minixml.h:69
GDALDataset
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:342
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1056
GDAL_GCP
Ground Control Point.
Definition: gdal.h:892
cpl_conv.h
gdal_priv.h
GIntBig
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:230
GUInt16
unsigned short GUInt16
Unsigned int16 type.
Definition: cpl_port.h:201
CPL_DISALLOW_COPY_ASSIGN
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:930
VSILFILE
FILE VSILFILE
Opaque type for a FILE that implements the VSIVirtualHandle API.
Definition: cpl_vsi.h:158
GUInt32
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:195