From 68be92331b62825d684f0d06a837b5440b65a205 Mon Sep 17 00:00:00 2001 From: Ynse Hoornenborg Date: Sat, 13 Jul 2024 09:23:29 +0200 Subject: [PATCH] PlaneCount calculation inside ObuColorConfig --- .../Heif/Av1/OpenBitstreamUnit/ObuColorConfig.cs | 16 +++++++++++++--- .../Heif/Av1/OpenBitstreamUnit/ObuReader.cs | 1 - .../Heif/Av1/OpenBitstreamUnit/ObuWriter.cs | 1 - 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuColorConfig.cs b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuColorConfig.cs index 3c7349b199..7e169f43fd 100644 --- a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuColorConfig.cs +++ b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuColorConfig.cs @@ -5,18 +5,28 @@ namespace SixLabors.ImageSharp.Formats.Heif.Av1.OpenBitstreamUnit; internal class ObuColorConfig { + private bool isMonochrome; + public bool IsColorDescriptionPresent { get; set; } /// - /// Gets or sets the number of color channels in this image. + /// Gets the number of color channels in this image. Can have the value 1 or 3. /// - public int PlaneCount { get; set; } + public int PlaneCount { get; private set; } /// /// Gets or sets a value indicating whether the image has a single greyscale plane, will have /// color planes otherwise. /// - public bool IsMonochrome { get; set; } + public bool IsMonochrome + { + get => this.isMonochrome; + set + { + this.PlaneCount = value ? 1 : Av1Constants.MaxPlanes; + this.isMonochrome = value; + } + } public ObuColorPrimaries ColorPrimaries { get; set; } diff --git a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuReader.cs b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuReader.cs index fc3b19d319..01e1a50c0f 100644 --- a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuReader.cs +++ b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuReader.cs @@ -465,7 +465,6 @@ internal class ObuReader colorConfig.IsMonochrome = reader.ReadBoolean(); } - colorConfig.PlaneCount = colorConfig.IsMonochrome ? 1 : Av1Constants.MaxPlanes; colorConfig.IsColorDescriptionPresent = reader.ReadBoolean(); colorConfig.ColorPrimaries = ObuColorPrimaries.Unspecified; colorConfig.TransferCharacteristics = ObuTransferCharacteristics.Unspecified; diff --git a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuWriter.cs b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuWriter.cs index 1b704309d1..4a154da0e7 100644 --- a/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuWriter.cs +++ b/src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuWriter.cs @@ -112,7 +112,6 @@ internal class ObuWriter writer.WriteBoolean(colorConfig.IsMonochrome); } - colorConfig.PlaneCount = colorConfig.IsMonochrome ? 1 : Av1Constants.MaxPlanes; writer.WriteBoolean(false); // colorConfig.IsColorDescriptionPresent if (colorConfig.IsMonochrome) {