Commit 0ea5ad39 authored by Albert Astals Cid's avatar Albert Astals Cid

Stop supporting openjpeg1, you really want to use openjpeg2 :)

parent ce8e17e4
......@@ -50,7 +50,7 @@ option(ENABLE_GLIB "Compile poppler glib wrapper." ON)
option(ENABLE_GTK_DOC "Whether to generate glib API documentation." OFF)
option(ENABLE_QT4 "Compile poppler qt4 wrapper." ON)
option(ENABLE_QT5 "Compile poppler qt5 wrapper." ON)
set(ENABLE_LIBOPENJPEG "auto" CACHE STRING "Use libopenjpeg for JPX streams. Possible values: auto, openjpeg1, openjpeg2, unmaintained, none. 'auto' prefers openjpeg2 over openjpeg1 if both are available. 'unmaintained' gives you the internal unmaintained decoder. Use at your own risk. 'none' compiles no JPX decoder at all. Default: auto")
set(ENABLE_LIBOPENJPEG "openjpeg2" CACHE STRING "Use libopenjpeg for JPX streams. Possible values: openjpeg2, unmaintained, none. 'unmaintained' gives you the internal unmaintained decoder. Use at your own risk. 'none' compiles no JPX decoder at all. Default: openjpeg2")
set(ENABLE_CMS "lcms2" CACHE STRING "Use color management system. Possible values: lcms2. Unset to disable color management system.")
set(ENABLE_DCTDECODER "libjpeg" CACHE STRING "Use libjpeg for DCT streams. Possible values: libjpeg, unmaintained, none. will use libjpeg if available or fail if not. 'unmaintained' gives you the internal unmaintained decoder. Use at your own risk. 'none' compiles no DCT decoder at all. Default: libjpeg")
option(ENABLE_LIBCURL "Build libcurl based HTTP support." ON)
......@@ -201,33 +201,9 @@ if(ENABLE_ZLIB_UNCOMPRESS AND NOT ENABLE_ZLIB)
message("Warning: ENABLE_ZLIB_UNCOMPRESS requires ENABLE_ZLIB")
set(ENABLE_ZLIB_UNCOMPRESS FALSE)
endif()
set(USE_OPENJPEG1 FALSE)
set(USE_OPENJPEG2 FALSE)
set(WITH_OPENJPEG FALSE)
if(ENABLE_LIBOPENJPEG STREQUAL "auto")
if(ENABLE_LIBOPENJPEG STREQUAL "openjpeg2")
find_package(LIBOPENJPEG2)
set(USE_OPENJPEG2 ${LIBOPENJPEG2_FOUND})
set(WITH_OPENJPEG ${LIBOPENJPEG2_FOUND})
if(NOT LIBOPENJPEG2_FOUND)
find_package(LIBOPENJPEG)
set(USE_OPENJPEG1 ${LIBOPENJPEG_FOUND})
set(WITH_OPENJPEG ${LIBOPENJPEG_FOUND})
if(NOT LIBOPENJPEG_FOUND)
message(FATAL_ERROR "Install libopenjpeg2 or libopenjpeg1 before trying to build poppler. You can also decide to use the internal unmaintained JPX decoder or none at all.")
endif()
endif()
set(HAVE_JPX_DECODER ON)
elseif(ENABLE_LIBOPENJPEG STREQUAL "openjpeg1")
find_package(LIBOPENJPEG)
set(USE_OPENJPEG1 ${LIBOPENJPEG_FOUND})
set(WITH_OPENJPEG ${LIBOPENJPEG_FOUND})
if(NOT LIBOPENJPEG_FOUND)
message(FATAL_ERROR "Install libopenjpeg1 before trying to build poppler. You can also decide to use the internal unmaintained JPX decoder or none at all.")
endif()
set(HAVE_JPX_DECODER ON)
elseif(ENABLE_LIBOPENJPEG STREQUAL "openjpeg2")
find_package(LIBOPENJPEG2)
set(USE_OPENJPEG2 ${LIBOPENJPEG2_FOUND})
set(WITH_OPENJPEG ${LIBOPENJPEG2_FOUND})
if(NOT LIBOPENJPEG2_FOUND)
message(FATAL_ERROR "Install libopenjpeg2 before trying to build poppler. You can also decide to use the internal unmaintained JPX decoder or none at all.")
......@@ -302,9 +278,6 @@ if(TIFF_FOUND)
include_directories(${TIFF_INCLUDE_DIR})
set(ENABLE_LIBTIFF ON)
endif()
if(LIBOPENJPEG_FOUND)
include_directories(${LIBOPENJPEG_INCLUDE_DIR})
endif()
if(LIBOPENJPEG2_FOUND)
include_directories(${LIBOPENJPEG2_INCLUDE_DIRS})
endif()
......@@ -486,17 +459,10 @@ if (ENABLE_NSS3)
)
set(poppler_LIBS ${poppler_LIBS} ${NSS3_LIBRARIES})
endif()
if(LIBOPENJPEG_FOUND)
if (LIBOPENJPEG2_FOUND)
set(poppler_SRCS ${poppler_SRCS}
poppler/JPEG2000Stream.cc
)
set(poppler_LIBS ${poppler_LIBS} ${LIBOPENJPEG_LIBRARIES})
add_definitions(-DUSE_OPENJPEG1)
elseif (LIBOPENJPEG2_FOUND)
set(poppler_SRCS ${poppler_SRCS}
poppler/JPEG2000Stream.cc
)
add_definitions(-DUSE_OPENJPEG2)
set(poppler_LIBS ${poppler_LIBS} ${LIBOPENJPEG2_LIBRARIES})
else ()
set(poppler_SRCS ${poppler_SRCS}
......@@ -658,11 +624,7 @@ if(ENABLE_XPDF_HEADERS)
poppler/CurlPDFDocBuilder.h
DESTINATION include/poppler)
endif()
if(LIBOPENJPEG_FOUND)
install(FILES
poppler/JPEG2000Stream.h
DESTINATION include/poppler)
elseif(LIBOPENJPEG2_FOUND)
if(LIBOPENJPEG2_FOUND)
install(FILES
poppler/JPEG2000Stream.h
DESTINATION include/poppler)
......@@ -772,13 +734,7 @@ show_end_message_yesno("use zlib compress" ENABLE_ZLIB)
show_end_message_yesno("use zlib uncompress" ENABLE_ZLIB_UNCOMPRESS)
show_end_message_yesno("use nss3" ENABLE_NSS3)
show_end_message_yesno("use curl" ENABLE_LIBCURL)
show_end_message_yesno("use libopenjpeg" WITH_OPENJPEG)
if(USE_OPENJPEG1)
message(" with openjpeg1")
endif()
if(USE_OPENJPEG2)
message(" with openjpeg2")
endif()
show_end_message_yesno("use libopenjpeg2" WITH_OPENJPEG)
show_end_message_yesno("use lcms2" USE_CMS)
show_end_message_yesno("command line utils" ENABLE_UTILS)
show_end_message("test data dir" ${TESTDATADIR})
......
......@@ -73,9 +73,6 @@
/* Define if you have the iconv() function and it works. */
#cmakedefine HAVE_ICONV 1
/* Define to 1 if you have the `openjpeg' library (-lopenjpeg). */
#cmakedefine HAVE_LIBOPENJPEG 1
/* Define to 1 if you have the `z' library (-lz). */
#cmakedefine HAVE_LIBZ 1
......@@ -100,9 +97,6 @@
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#cmakedefine HAVE_NDIR_H 1
/* Define to 1 if you have the <openjpeg.h> header file. */
#cmakedefine HAVE_OPENJPEG_H 1
/* Define to 1 if you have the `popen' function. */
#cmakedefine HAVE_POPEN 1
......
......@@ -24,7 +24,6 @@
+ ((minor) * 100) \
+ ((micro) * 1))
#ifdef USE_OPENJPEG2
#ifdef OPJ_VERSION_MAJOR
#define OPENJPEG_VERSION OPENJPEG_VERSION_ENCODE(OPJ_VERSION_MAJOR, OPJ_VERSION_MINOR, OPJ_VERSION_BUILD)
#else
......@@ -33,7 +32,6 @@
// assume there will be no API changes in 2.0.x.
#define OPENJPEG_VERSION OPENJPEG_VERSION_ENCODE(2, 0, 0)
#endif
#endif
struct JPXStreamPrivate {
opj_image_t *image;
......@@ -44,13 +42,7 @@ struct JPXStreamPrivate {
GBool indexed;
GBool inited;
int smaskInData;
#ifdef USE_OPENJPEG1
opj_dinfo_t *dinfo;
void init2(unsigned char *buf, int bufLen, OPJ_CODEC_FORMAT format, GBool indexed);
#endif
#ifdef USE_OPENJPEG2
void init2(OPJ_CODEC_FORMAT format, unsigned char *data, int length, GBool indexed);
#endif
};
static inline Guchar adjustComp(int r, int adjust, int depth, int sgndcorr, GBool indexed) {
......@@ -90,9 +82,6 @@ JPXStream::JPXStream(Stream *strA) : FilterStream(strA) {
priv->npixels = 0;
priv->ncomps = 0;
priv->indexed = gFalse;
#ifdef USE_OPENJPEG1
priv->dinfo = NULL;
#endif
}
JPXStream::~JPXStream() {
......@@ -112,13 +101,6 @@ void JPXStream::close() {
priv->image = NULL;
priv->npixels = 0;
}
#ifdef USE_OPENJPEG1
if (priv->dinfo != NULL) {
opj_destroy_decompress(priv->dinfo);
priv->dinfo = NULL;
}
#endif
}
Goffset JPXStream::getPos() {
......@@ -162,13 +144,8 @@ void JPXStream::getImageParams(int *bitsPerComponent, StreamColorSpaceMode *csMo
*bitsPerComponent = 8;
int numComps = (priv->image) ? priv->image->numcomps : 1;
if (priv->image) {
#ifdef USE_OPENJPEG1
if (priv->image->color_space == CLRSPC_SRGB && numComps == 4) { numComps = 3; }
else if (priv->image->color_space == CLRSPC_SYCC && numComps == 4) { numComps = 3; }
#else
if (priv->image->color_space == OPJ_CLRSPC_SRGB && numComps == 4) { numComps = 3; }
else if (priv->image->color_space == OPJ_CLRSPC_SYCC && numComps == 4) { numComps = 3; }
#endif
else if (numComps == 2) { numComps = 1; }
else if (numComps > 4) { numComps = 4; }
}
......@@ -189,127 +166,6 @@ static void libopenjpeg_warning_callback(const char *msg, void * /*client_data*/
error(errSyntaxWarning, -1, "{0:s}", msg);
}
#ifdef USE_OPENJPEG1
#define BUFFER_INITIAL_SIZE 4096
void JPXStream::init()
{
Object oLen, cspace, smaskInData;
if (getDict()) oLen = getDict()->lookup("Length");
if (getDict()) cspace = getDict()->lookup("ColorSpace");
if (getDict()) smaskInData = getDict()->lookup("SMaskInData");
int bufSize = BUFFER_INITIAL_SIZE;
if (oLen.isInt()) bufSize = oLen.getInt();
if (cspace.isArray() && cspace.arrayGetLength() > 0) {
Object cstype = cspace.arrayGet(0);
if (cstype.isName("Indexed")) priv->indexed = gTrue;
}
priv->smaskInData = 0;
if (smaskInData.isInt()) priv->smaskInData = smaskInData.getInt();
int length = 0;
unsigned char *buf = str->toUnsignedChars(&length, bufSize);
priv->init2(buf, length, CODEC_JP2, priv->indexed);
free(buf);
if (priv->image) {
int numComps = (priv->image) ? priv->image->numcomps : 1;
int alpha = 0;
if (priv->image) {
if (priv->image->color_space == CLRSPC_SRGB && numComps == 4) { numComps = 3; alpha = 1; }
else if (priv->image->color_space == CLRSPC_SYCC && numComps == 4) { numComps = 3; alpha = 1; }
else if (numComps == 2) { numComps = 1; alpha = 1; }
else if (numComps > 4) { numComps = 4; alpha = 1; }
else { alpha = 0; }
}
priv->npixels = priv->image->comps[0].w * priv->image->comps[0].h;
priv->ncomps = priv->image->numcomps;
if (alpha == 1 && priv->smaskInData == 0) priv->ncomps--;
for (int component = 0; component < priv->ncomps; component++) {
if (priv->image->comps[component].data == NULL) {
close();
break;
}
unsigned char *cdata = (unsigned char *)priv->image->comps[component].data;
int adjust = 0;
int depth = priv->image->comps[component].prec;
if (priv->image->comps[component].prec > 8)
adjust = priv->image->comps[component].prec - 8;
int sgndcorr = 0;
if (priv->image->comps[component].sgnd)
sgndcorr = 1 << (priv->image->comps[0].prec - 1);
for (int i = 0; i < priv->npixels; i++) {
int r = priv->image->comps[component].data[i];
*(cdata++) = adjustComp(r, adjust, depth, sgndcorr, priv->indexed);
}
}
} else
priv->npixels = 0;
priv->counter = 0;
priv->ccounter = 0;
priv->inited = gTrue;
}
void JPXStreamPrivate::init2(unsigned char *buf, int bufLen, OPJ_CODEC_FORMAT format, GBool indexed)
{
opj_cio_t *cio = NULL;
/* Use default decompression parameters */
opj_dparameters_t parameters;
opj_set_default_decoder_parameters(&parameters);
#ifdef WITH_OPENJPEG_IGNORE_PCLR_CMAP_CDEF_FLAG
if (indexed)
parameters.flags = OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG;
#endif
/* Configure the event manager to receive errors and warnings */
opj_event_mgr_t event_mgr;
memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
event_mgr.error_handler = libopenjpeg_error_callback;
event_mgr.warning_handler = libopenjpeg_warning_callback;
/* Get the decoder handle of the format */
dinfo = opj_create_decompress(format);
if (dinfo == NULL) goto error;
/* Catch events using our callbacks */
opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, NULL);
/* Setup the decoder decoding parameters */
opj_setup_decoder(dinfo, &parameters);
/* Open a byte stream */
cio = opj_cio_open((opj_common_ptr)dinfo, buf, bufLen);
if (cio == NULL) goto error;
/* Decode the stream and fill the image structure */
image = opj_decode(dinfo, cio);
/* Close the byte stream */
opj_cio_close(cio);
if (image == NULL) goto error;
else return;
error:
if (format == CODEC_JP2) {
error(errSyntaxWarning, -1, "Did not succeed opening JPX Stream as JP2, trying as J2K.");
init2(buf, bufLen, CODEC_J2K, indexed);
} else if (format == CODEC_J2K) {
error(errSyntaxWarning, -1, "Did not succeed opening JPX Stream as J2K, trying as JPT.");
init2(buf, bufLen, CODEC_JPT, indexed);
} else {
error(errSyntaxError, -1, "Did not succeed opening JPX Stream.");
}
}
#endif
#ifdef USE_OPENJPEG2
typedef struct JPXData_s
{
unsigned char *data;
......@@ -508,4 +364,3 @@ error:
error(errSyntaxError, -1, "Did no succeed opening JPX Stream.");
}
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment