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