Skip to content

Commit

Permalink
Added TIFF output support for both regions (CVT=TIFF) and tiles (TTL=…
Browse files Browse the repository at this point in the history
…<resolution>,<tile number>).

- TIFF encoder handles all bit depths, alpha channels, ICC profiles and basic TIFF and XMP metadata.
- QLT argument can be used to specify both compression as well as quality using the syntax QLT=<compression>:<quality>. For example QLT=WebP:50 will enable WebP compression within TIFF with a quality level of 50. Supported compression schemes are None, LZW, Deflate, Zstd, JPEG and WebP. Default compression is Deflate with level 1 (fastest).
  • Loading branch information
ruven committed Nov 20, 2024
1 parent 7b4ed28 commit 8820652
Show file tree
Hide file tree
Showing 14 changed files with 688 additions and 28 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
20/11/2024:
- Added TIFF output support for both regions (CVT=TIFF) and tiles (TTL=<resolution>,<tile number>). TIFF
encoder handles all bit depths, alpha channels, ICC profiles and basic TIFF and XMP metadata.
- QLT argument can be used to specify both compression as well as quality using the syntax QLT=<compression>:<quality>.
For example QLT=WebP:50 will enable WebP compression within TIFF with a quality level of 50. Supported compression
schemes are None, LZW, Deflate, Zstd, JPEG and WebP. Default compression is Deflate with level 1 (fastest).


18/11/2024:
- Correct bounding box calculation when max size has been set.
- Fixed bug in View.cc's getResolution() when a max size has been set. Fixes https://github.com/ruven/iipsrv/issues/274
Expand Down
6 changes: 5 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ FEATURES
* High performance with inbuilt configurable cache
* Support for extremely large images: tera-pixel and multi gigapixel support
* TIFF, JPEG2000 and JPEG input support
* JPEG, PNG, WebP and AVIF output support: export of whole or regions of images at any size
* JPEG, PNG, WebP, AVIF and TIFF output support: export of whole or regions of images at any size
* Supports IIP, Zoomify, DeepZoom and IIIF API's
* 1, 8, 16 and 32 bit image support including 32 bit floating point support
* CIELAB support with automatic CIELAB->sRGB color space conversion
Expand Down Expand Up @@ -404,6 +404,10 @@ FILESYSTEM_PREFIX: This is a prefix automatically added by the server to the beg

FILESYSTEM_SUFFIX: This is a suffix added to the end of each file system path. It can be combined with FILESYSTEM_PREFIX. It is not used in combination with FILENAME_PATTERN. If e.g. this is set to ".tif", an image URL such as "/UUID" will look for "${FILESYSTEM_PREFIX}/UUID.tif". In the IIIF info.json document, the image @id will be set without the ".tif" suffix.

TIFF_COMPRESSION: The default compression encoder for TIFF output. 0 = None, 1 = LZW, 2 = Deflate, 3 = JPEG, 4 = WebP, 5 = ZStandard. The default is 2 (Deflate).

TIFF_QUALITY: The default quality factor for compression when the client does not specify one. When using JPEG or WebP, value should be 0-100. For Deflate 1-9. For ZStandard 1-19. The default is 1.

JPEG_QUALITY: The default JPEG quality factor for compression when the client does not specify one. The value should be between 1 (highest level of compression) and 100 (highest image quality). The default is 75.

PNG_QUALITY: The default PNG quality factor for compression when the client does not specify one. The value should be between 1 (highest level of compression) and 9 (highest image quality). The default is 1.
Expand Down
1 change: 1 addition & 0 deletions src/CVT.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void CVT::send( Session* session ){
// Set up our output format handler
Compressor *compressor = NULL;
if( session->view->output_format == ImageEncoding::JPEG ) compressor = session->jpeg;
else if( session->view->output_format == ImageEncoding::TIFF ) compressor = session->tiff;
#ifdef HAVE_PNG
else if( session->view->output_format == ImageEncoding::PNG ) compressor = session->png;
#endif
Expand Down
32 changes: 31 additions & 1 deletion src/Environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#define WEBP_QUALITY 50
#define AVIF_QUALITY 50
#define AVIF_CODEC 0 // 0 = auto, 1 = aom, 2 = rav2e, 3 = svt
#define TIFF_COMPRESSION 2 // 0=None, 1=LZW, 2=Deflate, 3=JPEG, 4=WebP, 5=ZStandard
#define TIFF_QUALITY 1
#define MAX_CVT 5000
#define MAX_LAYERS 0
#define FILESYSTEM_PREFIX ""
Expand All @@ -46,7 +48,7 @@
#define INTERPOLATION 1 // 1: Bilinear
#define CORS "";
#define BASE_URL "";
#define CACHE_CONTROL "max-age=86400"; // 24 hours
#define CACHE_CONTROL "max-age=86400"; // 24 hours
#define ALLOW_UPSCALING true
#define URI_MAP ""
#define EMBED_ICC true
Expand Down Expand Up @@ -173,6 +175,34 @@ class Environment {
}


/// 0: None, 1: LZW, 2: Deflate, 3: JPEG, 4: WebP
static int getTIFFCompression(){
const char* envpara = getenv( "TIFF_COMPRESSION" );
int compression;
if( envpara ){
compression = atoi( envpara );
if( compression < 0 || compression > 4 ) compression = 0;
}
else compression = TIFF_COMPRESSION;

return compression;
}


static int getTIFFQuality(){
const char* envpara = getenv( "TIFF_QUALITY" );
int quality;
if( envpara ){
quality = atoi( envpara );
if( quality < 0 ) quality = 0;
if( quality > 100 ) quality = 100;
}
else quality = TIFF_QUALITY;

return quality;
}


static unsigned int getAVIFCodec(){
unsigned int codec;
const char* envpara = getenv( "AVIF_CODEC" );
Expand Down
3 changes: 2 additions & 1 deletion src/JTL.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
IIP JTL Command Handler Class Member Function: Export a single tile
Copyright (C) 2006-2023 Ruven Pillay.
Copyright (C) 2006-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
Expand Down Expand Up @@ -77,6 +77,7 @@ void JTL::send( Session* session, int resolution, int tile ){
ImageEncoding ct = session->view->output_format;
Compressor *compressor;
if( session->view->output_format == ImageEncoding::JPEG ) compressor = session->jpeg;
else if( session->view->output_format == ImageEncoding::TIFF ) compressor = session->tiff;
#ifdef HAVE_PNG
else if( session->view->output_format == ImageEncoding::PNG ) compressor = session->png;
#endif
Expand Down
15 changes: 12 additions & 3 deletions src/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,11 @@ int main( int argc, char *argv[] )
unsigned int avif_codec = Environment::getAVIFCodec();


// Get our default TIFF compression scheme
int tiff_compression = Environment::getTIFFCompression();
int tiff_quality = Environment::getTIFFQuality();


// Get our max CVT size
int max_CVT = Environment::getMaxCVT();

Expand Down Expand Up @@ -392,12 +397,14 @@ int main( int argc, char *argv[] )

logfile << "Setting filesystem prefix to '" << FIF::filesystem_prefix << "'" << endl;
logfile << "Setting filesystem suffix to '" << FIF::filesystem_suffix << "'" << endl;
logfile << "Setting default JPEG quality to " << jpeg_quality << endl;
logfile << "Setting default TIFF output compression/quality to "
<< TIFFCompressor::getCompressionName(tiff_compression) << "/" << tiff_quality << endl;
logfile << "Setting default JPEG output quality to " << jpeg_quality << endl;
#ifdef HAVE_PNG
logfile << "Setting default PNG compression level to " << png_quality << endl;
logfile << "Setting default PNG output compression level to " << png_quality << endl;
#endif
#ifdef HAVE_WEBP
logfile << "Setting default WebP compression level to ";
logfile << "Setting default WebP output compression level to ";
if( webp_quality == -1 ) logfile << "lossless" << endl;
else logfile << webp_quality << endl;
#endif
Expand Down Expand Up @@ -634,6 +641,7 @@ int main( int argc, char *argv[] )
// so that we can close the image on exceptions
IIPImage *image = NULL;
JPEGCompressor jpeg( jpeg_quality );
TIFFCompressor tiff( tiff_compression, tiff_quality );
#ifdef HAVE_PNG
PNGCompressor png( png_quality );
#endif
Expand Down Expand Up @@ -668,6 +676,7 @@ int main( int argc, char *argv[] )
session.response = &response;
session.view = &view;
session.jpeg = &jpeg;
session.tiff = &tiff;
#ifdef HAVE_PNG
session.png = &png;
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ iipsrv_fcgi_SOURCES = \
JPEGImage.h \
JPEGImage.cc \
Compressor.h \
TIFFCompressor.h \
TIFFCompressor.cc \
JPEGCompressor.h \
JPEGCompressor.cc \
RawTile.h \
Expand Down
Loading

0 comments on commit 8820652

Please sign in to comment.