lcorbasson / pdfsizeopt

Automatically exported from code.google.com/p/pdfsizeopt
0 stars 0 forks source link

jbig2enc for Mac OS X #49

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The only why to compile jbig2enc is through a homebrew formula from Misty De 
Meo but it seems pdfoptsize isn't compatible to that binary because jbig2 isn't 
executed. When running jbig2 as single command it's working properly, I also 
tested it with pdfbeads (http://rubygems.org/gems/pdfbeads).

http://www.diybookscanner.org/forum/viewtopic.php?f=3&t=683&p=10895#p10895

https://raw.github.com/mistydemeo/homebrew/55e72cf6b673d82838ea233022daecd77f738
c99/Library/Formula/jbig2enc.rb

Here is the output from pdfsizeopt:

python pdfsizeopt.py --use-pngout=true --use-jbig2=true --use-multivalent=true 
Scan-110805-0023_1L.pdf 
info: This is pdfsizeopt.py rUNKNOWN size=279220.
info: loading PDF from: Scan-110805-0023_1L.pdf
info: loaded PDF of 178418 bytes
info: separated to 17 objs + xref + trailer
warning: cannot parse obj 13: __main__.PdfTokenParseError: endobj/stream not 
found from ofs=177711 to ofs=177727
warning: cannot parse obj 13: __main__.PdfTokenParseError: endobj/stream not 
found from ofs=177711 to ofs=177727
info: found 0 Type1 fonts loaded
info: found 0 Type1C fonts loaded
info: will optimize image XObject 8; orig width=2273 height=3308 
colorspace=/DeviceGray bpc=8 filter=[ /LZWDecode ] dp=0 size=171101 
gs_device=pnggray
info: optimizing 1 images of 171101 bytes in total
info: writing ImageRenderer (171103 image bytes) to: pso.conv.pnggray.tmp.ps
info: executing ImageRenderer with Ghostscript: gs -q -dNOPAUSE -dBATCH 
-sDEVICE=pnggray -sOutputFile='pso.conv-%04d.pnggray.tmp.png' -f 
pso.conv.pnggray.tmp.ps
ImageRenderer: rendering image XObject 8 width=2273 height=3308 bpc=8 
colorspace=/DeviceGray filter=[/LZWDecode] decodeparms=null device=pnggray
ImageRenderer: all OK
info: loading image from: pso.conv-0001.pnggray.tmp.png
info: loaded PNG IDAT of 148478 bytes
info: executing image optimizer sam2p_np: sam2p -pdf:2 -c zip:1:9 -s 
Gray1:Indexed1:Gray2:Indexed2:Rgb1:Gray4:Indexed4:Rgb2:Gray8:Indexed8:Rgb4:Rgb8:
stop -- pso.conv-0001.pnggray.tmp.png pso.conv-8.sam2p-np.pdf
This is sam2p 0.49.
Available Loaders: PS PDF JAI PNG JPEG TIFF PNM BMP GIF LBM XPM PCX TGA.
Available Appliers: XWD Meta Empty BMP PNG TIFF6 TIFF6-JAI JPEG-JAI JPEG PNM 
GIF89a+LZW XPM PSL1C PSL23+PDF PSL2+PDF-JAI P-TrOpBb.
sam2p: Notice: PNM: loaded alpha, but no transparent pixels
sam2p: Notice: job: read InputFile: pso.conv-0001.pnggray.tmp.png
sam2p: Notice: writeTTT: using template: p02
sam2p: Notice: applyProfile: applied OutputRule #0
sam2p: Notice: job: written OutputFile: pso.conv-8.sam2p-np.pdf
Success.
info: loading image from: pso.conv-8.sam2p-np.pdf
info: loading PDF from: pso.conv-8.sam2p-np.pdf
info: loaded PDF of 108539 bytes
info: separated to 5 objs + xref + trailer
info: loaded PNG IDAT of 107818 bytes
info: executing image optimizer sam2p_pr: sam2p -c zip:15:9 -- 
pso.conv-0001.pnggray.tmp.png pso.conv-8.sam2p-pr.png
This is sam2p 0.49.
Available Loaders: PS PDF JAI PNG JPEG TIFF PNM BMP GIF LBM XPM PCX TGA.
Available Appliers: XWD Meta Empty BMP PNG TIFF6 TIFF6-JAI JPEG-JAI JPEG PNM 
GIF89a+LZW XPM PSL1C PSL23+PDF PSL2+PDF-JAI P-TrOpBb.
sam2p: Notice: PNM: loaded alpha, but no transparent pixels
sam2p: Notice: job: read InputFile: pso.conv-0001.pnggray.tmp.png
sam2p: Notice: applyProfile: applied OutputRule #2
sam2p: Notice: job: written OutputFile: pso.conv-8.sam2p-pr.png
Success.
info: loading image from: pso.conv-8.sam2p-pr.png
info: loaded PNG IDAT of 107922 bytes
info: executing image optimizer jbig2: jbig2 -p pso.conv-8.sam2p-pr.png 
>pso.conv-8.jbig2
Error in pixReadStreamPng: function not present
Error in pixReadStream: png: no pix returned
Error in pixRead: pix not read
info: jbig2 failed, status=0x300
Traceback (most recent call last):
  File "pdfsizeopt.py", line 6968, in <module>
    main(sys.argv)
  File "pdfsizeopt.py", line 6951, in main
    pdf.OptimizeImages(use_pngout=use_pngout, use_jbig2=use_jbig2)
  File "pdfsizeopt.py", line 5719, in OptimizeImages
    cmd_name='jbig2', do_just_read=True)[1]
  File "pdfsizeopt.py", line 5162, in ConvertImage
    assert 0, '%s failed (status)' % cmd_name
AssertionError: jbig2 failed (status)

Original issue reported on code.google.com by tristan....@gmail.com on 8 Aug 2011 at 4:43

Attachments:

GoogleCodeExporter commented 8 years ago
Could you please attach the jbig2 binary you are using (if it's not too big)?

FYI It works for me on Linux with the official jbig2 binary:

info: loaded PNG IDAT of 107922 bytes
info: executing image optimizer jbig2: jbig2 -p pso.conv-8.sam2p-pr.png 
>pso.conv-8.jbig2
info: executing image optimizer pngout: pngout pso.conv-0001.pnggray.tmp.png 
pso.conv-8.pngout.png
 In:  148813 bytes               pso.conv-0001.pnggray.tmp.png /c0 /f5 /d8
Out:   97776 bytes               pso.conv-8.pngout.png /c3 /f0 /d1, 2 colors
Chg:  -51037 bytes ( 65% of original)
info: loading image from: pso.conv-8.pngout.png
info: loaded PNG IDAT of 97701 bytes and PLTE of 6 bytes
info: optimized image XObject 8 file_name=pso.conv-8.jbig2 size=36812 (22%) 
methods=jbig2:36812,pngout:97950,sam2p_np:108007,sam2p_pr:108172,gs:148709,#orig
:171111
info: saved 134299 bytes (78%) on optimizable images
info: eliminated 3 duplicate objs
info: eliminated 7 unused objs in 4 classes
info: writing Multivalent input PDF: pso.conv.mi.tmp.pdf
info: saving PDF with 9 objs to: pso.conv.mi.tmp.pdf
info: generated 43614 bytes (24%)
info: executing Multivalent to optimize PDF: java -cp 
/home/pts/prg/pdfsizeopt/trunk/Multivalent.jar tool.pdf.Compress -nopagepiece 
-noalt pso.conv.mi.tmp.pdf
file:/home/pts/prg/pdfsizeopt/trunk/pso.conv.mi.tmp.pdf, 43614 bytes
PDF 1.5, producer=ImageMagick 6.7.1-0 2011-08-06 Q16 
http://www.imagemagick.org, creator=null
additional compression may be possible with:
         -compact
=> new length = 37466, saved 14%, elapsed time = 0 sec
info: Multivalent generated pso.conv.mi.tmp-o.pdf of 37488 bytes (86%)
info: compressed xref stream from 16 to 130 bytes (813%)
info: optimized to 37391 bytes after Multivalent (100%)
info: saving PDF to: /tmp/t.psom.pdf
info: generated 37391 bytes (21%)

As a temporary workaround, you can use pdfsizeopt --use-jbig2=false

FYI I've attached the offending pso.conv-8.sam2p-pr.png file for which the 
following command fails for you:

  jbig2 -p pso.conv-8.sam2p-pr.png >pso.conv-8.jbig2

Original comment by pts...@gmail.com on 8 Aug 2011 at 5:26

Attachments:

GoogleCodeExporter commented 8 years ago
Thank you for your support. Here's the binary.

Original comment by tristan....@gmail.com on 8 Aug 2011 at 9:13

Attachments:

GoogleCodeExporter commented 8 years ago
FYI See the expected output of

  jbig2 -p pso.conv-8.sam2p-pr.png >pso.conv-8.jbig2

attached.

Original comment by pts...@gmail.com on 26 Aug 2011 at 8:28

Attachments:

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Thank you for taking time to report this issue and attach all relevant files. 
Based on the information you have shared, I was able to provide a fix.

The most probable reason of the failure of your jbig2 binary is that it uses a 
leptonica library without png support compiled in. If you recompiled leptonica 
with png support (possibly compiling libpng as well), the errors

  Error in pixReadStreamPng: function not present
  Error in pixReadStream: png: no pix returned
  Error in pixRead: pix not read

would go away. However, this work is not necessary, because I compiled it for 
you (and for other pdfsizeopt users), just download 
http://pdfsizeopt.googlecode.com/files/jbig2.darwin , rename it to jbig2, chmod 
+x it, and move it next to pdfsizeopt.py. Please report whether it's successful.

For me it succeeds with the command

  jbig2 -p pso.conv-8.sam2p-pr.png >pso.conv-8.jbig2

, and it produces the expected output file.

FYI See the build.sh in 
http://code.google.com/p/pts-mini-gpl/source/browse/#svn/trunk/build-jbig2 how 
I compiled the jbig2 tool for Mac OS X 10.5. I basically downloaded the vanilla

* zlib-1.2.5.tar.gz
* libpng-1.2.46.tar.gz
* leptonica-1.68.tar.gz
* agl-jbig2enc-0.27-20-ge8be922.tar.gz

and compiled and installed them with the gcc-mp-4.4 in MacPorts.

Original comment by pts...@gmail.com on 27 Aug 2011 at 7:46