Group4 compression doesn't work

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

Add -monochrome to your command line. Group4 compression will not work unless the image is bilevel.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

We can reproduce the problem and should have a fix within the next few days. Thanks for the problem report.
Ivar Snaaijer
Posts: 21
Joined: 2006-02-22T09:22:30-07:00

Post by Ivar Snaaijer »

When i use

Code: Select all

convert -compress Group4 -type bilevel -monochrome loadFTPImg.asp.jpg loadFTPImg.asp_1.tiff
I get a good and appropriately small tiff file
when i use

Code: Select all

convert -compress Group4 -type bilevel -monochrome loadFTPImg.asp.jpg loadFTPImg.asp_2.pdf
I get a rather large pdf file, (looks like zip or fax), the pdf works.
When i use

Code: Select all

convert -compress Group4 loadFTPImg.asp.jpg loadFTPImg.asp_3.pdf
I get a pdf file with the size i expect, but the image gives an error (Acrobat 7 : a drawing error occurred)

I used :

Code: Select all

Version: ImageMagick 6.2.6 02/01/06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2006 ImageMagick Studio LLC
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

We can reproduce the problem you posted about and will have a fix in the next point release of ImageMagick, 6.2.6-2. Thanks for the problem report.
Ivar Snaaijer
Posts: 21
Joined: 2006-02-22T09:22:30-07:00

Post by Ivar Snaaijer »

I have installed

Code: Select all

Version: ImageMagick 6.2.6 02/24/06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2006 ImageMagick Studio LLC
and tried

Code: Select all

convert -compress Group4 -type bilevel -monochrome loadFTPImg.asp.jpg loadFTPImg.asp_2.pdf

convert -verbose -compress Group4 loadFTPImg.asp.jpg loadFTPImg.asp_3_new.pdf
first pdf is 121798 bytes, image in the pdf is runlength encoded, black and white, file opens in Acrobat reader 7

second pdf is 327,144 bytes, image in the pdf is runlength encoded, grayscale (as original), file opens in Acrobat reader 7

I also tried -compress Fax but get the same results (this did work better in the previous version)

I also tried -compress zip And got a much smaller file, that works in Acrobat.


As i understand it, for some reason the group4 encoding does not work in pdf yet. and it defaults to RLE.

It is an improvement but not yet completely finished, thanks for the quick fix. I have downloaded the code and try to make something of it, but it has been a long time ...
Ivar Snaaijer
Posts: 21
Joined: 2006-02-22T09:22:30-07:00

Post by Ivar Snaaijer »

I reverted back to the previous version and tried with -compression group4 only again. I also converted the same image by using ghostscript (GPL Ghostscript 8.50 (2005-12-31)) , some interesting differences in the object code are :

Image magic pdf :

Code: Select all

4 0 obj
<<
/Type /Page
/Parent 3 0 R
/Resources <<
/Font << /F0 8 0 R >>
/XObject << /Im0 9 0 R >>
/ProcSet 7 0 R >>

......

7 0 obj
[ /PDF /Text /ImageC ]
endobj

......

9 0 obj
<<
/Type /XObject
/Subtype /Image
/Name /Im0
/Filter [ /CCITTFaxDecode ]
/DecodeParms [ << >> << /K -1 /Columns 1620 /Rows 736 >> ]
/Width 1620
/Height 736
/ColorSpace 11 0 R
/BitsPerComponent 1
/Length 10 0 R
>>
stream

......

endstream
endobj
10 0 obj
15499
endobj

The object is coded a bit differently in the ghostscript pdf :

Code: Select all

4 0 obj
<</Type/Page/MediaBox [0 0 595 842]
/Rotate 90/Parent 3 0 R
/Resources<</ProcSet[/PDF /ImageB]
/XObject 8 0 R
>>

...

8 0 obj
<</R7
7 0 R>>
endobj
7 0 obj
<</Subtype/Image
/ImageMask true
/Width 1620
/Height 736
/BitsPerComponent 1
/Filter/CCITTFaxDecode
/DecodeParms<</K -1
/Columns 1620>>/Length 15274>>stream

......

endstream
endobj
The first +- 550 bytes of the two streams are the same, then there is a change, this can be due to compression settings, or something in the way the image is changed to monochrome.

I also find it interesting to see that imagemagick uses /ImageC (color images) and ghostscript uses /ImageB (grayscale or mask) in the Resource part. This should not have anything to do with it (eigther obsolete or only used for ps printing) it just caugt my eye.

This still leaves me with two possibilities; either the pdf code above is wrong, or the stream is broken, If i can find a proper binary editor to change the innards of the pdf I'm willing to try.
Ivar Snaaijer
Posts: 21
Joined: 2006-02-22T09:22:30-07:00

A fix !

Post by Ivar Snaaijer »

I used a hexeditor to change object 9 to

Code: Select all

...
/Name /Im0
/Filter [ /CCITTFaxDecode ]
/DecodeParms [ << /K -1 /Columns 1620 /Rows 736 >> ]
/Width 1620
/Height 736
...
(only romeved the extra << >> mentioned in the previous post)

and the pdf works fine.

For good measure did I also fit the stream generated by Image magic in the GhostScript pdf, and it looks exactly the same. so the compressed image always did work.
Ivar Snaaijer
Posts: 21
Joined: 2006-02-22T09:22:30-07:00

Some other interesting tidbits

Post by Ivar Snaaijer »

I retried to run the conversion again on two versions and i got interesting results, in speed, resulting file size and surprisingly 'verbosity' (the second run is done with 6.2.6 03/09/06 Q16) :

Code: Select all

C:\Documents and Settings\ivar\Desktop\imagemagick>convert -verbose -compress Group4 loadFTPImg.asp.jpg loadFTPImg.asp_3_new.pdf
loadFTPImg.asp.jpg JPEG 1620x736 1620x736+0+0 DirectClass 2e+002kb 0.070u 0:01
TIFF Directory at offset 0x0
  Image Width: 1620 Image Length: 736
  Resolution: 200, 200 pixels/inch
  Bits/Sample: 1
  Compression Scheme: CCITT Group 4
  Photometric Interpretation: min-is-white
  FillOrder: msb-to-lsb
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 736
  Planar Configuration: single image plane
  Software: ImageMagick 6.2.6 02/01/06 Q16 http://www.imagemagick.org
  DocumentName: c:\winnt\TEMP\magick-4d6uq7ho
loadFTPImg.asp.jpg=>c:\winnt\TEMP\magick-4d6uq7ho JPEG 1620x736 1620x736+0+0 PseudoClass 2c 2e+001kb 1.743u 0:04
TIFF Directory at offset 0x0
  Image Width: 106 Image Length: 48
  Resolution: 200, 200 pixels/inch
  Bits/Sample: 1
  Compression Scheme: CCITT Group 4
  Photometric Interpretation: min-is-white
  FillOrder: msb-to-lsb
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 48
  Planar Configuration: single image plane
  Software: ImageMagick 6.2.6 02/01/06 Q16 http://www.imagemagick.org
  DocumentName: c:\winnt\TEMP\magick-t8pkbg6r
loadFTPImg.asp.jpg=>c:\winnt\TEMP\magick-t8pkbg6r JPEG 1620x736=>106x48 106x48+0+0 PseudoClass 2c 730
loadFTPImg.asp.jpg=>loadFTPImg.asp_3_new.pdf JPEG 1620x736 1620x736+0+0 DirectClass 2e+001kb 1.923u 0:05

C:\Documents and Settings\ivar\Desktop\imagemagick>convert -verbose -compress Group4 loadFTPImg.asp.jpg loadFTPImg.asp_4_new.pdf
loadFTPImg.asp.jpg JPEG 1620x736 1620x736+0+0 DirectClass 2e+002kb 0.060u 0:01
loadFTPImg.asp.jpg=>loadFTPImg.asp_4_new.pdf JPEG 1620x736 1620x736+0+0 DirectClass 3e+002kb 0.330u 0:01

C:\Documents and Settings\ivar\Desktop\imagemagick>
these are the source and resulting files :

Code: Select all

22/02/2006  15:48              174,072 loadFTPImg.asp.jpg
16/03/2006  23:47               17,632 loadFTPImg.asp_3_new.pdf
16/03/2006  23:50              327,144 loadFTPImg.asp_4_new.pdf
The size of the '3' file is 5 bytes smaller because I removed the aforementioned code. because I removed the faulty part both files work.

I also took a look at the 6.2.6-2-Q16 code (yes older version) and found this code in pdf.c on line 1168.

Code: Select all

"/DecodeParms [ << >> << /K %s /Columns %ld /Rows %ld >> ]\n",
For some reason I think something went wrong with creating this releases since 6.2.6-1, because the results are so different.

note : when I change the commandline to "-compress Group4 -type bilevel -monochrome" I get a black/white runlength encoded image inside a pdf.
Post Reply