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