Exemple #1
0
        /// <summary>
        /// Applies the given colorblindness simulator to the image.
        /// </summary>
        /// <typeparam name="T">The pixel format.</typeparam>
        /// <typeparam name="TP">The packed format. <example>long, float.</example></typeparam>
        /// <param name="source">The image this method extends.</param>
        /// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
        /// <param name="rectangle">
        /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
        /// </param>
        /// <param name="progressHandler">A delegate which is called as progress is made processing the image.</param>
        /// <returns>The <see cref="Image{T,TP}"/>.</returns>
        public static Image <T, TP> ColorBlindness <T, TP>(this Image <T, TP> source, ColorBlindness colorBlindness, Rectangle rectangle, ProgressEventHandler progressHandler = null)
            where T : IPackedVector <TP>
            where TP : struct
        {
            IImageProcessor <T, TP> processor;

            switch (colorBlindness)
            {
            case ImageProcessorCore.ColorBlindness.Achromatomaly:
                processor = new AchromatomalyProcessor <T, TP>();
                break;

            case ImageProcessorCore.ColorBlindness.Achromatopsia:
                processor = new AchromatopsiaProcessor <T, TP>();
                break;

            case ImageProcessorCore.ColorBlindness.Deuteranomaly:
                processor = new DeuteranomalyProcessor <T, TP>();
                break;

            case ImageProcessorCore.ColorBlindness.Deuteranopia:
                processor = new DeuteranopiaProcessor <T, TP>();
                break;

            case ImageProcessorCore.ColorBlindness.Protanomaly:
                processor = new ProtanomalyProcessor <T, TP>();
                break;

            case ImageProcessorCore.ColorBlindness.Protanopia:
                processor = new ProtanopiaProcessor <T, TP>();
                break;

            case ImageProcessorCore.ColorBlindness.Tritanomaly:
                processor = new TritanomalyProcessor <T, TP>();
                break;

            default:
                processor = new TritanopiaProcessor <T, TP>();
                break;
            }

            processor.OnProgress += progressHandler;

            try
            {
                return(source.Process(rectangle, processor));
            }
            finally
            {
                processor.OnProgress -= progressHandler;
            }
        }
Exemple #2
0
        /// <summary>
        /// Applies the given colorblindness simulator to the image.
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <param name="source">The image this method extends.</param>
        /// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
        /// <param name="rectangle">
        /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
        /// </param>
        /// <returns>The <see cref="Image{TPixel}"/>.</returns>
        public static Image <TPixel> ColorBlindness <TPixel>(this Image <TPixel> source, ColorBlindness colorBlindness, Rectangle rectangle)
            where TPixel : struct, IPixel <TPixel>
        {
            IImageProcessor <TPixel> processor;

            switch (colorBlindness)
            {
            case ImageSharp.Processing.ColorBlindness.Achromatomaly:
                processor = new AchromatomalyProcessor <TPixel>();
                break;

            case ImageSharp.Processing.ColorBlindness.Achromatopsia:
                processor = new AchromatopsiaProcessor <TPixel>();
                break;

            case ImageSharp.Processing.ColorBlindness.Deuteranomaly:
                processor = new DeuteranomalyProcessor <TPixel>();
                break;

            case ImageSharp.Processing.ColorBlindness.Deuteranopia:
                processor = new DeuteranopiaProcessor <TPixel>();
                break;

            case ImageSharp.Processing.ColorBlindness.Protanomaly:
                processor = new ProtanomalyProcessor <TPixel>();
                break;

            case ImageSharp.Processing.ColorBlindness.Protanopia:
                processor = new ProtanopiaProcessor <TPixel>();
                break;

            case ImageSharp.Processing.ColorBlindness.Tritanomaly:
                processor = new TritanomalyProcessor <TPixel>();
                break;

            default:
                processor = new TritanopiaProcessor <TPixel>();
                break;
            }

            source.ApplyProcessor(processor, rectangle);
            return(source);
        }
Exemple #3
0
        /// <summary>
        /// Applies the given colorblindness simulator to the image.
        /// </summary>
        /// <typeparam name="TColor">The pixel format.</typeparam>
        /// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
        /// <param name="source">The image this method extends.</param>
        /// <param name="colorBlindness">The type of color blindness simulator to apply.</param>
        /// <param name="rectangle">
        /// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
        /// </param>
        /// <returns>The <see cref="Image{TColor, TPacked}"/>.</returns>
        public static Image <TColor, TPacked> ColorBlindness <TColor, TPacked>(this Image <TColor, TPacked> source, ColorBlindness colorBlindness, Rectangle rectangle)
            where TColor : struct, IPackedPixel <TPacked>
            where TPacked : struct, IEquatable <TPacked>
        {
            IImageFilteringProcessor <TColor, TPacked> processor;

            switch (colorBlindness)
            {
            case ImageSharp.ColorBlindness.Achromatomaly:
                processor = new AchromatomalyProcessor <TColor, TPacked>();
                break;

            case ImageSharp.ColorBlindness.Achromatopsia:
                processor = new AchromatopsiaProcessor <TColor, TPacked>();
                break;

            case ImageSharp.ColorBlindness.Deuteranomaly:
                processor = new DeuteranomalyProcessor <TColor, TPacked>();
                break;

            case ImageSharp.ColorBlindness.Deuteranopia:
                processor = new DeuteranopiaProcessor <TColor, TPacked>();
                break;

            case ImageSharp.ColorBlindness.Protanomaly:
                processor = new ProtanomalyProcessor <TColor, TPacked>();
                break;

            case ImageSharp.ColorBlindness.Protanopia:
                processor = new ProtanopiaProcessor <TColor, TPacked>();
                break;

            case ImageSharp.ColorBlindness.Tritanomaly:
                processor = new TritanomalyProcessor <TColor, TPacked>();
                break;

            default:
                processor = new TritanopiaProcessor <TColor, TPacked>();
                break;
            }

            return(source.Process(rectangle, processor));
        }