Decoding tiff 16bit compressed images doesn't work
This is to reference the issue with decoding YA tiff images.
I played around with it a bit and this is what I have found:
- Problem only seems to affect compressed images. Unpacking an image (tiffcp -c none) seems to make the reader work.
- Playing around with compression options, by changing strip size changes the effects on loaded image (tiffcp -c xx -r xx). I was also able to make an YA8 image disappear (show as completely transparent) by some compression options, but I was unable to make it display striped, as with YA16.
I'm going now. I may get back to it tomorrow.
That is, if you haven't fixed it by then :)
I don't know what the problem is yet, but even 16bit RGB images don't load properly.
convert cs3n2c16.png cs3n2c16.tif
tiffcp cs3n2c16.tif -c lzw test.tif
> readImage "test.tif" >>= (\(Right (ImageRGB16 im)) -> writePng "out.png" im )
results in corrupted image.
Perhaps more usefully
tiffcp flower-rgb-contig-16.tif -c packbits test.tif
> readImage "/tmp/bbb/test.tif" >>= (\(Right (ImageRGB16 im)) -> writePng "/tmp/bbb/out.png" im )
*** Exception: ./Data/Vector/Generic/Mutable.hs:590 (read): index out of bounds (7884,7884)
throws an exception. In this image, packing actually increases image size.
I've looked a bit tonight, and there is definitely something fishy going on, but I don't know what. I guess further investigation is required. Could you make a pull request with this two images in the test folder? (no need to include them in the test suite, as it's still buggy right now)
It would help fixing this issue
I thought they were there, I will look into it.
So far, I found one problem. Here
where unpacker (idx, offset, size) = do
let (writeIdx, tempStride) = offsetStride comp idx 1
_ <- uncompressAt compression str tempVec tempStride
writeIdx (offset, size)
mergeBackTempBuffer comp endianness tempVec (width * sampleCount)
idx size 1 outVec
startWriteOffset =
V.generate stripCount(width * rowPerStrip * sampleCount *)
sizes = V.zip3 startWriteOffset (tiffOffsets nfo) (tiffStripSize nfo)
I think size is used to mean two things. One is size of (possibly compresses) input data and another is size of uncompressed data. I tried simple fix, that passed the expected data length to mergeBackTempBuffer. It stopped the exception, corruption still remained.
The test images mentioned above are from the test suite, created with convert (from ImageMagick) and tiffcp (from libtiff). You want to include them in this form. Right? I'll go and do that.
I have added the images in pull request #62 . Changes I used, containing the mentioned potential fix are in tiff-debugging branch. It's all messy, but if you want it, it's there.
I will be leaving you to your debugging. It's getting late now and I also have other things to do. Also I don't know well enough what the code does.