Skip to content

Saving an example tiff file back to disk using the default TiffEncoder settings changes the image #2909

@lucienmaloney

Description

@lucienmaloney

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.7

Other ImageSharp packages and versions

SixLabors.ImageSharp.Drawing 2.1.5

Environment (Operating system, version and so on)

Windows 11 (also tested in WSL)

.NET Framework version

8

Description

Given the following image of a simple 2x2 black-and-white checkerboard:

Image

Running this through ImageSharp's default load and save results in the lower-right corner (mostly) vanishing:

Image

The equivalent image for png/gif/jpeg/bmp does not cut off the corner in this way, so it seems to have something to do with tiff encoding, and tiff compression in particular.

(Note the attached images are PNGs only because Github won't let me upload tifs directly. I've included the original files in a zip.)

Steps to Reproduce

Loading and saving the tiff file like should reproduce the corner effect:

using (SixLabors.ImageSharp.Image<Rgba32> image = SixLabors.ImageSharp.Image.Load<Rgba32>(path + "example32x32.tif"))
{
	using (FileStream stream = new FileStream(path + "example32x32-new.tif", FileMode.Create))
	{
		image.Save(stream, new TiffEncoder());
	}
}

(I also get the same result if dropping the generic.)

The only way to get the image save correctly it seems is to specify no compression:

using (SixLabors.ImageSharp.Image<Rgba32> image = SixLabors.ImageSharp.Image.Load<Rgba32>(path + "example32x32.tif"))
{
	using (FileStream stream = new FileStream(path + "example32x32-new-no-compression.tif", FileMode.Create))
	{
		image.Save(stream, new TiffEncoder() { Compression = SixLabors.ImageSharp.Formats.Tiff.Constants.TiffCompression.None });
	}
}

Instead of its default of LZW:

$ file *.tif
example32x32-new-no-compression.tif: TIFF image data, little-endian, direntries=22, height=32, bps=3350, compression=none, PhotometricIntepretation=RGB, width=32
example32x32-new.tif:                TIFF image data, little-endian, direntries=22, height=32, bps=458, compression=LZW, PhotometricIntepretation=RGB, width=32
example32x32.tif:                    TIFF image data, little-endian, direntries=21, height=32, bps=480, compression=LZW, PhotometricIntepretation=RGB, width=32

Images

See all 3 files in the attached zip.

tif-files.zip

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