JPEG2000 with GDAL OpenJpeg plugin
Since GDAL version 1.10.0, an OpenJpeg driver has been included in GDAL. However this driver is not compiled by default. This driver is intended to be used with OpenJpeg 2.0 official release. It allows to open Jpeg2000 datasets in OTB without using the home-made otb::JPEG2000ImageIO. The common otb::GDALImageIO is used instead.
There are 2 ways of using this driver :
- Use a GDAL library with a built-in OpenJpeg driver
- Use a standard GDAL library and configure an external OpenJpeg driver
Each case is detailed in the following sections.
Let's assume that OpenJpeg is not installed on your system. You can build it from sources using CMake.
The default CMake configuration is simple to perform, it will build the main codec. You can choose your own CMAKE_INSTALL_PREFIX depending on where you want to deploy the library.
Once you have finished the configure step of CMake, run 'make', then 'make install'
When building GDAL from sources, the different drivers to use can be chosen at the configure step. When calling the 'configure' script, add '--with-openjpeg=OPENJPEG_INSTALL' where OPENJPEG_INSTALL is the directory where OpenJpeg is installed. Examples of script to build GDAL are present in the repository OTB-DevUtils.
Note : if the GDAL library (libgdal.so) is not installed in the same directory as OpenJpeg, you will need to add the OpenJpeg library folder to your LD configuration (either with the variable LD_LIBRARY_PATH, or with the "/etc/ld.conf.d/" configuration).
If you don't want to re-compile your GDAL library, you can build separately an external driver that will be loaded at run-time. For this you will need :
- An OpenJpeg library installed (version 2.0)
- the headers of your GDAL library
- the source file of the OpenJpeg driver, available through GDAL sources in frmts/openjpeg/openjpegdataset.cpp. Make sure you take a source file from the same version as your current GDAL library.
Then the OpenJpeg plugin can be compiled with this command line :
g++ -fPIC -g -Wall openjpegdataset.cpp -shared -o gdal_JP2OpenJPEG.so -I$GDAL_INCLUDE_DIR -I$OPENJPEG_INSTALL_DIR/include -L. -lgdal -L$OPENJPEG_INSTALL_DIR/lib -lopenjp2
The name of the output shared library can't be changed, because 'JP2OpenJPEG' is the official name of the OpenJpeg driver in GDAL. In order for this plugin to be detected at run-time, you have to use the GDAL_DRIVER_PATH environment variable. Set it to the folder containing your plugin.
It seems that GDAL also have a standard location for plugins. Let say your GDAL library is installed in /usr/lib, you may already have a folder /usr/lib/gdalplugins. At run-time, GDAL will check this folder for external plugins (without having to define the GDAL_DRIVER_PATH).
Note : same remark as before about the location of the OpenJpeg library and your LD configuration.
OpenJpeg 2.1 ?