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)
71  {
72  m_bAllowGetFileSize = b;
73  }
74 
75  int SetOffset(GIntBig nNewOffset);
76  int ReadBox();
77 
78  int ReadFirst();
79  int ReadNext();
80 
81  int ReadFirstChild(GDALJP2Box *poSuperBox);
82  int ReadNextChild(GDALJP2Box *poSuperBox);
83 
84  GIntBig GetBoxOffset() const
85  {
86  return nBoxOffset;
87  }
88  GIntBig GetBoxLength() const
89  {
90  return nBoxLength;
91  }
92 
93  GIntBig GetDataOffset() const
94  {
95  return nDataOffset;
96  }
97  GIntBig GetDataLength() const;
98 
99  const char *GetType()
100  {
101  return szBoxType;
102  }
103 
104  GByte *ReadBoxData();
105 
106  int IsSuperBox();
107 
108  int DumpReadable(FILE *, int nIndentLevel = 0);
109 
110  VSILFILE *GetFILE()
111  {
112  return fpVSIL;
113  }
114 
115  const GByte *GetUUID()
116  {
117  return abyUUID;
118  }
119 
120  // write support
121  void SetType(const char *);
122  void SetWritableData(int nLength, const GByte *pabyData);
123  void AppendWritableData(int nLength, const void *pabyDataIn);
124  void AppendUInt32(GUInt32 nVal);
125  void AppendUInt16(GUInt16 nVal);
126  void AppendUInt8(GByte nVal);
127  const GByte *GetWritableData() const
128  {
129  return pabyData;
130  }
131  GByte *GetWritableBoxData() const;
132 
133  // factory methods.
134  static GDALJP2Box *CreateSuperBox(const char *pszType, int nCount,
135  const GDALJP2Box *const *papoBoxes);
136  static GDALJP2Box *CreateAsocBox(int nCount,
137  const GDALJP2Box *const *papoBoxes);
138  static GDALJP2Box *CreateLblBox(const char *pszLabel);
139  static GDALJP2Box *CreateLabelledXMLAssoc(const char *pszLabel,
140  const char *pszXML);
141  static GDALJP2Box *CreateUUIDBox(const GByte *pabyUUID, int nDataSize,
142  const GByte *pabyData);
143 
144  // JUMBF boxes (ISO/IEC 19566-5:2019)
145  static GDALJP2Box *CreateJUMBFDescriptionBox(const GByte *pabyUUIDType,
146  const char *pszLabel);
147  static GDALJP2Box *CreateJUMBFBox(const GDALJP2Box *poJUMBFDescriptionBox,
148  int nCount,
149  const GDALJP2Box *const *papoBoxes);
150 };
151 
152 /************************************************************************/
153 /* GDALJP2Metadata */
154 /************************************************************************/
155 
156 typedef struct _GDALJP2GeoTIFFBox GDALJP2GeoTIFFBox;
157 
158 class CPL_DLL GDALJP2Metadata
159 
160 {
161  private:
162  void CollectGMLData(GDALJP2Box *);
163  int GMLSRSLookup(const char *pszURN);
164 
165  int nGeoTIFFBoxesCount;
166  GDALJP2GeoTIFFBox *pasGeoTIFFBoxes;
167 
168  int nMSIGSize;
169  GByte *pabyMSIGData;
170 
171  void GetGMLJP2GeoreferencingInfo(int &nEPSGCode, double adfOrigin[2],
172  double adfXVector[2], double adfYVector[2],
173  const char *&pszComment,
174  CPLString &osDictBox, bool &bNeedAxisFlip);
175  static CPLXMLNode *CreateGDALMultiDomainMetadataXML(GDALDataset *poSrcDS,
176  int bMainMDDomainOnly);
177 
178  CPL_DISALLOW_COPY_ASSIGN(GDALJP2Metadata)
179 
180  public:
181  char **papszGMLMetadata;
182 
183  bool bHaveGeoTransform;
184  double adfGeoTransform[6];
185  bool bPixelIsPoint;
186 
187  OGRSpatialReference m_oSRS{};
188 
189  int nGCPCount;
190  GDAL_GCP *pasGCPList;
191 
192  char **papszRPCMD;
193 
194  char **papszMetadata; /* TIFFTAG_?RESOLUTION* for now from resd box */
195  char *pszXMPMetadata;
196  char *pszGDALMultiDomainMetadata; /* as serialized XML */
197  char *pszXMLIPR; /* if an IPR box with XML content has been found */
198 
199  void ReadBox(VSILFILE *fpVSIL, GDALJP2Box &oBox, int &iBox);
200 
201  public:
202  GDALJP2Metadata();
203  ~GDALJP2Metadata();
204 
205  int ReadBoxes(VSILFILE *fpVSIL);
206 
207  int ParseJP2GeoTIFF();
208  int ParseMSIG();
209  int ParseGMLCoverageDesc();
210 
211  int ReadAndParse(VSILFILE *fpVSIL, int nGEOJP2Index = 0,
212  int nGMLJP2Index = 1, int nMSIGIndex = 2,
213  int *pnIndexUsed = nullptr);
214  int ReadAndParse(const char *pszFilename, int nGEOJP2Index = 0,
215  int nGMLJP2Index = 1, int nMSIGIndex = 2,
216  int nWorldFileIndex = 3, int *pnIndexUsed = nullptr);
217 
218  // Write oriented.
219  void SetSpatialRef(const OGRSpatialReference *poSRS);
220  void SetGeoTransform(double *);
221  void SetGCPs(int, const GDAL_GCP *);
222  void SetRPCMD(char **papszRPCMDIn);
223 
224  GDALJP2Box *CreateJP2GeoTIFF();
225  GDALJP2Box *CreateGMLJP2(int nXSize, int nYSize);
226  GDALJP2Box *CreateGMLJP2V2(int nXSize, int nYSize,
227  const char *pszDefFilename,
228  GDALDataset *poSrcDS);
229 
230  static GDALJP2Box *
231  CreateGDALMultiDomainMetadataXMLBox(GDALDataset *poSrcDS,
232  int bMainMDDomainOnly);
233  static GDALJP2Box **CreateXMLBoxes(GDALDataset *poSrcDS, int *pnBoxes);
234  static GDALJP2Box *CreateXMPBox(GDALDataset *poSrcDS);
235  static GDALJP2Box *CreateIPRBox(GDALDataset *poSrcDS);
236  static int IsUUID_MSI(const GByte *abyUUID);
237  static int IsUUID_XMP(const GByte *abyUUID);
238 };
239 
240 CPLXMLNode *GDALGetJPEG2000Structure(const char *pszFilename, VSILFILE *fp,
241  CSLConstList papszOptions);
242 
243 const char CPL_DLL *GDALGetJPEG2000Reversibility(const char *pszFilename,
244  VSILFILE *fp);
245 #endif /* #ifndef DOXYGEN_SKIP */
246 
247 #endif /* ndef GDAL_JP2READER_H_INCLUDED */
GByte
unsigned char GByte
Unsigned byte type.
Definition: cpl_port.h:196
gdal.h
GDALGetJPEG2000Structure
CPLXMLNode * GDALGetJPEG2000Structure(const char *pszFilename, CSLConstList papszOptions)
Dump the structure of a JPEG2000 file as a XML tree.
Definition: gdaljp2structure.cpp:2362
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:166
CPLString
Convenient string class based on std::string.
Definition: cpl_string.h:311
CPLXMLNode
Document node structure.
Definition: cpl_minixml.h:69
GDALDataset
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:348
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition: cpl_port.h:1178
GDAL_GCP
Ground Control Point.
Definition: gdal.h:1051
cpl_conv.h
VSIVirtualHandle
Virtual file handle.
Definition: cpl_vsi_virtual.h:62
gdal_priv.h
GIntBig
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:226
GUInt16
unsigned short GUInt16
Unsigned int16 type.
Definition: cpl_port.h:194
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:1042
GUInt32
unsigned int GUInt32
Unsigned int32 type.
Definition: cpl_port.h:188