Skip to content

Commit

Permalink
Enable OpenJPEG support
Browse files Browse the repository at this point in the history
* Add check for OpenJPEG JPEG2000 library (code mainly from
  moravianlibrary/iipsrv-openjpeg).

* Use Kakadu by default (if available). OpenJPEG can be enforced by
  setting the environment variable USE_OPENJPEG=1.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Mar 17, 2016
1 parent 0733379 commit c4e6a34
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 7 deletions.
15 changes: 14 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ See COPYING.FCGI for licensing information for these libraries.
REQUIREMENTS
------------
Requirements: libtiff, zlib and the IJG JPEG development libraries.
Optional: libmemcached (for Memcached) and Kakadu (for JPEG2000)
Optional: libmemcached (for Memcached) and Kakadu or OpenJPEG (for JPEG2000)

Plus, of course, an fcgi-enabled web server. The server has been successfully
tested on the following servers:
Expand Down Expand Up @@ -115,6 +115,19 @@ following parameters to the ./configure command



OPTIONAL LIBRARIES: OPENJPEG
----------------------------
IIPImage is able to decode JPEG2000 images via the free software OpenJPEG
(https://github.com/uclouvain/openjpeg). This is still much slower than
decoding via the Kakadu SDK, and it is also highly experimental.

It is also possible to use both the Kakadu SDK and OpenJPEG.
Then the Kakadu SDK will be used by default.
OpenJPEG can be enabled by setting the environment variable USE_OPENJPEG
to any value larger than 0, for example with USE_OPENJPEG=1.



INSTALLATION
------------
Simply copy the executable called iipsrv.fcgi in the src subdirectory into
Expand Down
41 changes: 41 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,46 @@ AM_CONDITIONAL( [ENABLE_MODULES], [test x$modules = xtrue] )
AC_SUBST(DL_LIBS)


#************************************************************

# Check for OpenJPEG JPEG2000 library

AC_ARG_WITH( openjpeg,
[ --with-openjpeg=DIR location of the openjpeg source files],
openjpeg_path=$withval)


AC_CHECK_FILE($openjpeg_path/src/lib/openjp2/openjpeg.h,
AC_MSG_RESULT([configure: Found OpenJPEG sources. Will compile JPEG2000 support]); OPENJPEG=true,
AC_MSG_RESULT([configure: No OpenJPEG JPEG2000 Sources Found]); OPENJPEG=false
)

if test "x$OPENJPEG" = xtrue; then
INCLUDES="$INCLUDES -I$openjpeg_path/src/lib/openjp2/"
LIBS="$LIBS $openjpeg_path/bin/libopenjp2.so -lpthread"
else
PKG_CHECK_MODULES([OPENJPEG], [libopenjp2], [OPENJPEG=true], [OPENJPEG=false])
if test "x$OPENJPEG" = xtrue; then
INCLUDES="$INCLUDES $OPENJPEG_CFLAGS"
LIBS="$LIBS $OPENJPEG_LIBS"
fi
fi

if test "x$OPENJPEG" = xtrue; then
AC_DEFINE(HAVE_OPENJPEG)
EXTRAS="OpenJPEGImage.o"
fi

AM_CONDITIONAL([ENABLE_OPENJPEG], [test x$OPENJPEG = xtrue])

AC_SUBST(INCLUDES)
AC_SUBST(EXTRAS)

AC_CHECK_LIB(c,get_nprocs_conf,AC_DEFINE(NPROCS))

AC_SUBST(LIBS)


#************************************************************

# Check for Kakadu JPEG2000 library
Expand Down Expand Up @@ -346,6 +386,7 @@ Options Enabled:
---------------
Memcached: ${MEMCACHED}
JPEG2000 (Kakadu): ${KAKADU}
JPEG2000 (OpenJPEG): ${OPENJPEG}
])

# PNG Output: ${PNG}
Expand Down
9 changes: 9 additions & 0 deletions src/Environment.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ class Environment {
return layers;
}

static bool getUseOpenJPEG(){
char* envpara = getenv( "USE_OPENJPEG" );
int value;
if( envpara ) value = atoi( envpara );
else value = 0;

return (value > 0);
}


static std::string getFileSystemPrefix(){
char* envpara = getenv( "FILESYSTEM_PREFIX" );
Expand Down
22 changes: 18 additions & 4 deletions src/FIF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include "KakaduImage.h"
#endif

#ifdef HAVE_OPENJPEG
#include "OpenJPEGImage.h"
#endif

#define MAXIMAGECACHE 1000 // Max number of items in image cache


Expand Down Expand Up @@ -120,10 +124,20 @@ void FIF::run( Session* session, const string& src ){
if( session->loglevel >= 2 ) *(session->logfile) << "FIF :: TIFF image detected" << endl;
*session->image = new TPTImage( test );
}
#ifdef HAVE_KAKADU
#if defined(HAVE_KAKADU) || defined(HAVE_OPENJPEG)
else if( format == JPEG2000 ){
if( session->loglevel >= 2 ) *(session->logfile) << "FIF :: JPEG2000 image detected" << endl;
*session->image = new KakaduImage( test );
if( session->loglevel >= 2 )
*(session->logfile) << "FIF :: JPEG2000 image detected" << endl;
#if defined(HAVE_OPENJPEG)
if( session->useOpenJPEG )
*session->image = new OpenJPEGImage( test );
#endif
#if defined(HAVE_KAKADU)
#if defined(HAVE_OPENJPEG)
else
#endif
*session->image = new KakaduImage( test );
#endif
}
#endif
else throw string( "Unsupported image type: " + argument );
Expand All @@ -145,7 +159,7 @@ void FIF::run( Session* session, const string& src ){
throw string( "Unsupported image type: " + imtype );
}
else{
// Construct our dynamic loading image decoder
// Construct our dynamic loading image decoder
session->image = new DSOImage( test );
(*session->image)->Load( (*mod_it).second );
Expand Down
15 changes: 14 additions & 1 deletion src/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ int main( int argc, char *argv[] )
string filesystem_prefix = Environment::getFileSystemPrefix();


#if !defined(HAVE_OPENJPEG)
bool useOpenJPEG = false;
#elif defined(HAVE_KAKADU)
bool useOpenJPEG = Environment::getUseOpenJPEG();
#else
bool useOpenJPEG = true;
#endif


// Set up our watermark object
Watermark watermark( Environment::getWatermark(),
Environment::getWatermarkOpacity(),
Expand Down Expand Up @@ -290,7 +299,10 @@ int main( int argc, char *argv[] )
else logfile << max_layers << endl;
}
#ifdef HAVE_KAKADU
logfile << "Setting up JPEG2000 support via Kakadu SDK" << endl;
if(!useOpenJPEG) logfile << "Setting up JPEG2000 support via Kakadu SDK" << endl;
#endif
#ifdef HAVE_OPENJPEG
if(useOpenJPEG) logfile << "Setting up JPEG2000 support via OpenJPEG" << endl;
#endif
}

Expand Down Expand Up @@ -473,6 +485,7 @@ int main( int argc, char *argv[] )
session.out = &writer;
session.watermark = &watermark;
session.headers.clear();
session.useOpenJPEG = useOpenJPEG;

char* header = NULL;

Expand Down
6 changes: 5 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ if ENABLE_KAKADU
iipsrv_fcgi_LDADD += KakaduImage.o
endif

if ENABLE_OPENJPEG
iipsrv_fcgi_LDADD += OpenJPEGImage.o
endif

#if ENABLE_PNG
#iipsrv_fcgi_LDADD += PNGCompressor.o PTL.o
#endif
Expand All @@ -21,7 +25,7 @@ if ENABLE_MODULES
iipsrv_fcgi_LDADD += DSOImage.o
endif

EXTRA_iipsrv_fcgi_SOURCES = DSOImage.h DSOImage.cc KakaduImage.h KakaduImage.cc Main.cc
EXTRA_iipsrv_fcgi_SOURCES = DSOImage.h DSOImage.cc KakaduImage.h KakaduImage.cc Main.cc OpenJPEGImage.h OpenJPEGImage.cc

iipsrv_fcgi_SOURCES = \
IIPImage.h \
Expand Down
1 change: 1 addition & 0 deletions src/Task.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct Session {
IIPResponse* response;
Watermark* watermark;
int loglevel;
bool useOpenJPEG;
std::ofstream* logfile;
std::map <const std::string, std::string> headers;

Expand Down

0 comments on commit c4e6a34

Please sign in to comment.