Bug 693518

Summary: MuPDF fails to build against OpenJPEG 2.0
Product: MuPDF Reporter: Charlie Sharpsteen <source>
Component: fitzAssignee: MuPDF bugs <mupdf-bugs>
Status: RESOLVED FIXED    
Severity: major CC: jackie.rosen, michael, pipping, robin.watts, tor.andersson
Priority: P4    
Version: 1.1   
Hardware: All   
OS: All   
Customer: Word Size: ---
Attachments: openjpeg-2 pkgconfig patch
0001-Update-Makerules-use-of-pkg-config-we-need-openjpeg-.patch

Description Charlie Sharpsteen 2012-12-29 19:55:37 UTC
Looks like an API incompatibility with the latest version of OpenJPEG as MuPDF builds fine against the 1.5 release. Errors occur when building image_jpx.o and possible other files:


    CC build/debug/image_jpx.o
fitz/image_jpx.c:27:2: error: use of undeclared identifier 'opj_event_mgr_t'
        opj_event_mgr_t evtmgr;
        ^
fitz/image_jpx.c:29:2: error: unknown type name 'opj_dinfo_t'; did you mean 'opj_tp_info_t'?
        opj_dinfo_t *info;
        ^~~~~~~~~~~
        opj_tp_info_t
/usr/local/include/openjpeg-2.0/openjpeg.h:637:3: note: 'opj_tp_info_t' declared here
} opj_tp_info_t;
  ^
fitz/image_jpx.c:30:2: error: unknown type name 'opj_cio_t'; did you mean 'opj_poc_t'?
        opj_cio_t *cio;
        ^~~~~~~~~
        opj_poc_t
/usr/local/include/openjpeg-2.0/openjpeg.h:254:3: note: 'opj_poc_t' declared here
} opj_poc_t;
  ^
fitz/image_jpx.c:43:12: error: use of undeclared identifier 'CODEC_J2K'
                format = CODEC_J2K;
                         ^
fitz/image_jpx.c:45:12: error: use of undeclared identifier 'CODEC_JP2'
                format = CODEC_JP2;
                         ^
fitz/image_jpx.c:47:10: error: use of undeclared identifier 'evtmgr'
        memset(&evtmgr, 0, sizeof(evtmgr));
                ^
/usr/include/secure/_string.h:76:21: note: expanded from macro 'memset'
  ((__darwin_obsz0 (dest) != (size_t) -1)                               \
                    ^
/usr/include/secure/_common.h:38:55: note: expanded from macro '__darwin_obsz0'
#define __darwin_obsz0(object) __builtin_object_size (object, 0)
                                                      ^
fitz/image_jpx.c:47:10: error: use of undeclared identifier 'evtmgr'
        memset(&evtmgr, 0, sizeof(evtmgr));
                ^
/usr/include/secure/_string.h:77:30: note: expanded from macro 'memset'
   ? __builtin___memset_chk (dest, val, len, __darwin_obsz0 (dest))     \
                             ^
fitz/image_jpx.c:47:10: error: use of undeclared identifier 'evtmgr'
        memset(&evtmgr, 0, sizeof(evtmgr));
                ^
/usr/include/secure/_string.h:78:27: note: expanded from macro 'memset'
   : __inline_memset_chk (dest, val, len))
                          ^
fitz/image_jpx.c:48:2: error: use of undeclared identifier 'evtmgr'
        evtmgr.error_handler = fz_opj_error_callback;
        ^
fitz/image_jpx.c:49:2: error: use of undeclared identifier 'evtmgr'
        evtmgr.warning_handler = fz_opj_warning_callback;
        ^
fitz/image_jpx.c:50:2: error: use of undeclared identifier 'evtmgr'
        evtmgr.info_handler = fz_opj_info_callback;
        ^
fitz/image_jpx.c:56:7: warning: incompatible pointer types assigning to 'opj_tp_info_t *'
      (aka 'struct opj_tp_info *') from 'opj_codec_t *' (aka 'void **')
      [-Wincompatible-pointer-types]
        info = opj_create_decompress(format);
             ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fitz/image_jpx.c:57:2: warning: implicit declaration of function 'opj_set_event_mgr' is invalid
      in C99 [-Wimplicit-function-declaration]
        opj_set_event_mgr((opj_common_ptr)info, &evtmgr, ctx);
        ^
fitz/image_jpx.c:57:21: error: use of undeclared identifier 'opj_common_ptr'
        opj_set_event_mgr((opj_common_ptr)info, &evtmgr, ctx);
                           ^
fitz/image_jpx.c:58:20: warning: incompatible pointer types passing 'opj_tp_info_t *'
      (aka 'struct opj_tp_info *') to parameter of type 'opj_codec_t *' (aka 'void **')
      [-Wincompatible-pointer-types]
        opj_setup_decoder(info, &params);
                          ^~~~
/usr/local/include/openjpeg-2.0/openjpeg.h:1140:62: note: passing argument to parameter
      'p_codec' here
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
                                                             ^
fitz/image_jpx.c:60:8: warning: implicit declaration of function 'opj_cio_open' is invalid in
      C99 [-Wimplicit-function-declaration]
        cio = opj_cio_open((opj_common_ptr)info, data, size);
              ^
fitz/image_jpx.c:60:22: error: use of undeclared identifier 'opj_common_ptr'
        cio = opj_cio_open((opj_common_ptr)info, data, size);
                            ^
fitz/image_jpx.c:62:28: error: too few arguments to function call, expected 3, have 2
        jpx = opj_decode(info, cio);
              ~~~~~~~~~~          ^
/usr/local/include/openjpeg-2.0/openjpeg.h:1181:1: note: 'opj_decode' declared here
OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode(   opj_codec_t *p_decompressor,
^
/usr/local/include/openjpeg-2.0/openjpeg.h:59:20: note: expanded from macro 'OPJ_API'
#define OPJ_API    __attribute__ ((visibility ("default")))
                   ^
fitz/image_jpx.c:64:2: warning: implicit declaration of function 'opj_cio_close' is invalid in
      C99 [-Wimplicit-function-declaration]
        opj_cio_close(cio);
        ^
fitz/image_jpx.c:65:2: warning: implicit declaration of function 'opj_destroy_decompress' is
      invalid in C99 [-Wimplicit-function-declaration]
        opj_destroy_decompress(info);
        ^
fitz/image_jpx.c:95:26: error: use of undeclared identifier 'CLRSPC_SRGB'
        if (jpx->color_space == CLRSPC_SRGB && n == 4) { n = 3; a = 1; }
                                ^
fitz/image_jpx.c:96:31: error: use of undeclared identifier 'CLRSPC_SYCC'
        else if (jpx->color_space == CLRSPC_SYCC && n == 4) { n = 3; a = 1; }
                                     ^
6 warnings and 16 errors generated.
make: *** [build/debug/image_jpx.o] Error 1
Comment 1 Robin Watts 2013-01-11 15:46:11 UTC
I have an OpenJPEG2 branch on my git repo that updates MuPDF to work with OpenJPEG2. Unfortunately various files that work under 1.5.0 are broken under 2.0, so until these are fixed, we can't really upgrade.
Comment 2 Michael Weber 2013-06-06 13:41:27 UTC
Created attachment 9938 [details]
openjpeg-2 pkgconfig patch

with [1], and openjpeg-2 now supporting pkg-config, 
your makerules [3] should also refer to openjpeg-2 
lines 55 and 56 should refer to openjp2


[1] http://git.ghostscript.com/?p=mupdf.git;a=commit;h=a1c8ba17f74180c5e05c4eb7b67912d14ea7b080
[2] http://code.google.com/p/openjpeg/source/detail?r=2250
[3] http://git.ghostscript.com/?p=mupdf.git;a=blob;f=Makerules;h=9dd6717aa7ebeef522c26661ab01ad3b913ac3df;hb=HEAD
Comment 3 Robin Watts 2013-06-06 15:22:29 UTC
We now require openjpeg 2.0 or the link will fail. Our version contains several patches to avoid SEGVs and other nasties - as always linking with a system version will miss those out, and we do not support that configuration.

Having said that it would make sense for us to update Makerules to ask for the correct version of the system lib from pkg-config.

Unfortunately, it's not entirely clear to me how to do this. According to Tor, on debian "libopenjpeg2" gets you version 1.3. "libopenjpeg-dev" gets you a later version. We can't find "libopenjp2" on ubuntu either, so we're at a loss here.

What distro was this patch made on please?
Comment 4 Robin Watts 2013-06-06 15:25:36 UTC
Created attachment 9939 [details]
0001-Update-Makerules-use-of-pkg-config-we-need-openjpeg-.patch

The above patch in git format.
Comment 5 Michael Weber 2013-06-06 21:21:34 UTC
(In reply to comment #3)
> We now require openjpeg 2.0 or the link will fail. Our version contains
> several patches to avoid SEGVs and other nasties - as always linking with a
> system version will miss those out, and we do not support that configuration.
can you push these fixes upstream, pls. so "we all" can enjoy them.
 
> Having said that it would make sense for us to update Makerules to ask for
> the correct version of the system lib from pkg-config.

> 
> Unfortunately, it's not entirely clear to me how to do this. According to
> Tor, on debian "libopenjpeg2" gets you version 1.3. "libopenjpeg-dev" gets
> you a later version. We can't find "libopenjp2" on ubuntu either, so we're
> at a loss here.
um, http://patch-tracker.debian.org/package/openjpeg reveals some versions around 1.3 and 1.5.1, but no version 2.0.0.
What does `pkg-config --list-all | grep jpeg` say?

> What distro was this patch made on please?
Gentoo main repository. 
As mentioned, openjpeg release 2.0.0 per se has no pkg-config file, but it was later added (see the referred svn repo commit) named libopenjp2.pc . 

p.s. your static debian/mupdf.pc needs an update, too.

http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/app-text/mupdf/files/mupdf-9999-openjpeg2.patch?revision=1.2&view=markup
Comment 6 Michael Weber 2013-06-06 23:20:55 UTC
(In reply to comment #5)
> (In reply to comment #3)
> > We now require openjpeg 2.0 or the link will fail. Our version contains
> > several patches to avoid SEGVs and other nasties - as always linking with a
> > system version will miss those out, and we do not support that configuration.
> can you push these fixes upstream, pls. so "we all" can enjoy them.
I added your patches to the Gentoo openjpeg-9999 (live vcs version) package
http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/media-libs/openjpeg/files/openjpeg-9999-mupdf.patch?revision=1.1&view=markup

I did not look into the other submodules, any significant patches?
I admire your ability to patch/improve your "thirdparties", but from a source-distro point, it's pure compile time madness to accept (cascaded) bundled libs.

llpp checks commit 42db34aa08 of mupdf, which bundles openjpeg, which bundles zlib et al. We can't just boot-strap the whole dependency try for every single (top level) program. 

Btw. current llpp works with current mupdf after this patch
http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/app-text/llpp/files/llpp-9999-mupdf-trailer.patch?revision=1.1&view=markup
Comment 7 Michael Weber 2013-06-08 13:03:56 UTC
while you're at it, bug 694301 http://bugs.ghostscript.com/show_bug.cgi?id=694301
Comment 8 Tor Andersson 2014-04-23 07:40:28 UTC
Fixed in commit 11cd137420d45f795b67f54f73cbf97010206d7a
Author: Tor Andersson <tor.andersson@artifex.com>
Date:   Thu Apr 17 17:45:45 2014 +0200

    Fix 693518: update Makerules and debian/control
    
    Debian doesn't have libopenjp2 as a package (whereas gentoo does) so
    I've removed it from the control file. You'll need to use the
    thirdparty submodule for openjpeg2 until such a time as it exists.