Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: HEIF Driver 4 : * Author: Even Rouault <even.rouault at spatialys.com> 5 : * 6 : ****************************************************************************** 7 : * Copyright (c) 2020, Even Rouault <even.rouault at spatialys.com> 8 : * 9 : * Permission is hereby granted, free of charge, to any person obtaining a 10 : * copy of this software and associated documentation files (the "Software"), 11 : * to deal in the Software without restriction, including without limitation 12 : * the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 : * and/or sell copies of the Software, and to permit persons to whom the 14 : * Software is furnished to do so, subject to the following conditions: 15 : * 16 : * The above copyright notice and this permission notice shall be included 17 : * in all copies or substantial portions of the Software. 18 : * 19 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 22 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 : * DEALINGS IN THE SOFTWARE. 26 : ****************************************************************************/ 27 : 28 : #include "include_libheif.h" 29 : 30 : #include "heifdrivercore.h" 31 : 32 : /************************************************************************/ 33 : /* HEIFDriverIdentifySimplified() */ 34 : /************************************************************************/ 35 : 36 47875 : int HEIFDriverIdentifySimplified(GDALOpenInfo *poOpenInfo) 37 : 38 : { 39 47875 : if (STARTS_WITH_CI(poOpenInfo->pszFilename, "HEIF:")) 40 8 : return true; 41 : 42 47867 : if (poOpenInfo->nHeaderBytes < 12 || poOpenInfo->fpL == nullptr) 43 45342 : return false; 44 : 45 : // Simplistic test... 46 2525 : const unsigned char abySig1[] = "\x00" 47 : "\x00" 48 : "\x00" 49 : "\x20" 50 : "ftypheic"; 51 2525 : const unsigned char abySig2[] = "\x00" 52 : "\x00" 53 : "\x00" 54 : "\x18" 55 : "ftypheic"; 56 2525 : const unsigned char abySig3[] = "\x00" 57 : "\x00" 58 : "\x00" 59 : "\x18" 60 : "ftypmif1" 61 : "\x00" 62 : "\x00" 63 : "\x00" 64 : "\x00" 65 : "mif1heic"; 66 5050 : return (poOpenInfo->nHeaderBytes >= static_cast<int>(sizeof(abySig1)) && 67 2525 : memcmp(poOpenInfo->pabyHeader, abySig1, sizeof(abySig1)) == 0) || 68 2525 : (poOpenInfo->nHeaderBytes >= static_cast<int>(sizeof(abySig2)) && 69 7568 : memcmp(poOpenInfo->pabyHeader, abySig2, sizeof(abySig2)) == 0) || 70 2518 : (poOpenInfo->nHeaderBytes >= static_cast<int>(sizeof(abySig3)) && 71 5030 : memcmp(poOpenInfo->pabyHeader, abySig3, sizeof(abySig3)) == 0); 72 : } 73 : 74 : /************************************************************************/ 75 : /* HEIFDriverSetCommonMetadata() */ 76 : /************************************************************************/ 77 : 78 1227 : void HEIFDriverSetCommonMetadata(GDALDriver *poDriver) 79 : { 80 1227 : poDriver->SetDescription(DRIVER_NAME); 81 1227 : poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES"); 82 1227 : poDriver->SetMetadataItem( 83 : GDAL_DMD_LONGNAME, 84 1227 : "ISO/IEC 23008-12:2017 High Efficiency Image File Format"); 85 1227 : poDriver->SetMetadataItem(GDAL_DMD_MIMETYPE, "image/heic"); 86 1227 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/heif.html"); 87 1227 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "heic"); 88 : #ifdef HAS_CUSTOM_FILE_READER 89 1227 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 90 : #endif 91 : 92 1227 : poDriver->SetMetadataItem("LIBHEIF_VERSION", LIBHEIF_VERSION); 93 : 94 1227 : poDriver->pfnIdentify = HEIFDriverIdentifySimplified; 95 1227 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 96 1227 : } 97 : 98 : /************************************************************************/ 99 : /* DeclareDeferredHEIFPlugin() */ 100 : /************************************************************************/ 101 : 102 : #ifdef PLUGIN_FILENAME 103 1522 : void DeclareDeferredHEIFPlugin() 104 : { 105 1522 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 106 : { 107 301 : return; 108 : } 109 1221 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 110 : #ifdef PLUGIN_INSTALLATION_MESSAGE 111 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 112 : PLUGIN_INSTALLATION_MESSAGE); 113 : #endif 114 1221 : HEIFDriverSetCommonMetadata(poDriver); 115 1221 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 116 : } 117 : #endif