Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set the sampling factor for a JPEG encoded TIFF image. #1550

Open
makingbloke opened this issue Feb 12, 2024 · 1 comment
Open

Cannot set the sampling factor for a JPEG encoded TIFF image. #1550

makingbloke opened this issue Feb 12, 2024 · 1 comment

Comments

@makingbloke
Copy link

Magick.NET version

Magick.NET-Q16-x64 (13.5.0)

Environment (Operating system, version and so on)

Windows 11 / .Net 8 / VS2022

Description

I am creating a 1 page JPEG encoded TIFF image. I would like to be able to set the sampling factor for the page but no matter what I try (see console app below) the value of the YCbCr Subsampling tag always defaults to 1, 1 in the image.

Steps to Reproduce

This is a simple example to reproduce the issue and demonstrate the steps I have taken. (I am using proper images in my development code).

using ImageMagick;
using ImageMagick.Formats;

// For the purposes of demonstration create a simple blank image.
using MagickImage image = new(MagickColors.Red, 2550, 3450);

image.Settings.Verbose = true;
image.Settings.Debug = true;

image.Format = MagickFormat.Tif;

image.Density = new Density(300);

image.ColorType = ColorType.TrueColor;
image.ColorSpace = ColorSpace.YCbCr;

image.SetCompression(CompressionMethod.JPEG);

// I've tried all of these with values 4:2:0, 2x1, 4:2:2 and 2x2
// but none of them change the YCbCr Subsampling tag from the default 1, 1.
//
// image.Settings.SetDefine(MagickFormat.Tif, "sampling-factor", "4:2:0");
// image.Settings.SetDefine(MagickFormat.Tiff, "sampling-factor", "4:2:0");
// image.Settings.SetDefine(MagickFormat.Jpg, "sampling-factor", "4:2:0");
// image.Settings.SetDefine(MagickFormat.Jpeg, "sampling-factor", "4:2:0");
// image.Settings.SetDefine("sampling-factor", "4:2:0");

TiffWriteDefines writeDefines = new()
{
    JpegTablesMode = TiffJpegTablesMode.None,
    PreserveCompression = true,
    RowsPerStrip = image.Height
};

image.Write("Test.tif", writeDefines);
@dlemstra
Copy link
Owner

I do think this should be possible because I can see we use jpeg:sampling-factor in both the reader and writer. There might be a bug in the ImageMagick code but I will need to take some time to investigate that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants