Coder Social home page Coder Social logo

Simple conversion of Tiff file to PNG or JPG generates a strange result, even, at certain times, it is in 3D perspective about imagesharp HOT 6 OPEN

yuridiniz avatar yuridiniz commented on May 26, 2024
Simple conversion of Tiff file to PNG or JPG generates a strange result, even, at certain times, it is in 3D perspective

from imagesharp.

Comments (6)

shapeh avatar shapeh commented on May 26, 2024 2

..."all possible combinations someone comes up with a new tiff variant."

TIFF stands for Thousands of Incompatible File Formats!

Not helpful but couldn't help myself ;)

from imagesharp.

brianpopow avatar brianpopow commented on May 26, 2024

The expected decoded image Image_021.tiff should look like this:
expected

It actually looks like this from the main branch:
actual

The tiffinfo is:

TIFFReadDirectory: Warning, Unknown field with tag 347 (0x15b) encountered.
Image_021.tif: JPEG compression support is not configured.
=== TIFF directory 0 ===
TIFF Directory at offset 0x8 (8)
  Image Width: 1666 Image Length: 2359
  Resolution: 200, 200 pixels/inch
  Bits/Sample: 8
  Compression Scheme: JPEG
  Photometric Interpretation: YCbCr
  YCbCr Subsampling: 2, 2
  Samples/Pixel: 3
  Planar Configuration: single image plane
  Reference Black/White:
     0:     0   255
     1:   128   255
     2:   128   255

So this is a jpeg compressed tiff image. The image decodes correctly, if we set the ycbcrSubSampling to 1, 1 instead of 2, 2, since this is already handled by the jpeg decoding part.
I am not 100% sure if we always can assume ycbcrSubSampling to 1, 1 with tiff compressed jpeg's. @JimBobSquarePants any thoughts?

from imagesharp.

JimBobSquarePants avatar JimBobSquarePants commented on May 26, 2024

Does the tag specifically state the subsampling is 2, 2?

https://www.awaresystems.be/imaging/tiff/tifftags/ycbcrsubsampling.html

from imagesharp.

brianpopow avatar brianpopow commented on May 26, 2024

Does the tag specifically state the subsampling is 2, 2?

https://www.awaresystems.be/imaging/tiff/tifftags/ycbcrsubsampling.html

Yes YCbCrSubSampling is [2, 2] here in the example image Image_021.tiff as can be seen in the tiffinfo section above.

from imagesharp.

JimBobSquarePants avatar JimBobSquarePants commented on May 26, 2024

I had another dig through our Tiff code (I really do not enjoy how complicated it is to follow) and it appears to me that our jpeg scan decoder is already handling the deinterleaving so we can treat the subsampling as [1, 1] when using the jpeg decoder.

from imagesharp.

brianpopow avatar brianpopow commented on May 26, 2024

I had another dig through our Tiff code (I really do not enjoy how complicated it is to follow) and it appears to me that our jpeg scan decoder is already handling the deinterleaving so we can treat the subsampling as [1, 1] when using the jpeg decoder.

Ok, thanks for confirming. I think what makes it so complicated is the myriads of possible combinations of compressions, pixelformats and colorspaces. When ever I think now we finally covered all possible combinations someone comes up with a new tiff variant.

I will try to make a fix for that. @yuridiniz Is it ok, if we use your testimage in a unit-test?

from imagesharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.