From 6d9a04d38cec01db10ff9197a92489adbe33ad81 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Tue, 5 Oct 2021 14:27:27 +0200 Subject: [PATCH] Premultiply only if alpha representation is unknown or Unassociated --- .../Transforms/Resize/ResizeProcessor{TPixel}.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs index 1daed9ee63..c5e53318d2 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs @@ -188,8 +188,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms bool compand, bool premultiplyAlpha) { - bool pixelHasNoAlpha = PixelOperations.Instance.GetPixelTypeInfo()?.AlphaRepresentation == PixelAlphaRepresentation.None; - premultiplyAlpha &= !pixelHasNoAlpha; + PixelAlphaRepresentation? alphaRepresentation = PixelOperations.Instance.GetPixelTypeInfo()?.PixelAlphaRepresentation; + + // Premultiply only if alpha representation is unknown or Unassociated: + bool needsPremultiplication = alphaRepresentation == null || alphaRepresentation.Value == PixelAlphaRepresentation.Unassociated; + premultiplyAlpha &= needsPremultiplication; PixelConversionModifiers conversionModifiers = GetModifiers(compand, premultiplyAlpha); Buffer2DRegion sourceRegion = source.PixelBuffer.GetRegion(sourceRectangle);