Skip to content

Commit 75ea660

Browse files
committed
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.
1 parent 0579e74 commit 75ea660

File tree

8 files changed

+57
-39
lines changed

8 files changed

+57
-39
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: ruven

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
14/02/2024:
2+
- Harmonizied ICC profile handling between JTL and CVT and replaced EMBED_ICC startup parameter with
3+
more flexible MAX_ICC parameter, which defines the maximum acceptable size for an ICC profile.
4+
Profiles larger than this are stripped out of the output image. If set to -1, profiles are always
5+
added and if set to 0 never.
6+
7+
18
14/01/2025:
29
- Fix to TPTImage string concatenation bug, elimination of type warnings and documentation updates
310

README

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,7 @@ URI_MAP: Set a mapping from a URL prefix to a supported protocol. This enables i
451451

452452
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).
453453

454-
EMBED_ICC: Set whether the ICC profile is embedded within the output image.
455-
0 to strip profile, 1 to embed profile. The default is 1 (embedded profiles).
454+
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.
456455

457456
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.
458457

src/CVT.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
IIP CVT Command Handler Class Member Function
33
4-
Copyright (C) 2006-2024 Ruven Pillay.
4+
Copyright (C) 2006-2025 Ruven Pillay.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -511,9 +511,9 @@ void CVT::send( Session* session ){
511511
}
512512
}
513513

514-
// Embed ICC profile if of a reasonable size
515-
if( session->view->embedICC() && ((*session->image)->getMetadata("icc").size()>0) ){
516-
if( (*session->image)->getMetadata("icc").size() < 65536 ){
514+
// Embed ICC profile if we have one and it is of an acceptable size
515+
if( (*session->image)->getMetadata("icc").size() > 0 ){
516+
if( session->view->maxICC() == -1 || (*session->image)->getMetadata("icc").size() < (unsigned long) session->view->maxICC() ){
517517
if( session->loglevel >= 3 ){
518518
*(session->logfile) << "CVT :: Embedding ICC profile with size "
519519
<< (*session->image)->getMetadata("icc").size() << " bytes" << endl;

src/Environment.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
IIP Environment Variable Class
33
4-
Copyright (C) 2006-2024 Ruven Pillay
4+
Copyright (C) 2006-2025 Ruven Pillay
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -51,7 +51,7 @@
5151
#define CACHE_CONTROL "max-age=86400"; // 24 hours
5252
#define ALLOW_UPSCALING true
5353
#define URI_MAP ""
54-
#define EMBED_ICC true
54+
#define MAX_ICC 65536 // Max ICC profile size of 65k
5555
#define CODEC_PASSTHROUGH true
5656
#define KAKADU_READMODE 0
5757
#define IIIF_VERSION 3
@@ -381,12 +381,14 @@ class Environment {
381381
}
382382

383383

384-
static unsigned int getEmbedICC(){
385-
const char* envpara = getenv( "EMBED_ICC" );
386-
bool embed;
387-
if( envpara ) embed = atoi( envpara );
388-
else embed = EMBED_ICC;
389-
return embed;
384+
static int getMaxICC(){
385+
const char* envpara = getenv( "MAX_ICC" );
386+
int max_icc;
387+
if( envpara ){
388+
max_icc = atoi( envpara );
389+
}
390+
else max_icc = MAX_ICC;
391+
return max_icc;
390392
}
391393

392394

src/JTL.cc

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
IIP JTL Command Handler Class Member Function: Export a single tile
33
4-
Copyright (C) 2006-2024 Ruven Pillay.
4+
Copyright (C) 2006-2025 Ruven Pillay.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -149,17 +149,24 @@ void JTL::send( Session* session, int resolution, int tile ){
149149
compressor->setMetadata( (*session->image)->metadata );
150150

151151

152-
// Embed ICC profile
153-
if( session->view->embedICC() && (*session->image)->metadata["icc"].size() > 0 ){
154-
if( session->loglevel >= 3 ){
155-
*(session->logfile) << "JTL :: Embedding ICC profile with size "
156-
<< (*session->image)->getMetadata("icc").size() << " bytes" << endl;
152+
// Embed ICC profile if we have one and it is of an acceptable size
153+
if( (*session->image)->getMetadata("icc").size() > 0 ){
154+
if( session->view->maxICC() == -1 || (*session->image)->getMetadata("icc").size() < (unsigned long) session->view->maxICC() ){
155+
if( session->loglevel >= 3 ){
156+
*(session->logfile) << "JTL :: Embedding ICC profile with size "
157+
<< (*session->image)->getMetadata("icc").size() << " bytes" << endl;
158+
}
159+
compressor->embedICCProfile( true );
160+
}
161+
else{
162+
if( session->loglevel >= 3 ){
163+
*(session->logfile) << "JTL :: ICC profile with size "
164+
<< (*session->image)->getMetadata("icc").size() << " bytes is too large: Not embedding" << endl;
165+
}
157166
}
158-
compressor->embedICCProfile( true );
159167
}
160168

161169

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

src/Main.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
IIP FCGI server module - Main loop.
33
4-
Copyright (C) 2000-2024 Ruven Pillay
4+
Copyright (C) 2000-2025 Ruven Pillay
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -345,8 +345,8 @@ int main( int argc, char *argv[] )
345345
bool allow_upscaling = Environment::getAllowUpscaling();
346346

347347

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

351351

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

663665

664666
// Create an IIPResponse object - we use this for the OBJ requests.

src/View.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
Image View and Transform Parameters
33
4-
Copyright (C) 2003-2024 Ruven Pillay.
4+
Copyright (C) 2003-2025 Ruven Pillay.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -76,7 +76,7 @@ class View{
7676
int flip; /// Flip (1=horizontal, 2=vertical)
7777
bool maintain_aspect; /// Indicate whether aspect ratio should be maintained
7878
bool allow_upscaling; /// Indicate whether images may be served larger than the source file
79-
bool embed_icc; /// Indicate whether we should embed ICC profiles
79+
int max_icc; /// Maximum ICC profile size we allow to be embedded
8080
ImageEncoding output_format; /// Requested output format
8181
float contrast; /// Contrast adjustment requested by CNT command
8282
float gamma; /// Gamma adjustment requested by GAM command
@@ -102,7 +102,7 @@ class View{
102102
maintain_aspect = true;
103103
allow_upscaling = true;
104104
colorspace = ColorSpace::NONE;
105-
embed_icc = true;
105+
max_icc = -1;
106106
output_format = ImageEncoding::JPEG;
107107
equalization = false;
108108
minmax = false;
@@ -134,20 +134,20 @@ class View{
134134
bool allowUpscaling(){ return allow_upscaling; };
135135

136136

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

142142

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

152152

153153
/// Set the maximum view port dimension

0 commit comments

Comments
 (0)