Skip to content

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

@makingbloke

Description

@makingbloke

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions