From 0e4e9501e59f371b2d590173fd1709eaaa641730 Mon Sep 17 00:00:00 2001 From: Dmitry Pentin Date: Fri, 16 Jul 2021 15:11:10 +0300 Subject: [PATCH] Introduced JpegFrame ctor, closed some setters --- .../Jpeg/Components/Decoder/JpegFrame.cs | 43 +++++++++++++------ .../Formats/Jpeg/JpegDecoderCore.cs | 10 +---- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs index 01863b7a8..0e842de9d 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegFrame.cs @@ -10,15 +10,29 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder /// internal sealed class JpegFrame : IDisposable { + public JpegFrame(JpegFileMarker sofMarker, byte precision, int width, int height, byte componentCount) + { + this.Extended = sofMarker.Marker == JpegConstants.Markers.SOF1; + this.Progressive = sofMarker.Marker == JpegConstants.Markers.SOF2; + + this.Precision = precision; + this.MaxColorChannelValue = MathF.Pow(2, precision) - 1; + + this.PixelWidth = width; + this.PixelHeight = height; + + this.ComponentCount = componentCount; + } + /// - /// Gets or sets a value indicating whether the frame uses the extended specification. + /// Gets a value indicating whether the frame uses the extended specification. /// - public bool Extended { get; set; } + public bool Extended { get; private set; } /// - /// Gets or sets a value indicating whether the frame uses the progressive specification. + /// Gets a value indicating whether the frame uses the progressive specification. /// - public bool Progressive { get; set; } + public bool Progressive { get; private set; } /// /// Gets or sets a value indicating whether the frame is encoded using multiple scans (SOS markers). @@ -29,19 +43,24 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder public bool MultiScan { get; set; } /// - /// Gets or sets the precision. + /// Gets the precision. + /// + public byte Precision { get; private set; } + + /// + /// Gets the maximum color value derived from . /// - public byte Precision { get; set; } + public float MaxColorChannelValue { get; private set; } /// - /// Gets or sets the number of scanlines within the frame. + /// Gets the number of pixel per row. /// - public int PixelHeight { get; set; } + public int PixelHeight { get; private set; } /// - /// Gets or sets the number of samples per scanline. + /// Gets the number of pixels per line. /// - public int PixelWidth { get; set; } + public int PixelWidth { get; private set; } /// /// Gets the pixel size of the image. @@ -49,9 +68,9 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder public Size PixelSize => new Size(this.PixelWidth, this.PixelHeight); /// - /// Gets or sets the number of components within a frame. In progressive frames this value can range from only 1 to 4. + /// Gets the number of components within a frame. In progressive frames this value can range from only 1 to 4. /// - public byte ComponentCount { get; set; } + public byte ComponentCount { get; private set; } /// /// Gets or sets the component id collection. diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs index 406458fe3..86871fc00 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs @@ -828,15 +828,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg this.Metadata.GetJpegMetadata().ColorType = this.ColorSpace == JpegColorSpace.Grayscale ? JpegColorType.Luminance : JpegColorType.YCbCr; - this.Frame = new JpegFrame - { - Extended = frameMarker.Marker == JpegConstants.Markers.SOF1, - Progressive = frameMarker.Marker == JpegConstants.Markers.SOF2, - Precision = precision, - PixelHeight = frameHeight, - PixelWidth = frameWidth, - ComponentCount = componentCount - }; + this.Frame = new JpegFrame(frameMarker, precision, frameWidth, frameHeight, componentCount); if (!metadataOnly) {