dlemstra / dlemstra/Magick.NET

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

Open
#1,550 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4k
Forks
451
Avg merge
11h 55m
Merged PRs (30d)
3

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.