Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: GDAL WEBP Driver 4 : * Purpose: Implement GDAL WEBP Support based on libwebp 5 : * Author: Even Rouault, <even dot rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2011-2013, Even Rouault <even dot rouault at spatialys.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "webp_headers.h" 14 : #include "webpdrivercore.h" 15 : 16 : /************************************************************************/ 17 : /* WEBPDriverIdentify() */ 18 : /************************************************************************/ 19 : 20 51040 : int WEBPDriverIdentify(GDALOpenInfo *poOpenInfo) 21 : 22 : { 23 51040 : const int nHeaderBytes = poOpenInfo->nHeaderBytes; 24 51040 : const GByte *pabyHeader = poOpenInfo->pabyHeader; 25 : 26 51040 : if (nHeaderBytes < 20) 27 47782 : return FALSE; 28 : 29 3933 : return memcmp(pabyHeader, "RIFF", 4) == 0 && 30 3933 : memcmp(pabyHeader + 8, "WEBP", 4) == 0 && 31 675 : (memcmp(pabyHeader + 12, "VP8 ", 4) == 0 || 32 562 : memcmp(pabyHeader + 12, "VP8L", 4) == 0 || 33 3781 : memcmp(pabyHeader + 12, "VP8X", 4) == 0); 34 : } 35 : 36 : /************************************************************************/ 37 : /* WEBPDriverSetCommonMetadata() */ 38 : /************************************************************************/ 39 : 40 1304 : void WEBPDriverSetCommonMetadata(GDALDriver *poDriver) 41 : { 42 1304 : poDriver->SetDescription(DRIVER_NAME); 43 1304 : poDriver->SetMetadataItem(GDAL_DCAP_RASTER, "YES"); 44 1304 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "WEBP"); 45 1304 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/raster/webp.html"); 46 1304 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSION, "webp"); 47 1304 : poDriver->SetMetadataItem(GDAL_DMD_MIMETYPE, "image/webp"); 48 1304 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONDATATYPES, "Byte"); 49 : 50 1304 : poDriver->SetMetadataItem( 51 : GDAL_DMD_CREATIONOPTIONLIST, 52 : "<CreationOptionList>\n" 53 : " <Option name='QUALITY' type='float' description='good=100, bad=0' " 54 : "default='75'/>\n" 55 : #if WEBP_ENCODER_ABI_VERSION >= 0x0100 56 : " <Option name='LOSSLESS' type='boolean' description='Whether " 57 : "lossless compression should be used' default='FALSE'/>\n" 58 : #endif 59 : " <Option name='LOSSLESS_COPY' type='string-select' " 60 : "description='Whether conversion should be lossless' default='AUTO'>" 61 : " <Value>AUTO</Value>" 62 : " <Value>YES</Value>" 63 : " <Value>NO</Value>" 64 : " </Option>" 65 : " <Option name='PRESET' type='string-select' description='kind of " 66 : "image' default='DEFAULT'>\n" 67 : " <Value>DEFAULT</Value>\n" 68 : " <Value>PICTURE</Value>\n" 69 : " <Value>PHOTO</Value>\n" 70 : " <Value>DRAWING</Value>\n" 71 : " <Value>ICON</Value>\n" 72 : " <Value>TEXT</Value>\n" 73 : " </Option>\n" 74 : " <Option name='TARGETSIZE' type='int' description='if non-zero, " 75 : "desired target size in bytes. Has precedence over QUALITY'/>\n" 76 : " <Option name='PSNR' type='float' description='if non-zero, minimal " 77 : "distortion to to achieve. Has precedence over TARGETSIZE'/>\n" 78 : " <Option name='METHOD' type='int' description='quality/speed " 79 : "trade-off. fast=0, slower-better=6' default='4'/>\n" 80 : " <Option name='SEGMENTS' type='int' description='maximum number of " 81 : "segments [1-4]' default='4'/>\n" 82 : " <Option name='SNS_STRENGTH' type='int' description='Spatial Noise " 83 : "Shaping. off=0, maximum=100' default='50'/>\n" 84 : " <Option name='FILTER_STRENGTH' type='int' description='Filter " 85 : "strength. off=0, strongest=100' default='20'/>\n" 86 : " <Option name='FILTER_SHARPNESS' type='int' description='Filter " 87 : "sharpness. off=0, least sharp=7' default='0'/>\n" 88 : " <Option name='FILTER_TYPE' type='int' description='Filtering type. " 89 : "simple=0, strong=1' default='0'/>\n" 90 : " <Option name='AUTOFILTER' type='int' description=\"Auto adjust " 91 : "filter's strength. off=0, on=1\" default='0'/>\n" 92 : " <Option name='PASS' type='int' description='Number of entropy " 93 : "analysis passes [1-10]' default='1'/>\n" 94 : " <Option name='PREPROCESSING' type='int' description='Preprocessing " 95 : "filter. none=0, segment-smooth=1' default='0'/>\n" 96 : " <Option name='PARTITIONS' type='int' description='log2(number of " 97 : "token partitions) in [0..3]' default='0'/>\n" 98 : #if WEBP_ENCODER_ABI_VERSION >= 0x0002 99 : " <Option name='PARTITION_LIMIT' type='int' description='quality " 100 : "degradation allowed to fit the 512k limit on prediction modes coding " 101 : "(0=no degradation, 100=full)' default='0'/>\n" 102 : #endif 103 : #if WEBP_ENCODER_ABI_VERSION >= 0x0209 104 : " <Option name='EXACT' type='int' description='preserve the exact " 105 : "RGB values under transparent area. off=0, on=1' default='0'/>\n" 106 : #endif 107 1304 : "</CreationOptionList>\n"); 108 : 109 1304 : poDriver->SetMetadataItem(GDAL_DCAP_VIRTUALIO, "YES"); 110 : 111 1304 : poDriver->pfnIdentify = WEBPDriverIdentify; 112 : 113 1304 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 114 1304 : poDriver->SetMetadataItem(GDAL_DCAP_CREATECOPY, "YES"); 115 1304 : } 116 : 117 : /************************************************************************/ 118 : /* DeclareDeferredWEBPPlugin() */ 119 : /************************************************************************/ 120 : 121 : #ifdef PLUGIN_FILENAME 122 1595 : void DeclareDeferredWEBPPlugin() 123 : { 124 1595 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 125 : { 126 302 : return; 127 : } 128 1293 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 129 : #ifdef PLUGIN_INSTALLATION_MESSAGE 130 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 131 : PLUGIN_INSTALLATION_MESSAGE); 132 : #endif 133 1293 : WEBPDriverSetCommonMetadata(poDriver); 134 1293 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 135 : } 136 : #endif