Bug 691230 - Image is not shown
Summary: Image is not shown
Status: RESOLVED FIXED
Alias: None
Product: jbig2dec
Classification: Unclassified
Component: Missing Feature (show other bugs)
Version: master
Hardware: PC Windows XP
: P2 normal
Assignee: Henry Stiles
URL:
Keywords: bountiable
Depends on: 691247
Blocks:
  Show dependency tree
 
Reported: 2010-04-06 14:00 UTC by Josue Gomes
Modified: 2012-02-15 17:27 UTC (History)
5 users (show)

See Also:
Customer:
Word Size: ---


Attachments
Failing document (34.27 KB, application/pdf)
2010-04-06 14:00 UTC, Josue Gomes
Details
patch that adds basic halftone image support (12.05 KB, patch)
2012-01-09 20:46 UTC, Georg Gottleuber
Details | Diff
patch that adds basic halftone image support for ghostscript (13.39 KB, patch)
2012-01-11 20:29 UTC, Georg Gottleuber
Details | Diff
patch that adds basic halftone image support for ghostscript without warnings (17.69 KB, patch)
2012-01-12 22:24 UTC, Georg Gottleuber
Details | Diff
patch that adds basic halftone image support for ghostscript without warnings (20.36 KB, patch)
2012-01-12 22:57 UTC, Georg Gottleuber
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Josue Gomes 2010-04-06 14:00:01 UTC
Created attachment 6152 [details]
Failing document

The PDF document contains an image that is not shown by Ghostscript.
Also the image is not present when Ghostscript is used to convert the PDF document to an image document (eg TIFF or PNG).

This problem was detected and can be reproduced on versions 8.63, 8.64, 8.70 and 8.71 on Windows XP and Ubuntu Linux. Other systems or versions were not tested.

Ghostscript gives no error or warning messages.

Offending PDF document is attached.

-- Windows XP output

[C:\gs\gs8.71\bin]gswin32c Test_MARK1.pdf
GPL Ghostscript 8.71 (2010-02-10)
Copyright (C) 2010 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
>>showpage, press <return> to continue<<

GS>quit

[C:\gs\gs8.71\bin]

-- Ubuntu linux output

jgo@ubuntu:~$ gs Test_MARK1.pdf
GPL Ghostscript 8.70 (2009-07-31)
Copyright (C) 2009 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 1.
Page 1
>>showpage, press <return> to continue<<

jgo@ubuntu:~$
Comment 1 Marcos H. Woehrmann 2010-04-06 14:19:43 UTC
This file appears to contain a single JBIG2 image, so it's likely the problem is in the JBIG2 decoder.

I've duplicated the bug with head (r11022) and have verified that evince and Acrobat Reader 8.1.1 read the file correctly.
Comment 2 Masaki Ushizaka 2010-04-15 12:50:04 UTC
During the run with -Zw, it printed lines including following:

[w] jbig2dec WARNING unhandled segment type 'pattern dictionary' (segment 0x03)
[w] jbig2dec WARNING unhandled segment type 'immediate halftone region' (segment 0x04)

Looks like another unsupported segment data by jbig2dec.
Current jbig2dec source code has following 'unhandled' error message strings:

"unhandled segment type 'pattern dictionary'"
"unhandled segment type 'intermediate halftone region'"
"unhandled segment type 'immediate halftone region'"
"unhandled segment type 'immediate lossless halftone region'"
"unhandled segment type 'intermediate generic region'"
"unhandled segment type 'profile'"
"unhandled table segment"
Comment 3 Ralph Giles 2010-04-15 15:59:03 UTC
This is correct. I started implementing halftone support, but never completed the feature. Congratulations on finding a wild file which uses this code path!

Gorac recently contributed an implementation; this would be a nice addition to the ubc test suite files for verifying this. See bug 690979.
Comment 5 Masaki Ushizaka 2010-04-21 05:02:17 UTC
With Hin-Tak's help, I tried the patch from bug 690979, but it doesn't seem to solve this problem.  It suppressed the warning messages, but images still didn't come up.
Comment 6 Josue Gomes 2010-05-28 17:16:38 UTC
Any status on this?
Comment 7 Josue Gomes 2010-11-24 19:10:36 UTC
Also failing with GS 9.00 (2010-09-14).
Comment 8 Josue Gomes 2011-03-23 19:28:27 UTC
Also failing with 9.01
Comment 9 Henry Stiles 2011-12-14 18:45:46 UTC
Make P2 to increase the bounty.  This is missing functionality we really should have.
Comment 10 Georg Gottleuber 2012-01-09 20:46:24 UTC
Created attachment 8261 [details]
patch that adds basic halftone image support

I made a patch that adds basic halftone image support. It also works for the test sequence from JBIG2 standard (annex H).
Comment 11 Henry Stiles 2012-01-09 23:47:02 UTC
I integrated your patch but it does not seem to fix the original problem, we'll need Test_MARK1.pdf, the test file referenced in comment 1, to work before we can pay out the bounty.  I had to merge your patch manually, with conflicts, into ghostscript's version of jbig2dec which is a bit ahead of the standalone library, but I think I did everything correctly.  Did you check the original pdf file worked?  Thank you Georg.
Comment 12 Georg Gottleuber 2012-01-10 14:49:01 UTC
I was not aware of the jbig2dec copy included in ghostscript, so I tested with MuPDF an bare ./jbig2dec. Today I applied my patch to ghostscript-9.04. It worked. 

What I did:
1.) CFLAGS="-DJBIG2_HALFTONE" ./configure && make -j3

2.) I got a linker error because jbig2_halftone.c is not integrated in the build process properly. To add it modify base/jbig2.mak
--- base/jbig2.mak      2012-01-10 15:38:28.000000000 +0100
+++ base/jbig2.mak      2012-01-10 15:00:57.000000000 +0100
@@ -54,6 +54,7 @@
         $(JBIG2OBJ)jbig2_segment.$(OBJ) \
         $(JBIG2OBJ)jbig2_symbol_dict.$(OBJ) \
         $(JBIG2OBJ)jbig2_text.$(OBJ) \
+        $(JBIG2OBJ)jbig2_halftone.$(OBJ) \
         $(JBIG2OBJ)jbig2_metadata.$(OBJ) $(JBIG2_EXTRA_OBJS)
 
 libjbig2_OBJS=$(libjbig2_OBJS1) $(libjbig2_OBJS2)
@@ -152,6 +153,9 @@
 $(JBIG2OBJ)jbig2_page.$(OBJ) : $(JBIG2SRC)jbig2_page.c $(libjbig2_HDRS) $(JBIG2DEP)
        $(JBIG2_CC) $(JBIG2O_)jbig2_page.$(OBJ) $(C_) $(JBIG2SRC)jbig2_page.c
 
+$(JBIG2OBJ)jbig2_halftone.$(OBJ) : $(JBIG2SRC)jbig2_halftone.c $(libjbig2_HDRS) $(JBIG2DEP)
+       $(JBIG2_CC) $(JBIG2O_)jbig2_halftone.$(OBJ) $(C_) $(JBIG2SRC)jbig2_halftone.c
+
 $(JBIG2OBJ)jbig2_segment.$(OBJ) : $(JBIG2SRC)jbig2_segment.c $(libjbig2_HDRS) $(JBIG2DEP)
        $(JBIG2_CC) $(JBIG2O_)jbig2_segment.$(OBJ) $(C_) $(JBIG2SRC)jbig2_segment.c

3.) Apply my patch. 

Please also integrate my patch into jbig2dec.
Comment 13 Georg Gottleuber 2012-01-11 20:29:28 UTC
Created attachment 8270 [details]
patch that adds basic halftone image support for ghostscript

As discussed in IRC I made a patch for ghostscript from current git version.
Comment 14 Georg Gottleuber 2012-01-11 20:36:37 UTC
I give permission to distribute the patch above with GPL and Artifex commercial license.
Comment 15 Henry Stiles 2012-01-12 20:24:46 UTC
Looks good passed all the tests, a little warning cleanup is needed though:

jbig2dec/jbig2_halftone.c:68: warning: no previous prototype for 'jbig2_hd_new'
jbig2dec/jbig2_halftone.c:124: warning: no previous prototype for 'jbig2_hd_release'
jbig2dec/jbig2_halftone.c:265: warning: return makes integer from pointer without a cast
jbig2dec/jbig2_halftone.c:304: warning: no previous prototype for 'jbig2_decode_gray_scale_image'
jbig2dec/jbig2_halftone.c:393: warning: ISO C90 forbids mixed declarations and code
jbig2dec/jbig2_halftone.c:418: warning: ISO C90 forbids mixed declarations and code
jbig2dec/jbig2_halftone.c:453: warning: no previous prototype for 'jbig2_decode_ht_region_get_hpats'
jbig2dec/jbig2_halftone.c:491: warning: no previous prototype for 'jbig2_decode_halftone_region'
jbig2dec/jbig2_halftone.c:516: warning: ISO C90 forbids mixed declarations and code
jbig2dec/jbig2_halftone.c:540: warning: ISO C90 forbids mixed declarations and code
jbig2dec/jbig2_halftone.c:316: warning: 'ws' may be used uninitialized in this function
jbig2dec/jbig2_halftone.c:317: warning: 'as' may be used uninitialized in this function
Comment 16 Georg Gottleuber 2012-01-12 22:24:14 UTC
Created attachment 8272 [details]
patch that adds basic halftone image support for ghostscript without warnings

Oh thanks, I have overseen the warnings. Here a new patch with minor changes to avoid compiler warnings and a new jbig2_halftone.h header.
Comment 17 Georg Gottleuber 2012-01-12 22:57:08 UTC
Created attachment 8273 [details]
patch that adds basic halftone image support for ghostscript without warnings

Made a mistake. Please use this version.
Comment 19 Josue Gomes 2012-02-15 17:27:26 UTC
Successfully tested with GS 9.05