00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef GDAL_JP2READER_H_INCLUDED
00032 #define GDAL_JP2READER_H_INCLUDED
00033
00034 #include "cpl_conv.h"
00035 #include "cpl_vsi.h"
00036 #include "gdal.h"
00037 #include "gdal_priv.h"
00038 #include "cpl_minixml.h"
00039
00040
00041
00042
00043
00044 class CPL_DLL GDALJP2Box
00045 {
00046
00047 VSILFILE *fpVSIL;
00048
00049 char szBoxType[5];
00050
00051 GIntBig nBoxOffset;
00052 GIntBig nBoxLength;
00053
00054 GIntBig nDataOffset;
00055
00056 GByte abyUUID[16];
00057
00058 GByte *pabyData;
00059
00060 public:
00061 GDALJP2Box( VSILFILE * = NULL );
00062 ~GDALJP2Box();
00063
00064 int SetOffset( GIntBig nNewOffset );
00065 int ReadBox();
00066
00067 int ReadFirst();
00068 int ReadNext();
00069
00070 int ReadFirstChild( GDALJP2Box *poSuperBox );
00071 int ReadNextChild( GDALJP2Box *poSuperBox );
00072
00073 GIntBig GetBoxOffset() const { return nBoxOffset; }
00074 GIntBig GetBoxLength() const { return nBoxLength; }
00075
00076 GIntBig GetDataOffset() const { return nDataOffset; }
00077 GIntBig GetDataLength();
00078
00079 const char *GetType() { return szBoxType; }
00080
00081 GByte *ReadBoxData();
00082
00083 int IsSuperBox();
00084
00085 int DumpReadable( FILE *, int nIndentLevel = 0 );
00086
00087 VSILFILE *GetFILE() { return fpVSIL; }
00088
00089 const GByte *GetUUID() { return abyUUID; }
00090
00091
00092 void SetType( const char * );
00093 void SetWritableData( int nLength, const GByte *pabyData );
00094 void AppendWritableData( int nLength, const void *pabyDataIn );
00095 void AppendUInt32( GUInt32 nVal );
00096 void AppendUInt16( GUInt16 nVal );
00097 void AppendUInt8( GByte nVal );
00098 const GByte*GetWritableData() { return pabyData; }
00099
00100
00101 static GDALJP2Box *CreateSuperBox( const char* pszType,
00102 int nCount, GDALJP2Box **papoBoxes );
00103 static GDALJP2Box *CreateAsocBox( int nCount, GDALJP2Box **papoBoxes );
00104 static GDALJP2Box *CreateLblBox( const char *pszLabel );
00105 static GDALJP2Box *CreateLabelledXMLAssoc( const char *pszLabel,
00106 const char *pszXML );
00107 static GDALJP2Box *CreateUUIDBox( const GByte *pabyUUID,
00108 int nDataSize, const GByte *pabyData );
00109 };
00110
00111
00112
00113
00114
00115 typedef struct _GDALJP2GeoTIFFBox GDALJP2GeoTIFFBox;
00116
00117 class CPL_DLL GDALJP2Metadata
00118
00119 {
00120 private:
00121 void CollectGMLData( GDALJP2Box * );
00122 int GMLSRSLookup( const char *pszURN );
00123
00124 int nGeoTIFFBoxesCount;
00125 GDALJP2GeoTIFFBox *pasGeoTIFFBoxes;
00126
00127 int nMSIGSize;
00128 GByte *pabyMSIGData;
00129
00130 int GetGMLJP2GeoreferencingInfo( int& nEPSGCode,
00131 double adfOrigin[2],
00132 double adfXVector[2],
00133 double adfYVector[2],
00134 const char*& pszComment,
00135 CPLString& osDictBox,
00136 int& bNeedAxisFlip );
00137 static CPLXMLNode* CreateGDALMultiDomainMetadataXML(
00138 GDALDataset* poSrcDS,
00139 int bMainMDDomainOnly );
00140
00141 public:
00142 char **papszGMLMetadata;
00143
00144 int bHaveGeoTransform;
00145 double adfGeoTransform[6];
00146 int bPixelIsPoint;
00147
00148 char *pszProjection;
00149
00150 int nGCPCount;
00151 GDAL_GCP *pasGCPList;
00152
00153 char **papszRPCMD;
00154
00155 char **papszMetadata;
00156 char *pszXMPMetadata;
00157 char *pszGDALMultiDomainMetadata;
00158 char *pszXMLIPR;
00159
00160 public:
00161 GDALJP2Metadata();
00162 ~GDALJP2Metadata();
00163
00164 int ReadBoxes( VSILFILE * fpVSIL );
00165
00166 int ParseJP2GeoTIFF();
00167 int ParseMSIG();
00168 int ParseGMLCoverageDesc();
00169
00170 int ReadAndParse( VSILFILE * fpVSIL );
00171 int ReadAndParse( const char *pszFilename );
00172
00173
00174 void SetProjection( const char *pszWKT );
00175 void SetGeoTransform( double * );
00176 void SetGCPs( int, const GDAL_GCP * );
00177 void SetRPCMD( char** papszRPCMDIn );
00178
00179 GDALJP2Box *CreateJP2GeoTIFF();
00180 GDALJP2Box *CreateGMLJP2( int nXSize, int nYSize );
00181 GDALJP2Box *CreateGMLJP2V2( int nXSize, int nYSize,
00182 const char* pszDefFilename,
00183 GDALDataset* poSrcDS );
00184
00185 static GDALJP2Box* CreateGDALMultiDomainMetadataXMLBox(
00186 GDALDataset* poSrcDS,
00187 int bMainMDDomainOnly );
00188 static GDALJP2Box** CreateXMLBoxes( GDALDataset* poSrcDS,
00189 int* pnBoxes );
00190 static GDALJP2Box *CreateXMPBox ( GDALDataset* poSrcDS );
00191 static GDALJP2Box *CreateIPRBox ( GDALDataset* poSrcDS );
00192 static int IsUUID_MSI(const GByte *abyUUID);
00193 static int IsUUID_XMP(const GByte *abyUUID);
00194 };
00195
00196 #endif