Bug 56178 - monochrome TIFF with Compression Scheme: CCITT Group 4 not rendered correctly
Summary: monochrome TIFF with Compression Scheme: CCITT Group 4 not rendered correctly
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: filters and storage (show other bugs)
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Caolán McNamara
Whiteboard: BSA target:7.4.0
: 91461 (view as bug list)
Depends on:
Blocks: Images-TIFF
  Show dependency treegraph
Reported: 2012-10-19 12:35 UTC by stfhell
Modified: 2022-05-21 18:29 UTC (History)
8 users (show)

See Also:
Crash report or crash signature:

Attached: TIFF image (9.24 KB, image/tiff)
2012-10-19 12:35 UTC, stfhell
a bt at the moment bStatus gets sal_False (5.08 KB, text/plain)
2014-02-01 17:58 UTC, Julien Nabet
TIFF image loaded in Writer 5.0.0 RC3 (4.70 KB, image/png)
2015-07-19 09:08 UTC, Stanislav Horacek

Note You need to log in before you can comment on or make changes to this bug.
Description stfhell 2012-10-19 12:35:00 UTC
Created attachment 68796 [details]
Attached: TIFF image

LibreOffice/Linux is not able to insert the attached TIFF image in a Writer or Impress document. Error message: "Unknown graphic format".

The TIFF is a 1-bit Group-4-compressed TIFF image produced with GIMP. tiffinfo says:

TIFF Directory at offset 0x2f1c (12060)
  Subfile Type: (0 = 0x0)
  Image Width: 3156 Image Length: 1844
  Resolution: 600, 600 pixels/inch
  Bits/Sample: 1
  Compression Scheme: CCITT Group 4
  Photometric Interpretation: min-is-white
  Orientation: row 0 top, col 0 lhs
  Samples/Pixel: 1
  Rows/Strip: 64
  Planar Configuration: single image plane

Tested with LO and under Ubuntu 12.04 (64 and 32 bit).

Other 1-bit TIFFs work, for example one written by ImageMagick with tiffinfo
TIFF Directory at offset 0x42fa (17146)
  Image Width: 500 Image Length: 375
  Resolution: 72, 72 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: 375
  Planar Configuration: single image plane
  Page Number: 0-1
Comment 1 bfoman (inactive) 2013-05-08 13:29:00 UTC
Confirmed with:
Build ID: own W7 debug build
Windows 7 Professional SP1 64 bit

Error message: "Unknown graphic format". File is viewable and can be inserted in Word or Powerpoint 2010.
Comment 2 Bernhard Rohrer 2013-05-08 23:23:03 UTC
confirmed in Linux
Comment 3 Julien Nabet 2014-02-01 17:58:40 UTC
Created attachment 93187 [details]
a bt at the moment bStatus gets sal_False

Bt retrieved on pc Debian x86-64 with master sources updated yesterday
Comment 4 Julien Nabet 2014-02-01 18:01:18 UTC Comment hidden (obsolete)
Comment 5 Caolán McNamara 2014-02-07 16:09:23 UTC
There's a gadzillion tiff extensions and features and we don't implement them all (yet). I'd *guess* we haven't implemented CCITT Group 4 compression.
Comment 6 LE GARREC Vincent 2014-07-02 09:09:43 UTC Comment hidden (obsolete)
Comment 7 LE GARREC Vincent 2014-07-02 09:23:30 UTC Comment hidden (obsolete)
Comment 8 QA Administrators 2015-07-18 17:44:25 UTC Comment hidden (obsolete)
Comment 9 Stanislav Horacek 2015-07-19 09:08:09 UTC
Created attachment 117329 [details]
TIFF image loaded in Writer 5.0.0 RC3
Comment 10 Stanislav Horacek 2015-07-19 09:10:18 UTC
Now there is no error message and the TIFF is loaded, however it is still not rendered correctly - see the screenshot from Writer.

Tested in 4.4.2, 5.0.0 RC3 and recent master with the same result (OS: Kubuntu 15.04).
Comment 11 QA Administrators 2016-09-20 10:18:34 UTC Comment hidden (obsolete)
Comment 12 Stanislav Horacek 2016-09-22 18:59:38 UTC Comment hidden (obsolete)
Comment 13 Telesto 2016-11-18 14:47:36 UTC
Confirmed with:
Build ID: b223028d65d24ffcd8e27974c29c2744a5df6227
CPU Threads: 4; OS Version: Windows 6.2; UI Render: default; Layout Engine: new; 
TinderBox: Win-x86@62-merge-TDF, Branch:MASTER, Time: 2016-11-16_22:50:22
Locale: nl-NL (nl_NL); Calc: CL

When drag & drop & with Insert --> Image.
It works when I open c.q copy the image from IrfanView and paste it in Writer.
Comment 14 QA Administrators 2017-11-19 19:14:32 UTC Comment hidden (obsolete)
Comment 15 Stanislav Horacek 2017-11-21 18:41:47 UTC
The incorrect rendering of the image persists in: Version:
Build ID: 141fe1c5e7fbf67a083b34e49e19b6ea78a0eb2b
Comment 16 Timur 2021-05-05 10:34:11 UTC
*** Bug 91461 has been marked as a duplicate of this bug. ***
Comment 17 Julien Nabet 2022-05-16 09:17:10 UTC
Giving a new try here, I saw that LO enters CCIDecompressor::Read2DScanlineData.
It's expected since Group 4 uses 2D.
But on several lines (which corresponds about the number of garbage lines), it failed to read "n2DMode" value.

Taking a look at CCIDecompressor::ReadCodeAndDecode, the only case where m_bStatus is false is when nCodeBits = 0 and it happens when the nCode isn't in an initialized area of "pLookUp" (in our case m_p2DModeLookUp).

Now the main pb is to find doc about CCITT group 4 for tiff.
TIFF specs can be found here:
https://www.itu.int/itudoc/itu-t/com16/tiff-fx/docs/tiff6.pdf, the 2 related sections are:
- Section 10: Modified Huffman Compression
- Section 11: CCITT Bilevel Encodings

Also found https://www.itu.int/rec/dologin_pub.asp?lang=f&id=T-REC-T.6-198811-I!!PDF-E&type=items which at least explains the table CCI2DModeTable
(see https://opengrok.libreoffice.org/xref/core/vcl/source/filter/itiff/ccidecom.cxx?r=946b17b4#266).

Now is LO decode process is ok but the tiff is not standard (however no pb to open it on Gimp), is the process ok with just something lacking or is completely ko (but in this case the whole image would be garbage)?
Comment 18 Julien Nabet 2022-05-16 10:24:29 UTC
I took a look at what was one in libtiff or in https://github.com/openjdk/jdk, class src/java.desktop/share/classes/com/sun/imageio/plugins/tiff/TIFFFaxDecompressor.java, they don't search about n2dMode by just reading 10 bits but search about a0, a1, a2, b1, b2. Just wonder where the author found this way to search n2dmode...
Comment 19 Julien Nabet 2022-05-16 20:15:42 UTC
Caolán: any idea about how to keep on investigation or whom to ping?
Comment 20 Caolán McNamara 2022-05-21 18:20:25 UTC
I've committed a patch related to this issue.
It has been pushed to "master":


use libtiff for tiff import

It will be available in 7.4.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:

Affected users are encouraged to test the fix and report feedback.
Comment 21 Julien Nabet 2022-05-21 18:29:15 UTC
I confirm it works, very good (and quick!) job Caolán! :-)