#1107718 djvubind: program fails with tif, pnm, pbm, pgm and ppm images

#1107718#5
Date:
2025-06-12 19:44:13 UTC
From:
To:
Dear Maintainer,

the program fails with the mentioned files format, that according to the list
in line #393 of the command (/usr/bin/djvubind) should be supported as the
ones choosen to build the page list. I could get a djvu only using pbm
monochromatic format.

If using any other format it crash with an exception as described in bug
#1107584, it seems always for the same reason.

It fails when running cjb2 using the file it itself create in the _csepdjvu
function of /usr/lib/python3/dist-packages/djvubind/encode.py

What I found is that the crash happens when processing the first image of the
batch, as the following

* at line 134 of /usr/lib/python3/dist-packages/djvubind/encode.py it converts
  the image from the original format to a TIFF image named temp_textual.tif
  using the command: convert image001.tif +opaque black -monochrome temp_textual.tif
* at line 137 of /usr/lib/python3/dist-packages/djvubind/encode.py it calls
  the _cjb2 function of the same file to process temp_textual.tif to
  enc_bitonal_out.djvu
* in the functions _cjb2 at line 83 and 84 of
  /usr/lib/python3/dist-packages/djvubind/encode.py it build and then ask for
  the execution of the command (I got it by a print):
  cjb2 -dpi 350 -lossy temp_textual.tif enc_bitonal_out.djvu
* the command fails (I tested it directly in the file temp_textual.tif) with
  the following output:
$ cjb2 -dpi 350 -lossy temp_textual.tif enc_bitonal_out.djvu
*** Tiff image is not bitonal
*** (cjb2.cpp:754)
*** 'void read_tiff(CCImage&, DJVU::ByteStream*, cjb2opts&)'
* because #1107584 just an exception is reported

The only way I got to have the program give me an output is to change, in
/usr/lib/python3/dist-packages/djvubind/encode.py, the name of
temp_textual.tif in temp_textual.pbm, so that cjb2 is called as:
cjb2 -dpi 350 -lossy temp_textual.pbm enc_bitonal_out.djvu
that's do not fails.

I noted that in /usr/lib/python3/dist-packages/djvubind/encode.py, at line 76,
a temporary pbm image is created if the input file passed to _cjb2 is not in
the tif, pbm, pgm, pnm, rle format so cjb2 should be capable to process a
monocromatic tiff.

I'm nor an imagemagick or a djvu tools expert so I don't know if the problem
is something wrong in the temp_textual.tif creation by convert, or in the
processing of that tif by cjb2, but it seems that the only format supported
here should be pbm.

I tested this on a bookworm workstation, but I could reproduce the same
behaviour also using the testing (trixie) version of the programs.