Juicy.Pixels icon indicating copy to clipboard operation
Juicy.Pixels copied to clipboard

Decoding tiff 16bit compressed images doesn't work

Open iger opened this issue 11 years ago • 6 comments

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.

iger avatar Mar 17 '14 16:03 iger

That is, if you haven't fixed it by then :)

iger avatar Mar 17 '14 16:03 iger

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.

iger avatar Mar 18 '14 20:03 iger

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

Twinside avatar Mar 18 '14 22:03 Twinside

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.

iger avatar Mar 18 '14 22:03 iger

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.

iger avatar Mar 18 '14 22:03 iger

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.

iger avatar Mar 18 '14 22:03 iger