LCOV - code coverage report
Current view: top level - frmts/mrf - mrfdrivercore.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 39 40 97.5 %
Date: 2025-01-18 12:42:00 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2002-2012, California Institute of Technology.
       3             :  * All rights reserved.  Based on Government Sponsored Research under contracts
       4             :  * NAS7-1407 and/or NAS7-03001.
       5             :  *
       6             :  * Redistribution and use in source and binary forms, with or without
       7             :  * modification, are permitted provided that the following conditions are met:
       8             :  *   1. Redistributions of source code must retain the above copyright notice,
       9             :  * this list of conditions and the following disclaimer.
      10             :  *   2. Redistributions in binary form must reproduce the above copyright
      11             :  * notice, this list of conditions and the following disclaimer in the
      12             :  * documentation and/or other materials provided with the distribution.
      13             :  *   3. Neither the name of the California Institute of Technology (Caltech),
      14             :  * its operating division the Jet Propulsion Laboratory (JPL), the National
      15             :  * Aeronautics and Space Administration (NASA), nor the names of its
      16             :  * contributors may be used to endorse or promote products derived from this
      17             :  * software without specific prior written permission.
      18             :  *
      19             :  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
      20             :  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      21             :  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
      22             :  * ARE DISCLAIMED. IN NO EVENT SHALL THE CALIFORNIA INSTITUTE OF TECHNOLOGY BE
      23             :  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
      24             :  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
      25             :  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
      26             :  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
      27             :  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
      28             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
      29             :  * POSSIBILITY OF SUCH DAMAGE.
      30             :  *
      31             :  * Copyright 2014-2021 Esri
      32             :  *
      33             :  * Licensed under the Apache License, Version 2.0 (the "License");
      34             :  * you may not use this file except in compliance with the License.
      35             :  * You may obtain a copy of the License at
      36             :  *
      37             :  * http://www.apache.org/licenses/LICENSE-2.0
      38             :  *
      39             :  * Unless required by applicable law or agreed to in writing, software
      40             :  * distributed under the License is distributed on an "AS IS" BASIS,
      41             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      42             :  * See the License for the specific language governing permissions and
      43             :  * limitations under the License.
      44             :  *
      45             :  *  Functions used by the driver, should have prototypes in the header file
      46             :  *
      47             :  *  Author: Lucian Plesea
      48             :  */
      49             : 
      50             : #include "mrfdrivercore.h"
      51             : #include "cpl_string.h"
      52             : 
      53             : #if defined(LERC)
      54        3891 : static bool IsLerc1(const char *s)
      55             : {
      56             :     static const char L1sig[] = "CntZImage ";
      57        3891 :     return !strncmp(s, L1sig, sizeof(L1sig) - 1);
      58             : }
      59             : 
      60        3881 : static bool IsLerc2(const char *s)
      61             : {
      62             :     static const char L2sig[] = "Lerc2 ";
      63        3881 :     return !strncmp(s, L2sig, sizeof(L2sig) - 1);
      64             : }
      65             : #endif
      66             : 
      67             : /************************************************************************/
      68             : /*                     MRFDriverIdentify()                              */
      69             : /************************************************************************/
      70             : 
      71             : /**
      72             :  *\brief Idenfity a MRF file, lightweight
      73             :  *
      74             :  * Lightweight test, otherwise Open gets called.
      75             :  *
      76             :  */
      77       53043 : int MRFDriverIdentify(GDALOpenInfo *poOpenInfo)
      78             : 
      79             : {
      80       53043 :     if (STARTS_WITH(poOpenInfo->pszFilename, "<MRF_META>"))
      81           0 :         return TRUE;
      82             : 
      83      106068 :     CPLString fn(poOpenInfo->pszFilename);
      84       53041 :     if (fn.find(":MRF:") != std::string::npos)
      85          10 :         return TRUE;
      86             : 
      87       53017 :     if (poOpenInfo->nHeaderBytes < 10)
      88       48695 :         return FALSE;
      89             : 
      90        4322 :     const char *pszHeader = reinterpret_cast<char *>(poOpenInfo->pabyHeader);
      91        4322 :     fn.assign(pszHeader, pszHeader + poOpenInfo->nHeaderBytes);
      92        4320 :     if (STARTS_WITH(fn, "<MRF_META>"))
      93         429 :         return TRUE;
      94             : 
      95             : #if defined(LERC)  // Could be single LERC tile
      96        3891 :     if (IsLerc1(fn) || IsLerc2(fn))
      97          12 :         return TRUE;
      98             : #endif
      99             : 
     100             :     // accept a tar file if the first file has no folder look like an MRF
     101        3615 :     if (poOpenInfo->eAccess == GA_ReadOnly && fn.size() > 600 &&
     102        2496 :         (fn[262] == 0 || fn[262] == 32) && STARTS_WITH(fn + 257, "ustar") &&
     103        7496 :         strlen(CPLGetPathSafe(fn).c_str()) == 0 &&
     104           2 :         STARTS_WITH(fn + 512, "<MRF_META>"))
     105             :     {
     106           2 :         return TRUE;
     107             :     }
     108             : 
     109        3877 :     return FALSE;
     110             : }
     111             : 
     112             : /************************************************************************/
     113             : /*                      MRFDriverSetCommonMetadata()                    */
     114             : /************************************************************************/
     115             : 
     116        1381 : void MRFDriverSetCommonMetadata(GDALDriver *poDriver)
     117             : {
     118        1381 :     poDriver->SetDescription(DRIVER_NAME);
     119        1381 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "Meta Raster Format");
     120        1381 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/marfa.html");
     121        1381 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "mrf");
     122        1381 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
     123        1381 :     poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES");
     124             : 
     125        1381 :     poDriver->SetMetadataItem(
     126             :         GDAL_DMD_OPENOPTIONLIST,
     127             :         "<OpenOptionList>"
     128             :         "    <Option name='NOERRORS' type='boolean' description='Ignore "
     129             :         "decompression errors' default='FALSE'/>"
     130             :         "    <Option name='ZSLICE' type='int' description='For a third "
     131             :         "dimension MRF, pick a slice' default='0'/>"
     132        1381 :         "</OpenOptionList>");
     133             : 
     134             :     // These will need to be revisited, do we support complex data types too?
     135        1381 :     poDriver->SetMetadataItem(
     136             :         GDAL_DMD_CREATIONDATATYPES,
     137        1381 :         "Byte Int8 Int16 UInt16 Int32 UInt32 Int64 UInt64 Float32 Float64");
     138             : 
     139        1381 :     poDriver->pfnIdentify = MRFDriverIdentify;
     140        1381 :     poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES");
     141        1381 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATE, "YES");
     142        1381 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES");
     143        1381 : }
     144             : 
     145             : /************************************************************************/
     146             : /*                     DeclareDeferredMRFPlugin()                       */
     147             : /************************************************************************/
     148             : 
     149             : #ifdef PLUGIN_FILENAME
     150             : void DeclareDeferredMRFPlugin()
     151             : {
     152             :     if (GDALGetDriverByName(DRIVER_NAME) != nullptr)
     153             :     {
     154             :         return;
     155             :     }
     156             :     auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME);
     157             : #ifdef PLUGIN_INSTALLATION_MESSAGE
     158             :     poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE,
     159             :                               PLUGIN_INSTALLATION_MESSAGE);
     160             : #endif
     161             :     MRFDriverSetCommonMetadata(poDriver);
     162             :     GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver);
     163             : }
     164             : #endif

Generated by: LCOV version 1.14