public ConverterToLinear(TTo[] inverseGammaTable) { Processor = new Converter(inverseGammaTable); Processor3A = new Converter3A(inverseGammaTable); Processor3X = new Converter3X(inverseGammaTable); }
public ConversionTransform(PixelSource source, ColorProfile?sourceProfile, ColorProfile?destProfile, PixelFormat destFormat, bool videoLevels = false) : base(source) { var srcProfile = sourceProfile as CurveProfile ?? ColorProfile.sRGB; var dstProfile = destProfile as CurveProfile ?? ColorProfile.sRGB; var srcFormat = source.Format; processor = null !; Format = destFormat; if (srcFormat.BitsPerPixel != Format.BitsPerPixel) { lineBuff = BufferPool.Rent(BufferStride, true); lineBuff.AsSpan().Clear(); } if (srcFormat.ColorRepresentation == PixelColorRepresentation.Cmyk && srcFormat.BitsPerPixel == 64 && Format.BitsPerPixel == 32) { processor = NarrowingConverter.Instance; } else if (videoLevels && srcFormat.BitsPerPixel == 8 && Format.BitsPerPixel == 8) { processor = VideoLevelsConverter.Instance; } else if (srcFormat.Encoding == PixelValueEncoding.Companded && Format.Encoding == PixelValueEncoding.Linear) { if (Format.NumericRepresentation == PixelNumericRepresentation.Fixed) { if (srcFormat.AlphaRepresentation != PixelAlphaRepresentation.None) { processor = srcProfile.GetConverter <byte, ushort>(ConverterDirection.ToLinear).Processor3A; } else { processor = srcProfile.GetConverter <byte, ushort>(ConverterDirection.ToLinear, videoLevels).Processor; } } else if (srcFormat.NumericRepresentation == PixelNumericRepresentation.UnsignedInteger && Format.NumericRepresentation == PixelNumericRepresentation.Float) { if (srcFormat.AlphaRepresentation != PixelAlphaRepresentation.None) { processor = srcProfile.GetConverter <byte, float>(ConverterDirection.ToLinear).Processor3A; } else if (srcFormat.ChannelCount == 3 && Format.ChannelCount == 4) { processor = srcProfile.GetConverter <byte, float>(ConverterDirection.ToLinear).Processor3X; } else { processor = srcProfile.GetConverter <byte, float>(ConverterDirection.ToLinear, videoLevels).Processor; } } else if (Format.NumericRepresentation == PixelNumericRepresentation.Float) { if (srcFormat.AlphaRepresentation != PixelAlphaRepresentation.None) { processor = srcProfile.GetConverter <float, float>(ConverterDirection.ToLinear).Processor3A; } else { processor = srcProfile.GetConverter <float, float>(ConverterDirection.ToLinear).Processor; } } } else if (srcFormat.Encoding == PixelValueEncoding.Linear && Format.Encoding == PixelValueEncoding.Companded) { if (srcFormat.NumericRepresentation == PixelNumericRepresentation.Fixed) { if (srcFormat.AlphaRepresentation != PixelAlphaRepresentation.None) { processor = dstProfile.GetConverter <ushort, byte>(ConverterDirection.FromLinear).Processor3A; } else { processor = dstProfile.GetConverter <ushort, byte>(ConverterDirection.FromLinear).Processor; } } else if (srcFormat.NumericRepresentation == PixelNumericRepresentation.Float && Format.NumericRepresentation == PixelNumericRepresentation.UnsignedInteger) { if (srcFormat.AlphaRepresentation != PixelAlphaRepresentation.None) { processor = dstProfile.GetConverter <float, byte>(ConverterDirection.FromLinear).Processor3A; } else if (srcFormat.ChannelCount == 4 && Format.ChannelCount == 3) { processor = dstProfile.GetConverter <float, byte>(ConverterDirection.FromLinear).Processor3X; } else { processor = dstProfile.GetConverter <float, byte>(ConverterDirection.FromLinear).Processor; } } else if (srcFormat.NumericRepresentation == PixelNumericRepresentation.Float) { if (srcFormat.AlphaRepresentation != PixelAlphaRepresentation.None) { processor = dstProfile.GetConverter <float, float>(ConverterDirection.FromLinear).Processor3A; } else { processor = dstProfile.GetConverter <float, float>(ConverterDirection.FromLinear).Processor; } } } else if (srcFormat.NumericRepresentation == PixelNumericRepresentation.UnsignedInteger && Format.NumericRepresentation == PixelNumericRepresentation.Float) { if (srcFormat.AlphaRepresentation == PixelAlphaRepresentation.Unassociated) { processor = FloatConverter.Widening.InstanceFullRange.Processor3A; } else if (srcFormat.AlphaRepresentation == PixelAlphaRepresentation.None && srcFormat.ChannelCount == 3 && Format.ChannelCount == 4) { processor = FloatConverter.Widening.InstanceFullRange.Processor3X; } else { processor = videoLevels ? FloatConverter.Widening.InstanceVideoRange.Processor : FloatConverter.Widening.InstanceFullRange.Processor; } } else if (srcFormat.NumericRepresentation == PixelNumericRepresentation.Float && Format.NumericRepresentation == PixelNumericRepresentation.UnsignedInteger) { if (Format.AlphaRepresentation != PixelAlphaRepresentation.None) { processor = FloatConverter.Narrowing.Instance.Processor3A; } else if (srcFormat.AlphaRepresentation == PixelAlphaRepresentation.None && srcFormat.ChannelCount == 4 && Format.ChannelCount == 3) { processor = FloatConverter.Narrowing.Instance.Processor3X; } else { processor = FloatConverter.Narrowing.Instance.Processor; } } else if (srcFormat.NumericRepresentation == Format.NumericRepresentation && srcFormat.ChannelCount != Format.ChannelCount) { if (srcFormat.NumericRepresentation == PixelNumericRepresentation.Float) { processor = ChannelChanger <float> .GetConverter(srcFormat.ChannelCount, Format.ChannelCount); } else if (srcFormat.NumericRepresentation == PixelNumericRepresentation.Fixed) { processor = ChannelChanger <ushort> .GetConverter(srcFormat.ChannelCount, Format.ChannelCount); } else { processor = ChannelChanger <byte> .GetConverter(srcFormat.ChannelCount, Format.ChannelCount); } } if (processor is null) { throw new NotSupportedException("Unsupported pixel format"); } }