Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: PNG Driver 4 : * Purpose: Implement GDAL PNG Support 5 : * Author: Frank Warmerdam, warmerda@home.com 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2000, Frank Warmerdam 9 : * Copyright (c) 2007-2014, Even Rouault <even dot rouault at spatialys.com> 10 : * 11 : * SPDX-License-Identifier: MIT 12 : ******************************************************************************/ 13 : 14 : #include "pngdrivercore.h" 15 : 16 : /************************************************************************/ 17 : /* PNGDriverIdentify() */ 18 : /************************************************************************/ 19 : 20 70803 : int PNGDriverIdentify(GDALOpenInfo *poOpenInfo) 21 : 22 : { 23 70803 : constexpr GByte png_signature[] = {137, 80, 78, 71, 13, 10, 26, 10}; 24 70803 : if (poOpenInfo->fpL == nullptr || 25 17636 : poOpenInfo->nHeaderBytes < static_cast<int>(sizeof(png_signature))) 26 53441 : return FALSE; 27 : 28 17362 : if (memcmp(poOpenInfo->pabyHeader, png_signature, sizeof(png_signature)) != 29 : 0) 30 7060 : return FALSE; 31 : 32 10302 : return TRUE; 33 : } 34 : 35 : /************************************************************************/ 36 : /* PNGDriverSetCommonMetadata() */ 37 : /************************************************************************/ 38 : 39 1339 : void PNGDriverSetCommonMetadata(GDALDriver *poDriver) 40 : { 41 1339 : poDriver->SetDescription(DRIVER_NAME); 42 1339 : poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES"); 43 1339 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "Portable Network Graphics"); 44 1339 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/png.html"); 45 1339 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "png"); 46 1339 : poDriver->SetMetadataItem(GDAL_DMD_MIMETYPE, "image/png"); 47 : 48 1339 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONDATATYPES, "Byte UInt16"); 49 1339 : poDriver->SetMetadataItem( 50 : GDAL_DMD_CREATIONOPTIONLIST, 51 : "<CreationOptionList>\n" 52 : " <Option name='WORLDFILE' type='boolean' description='Create world " 53 : "file' default='FALSE'/>\n" 54 : " <Option name='ZLEVEL' type='int' description='DEFLATE compression " 55 : "level 1-9' default='6'/>\n" 56 : " <Option name='SOURCE_ICC_PROFILE' type='string' description='ICC " 57 : "Profile'/>\n" 58 : " <Option name='SOURCE_ICC_PROFILE_NAME' type='string' " 59 : "description='ICC Profile name'/>\n" 60 : " <Option name='SOURCE_PRIMARIES_RED' type='string' " 61 : "description='x,y,1.0 (xyY) red chromaticity'/>\n" 62 : " <Option name='SOURCE_PRIMARIES_GREEN' type='string' " 63 : "description='x,y,1.0 (xyY) green chromaticity'/>\n" 64 : " <Option name='SOURCE_PRIMARIES_BLUE' type='string' " 65 : "description='x,y,1.0 (xyY) blue chromaticity'/>\n" 66 : " <Option name='SOURCE_WHITEPOINT' type='string' " 67 : "description='x,y,1.0 (xyY) whitepoint'/>\n" 68 : " <Option name='PNG_GAMMA' type='string' description='Gamma'/>\n" 69 : " <Option name='TITLE' type='string' description='Title'/>\n" 70 : " <Option name='DESCRIPTION' type='string' " 71 : "description='Description'/>\n" 72 : " <Option name='COPYRIGHT' type='string' description='Copyright'/>\n" 73 : " <Option name='COMMENT' type='string' description='Comment'/>\n" 74 : " <Option name='WRITE_METADATA_AS_TEXT' type='boolean' " 75 : "description='Whether to write source dataset metadata in TEXT chunks' " 76 : "default='FALSE'/>\n" 77 : " <Option name='NBITS' type='int' description='Force output bit " 78 : "depth: 1, 2 or 4'/>\n" 79 1339 : "</CreationOptionList>\n"); 80 : 81 1339 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 82 : 83 1339 : poDriver->pfnIdentify = PNGDriverIdentify; 84 1339 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 85 1339 : poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES"); 86 1339 : } 87 : 88 : /************************************************************************/ 89 : /* DeclareDeferredPNGPlugin() */ 90 : /************************************************************************/ 91 : 92 : #ifdef PLUGIN_FILENAME 93 1595 : void DeclareDeferredPNGPlugin() 94 : { 95 1595 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 96 : { 97 302 : return; 98 : } 99 1293 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 100 : #ifdef PLUGIN_INSTALLATION_MESSAGE 101 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 102 : PLUGIN_INSTALLATION_MESSAGE); 103 : #endif 104 1293 : PNGDriverSetCommonMetadata(poDriver); 105 1293 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 106 : } 107 : #endif