2018.03.02 05:38 "[Tiff] TIFFReadScanline error when trying to read TIFF containing compressed JPEG", by David Cook

I've already reported the problem to http://bugzilla.maptools.org/show_bug.cgi?id=2140, but I am hoping to reach the most people by emailing here too. I'll post my comment below.

"I'm commenting here because I've encountered the error "TIFFReadScanline:

scanline oriented access is not supported for downsampled JPEG compressed

images, consider enabling TIFF_JPEGCOLORMODE as JPEGCOLORMODE_RGB" while using

the Python library Pillow and I traced the error back to this line in libtiff:


For Pillow, the problem is being tracked at

https://github.com/python-pillow/Pillow/issues/2926. I've spent most of the day

trying to figure out how to enable TIFF_JPEGCOLORMODE as JPEGCOLORMODE_RGB, and

I did achieve it, which prevented the error from occurring.

However, when I try to convert the TIFF into other formats like JPEG and PNG,

the colours are all wrong. I noticed though that the file format conversion

works fine when I'm just using greyscale and not colour though.

Looking at https://en.wikipedia.org/wiki/YCbCr, it looks like the grey Y image

is working fine, but I'm getting the Cr (ie green/pink) image when I'm trying

to get a RGB image.

According to this line

https://gitlab.com/libtiff/libtiff/blob/master/libtiff/tif_jpeg.c#L1276, the

YCbCr should've been converted to RGB, so I don't know what's happening.

I don't know if this is a case of a bug in libtiff or if it's a problem with

how Pillow is using libtiff.

I'm on Ubuntu 16.04.03 using the packaged version of libtiff5 which is 4.0.6-1.

As for Pillow, I'm using the current development branch, and I've added my own

block that looks like this:

uint32 compression;

TIFFGetField(tiff, TIFFTAG_COMPRESSION, &compression);

if (compression && compression == COMPRESSION_JPEG){




If anyone can provide any insight, I'd be grateful!

David Cook

Systems Librarian

Prosentient Systems

72/330 Wattle St

Ultimo, NSW 2007


Office: 02 9212 0899

Direct: 02 8005 0595