LCOV - code coverage report
Current view: top level - gcore - gdaljp2metadata.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 17 17 100.0 %
Date: 2024-05-04 12:52:34 Functions: 8 8 100.0 %

          Line data    Source code
       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         121 :     void SetAllowGetFileSize(bool b)
      71             :     {
      72         121 :         m_bAllowGetFileSize = b;
      73         121 :     }
      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         357 :     GIntBig GetBoxOffset() const
      85             :     {
      86         357 :         return nBoxOffset;
      87             :     }
      88             : 
      89         387 :     GIntBig GetBoxLength() const
      90             :     {
      91         387 :         return nBoxLength;
      92             :     }
      93             : 
      94        1203 :     GIntBig GetDataOffset() const
      95             :     {
      96        1203 :         return nDataOffset;
      97             :     }
      98             : 
      99             :     GIntBig GetDataLength() const;
     100             : 
     101       64267 :     const char *GetType()
     102             :     {
     103       64267 :         return szBoxType;
     104             :     }
     105             : 
     106             :     GByte *ReadBoxData();
     107             : 
     108             :     int IsSuperBox();
     109             : 
     110             :     int DumpReadable(FILE *, int nIndentLevel = 0);
     111             : 
     112         531 :     VSILFILE *GetFILE()
     113             :     {
     114         531 :         return fpVSIL;
     115             :     }
     116             : 
     117         667 :     const GByte *GetUUID()
     118             :     {
     119         667 :         return abyUUID;
     120             :     }
     121             : 
     122             :     // write support
     123             :     void SetType(const char *);
     124             :     void SetWritableData(int nLength, const GByte *pabyData);
     125             :     void AppendWritableData(int nLength, const void *pabyDataIn);
     126             :     void AppendUInt32(GUInt32 nVal);
     127             :     void AppendUInt16(GUInt16 nVal);
     128             :     void AppendUInt8(GByte nVal);
     129             : 
     130         995 :     const GByte *GetWritableData() const
     131             :     {
     132         995 :         return pabyData;
     133             :     }
     134             : 
     135             :     GByte *GetWritableBoxData() const;
     136             : 
     137             :     // factory methods.
     138             :     static GDALJP2Box *CreateSuperBox(const char *pszType, int nCount,
     139             :                                       const GDALJP2Box *const *papoBoxes);
     140             :     static GDALJP2Box *CreateAsocBox(int nCount,
     141             :                                      const GDALJP2Box *const *papoBoxes);
     142             :     static GDALJP2Box *CreateLblBox(const char *pszLabel);
     143             :     static GDALJP2Box *CreateLabelledXMLAssoc(const char *pszLabel,
     144             :                                               const char *pszXML);
     145             :     static GDALJP2Box *CreateUUIDBox(const GByte *pabyUUID, int nDataSize,
     146             :                                      const GByte *pabyData);
     147             : 
     148             :     // JUMBF boxes (ISO/IEC 19566-5:2019)
     149             :     static GDALJP2Box *CreateJUMBFDescriptionBox(const GByte *pabyUUIDType,
     150             :                                                  const char *pszLabel);
     151             :     static GDALJP2Box *CreateJUMBFBox(const GDALJP2Box *poJUMBFDescriptionBox,
     152             :                                       int nCount,
     153             :                                       const GDALJP2Box *const *papoBoxes);
     154             : };
     155             : 
     156             : /************************************************************************/
     157             : /*                           GDALJP2Metadata                            */
     158             : /************************************************************************/
     159             : 
     160             : typedef struct _GDALJP2GeoTIFFBox GDALJP2GeoTIFFBox;
     161             : 
     162             : class CPL_DLL GDALJP2Metadata
     163             : 
     164             : {
     165             :   private:
     166             :     void CollectGMLData(GDALJP2Box *);
     167             :     int GMLSRSLookup(const char *pszURN);
     168             : 
     169             :     int nGeoTIFFBoxesCount;
     170             :     GDALJP2GeoTIFFBox *pasGeoTIFFBoxes;
     171             : 
     172             :     int nMSIGSize;
     173             :     GByte *pabyMSIGData;
     174             : 
     175             :     void GetGMLJP2GeoreferencingInfo(int &nEPSGCode, double adfOrigin[2],
     176             :                                      double adfXVector[2], double adfYVector[2],
     177             :                                      const char *&pszComment,
     178             :                                      CPLString &osDictBox, bool &bNeedAxisFlip);
     179             :     static CPLXMLNode *CreateGDALMultiDomainMetadataXML(GDALDataset *poSrcDS,
     180             :                                                         int bMainMDDomainOnly);
     181             : 
     182             :     CPL_DISALLOW_COPY_ASSIGN(GDALJP2Metadata)
     183             : 
     184             :   public:
     185             :     char **papszGMLMetadata;
     186             : 
     187             :     bool bHaveGeoTransform;
     188             :     double adfGeoTransform[6];
     189             :     bool bPixelIsPoint;
     190             : 
     191             :     OGRSpatialReference m_oSRS{};
     192             : 
     193             :     int nGCPCount;
     194             :     GDAL_GCP *pasGCPList;
     195             : 
     196             :     char **papszRPCMD;
     197             : 
     198             :     char **papszMetadata; /* TIFFTAG_?RESOLUTION* for now from resd box */
     199             :     char *pszXMPMetadata;
     200             :     char *pszGDALMultiDomainMetadata; /* as serialized XML */
     201             :     char *pszXMLIPR; /* if an IPR box with XML content has been found */
     202             : 
     203             :     void ReadBox(VSILFILE *fpVSIL, GDALJP2Box &oBox, int &iBox);
     204             : 
     205             :   public:
     206             :     GDALJP2Metadata();
     207             :     ~GDALJP2Metadata();
     208             : 
     209             :     int ReadBoxes(VSILFILE *fpVSIL);
     210             : 
     211             :     int ParseJP2GeoTIFF();
     212             :     int ParseMSIG();
     213             :     int ParseGMLCoverageDesc();
     214             : 
     215             :     int ReadAndParse(VSILFILE *fpVSIL, int nGEOJP2Index = 0,
     216             :                      int nGMLJP2Index = 1, int nMSIGIndex = 2,
     217             :                      int *pnIndexUsed = nullptr);
     218             :     int ReadAndParse(const char *pszFilename, int nGEOJP2Index = 0,
     219             :                      int nGMLJP2Index = 1, int nMSIGIndex = 2,
     220             :                      int nWorldFileIndex = 3, int *pnIndexUsed = nullptr);
     221             : 
     222             :     // Write oriented.
     223             :     void SetSpatialRef(const OGRSpatialReference *poSRS);
     224             :     void SetGeoTransform(double *);
     225             :     void SetGCPs(int, const GDAL_GCP *);
     226             :     void SetRPCMD(char **papszRPCMDIn);
     227             : 
     228             :     GDALJP2Box *CreateJP2GeoTIFF();
     229             :     GDALJP2Box *CreateGMLJP2(int nXSize, int nYSize);
     230             :     GDALJP2Box *CreateGMLJP2V2(int nXSize, int nYSize,
     231             :                                const char *pszDefFilename,
     232             :                                GDALDataset *poSrcDS);
     233             : 
     234             :     static GDALJP2Box *
     235             :     CreateGDALMultiDomainMetadataXMLBox(GDALDataset *poSrcDS,
     236             :                                         int bMainMDDomainOnly);
     237             :     static GDALJP2Box **CreateXMLBoxes(GDALDataset *poSrcDS, int *pnBoxes);
     238             :     static GDALJP2Box *CreateXMPBox(GDALDataset *poSrcDS);
     239             :     static GDALJP2Box *CreateIPRBox(GDALDataset *poSrcDS);
     240             :     static int IsUUID_MSI(const GByte *abyUUID);
     241             :     static int IsUUID_XMP(const GByte *abyUUID);
     242             : 
     243             :     static bool IsSRSCompatible(const OGRSpatialReference *poSRS);
     244             : };
     245             : 
     246             : CPLXMLNode *GDALGetJPEG2000Structure(const char *pszFilename, VSILFILE *fp,
     247             :                                      CSLConstList papszOptions);
     248             : 
     249             : const char CPL_DLL *GDALGetJPEG2000Reversibility(const char *pszFilename,
     250             :                                                  VSILFILE *fp);
     251             : #endif /* #ifndef DOXYGEN_SKIP */
     252             : 
     253             : #endif /* ndef GDAL_JP2READER_H_INCLUDED */

Generated by: LCOV version 1.14