LCOV - code coverage report
Current view: top level - frmts/mrsid - mrsiddrivercore.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 17 17 100.0 %
Date: 2024-05-06 22:33:47 Functions: 2 2 100.0 %

          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             :  * Permission is hereby granted, free of charge, to any person obtaining a
      11             :  * copy of this software and associated documentation files (the "Software"),
      12             :  * to deal in the Software without restriction, including without limitation
      13             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      14             :  * and/or sell copies of the Software, and to permit persons to whom the
      15             :  * Software is furnished to do so, subject to the following conditions:
      16             :  *
      17             :  * The above copyright notice and this permission notice shall be included
      18             :  * in all copies or substantial portions of the Software.
      19             :  *
      20             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      21             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      22             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      23             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      24             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      25             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      26             :  * DEALINGS IN THE SOFTWARE.
      27             :  ****************************************************************************/
      28             : 
      29             : #include "mrsiddrivercore.h"
      30             : 
      31             : #include "mrsiddataset_headers_include.h"
      32             : 
      33             : /************************************************************************/
      34             : /*                         MrSIDIdentify()                              */
      35             : /*                                                                      */
      36             : /*          Identify method that only supports MrSID files.             */
      37             : /************************************************************************/
      38             : 
      39       50791 : int MrSIDIdentify(GDALOpenInfo *poOpenInfo)
      40             : {
      41       50791 :     if (poOpenInfo->nHeaderBytes < 32)
      42       46348 :         return FALSE;
      43             : 
      44        4443 :     if (!STARTS_WITH_CI((const char *)poOpenInfo->pabyHeader, "msid"))
      45        4419 :         return FALSE;
      46             : 
      47          24 :     return TRUE;
      48             : }
      49             : 
      50             : #ifdef MRSID_J2K
      51             : 
      52             : static const unsigned char jpc_header[] = {0xff, 0x4f};
      53             : 
      54             : /************************************************************************/
      55             : /*                         JP2Identify()                                */
      56             : /*                                                                      */
      57             : /*        Identify method that only supports JPEG2000 files.            */
      58             : /************************************************************************/
      59             : 
      60             : int MrSIDJP2Identify(GDALOpenInfo *poOpenInfo)
      61             : {
      62             :     if (poOpenInfo->nHeaderBytes < 32)
      63             :         return FALSE;
      64             : 
      65             :     if (memcmp(poOpenInfo->pabyHeader, jpc_header, sizeof(jpc_header)) == 0)
      66             :     {
      67             :         const char *pszExtension = CPLGetExtension(poOpenInfo->pszFilename);
      68             : 
      69             :         if (!EQUAL(pszExtension, "jpc") && !EQUAL(pszExtension, "j2k") &&
      70             :             !EQUAL(pszExtension, "jp2") && !EQUAL(pszExtension, "jpx") &&
      71             :             !EQUAL(pszExtension, "j2c") && !EQUAL(pszExtension, "ntf"))
      72             :             return FALSE;
      73             :     }
      74             :     else if (!STARTS_WITH_CI((const char *)poOpenInfo->pabyHeader + 4, "jP  "))
      75             :         return FALSE;
      76             : 
      77             :     return TRUE;
      78             : }
      79             : 
      80             : #endif
      81             : 
      82             : /************************************************************************/
      83             : /*                     MrSIDDriverSetCommonMetadata()                   */
      84             : /************************************************************************/
      85             : 
      86        1219 : void MrSIDDriverSetCommonMetadata(GDALDriver *poDriver)
      87             : {
      88        1219 :     poDriver->SetDescription(MRSID_DRIVER_NAME);
      89        1219 :     poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES");
      90        1219 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME,
      91             :                               "Multi-resolution Seamless Image Database "
      92        1219 :                               "(MrSID)");
      93        1219 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/mrsid.html");
      94        1219 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "sid");
      95             : 
      96             : #ifdef MRSID_ESDK
      97             :     poDriver->SetMetadataItem(GDAL_DMD_CREATIONDATATYPES,
      98             :                               "Byte Int16 UInt16 Int32 UInt32 "
      99             :                               "Float32 Float64");
     100             :     poDriver->SetMetadataItem(
     101             :         GDAL_DMD_CREATIONOPTIONLIST,
     102             :         "<CreationOptionList>"
     103             :         // Version 2 Options
     104             :         "   <Option name='COMPRESSION' type='double' description='Set "
     105             :         "compression ratio (0.0 default is meant to be lossless)'/>"
     106             :         // Version 3 Options
     107             :         "   <Option name='TWOPASS' type='int' description='Use twopass "
     108             :         "optimizer algorithm'/>"
     109             :         "   <Option name='FILESIZE' type='int' description='Set target file "
     110             :         "size (0 implies lossless compression)'/>"
     111             :         // Version 2 and 3 Option
     112             :         "   <Option name='WORLDFILE' type='boolean' description='Write out "
     113             :         "world file'/>"
     114             :         // Version Type
     115             :         "   <Option name='VERSION' type='int' description='Valid versions are "
     116             :         "2 and 3, default = 3'/>"
     117             :         "</CreationOptionList>");
     118             : 
     119             :     poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES");
     120             : #else
     121             :     // In read-only mode, we support VirtualIO. I don't think this is the case
     122             :     // for MrSIDCreateCopy().
     123        1219 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
     124             : #endif
     125        1219 :     poDriver->pfnIdentify = MrSIDIdentify;
     126        1219 :     poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES");
     127        1219 : }
     128             : 
     129             : /************************************************************************/
     130             : /*                  JP2MrSIDDriverSetCommonMetadata()                   */
     131             : /************************************************************************/
     132             : 
     133             : #ifdef MRSID_J2K
     134             : 
     135             : void JP2MrSIDDriverSetCommonMetadata(GDALDriver *poDriver)
     136             : {
     137             :     poDriver->SetDescription(JP2MRSID_DRIVER_NAME);
     138             :     poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES");
     139             :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "MrSID JPEG2000");
     140             :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC,
     141             :                               "drivers/raster/jp2mrsid.html");
     142             :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "jp2");
     143             : 
     144             : #ifdef MRSID_ESDK
     145             :     poDriver->SetMetadataItem(GDAL_DMD_CREATIONDATATYPES, "Byte Int16 UInt16");
     146             :     poDriver->SetMetadataItem(
     147             :         GDAL_DMD_CREATIONOPTIONLIST,
     148             :         "<CreationOptionList>"
     149             :         "   <Option name='COMPRESSION' type='double' description='Set "
     150             :         "compression ratio (0.0 default is meant to be lossless)'/>"
     151             :         "   <Option name='WORLDFILE' type='boolean' description='Write out "
     152             :         "world file'/>"
     153             :         "   <Option name='XMLPROFILE' type='string' description='Use named xml "
     154             :         "profile file'/>"
     155             :         "</CreationOptionList>");
     156             : 
     157             :     poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES");
     158             : #else
     159             :     /* In read-only mode, we support VirtualIO. I don't think this is the case
     160             :      */
     161             :     /* for JP2CreateCopy() */
     162             :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
     163             : #endif
     164             :     poDriver->pfnIdentify = MrSIDJP2Identify;
     165             :     poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES");
     166             : }
     167             : 
     168             : #endif
     169             : 
     170             : /************************************************************************/
     171             : /*                     DeclareDeferredMrSIDPlugin()                     */
     172             : /************************************************************************/
     173             : 
     174             : #ifdef PLUGIN_FILENAME
     175             : void DeclareDeferredMrSIDPlugin()
     176             : {
     177             :     if (GDALGetDriverByName(MRSID_DRIVER_NAME) != nullptr)
     178             :     {
     179             :         return;
     180             :     }
     181             :     {
     182             :         auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME);
     183             : #ifdef PLUGIN_INSTALLATION_MESSAGE
     184             :         poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE,
     185             :                                   PLUGIN_INSTALLATION_MESSAGE);
     186             : #endif
     187             :         MrSIDDriverSetCommonMetadata(poDriver);
     188             :         GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver);
     189             :     }
     190             : #ifdef MRSID_J2K
     191             :     {
     192             :         auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME);
     193             : #ifdef PLUGIN_INSTALLATION_MESSAGE
     194             :         poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE,
     195             :                                   PLUGIN_INSTALLATION_MESSAGE);
     196             : #endif
     197             :         JP2MrSIDDriverSetCommonMetadata(poDriver);
     198             :         GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver);
     199             :     }
     200             : #endif
     201             : }
     202             : #endif

Generated by: LCOV version 1.14