LCOV - code coverage report
Current view: top level - frmts/basisu_ktx2 - basisudrivercore.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 41 41 100.0 %
Date: 2024-11-21 22:18:42 Functions: 6 6 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  OpenGIS Simple Features Reference Implementation
       4             :  * Purpose:  Implements Basis Universal / KTX2 driver.
       5             :  * Author:   Even Rouault, <even dot rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2022, Even Rouault <even dot rouault at spatialys.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "basisudrivercore.h"
      14             : #include "commoncore.h"
      15             : 
      16             : /************************************************************************/
      17             : /*                     BASISUDriverIdentify()                           */
      18             : /************************************************************************/
      19             : 
      20       50390 : int BASISUDriverIdentify(GDALOpenInfo *poOpenInfo)
      21             : 
      22             : {
      23       50390 :     if (STARTS_WITH(poOpenInfo->pszFilename, "BASISU:"))
      24          12 :         return true;
      25             :     // See
      26             :     // https://github.com/BinomialLLC/basis_universal/blob/master/spec/basis_spec.txt
      27       50378 :     constexpr int HEADER_SIZE = 77;
      28       50378 :     if (!(poOpenInfo->fpL != nullptr &&
      29        2770 :           poOpenInfo->nHeaderBytes >= HEADER_SIZE &&
      30        2490 :           poOpenInfo->pabyHeader[0] == 0x73 &&         // Signature
      31          65 :           poOpenInfo->pabyHeader[1] == 0x42 &&         // Signature
      32          65 :           poOpenInfo->pabyHeader[4] == HEADER_SIZE &&  // Header size
      33          65 :           poOpenInfo->pabyHeader[5] == 0))             // Header size
      34             :     {
      35       50313 :         return false;
      36             :     }
      37          65 :     const uint32_t nDataSize = CPL_LSBUINT32PTR(poOpenInfo->pabyHeader + 8);
      38          65 :     VSIFSeekL(poOpenInfo->fpL, 0, SEEK_END);
      39          65 :     const auto nFileSize = VSIFTellL(poOpenInfo->fpL);
      40          65 :     VSIFSeekL(poOpenInfo->fpL, 0, SEEK_SET);
      41          65 :     return nDataSize + HEADER_SIZE == nFileSize;
      42             : }
      43             : 
      44             : /************************************************************************/
      45             : /*                      BASISUDriverSetCommonMetadata()                 */
      46             : /************************************************************************/
      47             : 
      48        1303 : void BASISUDriverSetCommonMetadata(GDALDriver *poDriver)
      49             : {
      50        1303 :     poDriver->SetDescription(BASISU_DRIVER_NAME);
      51        1303 :     poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES");
      52        1303 :     poDriver->SetMetadataItem(GDAL_DMD_LONGNAME,
      53        1303 :                               "Basis Universal texture format");
      54        1303 :     poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/basisu.html");
      55        1303 :     poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "basis");
      56        1303 :     poDriver->SetMetadataItem(GDAL_DMD_CREATIONDATATYPES, "Byte");
      57             : 
      58        1303 :     poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES");
      59             : 
      60        1303 :     poDriver->SetMetadataItem(
      61             :         GDAL_DMD_CREATIONOPTIONLIST,
      62        2606 :         GDAL_KTX2_BASISU_GetCreationOptions(/* bIsKTX2 = */ false).c_str());
      63             : 
      64        1303 :     poDriver->pfnIdentify = BASISUDriverIdentify;
      65        1303 :     poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES");
      66        1303 :     poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES");
      67        1303 : }
      68             : 
      69             : /************************************************************************/
      70             : /*                     DeclareDeferredBASISUPlugin()                    */
      71             : /************************************************************************/
      72             : 
      73             : #ifdef PLUGIN_FILENAME
      74        1595 : void DeclareDeferredBASISUPlugin()
      75             : {
      76        1595 :     if (GDALGetDriverByName(BASISU_DRIVER_NAME) != nullptr)
      77             :     {
      78         302 :         return;
      79             :     }
      80        1293 :     auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME);
      81             : #ifdef PLUGIN_INSTALLATION_MESSAGE
      82             :     poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE,
      83             :                               PLUGIN_INSTALLATION_MESSAGE);
      84             : #endif
      85        1293 :     BASISUDriverSetCommonMetadata(poDriver);
      86        1293 :     GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver);
      87             : }
      88             : 
      89        1595 : void DeclareDeferredBASISU_KTX2Plugin()
      90             : {
      91        1595 :     DeclareDeferredBASISUPlugin();
      92        1595 :     DeclareDeferredKTX2Plugin();
      93        1595 : }
      94             : 
      95             : #endif

Generated by: LCOV version 1.14