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 "ktx2drivercore.h" 14 : #include "commoncore.h" 15 : 16 : /************************************************************************/ 17 : /* KTX2DriverIdentify() */ 18 : /************************************************************************/ 19 : 20 50385 : int KTX2DriverIdentify(GDALOpenInfo *poOpenInfo) 21 : 22 : { 23 50385 : constexpr GByte KTX2Signature[] = {0xAB, 0x4B, 0x54, 0x58, 0x20, 0x32, 24 : 0x30, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A}; 25 50385 : if (STARTS_WITH(poOpenInfo->pszFilename, "KTX2:")) 26 16 : return true; 27 53126 : return poOpenInfo->fpL != nullptr && 28 2757 : poOpenInfo->nHeaderBytes >= 29 53126 : static_cast<int>(sizeof(KTX2Signature)) && 30 2548 : memcmp(poOpenInfo->pabyHeader, KTX2Signature, 31 50369 : sizeof(KTX2Signature)) == 0; 32 : } 33 : 34 : /************************************************************************/ 35 : /* KTX2DriverSetCommonMetadata() */ 36 : /************************************************************************/ 37 : 38 1303 : void KTX2DriverSetCommonMetadata(GDALDriver *poDriver) 39 : { 40 1303 : poDriver->SetDescription(KTX2_DRIVER_NAME); 41 1303 : poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES"); 42 1303 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "KTX2 texture format"); 43 1303 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/ktx2.html"); 44 1303 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "ktx2"); 45 1303 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONDATATYPES, "Byte"); 46 : 47 1303 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 48 : 49 1303 : poDriver->SetMetadataItem( 50 : GDAL_DMD_CREATIONOPTIONLIST, 51 2606 : GDAL_KTX2_BASISU_GetCreationOptions(/* bIsKTX2 = */ true).c_str()); 52 : 53 1303 : poDriver->pfnIdentify = KTX2DriverIdentify; 54 1303 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 55 1303 : poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES"); 56 1303 : } 57 : 58 : /************************************************************************/ 59 : /* DeclareDeferredKTX2Plugin() */ 60 : /************************************************************************/ 61 : 62 : #ifdef PLUGIN_FILENAME 63 1595 : void DeclareDeferredKTX2Plugin() 64 : { 65 1595 : if (GDALGetDriverByName(KTX2_DRIVER_NAME) != nullptr) 66 : { 67 302 : return; 68 : } 69 1293 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 70 : #ifdef PLUGIN_INSTALLATION_MESSAGE 71 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 72 : PLUGIN_INSTALLATION_MESSAGE); 73 : #endif 74 1293 : KTX2DriverSetCommonMetadata(poDriver); 75 1293 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 76 : } 77 : #endif