Skip to content

Simple conversion of Tiff file to PNG or JPG generates a strange result, even, at certain times, it is in 3D perspective #2679

Description

@yuridiniz

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

3.1.2

Other ImageSharp packages and versions

No

Environment (Operating system, version and so on)

Linux / Windows

.NET Framework version

.NET 6

Description

I have attached the images that are generating this behavior

Steps to Reproduce

O problema ocorreu em uma imagem específica, segue código mínimo para reprodução:

using (var inImg = File.OpenRead("Image_025.tif"))
using (var outImg = File.Create("Image_025.png"))
using (var imagem = Image.Load(inImg))
{
    imagem?.Save(outImg, new PngEncoder());
}

Images

Img.zip

Activity

  1. brianpopow commented on Mar 6, 2024

    @brianpopow
    Collaborator

    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?

  2. JimBobSquarePants commented on Mar 6, 2024

    @JimBobSquarePants
    Member

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

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

  3. brianpopow commented on Mar 7, 2024

    @brianpopow
    Collaborator

    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.

  4. JimBobSquarePants commented on Mar 11, 2024

    @JimBobSquarePants
    Member

    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.

  5. brianpopow commented on Mar 11, 2024

    @brianpopow
    Collaborator

    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?

  6. shapeh commented on Apr 16, 2024

    @shapeh

    ..."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 ;)

  7. brianpopow commented on Aug 24, 2024

    @brianpopow
    Collaborator

    Since #2789 was merged, I will close this now as completed

  8. added a commit that references this issue on Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions