Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL 4 : * Purpose: MrSID driver 5 : * Author: Even Rouault, <even.rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2023, Even Rouault, <even.rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "mrsiddrivercore.h" 14 : 15 : #include "mrsiddataset_headers_include.h" 16 : 17 : /************************************************************************/ 18 : /* MrSIDIdentify() */ 19 : /* */ 20 : /* Identify method that only supports MrSID files. */ 21 : /************************************************************************/ 22 : 23 53533 : int MrSIDIdentify(GDALOpenInfo *poOpenInfo) 24 : { 25 53533 : if (poOpenInfo->nHeaderBytes < 32) 26 48914 : return FALSE; 27 : 28 4619 : if (!STARTS_WITH_CI((const char *)poOpenInfo->pabyHeader, "msid")) 29 4598 : return FALSE; 30 : 31 21 : return TRUE; 32 : } 33 : 34 : #ifdef MRSID_J2K 35 : 36 : static const unsigned char jpc_header[] = {0xff, 0x4f}; 37 : 38 : /************************************************************************/ 39 : /* JP2Identify() */ 40 : /* */ 41 : /* Identify method that only supports JPEG2000 files. */ 42 : /************************************************************************/ 43 : 44 : int MrSIDJP2Identify(GDALOpenInfo *poOpenInfo) 45 : { 46 : if (poOpenInfo->nHeaderBytes < 32) 47 : return FALSE; 48 : 49 : if (memcmp(poOpenInfo->pabyHeader, jpc_header, sizeof(jpc_header)) == 0) 50 : { 51 : const char *pszExtension = CPLGetExtension(poOpenInfo->pszFilename); 52 : 53 : if (!EQUAL(pszExtension, "jpc") && !EQUAL(pszExtension, "j2k") && 54 : !EQUAL(pszExtension, "jp2") && !EQUAL(pszExtension, "jpx") && 55 : !EQUAL(pszExtension, "j2c") && !EQUAL(pszExtension, "ntf")) 56 : return FALSE; 57 : } 58 : else if (!STARTS_WITH_CI((const char *)poOpenInfo->pabyHeader + 4, "jP ")) 59 : return FALSE; 60 : 61 : return TRUE; 62 : } 63 : 64 : #endif 65 : 66 : /************************************************************************/ 67 : /* MrSIDDriverSetCommonMetadata() */ 68 : /************************************************************************/ 69 : 70 1293 : void MrSIDDriverSetCommonMetadata(GDALDriver *poDriver) 71 : { 72 1293 : poDriver->SetDescription(MRSID_DRIVER_NAME); 73 1293 : poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES"); 74 1293 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, 75 : "Multi-resolution Seamless Image Database " 76 1293 : "(MrSID)"); 77 1293 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/mrsid.html"); 78 1293 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "sid"); 79 : 80 : #ifdef MRSID_ESDK 81 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONDATATYPES, 82 : "Byte Int16 UInt16 Int32 UInt32 " 83 : "Float32 Float64"); 84 : poDriver->SetMetadataItem( 85 : GDAL_DMD_CREATIONOPTIONLIST, 86 : "<CreationOptionList>" 87 : // Version 2 Options 88 : " <Option name='COMPRESSION' type='double' description='Set " 89 : "compression ratio (0.0 default is meant to be lossless)'/>" 90 : // Version 3 Options 91 : " <Option name='TWOPASS' type='int' description='Use twopass " 92 : "optimizer algorithm'/>" 93 : " <Option name='FILESIZE' type='int' description='Set target file " 94 : "size (0 implies lossless compression)'/>" 95 : // Version 2 and 3 Option 96 : " <Option name='WORLDFILE' type='boolean' description='Write out " 97 : "world file'/>" 98 : // Version Type 99 : " <Option name='VERSION' type='int' description='Valid versions are " 100 : "2 and 3, default = 3'/>" 101 : "</CreationOptionList>"); 102 : 103 : poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES"); 104 : #else 105 : // In read-only mode, we support VirtualIO. I don't think this is the case 106 : // for MrSIDCreateCopy(). 107 1293 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 108 : #endif 109 1293 : poDriver->pfnIdentify = MrSIDIdentify; 110 1293 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 111 1293 : } 112 : 113 : /************************************************************************/ 114 : /* JP2MrSIDDriverSetCommonMetadata() */ 115 : /************************************************************************/ 116 : 117 : #ifdef MRSID_J2K 118 : 119 : void JP2MrSIDDriverSetCommonMetadata(GDALDriver *poDriver) 120 : { 121 : poDriver->SetDescription(JP2MRSID_DRIVER_NAME); 122 : poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES"); 123 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "MrSID JPEG2000"); 124 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, 125 : "drivers/raster/jp2mrsid.html"); 126 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "jp2"); 127 : 128 : #ifdef MRSID_ESDK 129 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONDATATYPES, "Byte Int16 UInt16"); 130 : poDriver->SetMetadataItem( 131 : GDAL_DMD_CREATIONOPTIONLIST, 132 : "<CreationOptionList>" 133 : " <Option name='COMPRESSION' type='double' description='Set " 134 : "compression ratio (0.0 default is meant to be lossless)'/>" 135 : " <Option name='WORLDFILE' type='boolean' description='Write out " 136 : "world file'/>" 137 : " <Option name='XMLPROFILE' type='string' description='Use named xml " 138 : "profile file'/>" 139 : "</CreationOptionList>"); 140 : 141 : poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES"); 142 : #else 143 : /* In read-only mode, we support VirtualIO. I don't think this is the case 144 : */ 145 : /* for JP2CreateCopy() */ 146 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 147 : #endif 148 : poDriver->pfnIdentify = MrSIDJP2Identify; 149 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 150 : } 151 : 152 : #endif 153 : 154 : /************************************************************************/ 155 : /* DeclareDeferredMrSIDPlugin() */ 156 : /************************************************************************/ 157 : 158 : #ifdef PLUGIN_FILENAME 159 : void DeclareDeferredMrSIDPlugin() 160 : { 161 : if (GDALGetDriverByName(MRSID_DRIVER_NAME) != nullptr) 162 : { 163 : return; 164 : } 165 : { 166 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 167 : #ifdef PLUGIN_INSTALLATION_MESSAGE 168 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 169 : PLUGIN_INSTALLATION_MESSAGE); 170 : #endif 171 : MrSIDDriverSetCommonMetadata(poDriver); 172 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 173 : } 174 : #ifdef MRSID_J2K 175 : { 176 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 177 : #ifdef PLUGIN_INSTALLATION_MESSAGE 178 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 179 : PLUGIN_INSTALLATION_MESSAGE); 180 : #endif 181 : JP2MrSIDDriverSetCommonMetadata(poDriver); 182 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 183 : } 184 : #endif 185 : } 186 : #endif