Skip to content

Commit

Permalink
Harmonizied ICC profile handling between JTL and CVT and replaced EMB…
Browse files Browse the repository at this point in the history
…ED_ICC startup parameter with more flexible MAX_ICC parameter, which defines the maximum acceptable size for an ICC profile.

Profiles larger than this are stripped out of the output image. If set to -1, profiles are always added and if set to 0 never.
  • Loading branch information
ruven committed Feb 14, 2025
1 parent 0579e74 commit 75ea660
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 39 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: ruven
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
14/02/2024:
- Harmonizied ICC profile handling between JTL and CVT and replaced EMBED_ICC startup parameter with
more flexible MAX_ICC parameter, which defines the maximum acceptable size for an ICC profile.
Profiles larger than this are stripped out of the output image. If set to -1, profiles are always
added and if set to 0 never.


14/01/2025:
- Fix to TPTImage string concatenation bug, elimination of type warnings and documentation updates

Expand Down
3 changes: 1 addition & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,7 @@ URI_MAP: Set a mapping from a URL prefix to a supported protocol. This enables i

CACHE_CONTROL: Set the HTTP Cache-Control header. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 for a full list of options. If not set, header defaults to "max-age=86400" (24 hours).

EMBED_ICC: Set whether the ICC profile is embedded within the output image.
0 to strip profile, 1 to embed profile. The default is 1 (embedded profiles).
MAX_ICC: Set the maximum ICC profile size in bytes that is allowed to be embedded within an output image. This is set by default to 65535 bytes. If set to -1, no limit is set and all profiles are embedded. If set to 0, no profiles are embedded.

OMP_NUM_THREADS: Set the number of OpenMP threads to be used by the iipsrv image processing routines (See OpenMP specification for details). All available processor threads are used by default.

Expand Down
8 changes: 4 additions & 4 deletions src/CVT.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
IIP CVT Command Handler Class Member Function
Copyright (C) 2006-2024 Ruven Pillay.
Copyright (C) 2006-2025 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 @@ -511,9 +511,9 @@ void CVT::send( Session* session ){
}
}

// Embed ICC profile if of a reasonable size
if( session->view->embedICC() && ((*session->image)->getMetadata("icc").size()>0) ){
if( (*session->image)->getMetadata("icc").size() < 65536 ){
// Embed ICC profile if we have one and it is of an acceptable size
if( (*session->image)->getMetadata("icc").size() > 0 ){
if( session->view->maxICC() == -1 || (*session->image)->getMetadata("icc").size() < (unsigned long) session->view->maxICC() ){
if( session->loglevel >= 3 ){
*(session->logfile) << "CVT :: Embedding ICC profile with size "
<< (*session->image)->getMetadata("icc").size() << " bytes" << endl;
Expand Down
18 changes: 10 additions & 8 deletions src/Environment.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
IIP Environment Variable Class
Copyright (C) 2006-2024 Ruven Pillay
Copyright (C) 2006-2025 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 @@ -51,7 +51,7 @@
#define CACHE_CONTROL "max-age=86400"; // 24 hours
#define ALLOW_UPSCALING true
#define URI_MAP ""
#define EMBED_ICC true
#define MAX_ICC 65536 // Max ICC profile size of 65k
#define CODEC_PASSTHROUGH true
#define KAKADU_READMODE 0
#define IIIF_VERSION 3
Expand Down Expand Up @@ -381,12 +381,14 @@ class Environment {
}


static unsigned int getEmbedICC(){
const char* envpara = getenv( "EMBED_ICC" );
bool embed;
if( envpara ) embed = atoi( envpara );
else embed = EMBED_ICC;
return embed;
static int getMaxICC(){
const char* envpara = getenv( "MAX_ICC" );
int max_icc;
if( envpara ){
max_icc = atoi( envpara );
}
else max_icc = MAX_ICC;
return max_icc;
}


Expand Down
23 changes: 15 additions & 8 deletions 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-2024 Ruven Pillay.
Copyright (C) 2006-2025 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 @@ -149,17 +149,24 @@ void JTL::send( Session* session, int resolution, int tile ){
compressor->setMetadata( (*session->image)->metadata );


// Embed ICC profile
if( session->view->embedICC() && (*session->image)->metadata["icc"].size() > 0 ){
if( session->loglevel >= 3 ){
*(session->logfile) << "JTL :: Embedding ICC profile with size "
<< (*session->image)->getMetadata("icc").size() << " bytes" << endl;
// Embed ICC profile if we have one and it is of an acceptable size
if( (*session->image)->getMetadata("icc").size() > 0 ){
if( session->view->maxICC() == -1 || (*session->image)->getMetadata("icc").size() < (unsigned long) session->view->maxICC() ){
if( session->loglevel >= 3 ){
*(session->logfile) << "JTL :: Embedding ICC profile with size "
<< (*session->image)->getMetadata("icc").size() << " bytes" << endl;
}
compressor->embedICCProfile( true );
}
else{
if( session->loglevel >= 3 ){
*(session->logfile) << "JTL :: ICC profile with size "
<< (*session->image)->getMetadata("icc").size() << " bytes is too large: Not embedding" << endl;
}
}
compressor->embedICCProfile( true );
}



RawTile rawtile = tilemanager.getTile( resolution, tile, session->view->xangle,
session->view->yangle, session->view->getLayers(), ct );

Expand Down
12 changes: 7 additions & 5 deletions src/Main.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
IIP FCGI server module - Main loop.
Copyright (C) 2000-2024 Ruven Pillay
Copyright (C) 2000-2025 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 @@ -345,8 +345,8 @@ int main( int argc, char *argv[] )
bool allow_upscaling = Environment::getAllowUpscaling();


// Get the ICC embedding setting
bool embed_icc = Environment::getEmbedICC();
// Get the max ICC profile size we allow to be embedded
int max_icc = Environment::getMaxICC();


// Get codec passthrough setting
Expand Down Expand Up @@ -429,7 +429,9 @@ int main( int argc, char *argv[] )
else logfile << max_layers << endl;
}
logfile << "Setting Allow Upscaling to " << (allow_upscaling? "true" : "false") << endl;
logfile << "Setting ICC profile embedding to " << (embed_icc? "true" : "false") << endl;
logfile << "Setting maximum ICC profile size to ";
if( max_icc < 0 ) logfile << "unlimited" << endl;
else logfile << max_icc << " bytes" << endl;
logfile << "Setting codec passthrough to " << (IIPImage::codec_passthrough? "true" : "false") << endl;
if( !copyright.empty() ) logfile << "Setting default rights/copyright statement to '" << copyright << "'" << endl;
logfile << "Setting up TIFF support via " << TPTImage::getCodecVersion() << endl;
Expand Down Expand Up @@ -658,7 +660,7 @@ int main( int argc, char *argv[] )
if( max_CVT != 0 ) view.setMaxSize( max_CVT );
if( max_layers != 0 ) view.setMaxLayers( max_layers );
view.setAllowUpscaling( allow_upscaling );
view.setEmbedICC( embed_icc );
view.setMaxICC( max_icc );


// Create an IIPResponse object - we use this for the OBJ requests.
Expand Down
24 changes: 12 additions & 12 deletions src/View.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
Image View and Transform Parameters
Copyright (C) 2003-2024 Ruven Pillay.
Copyright (C) 2003-2025 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 @@ -76,7 +76,7 @@ class View{
int flip; /// Flip (1=horizontal, 2=vertical)
bool maintain_aspect; /// Indicate whether aspect ratio should be maintained
bool allow_upscaling; /// Indicate whether images may be served larger than the source file
bool embed_icc; /// Indicate whether we should embed ICC profiles
int max_icc; /// Maximum ICC profile size we allow to be embedded
ImageEncoding output_format; /// Requested output format
float contrast; /// Contrast adjustment requested by CNT command
float gamma; /// Gamma adjustment requested by GAM command
Expand All @@ -102,7 +102,7 @@ class View{
maintain_aspect = true;
allow_upscaling = true;
colorspace = ColorSpace::NONE;
embed_icc = true;
max_icc = -1;
output_format = ImageEncoding::JPEG;
equalization = false;
minmax = false;
Expand Down Expand Up @@ -134,20 +134,20 @@ class View{
bool allowUpscaling(){ return allow_upscaling; };


/// Set the embed_icc flag
/** @param embed embed icc profile flag
/// Set the maximum ICC profile size we allow to be embedded
/** @param max maximum icc profile size
*/
void setEmbedICC( bool embed ){ embed_icc = embed; };
void setMaxICC( int max ){ max_icc = max; };


/// Get the embed_icc flag - disable in case of certain types of processing
/** @return whether ICC profile should be embedded
/// Get the maximum ICC profile size we allow to be embedded - disable if certain processing has been carried out
/** @return max ICC profile size
*/
bool embedICC(){
int maxICC(){
// Disable if colour-mapping, twist, hill-shading or greyscale conversion applied
if( cmapped || shaded || ctw.size() || colorspace==ColorSpace::GREYSCALE ) return false;
return embed_icc;
};
if( cmapped || shaded || ctw.size() || colorspace==ColorSpace::GREYSCALE ) return 0;
return max_icc;
}


/// Set the maximum view port dimension
Expand Down

0 comments on commit 75ea660

Please sign in to comment.