mirror of https://github.com/SixLabors/ImageSharp
5 changed files with 68 additions and 40 deletions
@ -1,32 +0,0 @@ |
|||||
// Copyright (c) Six Labors.
|
|
||||
// Licensed under the Apache License, Version 2.0.
|
|
||||
|
|
||||
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; |
|
||||
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters; |
|
||||
using SixLabors.ImageSharp.PixelFormats; |
|
||||
|
|
||||
namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Spectral converter for TIFF's which use the JPEG compression.
|
|
||||
/// The compressed jpeg data should be always treated as RGB color space.
|
|
||||
/// If PhotometricInterpretation indicates the data is YCbCr, the color decoder will handle the conversion.
|
|
||||
/// </summary>
|
|
||||
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
|
|
||||
internal sealed class RgbJpegSpectralConverter<TPixel> : SpectralConverter<TPixel> |
|
||||
where TPixel : unmanaged, IPixel<TPixel> |
|
||||
{ |
|
||||
/// <summary>
|
|
||||
/// Initializes a new instance of the <see cref="RgbJpegSpectralConverter{TPixel}"/> class.
|
|
||||
/// This Spectral converter will always convert the pixel data to RGB color.
|
|
||||
/// </summary>
|
|
||||
/// <param name="configuration">The configuration.</param>
|
|
||||
public RgbJpegSpectralConverter(Configuration configuration) |
|
||||
: base(configuration) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
/// <inheritdoc/>
|
|
||||
protected override JpegColorConverterBase GetColorConverter(JpegFrame frame, IRawJpegData jpegData) => JpegColorConverterBase.GetConverter(JpegColorSpace.RGB, frame.Precision); |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,50 @@ |
|||||
|
// Copyright (c) Six Labors.
|
||||
|
// Licensed under the Apache License, Version 2.0.
|
||||
|
|
||||
|
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder; |
||||
|
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters; |
||||
|
using SixLabors.ImageSharp.Formats.Tiff.Constants; |
||||
|
using SixLabors.ImageSharp.PixelFormats; |
||||
|
|
||||
|
namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Spectral converter for YCbCr TIFF's which use the JPEG compression.
|
||||
|
/// The jpeg data should be always treated as RGB color space.
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="TPixel">The type of the pixel.</typeparam>
|
||||
|
internal sealed class TiffJpegSpectralConverter<TPixel> : SpectralConverter<TPixel> |
||||
|
where TPixel : unmanaged, IPixel<TPixel> |
||||
|
{ |
||||
|
private readonly TiffPhotometricInterpretation photometricInterpretation; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Initializes a new instance of the <see cref="TiffJpegSpectralConverter{TPixel}"/> class.
|
||||
|
/// This Spectral converter will always convert the pixel data to RGB color.
|
||||
|
/// </summary>
|
||||
|
/// <param name="configuration">The configuration.</param>
|
||||
|
/// <param name="photometricInterpretation">Tiff photometric interpretation.</param>
|
||||
|
public TiffJpegSpectralConverter(Configuration configuration, TiffPhotometricInterpretation photometricInterpretation) |
||||
|
: base(configuration) |
||||
|
=> this.photometricInterpretation = photometricInterpretation; |
||||
|
|
||||
|
/// <inheritdoc/>
|
||||
|
protected override JpegColorConverterBase GetColorConverter(JpegFrame frame, IRawJpegData jpegData) |
||||
|
{ |
||||
|
JpegColorSpace colorSpace = GetJpegColorSpaceFromPhotometricInterpretation(this.photometricInterpretation); |
||||
|
return JpegColorConverterBase.GetConverter(colorSpace, frame.Precision); |
||||
|
} |
||||
|
|
||||
|
/// <remarks>
|
||||
|
/// This converter must be used only for RGB and YCbCr color spaces for performance reasons.
|
||||
|
/// For grayscale images <see cref="GrayJpegSpectralConverter{TPixel}"/> must be used.
|
||||
|
/// </remarks>
|
||||
|
private static JpegColorSpace GetJpegColorSpaceFromPhotometricInterpretation(TiffPhotometricInterpretation interpretation) |
||||
|
=> interpretation switch |
||||
|
{ |
||||
|
TiffPhotometricInterpretation.Rgb => JpegColorSpace.RGB, |
||||
|
TiffPhotometricInterpretation.YCbCr => JpegColorSpace.RGB, |
||||
|
_ => throw new InvalidImageContentException($"Invalid tiff photometric interpretation for jpeg encoding: {interpretation}"), |
||||
|
}; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue