From ea373bae0046910d3f01e0200a0dc38e32fba59e Mon Sep 17 00:00:00 2001 From: "A. Molzer" <5550310+197g@users.noreply.github.com> Date: Mon, 5 Jan 2026 21:13:59 +0100 Subject: [PATCH] Fix YCbCr encoding not having subsampling --- src/encoder/mod.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/encoder/mod.rs b/src/encoder/mod.rs index 6c1a965..45024e3 100644 --- a/src/encoder/mod.rs +++ b/src/encoder/mod.rs @@ -11,7 +11,10 @@ use std::{ use crate::{ decoder::ifd::Entry, error::{TiffResult, UsageError}, - tags::{CompressionMethod, ExtraSamples, IfdPointer, ResolutionUnit, SampleFormat, Tag, Type}, + tags::{ + CompressionMethod, ExtraSamples, IfdPointer, PhotometricInterpretation, ResolutionUnit, + SampleFormat, Tag, Type, + }, Directory, TiffError, TiffFormatError, }; @@ -565,6 +568,12 @@ impl<'a, W: 'a + Write + Seek, T: ColorType, K: TiffKind> ImageEncoder<'a, W, T, encoder.write_tag(Tag::PhotometricInterpretation, ::TIFF_VALUE.to_u16())?; + if matches!(::TIFF_VALUE, PhotometricInterpretation::YCbCr) { + // The default for this tag is 2,2 for subsampling but we do not support such a + // transformation. Instead all samples must be provided. + encoder.write_tag(Tag::ChromaSubsampling, &[1u16, 1u16][..])?; + } + encoder.write_tag(Tag::RowsPerStrip, u32::try_from(rows_per_strip)?)?; encoder.write_tag(