Skip to content

Commit

Permalink
Added new IIIF_DELIMITTER configuration parameter to enable page or s…
Browse files Browse the repository at this point in the history
…tack slice selection. Now disabled by default unless IIIF_DELIMITTER is set. Resolves: #261
  • Loading branch information
ruven committed Oct 19, 2023
1 parent 268b5d8 commit 3539288
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
19/10/2023:
- Added new IIIF_DELIMITTER configuration parameter to enable page or stack slice selection. Now disabled
by default unless IIIF_DELIMITTER is set. Resolves: https://github.com/ruven/iipsrv/issues/261


03/10/2023:
- Cleanup of autoconf C++ checks and added conditional building of FCGI
- Fixes for compilation errors on Mac OS X / clang
Expand Down
3 changes: 3 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ recovery, 2 for 'resilient' mode with maximum recovery from codestream errors. S
IIIF_VERSION: Set the major IIIF Image API version. Values should be a single digit. For example: 2 for versions 2 or 2.1 etc.
3 for IIIF version 3.x. If not set, defaults to version IIIF 3.x

IIIF_DELIMITTER: Set delimitter to enable page or slice selection for a multi-page or image stack for IIIF requests.
Delimitter can be a single character or an arbitrary string. Disabled by default.

DECODER_MODULES: Comma separated list of external modules for decoding
other image formats. This is only necessary if you have activated
--enable-modules for ./configure and written your own image format
Expand Down
7 changes: 7 additions & 0 deletions src/Environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#define EMBED_ICC true
#define KAKADU_READMODE 0
#define IIIF_VERSION 3
#define IIIF_DELIMITTER ""


#include <string>
Expand Down Expand Up @@ -343,6 +344,12 @@ class Environment {
}


static std::string getIIIFDelimitter(){
const char* envpara = getenv( "IIIF_DELIMITTER" );
if( envpara ) return std::string( envpara );
else return IIIF_DELIMITTER;
}

};


Expand Down
14 changes: 10 additions & 4 deletions src/IIIF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@

using namespace std;


// Need to initialize static member
string IIIF::delimitter = "";


// The request is in the form {identifier}/{region}/{size}/{rotation}/{quality}{.format}
// eg. filename.tif/full/full/0/native.jpg
// or in the form {identifier}/info.json
Expand Down Expand Up @@ -121,11 +126,12 @@ void IIIF::run( Session* session, const string& src )
return;
}

// Re-usable string position variable
size_t pos;

// Extract any meta-identifier in the file name that may refer to a page within an image stack or multi-page image
// These consist of a semi-colon and a page or stack index of the form <image>;<index> For example: image.tif;3
const char delimitter = ',';
if( filename.find_last_of( delimitter ) != string::npos ){
size_t pos = filename.find_last_of( delimitter );
if( IIIF::delimitter.size() && ( (pos=filename.rfind(IIIF::delimitter)) != string::npos ) ){
int page = atoi( filename.substr(pos+1).c_str() );
session->view->xangle = page;
filename = filename.substr(0,pos);
Expand Down Expand Up @@ -158,7 +164,7 @@ void IIIF::run( Session* session, const string& src )

// Check whether the client has requested a specific IIIF version within the HTTP Accept header
// - first look for the protocol prefix
size_t pos = session->headers["HTTP_ACCEPT"].find( IIIF_PROTOCOL );
pos = session->headers["HTTP_ACCEPT"].find( IIIF_PROTOCOL );
if( pos != string::npos ){
// The Accept header should contain a versioned context string of the form http://iiif.io/api/image/3/context.json
string profile = session->headers["HTTP_ACCEPT"].substr( pos, string(IIIF_PROTOCOL).size()+15 );
Expand Down
7 changes: 7 additions & 0 deletions src/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ int main( int argc, char *argv[] )
unsigned int iiif_version = Environment::getIIIFVersion();


// Set our IIIF multi-page delimitter
IIIF::delimitter = Environment::getIIIFDelimitter();


// Create our image processing engine
Transform processor;

Expand Down Expand Up @@ -367,6 +371,9 @@ int main( int argc, char *argv[] )
logfile << "Setting HTTP Cache-Control header to '" << cache_control << "'" << endl;
logfile << "Setting 3D file sequence name pattern to '" << filename_pattern << "'" << endl;
logfile << "Setting default IIIF Image API version to " << iiif_version << endl;
if( IIIF::delimitter.size() ){
logfile << "Setting default IIIF multi-page delimitter to '" << IIIF::delimitter << "'" << endl;
}
if( !cors.empty() ) logfile << "Setting Cross Origin Resource Sharing to '" << cors << "'" << endl;
if( !base_url.empty() ) logfile << "Setting base URL to '" << base_url << "'" << endl;
if( max_layers != 0 ){
Expand Down
2 changes: 1 addition & 1 deletion src/Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/


#ifndef _TASK_H
#define _TASK_H

Expand Down Expand Up @@ -355,6 +354,7 @@ class DeepZoom : public Task {
/// IIIF Command
class IIIF : public Task {
public:
static std::string delimitter;
void run( Session* session, const std::string& argument );
};

Expand Down

0 comments on commit 3539288

Please sign in to comment.