diff --git a/ChangeLog b/ChangeLog index 3eee55ae..4b0d2500 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +16/01/2024: + - Added ability to specify lossless WebP compression by specifying a quality factor of -1 + + 15/01/2024: - Fix to IIIF size calculation for region requests that go beyond the boundaries of the image diff --git a/src/Environment.h b/src/Environment.h index 076d10cc..a3050f37 100644 --- a/src/Environment.h +++ b/src/Environment.h @@ -148,8 +148,8 @@ class Environment { int quality; if( envpara ){ quality = atoi( envpara ); - if( quality > 100 ) quality = 900; - if( quality < 0 ) quality = 0; + if( quality > 100 ) quality = 100; + if( quality < -1 ) quality = -1; // Allow -1 = lossless } else quality = WEBP_QUALITY; diff --git a/src/Main.cc b/src/Main.cc index a5df5f69..1d10a798 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -385,7 +385,9 @@ int main( int argc, char *argv[] ) logfile << "Setting default PNG compression level to " << png_quality << endl; #endif #ifdef HAVE_WEBP - logfile << "Setting default WebP compression level to " << webp_quality << endl; + logfile << "Setting default WebP compression level to "; + if( webp_quality == -1 ) logfile << "lossless" << endl; + else logfile << webp_quality << endl; #endif logfile << "Setting maximum CVT size to " << max_CVT << endl; logfile << "Setting HTTP Cache-Control header to '" << cache_control << "'" << endl; diff --git a/src/WebPCompressor.h b/src/WebPCompressor.h index 5466ab96..7e870773 100644 --- a/src/WebPCompressor.h +++ b/src/WebPCompressor.h @@ -1,7 +1,7 @@ /* WebP Compressor Class: Handles alpha channels, ICC profiles and XMP metadata - Copyright (C) 2022-2023 Ruven Pillay + Copyright (C) 2022-2024 Ruven Pillay This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -65,7 +65,15 @@ class WebPCompressor : public Compressor { WebPConfigInit( &config ); config.method = 0; // Fastest encoding config.thread_level = 1; // Enable threading - config.quality = this->Q; // WebP's quality range is 0-100 + + // Update our WebP config structure depending on whether lossless or lossy compression requested + if( compressionLevel == -1 ){ + // -1 indicates lossless + config.lossless = 1; + config.quality = 0; // Zero means fastest for lossless + } + // WebP's lossy quality range is 0-100 + else config.quality = this->Q; // Create our muxer object mux = WebPMuxNew(); @@ -138,12 +146,18 @@ class WebPCompressor : public Compressor { // WebP quality ranges from 0 (best compression - smallest size) to 100 (worst compression - largest size) this->Q = quality; - // WebP compression level - if( Q < 0 ) Q = 0; + // Limit to WebP quality range - negative values indicate lossless + if( this->Q < 1 ) Q = -1; else if( Q > 100 ) Q = 100; - // Update our WebP config structure - config.quality = Q; + // Update our WebP config structure depending on whether lossless or lossy compression requested + if( this->Q == -1 ){ + // -1 indicates lossless + config.lossless = 1; + config.quality = 0; // Zero means fastest for lossless + } + // WebP's lossy quality range is 0-100 + else config.quality = this->Q; }