Skip to content

A Swiss Army knife for developers.

Ported Color Blindness SImulator to DevToys 2.0 (#969)

Etienne BAUDOUX59814cf2af55
diff --git a/src/app/dev/DevToys.Api/Tool/GUI/PredefinedCommonToolGroupNames.cs b/src/app/dev/DevToys.Api/Tool/GUI/PredefinedCommonToolGroupNames.cs
index ed8d5639c..c29ca7bc5 100644
--- a/src/app/dev/DevToys.Api/Tool/GUI/PredefinedCommonToolGroupNames.cs
+++ b/src/app/dev/DevToys.Api/Tool/GUI/PredefinedCommonToolGroupNames.cs
@@ -5,4 +5,5 @@ public static class PredefinedCommonToolGroupNames
public const string EncodersDecoders = "Encoders / Decoders";
public const string Converters = "Converters";
public const string Generators = "Generators";
+ public const string Graphic = "Graphic";
}
diff --git a/src/app/dev/DevToys.Api/Tool/SmartDetection/PredefinedCommonDataTypeNames.cs b/src/app/dev/DevToys.Api/Tool/SmartDetection/PredefinedCommonDataTypeNames.cs
index d8d8eba8d..c1f998e35 100644
--- a/src/app/dev/DevToys.Api/Tool/SmartDetection/PredefinedCommonDataTypeNames.cs
+++ b/src/app/dev/DevToys.Api/Tool/SmartDetection/PredefinedCommonDataTypeNames.cs
@@ -8,6 +8,7 @@ public static class PredefinedCommonDataTypeNames
public const string Base64Text = "base64Text";
public const string Base64Image = "base64Image";
public const string Image = "image";
+ public const string ImageFile = "imageFile";
public const string File = "file";
public const string Files = "files";
public const string GZip = "gzip";
diff --git a/src/app/dev/DevToys.Tools/DevToys.Tools.csproj b/src/app/dev/DevToys.Tools/DevToys.Tools.csproj
index efb3a037f..984d8f382 100644
--- a/src/app/dev/DevToys.Tools/DevToys.Tools.csproj
+++ b/src/app/dev/DevToys.Tools/DevToys.Tools.csproj
@@ -84,6 +84,16 @@
<AutoGen>True</AutoGen>
<DependentUpon>HashAndChecksumGenerator.resx</DependentUpon>
</Compile>
+ <Compile Update="Tools\Graphic\ColorBlindnessSimulator\ColorBlindnessSimulator.Designer.cs">
+ <DesignTime>True</DesignTime>
+ <AutoGen>True</AutoGen>
+ <DependentUpon>ColorBlindnessSimulator.resx</DependentUpon>
+ </Compile>
+ <Compile Update="Tools\Graphic\Graphic.Designer.cs">
+ <DependentUpon>Graphic.resx</DependentUpon>
+ <DesignTime>True</DesignTime>
+ <AutoGen>True</AutoGen>
+ </Compile>
<Compile Update="Tools\Test\Test.Designer.cs">
<DependentUpon>Test.resx</DependentUpon>
<DesignTime>True</DesignTime>
@@ -135,6 +145,14 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>HashAndChecksumGenerator.Designer.cs</LastGenOutput>
</EmbeddedResource>
+ <EmbeddedResource Update="Tools\Graphic\ColorBlindnessSimulator\ColorBlindnessSimulator.resx">
+ <Generator>ResXFileCodeGenerator</Generator>
+ <LastGenOutput>ColorBlindnessSimulator.Designer.cs</LastGenOutput>
+ </EmbeddedResource>
+ <EmbeddedResource Update="Tools\Graphic\Graphic.resx">
+ <LastGenOutput>Graphic.Designer.cs</LastGenOutput>
+ <Generator>ResXFileCodeGenerator</Generator>
+ </EmbeddedResource>
<EmbeddedResource Update="Tools\Test\Test.resx">
<LastGenOutput>Test.Designer.cs</LastGenOutput>
<Generator>ResXFileCodeGenerator</Generator>
diff --git a/src/app/dev/DevToys.Tools/Helpers/ColorBlindnessSimulatorHelper.cs b/src/app/dev/DevToys.Tools/Helpers/ColorBlindnessSimulatorHelper.cs
new file mode 100644
index 000000000..ad62fa8fa
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Helpers/ColorBlindnessSimulatorHelper.cs
@@ -0,0 +1,208 @@
+using SixLabors.ImageSharp;
+using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.ImageSharp.Processing;
+
+namespace DevToys.Tools.Helpers;
+
+internal static class ColorBlindnessSimulatorHelper
+{
+ // Original source: https://github.com/DaltonLens/libDaltonLens/blob/master/libDaltonLens.c
+ // http://daltonlens.org
+
+ private struct Brettel1997Parameters
+ {
+ /// <summary>
+ /// Transformation using plane 1 == rgbFromLms . projection1 . lmsFromRgb
+ /// </summary>
+ internal float[] RgbCvdFromRgb1 { get; set; }
+
+ /// <summary>
+ /// Full transformation using plane 2 == rgbFromLms . projection2 . lmsFromRgb
+ /// </summary>
+ internal float[] RgbCvdFromRgb2 { get; set; }
+
+ /// <summary>
+ /// Normal of the separation plane to pick the right transform, already in the RGB space == normalInLms . lmsFromRgb
+ /// </summary>
+ internal float[] SeparationPlaneNormalInRgb { get; set; }
+ }
+
+ /// <summary>
+ /// Represents the default severity of the color blindness.
+ /// </summary>
+ private const float Severity = 1f;
+
+ private static readonly Brettel1997Parameters ProtanopiaParameters
+ = new()
+ {
+ RgbCvdFromRgb1 = new[] { 0.14980f, 1.19548f, -0.34528f, 0.10764f, 0.84864f, 0.04372f, 0.00384f, -0.00540f, 1.00156f },
+ RgbCvdFromRgb2 = new[] { 0.14570f, 1.16172f, -0.30742f, 0.10816f, 0.85291f, 0.03892f, 0.00386f, -0.00524f, 1.00139f },
+ SeparationPlaneNormalInRgb = new[] { 0.00048f, 0.00393f, -0.00441f }
+ };
+
+ private static readonly Brettel1997Parameters TritanopiaParameters
+ = new()
+ {
+ RgbCvdFromRgb1 = new[] { 1.01277f, 0.13548f, -0.14826f, -0.01243f, 0.86812f, 0.14431f, 0.07589f, 0.80500f, 0.11911f },
+ RgbCvdFromRgb2 = new[] { 0.93678f, 0.18979f, -0.12657f, 0.06154f, 0.81526f, 0.12320f, -0.37562f, 1.12767f, 0.24796f },
+ SeparationPlaneNormalInRgb = new[] { 0.03901f, -0.02788f, -0.01113f }
+ };
+
+ private static readonly Brettel1997Parameters DeuteranopiaParameters
+ = new()
+ {
+ RgbCvdFromRgb1 = new[] { 0.36477f, 0.86381f, -0.22858f, 0.26294f, 0.64245f, 0.09462f, -0.02006f, 0.02728f, 0.99278f },
+ RgbCvdFromRgb2 = new[] { 0.37298f, 0.88166f, -0.25464f, 0.25954f, 0.63506f, 0.10540f, -0.01980f, 0.02784f, 0.99196f },
+ SeparationPlaneNormalInRgb = new[] { -0.00281f, -0.00611f, 0.00892f }
+ };
+
+ internal static Image<Rgba32>? SimulateColorBlindness(
+ Image<Rgba32> inputImage,
+ ColorBlindnessMode colorBlindnessMode,
+ Action<int> progressReport,
+ CancellationToken cancellationToken)
+ {
+ return colorBlindnessMode switch
+ {
+ ColorBlindnessMode.Protanopia
+ => SimulateColorBlindness(
+ inputImage,
+ ProtanopiaParameters,
+ progressReport,
+ cancellationToken),
+
+ ColorBlindnessMode.Tritanopia
+ => SimulateColorBlindness(
+ inputImage,
+ TritanopiaParameters,
+ progressReport,
+ cancellationToken),
+
+ ColorBlindnessMode.Deuteranopia
+ => SimulateColorBlindness(
+ inputImage,
+ DeuteranopiaParameters,
+ progressReport,
+ cancellationToken),
+
+ _ => throw new NotSupportedException(),
+ };
+ }
+
+ private static Image<Rgba32>? SimulateColorBlindness(Image<Rgba32> inputImage, Brettel1997Parameters brettel1997Parameters, Action<int> progressReport, CancellationToken cancellationToken)
+ {
+ Guard.IsNotNull(inputImage);
+
+ Image<Rgba32> outputImage = inputImage.Clone();
+ int imagePixelCount = outputImage.Width * outputImage.Height;
+ long pixelTreated = 0;
+ float[]? separationPlaneNormalInRgb = brettel1997Parameters.SeparationPlaneNormalInRgb;
+
+ try
+ {
+ outputImage
+ .ProcessPixelRows(
+ (PixelAccessor<Rgba32> accessor) =>
+ {
+ for (int i = 0; i < outputImage.Height; i++)
+ {
+ Span<Rgba32> pixelRow = accessor.GetRowSpan(i);
+
+ // pixelRow.Length has the same value as accessor.Width,
+ // but using pixelRow.Length allows the JIT to optimize away bounds checks.
+ for (int j = 0; j < pixelRow.Length; j++)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+
+ // Get a reference to the pixel at position j.
+ ref Rgba32 pixel = ref pixelRow[j];
+
+ // Convert the pixel to linear RGB.
+ float linearR = SRgbToLinearRgb(pixel.R);
+ float linearG = SRgbToLinearRgb(pixel.G);
+ float linearB = SRgbToLinearRgb(pixel.B);
+
+ float dotWithSepPlane
+ = linearR * separationPlaneNormalInRgb[0]
+ + linearG * separationPlaneNormalInRgb[1]
+ + linearB * separationPlaneNormalInRgb[2];
+
+ float[] rgbCvdFromRgb;
+ if (dotWithSepPlane >= 0)
+ {
+ rgbCvdFromRgb = brettel1997Parameters.RgbCvdFromRgb1;
+ }
+ else
+ {
+ rgbCvdFromRgb = brettel1997Parameters.RgbCvdFromRgb2;
+ }
+
+ // Apply the color blindness transform.
+ float rCvd = rgbCvdFromRgb[0] * linearR + rgbCvdFromRgb[1] * linearG + rgbCvdFromRgb[2] * linearB; // R
+ float gCvd = rgbCvdFromRgb[3] * linearR + rgbCvdFromRgb[4] * linearG + rgbCvdFromRgb[5] * linearB; // G
+ float bCvd = rgbCvdFromRgb[6] * linearR + rgbCvdFromRgb[7] * linearG + rgbCvdFromRgb[8] * linearB; // B
+
+ // Apply the severity factor as a linear interpolation.
+ // It's the same to do it in the RGB space or in the LMS
+ // space since it's a linear transform.
+ rCvd = rCvd * Severity + linearR * (1f - Severity);
+ gCvd = gCvd * Severity + linearG * (1f - Severity);
+ bCvd = bCvd * Severity + linearB * (1f - Severity);
+
+ // Encode as sRGB and write the result.
+ var newPixel
+ = new Rgba32(
+ LinearRgbToSRgb(rCvd),
+ LinearRgbToSRgb(gCvd),
+ LinearRgbToSRgb(bCvd),
+ pixel.A);
+
+ // Overwrite the pixel referenced by 'ref Rgba32 pixel':
+ pixel = newPixel;
+
+ pixelTreated++;
+ progressReport((int)(100 * pixelTreated / imagePixelCount));
+ }
+ }
+ });
+ }
+ catch (OperationCanceledException)
+ {
+ outputImage.Dispose();
+ return null;
+ }
+
+ return outputImage;
+ }
+
+ private static float SRgbToLinearRgb(byte input)
+ {
+ float floatInput = input / 255f;
+ if (floatInput < 0.04045f)
+ {
+ return floatInput / 12.92f;
+ }
+
+ return MathF.Pow((floatInput + 0.055f) / 1.055f, 2.4f);
+ }
+
+ private static byte LinearRgbToSRgb(float input)
+ {
+ if (input <= 0f)
+ {
+ return 0;
+ }
+
+ if (input >= 1f)
+ {
+ return 255;
+ }
+
+ if (input < 0.0031308f)
+ {
+ return (byte)(0.5f + (input * 12.92 * 255f));
+ }
+
+ return (byte)(255f * (MathF.Pow(input, 1f / 2.4f) * 1.055f - 0.055f));
+ }
+}
diff --git a/src/app/dev/DevToys.Tools/SmartDetection/ColorBlindnessSimulatorImageFileDataTypeDetector.cs b/src/app/dev/DevToys.Tools/SmartDetection/ColorBlindnessSimulatorImageFileDataTypeDetector.cs
new file mode 100644
index 000000000..c449fd8a0
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/SmartDetection/ColorBlindnessSimulatorImageFileDataTypeDetector.cs
@@ -0,0 +1,32 @@
+namespace DevToys.Tools.SmartDetection;
+
+[Export(typeof(IDataTypeDetector))]
+[DataTypeName("ColorBlindnessSimulatorImageFile", baseName: PredefinedCommonDataTypeNames.File)]
+internal sealed partial class ColorBlindnessSimulatorImageFileDataTypeDetector : IDataTypeDetector
+{
+ internal static readonly string[] SupportedFileTypes = new[]
+ {
+ ".bmp",
+ ".jpeg",
+ ".jpg",
+ ".pbm",
+ ".png",
+ ".tiff",
+ ".tga",
+ ".webp"
+ };
+
+ public ValueTask<DataDetectionResult> TryDetectDataAsync(object data, DataDetectionResult? resultFromBaseDetector, CancellationToken cancellationToken)
+ {
+ if (resultFromBaseDetector is not null
+ && resultFromBaseDetector.Data is FileInfo dataFile)
+ {
+ if (SupportedFileTypes.Contains(dataFile.Extension, StringComparer.OrdinalIgnoreCase))
+ {
+ return ValueTask.FromResult(new DataDetectionResult(Success: true, Data: dataFile));
+ }
+ }
+
+ return ValueTask.FromResult(DataDetectionResult.Unsuccessful);
+ }
+}
diff --git a/src/app/dev/DevToys.Tools/SmartDetection/ImageFileDataTypeDetector.cs b/src/app/dev/DevToys.Tools/SmartDetection/ImageFileDataTypeDetector.cs
new file mode 100644
index 000000000..7e2b31a0f
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/SmartDetection/ImageFileDataTypeDetector.cs
@@ -0,0 +1,20 @@
+namespace DevToys.Tools.SmartDetection;
+
+[Export(typeof(IDataTypeDetector))]
+[DataTypeName(PredefinedCommonDataTypeNames.ImageFile, baseName: PredefinedCommonDataTypeNames.File)]
+internal sealed partial class ImageFileDataTypeDetector : IDataTypeDetector
+{
+ public ValueTask<DataDetectionResult> TryDetectDataAsync(object data, DataDetectionResult? resultFromBaseDetector, CancellationToken cancellationToken)
+ {
+ if (resultFromBaseDetector is not null
+ && resultFromBaseDetector.Data is FileInfo dataFile)
+ {
+ if (PredefinedSupportedImageFormats.ImageFileExtensions.Contains(dataFile.Extension, StringComparer.OrdinalIgnoreCase))
+ {
+ return ValueTask.FromResult(new DataDetectionResult(Success: true, Data: dataFile));
+ }
+ }
+
+ return ValueTask.FromResult(DataDetectionResult.Unsuccessful);
+ }
+}
diff --git a/src/app/dev/DevToys.Tools/Strings/GlobalStrings/GlobalStrings.Designer.cs b/src/app/dev/DevToys.Tools/Strings/GlobalStrings/GlobalStrings.Designer.cs
index bd8319b45..8149048f2 100644
--- a/src/app/dev/DevToys.Tools/Strings/GlobalStrings/GlobalStrings.Designer.cs
+++ b/src/app/dev/DevToys.Tools/Strings/GlobalStrings/GlobalStrings.Designer.cs
@@ -68,5 +68,14 @@ namespace DevToys.Tools.Strings.GlobalStrings {
return ResourceManager.GetString("FileNotFound", resourceCulture);
}
}
+
+ /// <summary>
+ /// Looks up a localized string similar to File &apos;{0}&apos; is not supported. Only files of type {1} are supported..
+ /// </summary>
+ internal static string FileTypeNotSupported {
+ get {
+ return ResourceManager.GetString("FileTypeNotSupported", resourceCulture);
+ }
+ }
}
}
diff --git a/src/app/dev/DevToys.Tools/Strings/GlobalStrings/GlobalStrings.resx b/src/app/dev/DevToys.Tools/Strings/GlobalStrings/GlobalStrings.resx
index e0c13a055..95e825415 100644
--- a/src/app/dev/DevToys.Tools/Strings/GlobalStrings/GlobalStrings.resx
+++ b/src/app/dev/DevToys.Tools/Strings/GlobalStrings/GlobalStrings.resx
@@ -119,5 +119,10 @@
</resheader>
<data name="FileNotFound" xml:space="preserve">
<value>File '{0}' was not found.</value>
+ <comment>{0} is a file name.</comment>
+ </data>
+ <data name="FileTypeNotSupported" xml:space="preserve">
+ <value>File '{0}' is not supported. Only files of type {1} are supported.</value>
+ <comment>{0} is a file name. {1} is a list of file extensions</comment>
</data>
</root>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Tools/Tools/Graphic/ColorBlindnessSimulator/ColorBlindnessSimulator.Designer.cs b/src/app/dev/DevToys.Tools/Tools/Graphic/ColorBlindnessSimulator/ColorBlindnessSimulator.Designer.cs
new file mode 100644
index 000000000..2628a028d
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Tools/Graphic/ColorBlindnessSimulator/ColorBlindnessSimulator.Designer.cs
@@ -0,0 +1,171 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace DevToys.Tools.Tools.Graphic.ColorBlindnessSimulator {
+ using System;
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class ColorBlindnessSimulator {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal ColorBlindnessSimulator() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DevToys.Tools.Tools.Graphic.ColorBlindnessSimulator.ColorBlindnessSimulator", typeof(ColorBlindnessSimulator).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Color Blindness Simulator tool.
+ /// </summary>
+ internal static string AccessibleName {
+ get {
+ return ResourceManager.GetString("AccessibleName", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Simulate color blindness on a picture or screenshot.
+ /// </summary>
+ internal static string Description {
+ get {
+ return ResourceManager.GetString("Description", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Deuteranopia simulation.
+ /// </summary>
+ internal static string DeuteranopiaSimulation {
+ get {
+ return ResourceManager.GetString("DeuteranopiaSimulation", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Image file path to treat.
+ /// </summary>
+ internal static string InputOptionDescription {
+ get {
+ return ResourceManager.GetString("InputOptionDescription", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Color Blindness Simulator.
+ /// </summary>
+ internal static string LongDisplayTitle {
+ get {
+ return ResourceManager.GetString("LongDisplayTitle", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Original.
+ /// </summary>
+ internal static string OriginalPicture {
+ get {
+ return ResourceManager.GetString("OriginalPicture", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Directory where the result should be persisted. By default, use input file&apos;s directory.
+ /// </summary>
+ internal static string OutputDirectoryOptionDescription {
+ get {
+ return ResourceManager.GetString("OutputDirectoryOptionDescription", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Protanopia simulation.
+ /// </summary>
+ internal static string ProtanopiaSimulation {
+ get {
+ return ResourceManager.GetString("ProtanopiaSimulation", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Tritanopia Protanopia Deuteranopia Dalton Daltonism Daltonist.
+ /// </summary>
+ internal static string SearchKeywords {
+ get {
+ return ResourceManager.GetString("SearchKeywords", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Color Blindness Simulator.
+ /// </summary>
+ internal static string ShortDisplayTitle {
+ get {
+ return ResourceManager.GetString("ShortDisplayTitle", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Hides the progress of the hashing operation.
+ /// </summary>
+ internal static string SilentOptionDescription {
+ get {
+ return ResourceManager.GetString("SilentOptionDescription", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Tritanopia simulation.
+ /// </summary>
+ internal static string TritanopiaSimulation {
+ get {
+ return ResourceManager.GetString("TritanopiaSimulation", resourceCulture);
+ }
+ }
+ }
+}
diff --git a/src/app/dev/DevToys.Tools/Tools/Graphic/ColorBlindnessSimulator/ColorBlindnessSimulator.resx b/src/app/dev/DevToys.Tools/Tools/Graphic/ColorBlindnessSimulator/ColorBlindnessSimulator.resx
new file mode 100644
index 000000000..90b653dd2
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Tools/Graphic/ColorBlindnessSimulator/ColorBlindnessSimulator.resx
@@ -0,0 +1,157 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <data name="AccessibleName" xml:space="preserve">
+ <value>Color Blindness Simulator tool</value>
+ </data>
+ <data name="Description" xml:space="preserve">
+ <value>Simulate color blindness on a picture or screenshot</value>
+ </data>
+ <data name="DeuteranopiaSimulation" xml:space="preserve">
+ <value>Deuteranopia simulation</value>
+ </data>
+ <data name="InputOptionDescription" xml:space="preserve">
+ <value>Image file path to treat</value>
+ </data>
+ <data name="LongDisplayTitle" xml:space="preserve">
+ <value>Color Blindness Simulator</value>
+ </data>
+ <data name="OriginalPicture" xml:space="preserve">
+ <value>Original</value>
+ </data>
+ <data name="OutputDirectoryOptionDescription" xml:space="preserve">
+ <value>Directory where the result should be persisted. By default, use input file's directory</value>
+ </data>
+ <data name="ProtanopiaSimulation" xml:space="preserve">
+ <value>Protanopia simulation</value>
+ </data>
+ <data name="SearchKeywords" xml:space="preserve">
+ <value>Tritanopia Protanopia Deuteranopia Dalton Daltonism Daltonist</value>
+ <comment>Alternative search keywords.</comment>
+ </data>
+ <data name="ShortDisplayTitle" xml:space="preserve">
+ <value>Color Blindness Simulator</value>
+ </data>
+ <data name="SilentOptionDescription" xml:space="preserve">
+ <value>Hides the progress of the hashing operation</value>
+ </data>
+ <data name="TritanopiaSimulation" xml:space="preserve">
+ <value>Tritanopia simulation</value>
+ </data>
+</root>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Tools/Tools/Graphic/ColorBlindnessSimulator/ColorBlindnessSimulatorCommandLineTool.cs b/src/app/dev/DevToys.Tools/Tools/Graphic/ColorBlindnessSimulator/ColorBlindnessSimulatorCommandLineTool.cs
new file mode 100644
index 000000000..10e873765
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Tools/Graphic/ColorBlindnessSimulator/ColorBlindnessSimulatorCommandLineTool.cs
@@ -0,0 +1,166 @@
+using DevToys.Api.Tool.CLI;
+using DevToys.Tools.Helpers;
+using DevToys.Tools.SmartDetection;
+using DevToys.Tools.Strings.GlobalStrings;
+using Microsoft.Extensions.Logging;
+using SixLabors.ImageSharp;
+using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.ImageSharp.Processing;
+
+namespace DevToys.Tools.Tools.Graphic.ColorBlindnessSimulator;
+
+[Export(typeof(ICommandLineTool))]
+[Name("ColorBlindnessSimulator")]
+[CommandName(
+ Name = "colorblindsimulator",
+ Alias = "cbs",
+ ResourceManagerBaseName = "DevToys.Tools.Tools.Graphic.ColorBlindnessSimulator.ColorBlindnessSimulator",
+ DescriptionResourceName = nameof(ColorBlindnessSimulator.Description))]
+internal sealed class ColorBlindnessSimulatorCommandLineTool : ICommandLineTool
+{
+ [CommandLineOption(
+ Name = "input",
+ Alias = "i",
+ IsRequired = true,
+ DescriptionResourceName = nameof(ColorBlindnessSimulator.InputOptionDescription))]
+ internal FileInfo Input { get; set; } = null!;
+
+ [CommandLineOption(
+ Name = "outputDirectory",
+ Alias = "o",
+ DescriptionResourceName = nameof(ColorBlindnessSimulator.OutputDirectoryOptionDescription))]
+ internal DirectoryInfo? OutputFile { get; set; }
+
+ [CommandLineOption(
+ Name = "silent",
+ Alias = "s",
+ DescriptionResourceName = nameof(ColorBlindnessSimulator.SilentOptionDescription))]
+ internal bool Silent { get; set; } = false;
+
+ public async ValueTask<int> InvokeAsync(ILogger logger, CancellationToken cancellationToken)
+ {
+ if (Input is null)
+ {
+ return -1;
+ }
+
+ if (!Input.Exists)
+ {
+ Console.Error.WriteLine(string.Format(GlobalStrings.FileNotFound, Input.FullName));
+ return -1;
+ }
+
+ string fileExtension = Input.Extension;
+ bool isSupportedImageFile = ColorBlindnessSimulatorImageFileDataTypeDetector.SupportedFileTypes.Any(ext => ext.Equals(fileExtension, StringComparison.OrdinalIgnoreCase));
+ if (!isSupportedImageFile)
+ {
+ Console.Error.WriteLine(
+ string.Format(
+ GlobalStrings.FileTypeNotSupported,
+ Input.FullName,
+ string.Join(", ", ColorBlindnessSimulatorImageFileDataTypeDetector.SupportedFileTypes)));
+ return -1;
+ }
+
+ await SimulateAsync(cancellationToken);
+
+ return 0;
+ }
+
+ private async Task SimulateAsync(CancellationToken cancellationToken)
+ {
+ string protanopiaOutputFilePath = string.Empty;
+ string tritanopiaOutputFilePath = string.Empty;
+ string deuteranopiaOutputFilePath = string.Empty;
+
+ ConsoleProgressBar? progressBar = Silent ? null : new ConsoleProgressBar();
+ using (progressBar)
+ {
+ int protanopiaProgress = 0;
+ int tritanopiaProgress = 0;
+ int deuteranopiaProgress = 0;
+
+ using Stream fileStream = Input.OpenRead();
+ using Image<Rgba32> originalImage = await Image.LoadAsync<Rgba32>(fileStream, cancellationToken);
+
+ var simulationTasks
+ = new List<Task<Image<Rgba32>?>>
+ {
+ Task.Run(() =>
+ ColorBlindnessSimulatorHelper.SimulateColorBlindness(
+ originalImage,
+ ColorBlindnessMode.Protanopia,
+ (progress) =>
+ {
+ protanopiaProgress = progress;
+ UpdateProgress();
+ },
+ cancellationToken)),
+
+ Task.Run(() =>
+ ColorBlindnessSimulatorHelper.SimulateColorBlindness(
+ originalImage,
+ ColorBlindnessMode.Tritanopia,
+ (progress) =>
+ {
+ tritanopiaProgress = progress;
+ UpdateProgress();
+ },
+ cancellationToken)),
+
+ Task.Run(() =>
+ ColorBlindnessSimulatorHelper.SimulateColorBlindness(
+ originalImage,
+ ColorBlindnessMode.Deuteranopia,
+ (progress) =>
+ {
+ deuteranopiaProgress = progress;
+ UpdateProgress();
+ },
+ cancellationToken)),
+ };
+
+ await Task.WhenAll(simulationTasks);
+
+ using Image<Rgba32>? protanopiaImage = simulationTasks[0].Result;
+ using Image<Rgba32>? tritanopiaImage = simulationTasks[1].Result;
+ using Image<Rgba32>? deuteranopiaImage = simulationTasks[2].Result;
+
+ string outputFileName = Path.GetFileNameWithoutExtension(Input.Name);
+ string outputDirectoryPath = OutputFile is null ? Path.GetDirectoryName(Input.FullName)! : OutputFile.FullName;
+ Directory.CreateDirectory(outputDirectoryPath);
+ string outputExtension = Path.GetExtension(Input.Name);
+
+ protanopiaOutputFilePath = Path.Combine(outputDirectoryPath, outputFileName + "-protanopia" + outputExtension);
+ tritanopiaOutputFilePath = Path.Combine(outputDirectoryPath, outputFileName + "-tritanopia" + outputExtension);
+ deuteranopiaOutputFilePath = Path.Combine(outputDirectoryPath, outputFileName + "-deuteranopia" + outputExtension);
+
+ if (protanopiaImage is not null)
+ {
+ progressBar?.Report(98);
+ await protanopiaImage.SaveAsync(protanopiaOutputFilePath, cancellationToken);
+ }
+
+ if (tritanopiaImage is not null)
+ {
+ progressBar?.Report(99);
+ await tritanopiaImage.SaveAsync(tritanopiaOutputFilePath, cancellationToken);
+ }
+
+ if (deuteranopiaImage is not null)
+ {
+ progressBar?.Report(100);
+ await deuteranopiaImage.SaveAsync(deuteranopiaOutputFilePath, cancellationToken);
+ }
+
+ void UpdateProgress()
+ {
+ progressBar?.Report(Math.Min((protanopiaProgress + tritanopiaProgress + deuteranopiaProgress) / 3, 97));
+ }
+ }
+
+ Console.WriteLine(protanopiaOutputFilePath);
+ Console.WriteLine(tritanopiaOutputFilePath);
+ Console.WriteLine(deuteranopiaOutputFilePath);
+ }
+}
diff --git a/src/app/dev/DevToys.Tools/Tools/Graphic/ColorBlindnessSimulator/ColorBlindnessSimulatorGuiTool.cs b/src/app/dev/DevToys.Tools/Tools/Graphic/ColorBlindnessSimulator/ColorBlindnessSimulatorGuiTool.cs
new file mode 100644
index 000000000..d5e6f1c89
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Tools/Graphic/ColorBlindnessSimulator/ColorBlindnessSimulatorGuiTool.cs
@@ -0,0 +1,311 @@
+using DevToys.Tools.Helpers;
+using DevToys.Tools.SmartDetection;
+using Microsoft.Extensions.Logging;
+using SixLabors.ImageSharp;
+using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.ImageSharp.Processing;
+
+namespace DevToys.Tools.Tools.Graphic.ColorBlindnessSimulator;
+
+[Export(typeof(IGuiTool))]
+[Name("ColorBlindnessSimulator")]
+[ToolDisplayInformation(
+ IconFontName = "DevToys-Tools-Icons",
+ IconGlyph = '\u0101',
+ GroupName = PredefinedCommonToolGroupNames.Graphic,
+ ResourceManagerAssemblyIdentifier = nameof(DevToysToolsResourceManagerAssemblyIdentifier),
+ ResourceManagerBaseName = "DevToys.Tools.Tools.Graphic.ColorBlindnessSimulator.ColorBlindnessSimulator",
+ ShortDisplayTitleResourceName = nameof(ColorBlindnessSimulator.ShortDisplayTitle),
+ LongDisplayTitleResourceName = nameof(ColorBlindnessSimulator.LongDisplayTitle),
+ DescriptionResourceName = nameof(ColorBlindnessSimulator.Description),
+ AccessibleNameResourceName = nameof(ColorBlindnessSimulator.AccessibleName))]
+[AcceptedDataTypeName(PredefinedCommonDataTypeNames.Image)]
+[AcceptedDataTypeName("ColorBlindnessSimulatorImageFile")]
+internal sealed class ColorBlindnessSimulatorGuiTool : IGuiTool, IDisposable
+{
+ private enum GridRows
+ {
+ FileInput,
+ FirstLineResult,
+ SecondLineResult
+ }
+
+ private enum GridColumns
+ {
+ Left,
+ Right
+ }
+
+ private readonly object _lock = new();
+ private readonly DisposableSemaphore _semaphore = new();
+ private readonly ILogger _logger;
+ private readonly IFileStorage _fileStorage;
+ private readonly IUIFileSelector _fileSelector = FileSelector();
+ private readonly IUIImageViewer _originalImageViewer = ImageViewer();
+ private readonly IUIImageViewer _protanopiaImageViewer = ImageViewer();
+ private readonly IUIImageViewer _tritanopiaImageViewer = ImageViewer();
+ private readonly IUIImageViewer _deuteranopiaImageViewer = ImageViewer();
+ private readonly IUIStack _progressStack = Stack();
+ private readonly IUIProgressBar _progressBar = ProgressBar();
+
+ private CancellationTokenSource? _cancellationTokenSource;
+ private SandboxedFileReader? _selectedFile;
+
+ [ImportingConstructor]
+ public ColorBlindnessSimulatorGuiTool(IFileStorage fileStorage)
+ {
+ _logger = this.Log();
+ _fileStorage = fileStorage;
+ }
+
+ // For unit tests.
+ internal Task? WorkTask { get; private set; }
+
+ public UIToolView View
+ => new(
+ isScrollable: false,
+ Grid()
+ .RowLargeSpacing()
+ .ColumnLargeSpacing()
+
+ .Rows(
+ (GridRows.FileInput, Auto),
+ (GridRows.FirstLineResult, new UIGridLength(1, UIGridUnitType.Fraction)),
+ (GridRows.SecondLineResult, new UIGridLength(1, UIGridUnitType.Fraction)))
+
+ .Columns(
+ (GridColumns.Left, new UIGridLength(1, UIGridUnitType.Fraction)),
+ (GridColumns.Right, new UIGridLength(1, UIGridUnitType.Fraction)))
+
+ .Cells(
+ Cell(
+ GridRows.FileInput,
+ GridRows.FileInput,
+ GridColumns.Left,
+ GridColumns.Right,
+
+ _fileSelector
+ .CanSelectOneFile()
+ .LimitFileTypesTo(ColorBlindnessSimulatorImageFileDataTypeDetector.SupportedFileTypes)
+ .OnFilesSelected(OnFilesSelected)),
+
+ Cell(
+ GridRows.FirstLineResult,
+ GridColumns.Left,
+
+ _originalImageViewer
+ .Title(ColorBlindnessSimulator.OriginalPicture)
+ .Hide()),
+
+ Cell(
+ GridRows.FirstLineResult,
+ GridColumns.Right,
+
+ _protanopiaImageViewer
+ .Title(ColorBlindnessSimulator.ProtanopiaSimulation)
+ .Hide()),
+
+ Cell(
+ GridRows.SecondLineResult,
+ GridColumns.Left,
+
+ _tritanopiaImageViewer
+ .Title(ColorBlindnessSimulator.TritanopiaSimulation)
+ .Hide()),
+
+ Cell(
+ GridRows.SecondLineResult,
+ GridColumns.Right,
+
+ _deuteranopiaImageViewer
+ .Title(ColorBlindnessSimulator.DeuteranopiaSimulation)
+ .Hide()),
+
+ Cell(GridRows.FirstLineResult,
+ GridRows.SecondLineResult,
+ GridColumns.Left,
+ GridColumns.Right,
+
+ _progressStack
+ .AlignHorizontally(UIHorizontalAlignment.Center)
+ .AlignVertically(UIVerticalAlignment.Center)
+ .Horizontal()
+ .SmallSpacing()
+ .Hide()
+
+ .WithChildren(
+ _progressBar,
+ Button()
+ .Icon("FluentSystemIcons", '\uF75A')
+ .OnClick(CancelSimulation)))));
+
+ public async void OnDataReceived(string dataTypeName, object? parsedData)
+ {
+ if (dataTypeName == PredefinedCommonDataTypeNames.Image && parsedData is Image<Rgba32> image)
+ {
+ FileInfo temporaryFile = _fileStorage.CreateSelfDestroyingTempFile("png");
+
+ using (image)
+ {
+ using Stream fileStream = _fileStorage.OpenWriteFile(temporaryFile.FullName, replaceIfExist: true);
+ await image.SaveAsPngAsync(fileStream);
+ }
+
+ _fileSelector.WithFiles(SandboxedFileReader.FromFileInfo(temporaryFile)); // This will trigger a new simulation.
+ }
+ else if (dataTypeName == "ColorBlindnessSimulatorImageFile" && parsedData is FileInfo file)
+ {
+ _fileSelector.WithFiles(SandboxedFileReader.FromFileInfo(file)); // This will trigger a new simulation.
+ }
+ }
+
+ public void Dispose()
+ {
+ _selectedFile?.Dispose();
+ CancelSimulation();
+ _semaphore.Dispose();
+ }
+
+ private void OnFilesSelected(SandboxedFileReader[] files)
+ {
+ Guard.HasSizeEqualTo(files, 1);
+
+ _selectedFile?.Dispose();
+ _selectedFile = files[0];
+
+ CancelSimulation();
+
+ _cancellationTokenSource = new CancellationTokenSource();
+ WorkTask = SimulateAsync(_selectedFile, _cancellationTokenSource.Token);
+ }
+
+ private void CancelSimulation()
+ {
+ lock (_lock)
+ {
+ try
+ {
+ _cancellationTokenSource?.Cancel();
+ }
+ catch
+ {
+ // Ignore.
+ }
+ finally
+ {
+ _cancellationTokenSource?.Dispose();
+ }
+
+ _originalImageViewer.Clear();
+ _protanopiaImageViewer.Clear();
+ _tritanopiaImageViewer.Clear();
+ _deuteranopiaImageViewer.Clear();
+ _originalImageViewer.Hide();
+ _protanopiaImageViewer.Hide();
+ _tritanopiaImageViewer.Hide();
+ _deuteranopiaImageViewer.Hide();
+
+ _progressBar.Progress(0);
+ _progressStack.Hide();
+ }
+ }
+
+ private async Task SimulateAsync(SandboxedFileReader file, CancellationToken cancellationToken)
+ {
+ _progressStack.Show();
+
+ int protanopiaProgress = 0;
+ int tritanopiaProgress = 0;
+ int deuteranopiaProgress = 0;
+
+ using Stream fileStream = await file.GetNewAccessToFileContentAsync(cancellationToken);
+ Image<Rgba32> originalImage = await Image.LoadAsync<Rgba32>(fileStream, cancellationToken);
+
+ var simulationTasks
+ = new List<Task<Image<Rgba32>?>>
+ {
+ SimulateAsync(
+ originalImage,
+ ColorBlindnessMode.Protanopia,
+ (progress) =>
+ {
+ protanopiaProgress = progress;
+ UpdateProgress();
+ },
+ cancellationToken),
+
+ SimulateAsync(
+ originalImage,
+ ColorBlindnessMode.Tritanopia,
+ (progress) =>
+ {
+ tritanopiaProgress = progress;
+ UpdateProgress();
+ },
+ cancellationToken),
+
+ SimulateAsync(
+ originalImage,
+ ColorBlindnessMode.Deuteranopia,
+ (progress) =>
+ {
+ deuteranopiaProgress = progress;
+ UpdateProgress();
+ },
+ cancellationToken),
+ };
+
+ await Task.WhenAll(simulationTasks);
+
+ lock (_lock)
+ {
+ _progressStack.Hide();
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+ if (simulationTasks[0].Result is not null)
+ {
+ simulationTasks[0].Result!.Dispose();
+ }
+ if (simulationTasks[1].Result is not null)
+ {
+ simulationTasks[1].Result!.Dispose();
+ }
+ if (simulationTasks[2].Result is not null)
+ {
+ simulationTasks[2].Result!.Dispose();
+ }
+
+ return;
+ }
+
+ Guard.IsNotNull(simulationTasks[0].Result);
+ Guard.IsNotNull(simulationTasks[1].Result);
+ Guard.IsNotNull(simulationTasks[2].Result);
+ Image<Rgba32> protanopiaImage = simulationTasks[0].Result!;
+ Image<Rgba32> tritanopiaImage = simulationTasks[1].Result!;
+ Image<Rgba32> deuteranopiaImage = simulationTasks[2].Result!;
+
+ _originalImageViewer.WithImage(originalImage, disposeAutomatically: true).Show();
+ _protanopiaImageViewer.WithImage(protanopiaImage, disposeAutomatically: true).Show();
+ _tritanopiaImageViewer.WithImage(tritanopiaImage, disposeAutomatically: true).Show();
+ _deuteranopiaImageViewer.WithImage(deuteranopiaImage, disposeAutomatically: true).Show();
+ }
+
+ void UpdateProgress()
+ {
+ _progressBar.Progress((protanopiaProgress + tritanopiaProgress + deuteranopiaProgress) / 3);
+ }
+ }
+
+ private static async Task<Image<Rgba32>?> SimulateAsync(
+ Image<Rgba32> originalImage,
+ ColorBlindnessMode colorBlindnessMode,
+ Action<int> progressReport,
+ CancellationToken cancellationToken)
+ {
+ await TaskSchedulerAwaiter.SwitchOffMainThreadAsync(cancellationToken);
+
+ return ColorBlindnessSimulatorHelper.SimulateColorBlindness(originalImage, colorBlindnessMode, progressReport, cancellationToken);
+ }
+}
diff --git a/src/app/dev/DevToys.Tools/Tools/Graphic/Graphic.Designer.cs b/src/app/dev/DevToys.Tools/Tools/Graphic/Graphic.Designer.cs
new file mode 100644
index 000000000..f28323f4f
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Tools/Graphic/Graphic.Designer.cs
@@ -0,0 +1,81 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+// This code was generated by a tool.
+// Runtime Version:4.0.30319.42000
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+namespace DevToys.Tools.Tools.Graphic {
+ using System;
+
+
+ /// <summary>
+ /// A strongly-typed resource class, for looking up localized strings, etc.
+ /// </summary>
+ // This class was auto-generated by the StronglyTypedResourceBuilder
+ // class via a tool like ResGen or Visual Studio.
+ // To add or remove a member, edit your .ResX file then rerun ResGen
+ // with the /str option, or rebuild your VS project.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Graphic {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Graphic() {
+ }
+
+ /// <summary>
+ /// Returns the cached ResourceManager instance used by this class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DevToys.Tools.Tools.Graphic.Graphic", typeof(Graphic).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ /// <summary>
+ /// Overrides the current thread's CurrentUICulture property for all
+ /// resource lookups using this strongly typed resource class.
+ /// </summary>
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Graphic.
+ /// </summary>
+ internal static string AccessibleName {
+ get {
+ return ResourceManager.GetString("AccessibleName", resourceCulture);
+ }
+ }
+
+ /// <summary>
+ /// Looks up a localized string similar to Graphic.
+ /// </summary>
+ internal static string DisplayTitle {
+ get {
+ return ResourceManager.GetString("DisplayTitle", resourceCulture);
+ }
+ }
+ }
+}
diff --git a/src/app/dev/DevToys.Tools/Tools/Graphic/Graphic.resx b/src/app/dev/DevToys.Tools/Tools/Graphic/Graphic.resx
new file mode 100644
index 000000000..fa573fa90
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Tools/Graphic/Graphic.resx
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+ <!--
+ Microsoft ResX Schema
+
+ Version 2.0
+
+ The primary goals of this format is to allow a simple XML format
+ that is mostly human readable. The generation and parsing of the
+ various data types are done through the TypeConverter classes
+ associated with the data types.
+
+ Example:
+
+ ... ado.net/XML headers & schema ...
+ <resheader name="resmimetype">text/microsoft-resx</resheader>
+ <resheader name="version">2.0</resheader>
+ <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+ <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+ <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+ <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+ <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+ <value>[base64 mime encoded serialized .NET Framework object]</value>
+ </data>
+ <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+ <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+ <comment>This is a comment</comment>
+ </data>
+
+ There are any number of "resheader" rows that contain simple
+ name/value pairs.
+
+ Each data row contains a name, and value. The row also contains a
+ type or mimetype. Type corresponds to a .NET class that support
+ text/value conversion through the TypeConverter architecture.
+ Classes that don't support this are serialized and stored with the
+ mimetype set.
+
+ The mimetype is used for serialized objects, and tells the
+ ResXResourceReader how to depersist the object. This is currently not
+ extensible. For a given mimetype the value must be set accordingly:
+
+ Note - application/x-microsoft.net.object.binary.base64 is the format
+ that the ResXResourceWriter will generate, however the reader can
+ read any of the formats listed below.
+
+ mimetype: application/x-microsoft.net.object.binary.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.soap.base64
+ value : The object must be serialized with
+ : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+ : and then encoded with base64 encoding.
+
+ mimetype: application/x-microsoft.net.object.bytearray.base64
+ value : The object must be serialized into a byte array
+ : using a System.ComponentModel.TypeConverter
+ : and then encoded with base64 encoding.
+ -->
+ <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+ <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+ <xsd:element name="root" msdata:IsDataSet="true">
+ <xsd:complexType>
+ <xsd:choice maxOccurs="unbounded">
+ <xsd:element name="metadata">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" />
+ </xsd:sequence>
+ <xsd:attribute name="name" use="required" type="xsd:string" />
+ <xsd:attribute name="type" type="xsd:string" />
+ <xsd:attribute name="mimetype" type="xsd:string" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="assembly">
+ <xsd:complexType>
+ <xsd:attribute name="alias" type="xsd:string" />
+ <xsd:attribute name="name" type="xsd:string" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="data">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+ <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+ <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+ <xsd:attribute ref="xml:space" />
+ </xsd:complexType>
+ </xsd:element>
+ <xsd:element name="resheader">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+ </xsd:sequence>
+ <xsd:attribute name="name" type="xsd:string" use="required" />
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:schema>
+ <resheader name="resmimetype">
+ <value>text/microsoft-resx</value>
+ </resheader>
+ <resheader name="version">
+ <value>2.0</value>
+ </resheader>
+ <resheader name="reader">
+ <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <resheader name="writer">
+ <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+ </resheader>
+ <data name="AccessibleName" xml:space="preserve">
+ <value>Graphic</value>
+ </data>
+ <data name="DisplayTitle" xml:space="preserve">
+ <value>Graphic</value>
+ </data>
+</root>
\ No newline at end of file
diff --git a/src/app/dev/DevToys.Tools/Tools/Graphic/GraphicGroup.cs b/src/app/dev/DevToys.Tools/Tools/Graphic/GraphicGroup.cs
new file mode 100644
index 000000000..67d8a78cc
--- /dev/null
+++ b/src/app/dev/DevToys.Tools/Tools/Graphic/GraphicGroup.cs
@@ -0,0 +1,15 @@
+namespace DevToys.Tools.Tools.Graphic;
+
+[Export(typeof(GuiToolGroup))]
+[Name(PredefinedCommonToolGroupNames.Graphic)]
+internal sealed class GraphicGroup : GuiToolGroup
+{
+ [ImportingConstructor]
+ internal GraphicGroup()
+ {
+ IconFontName = "DevToys-Tools-Icons";
+ IconGlyph = '\u0129';
+ DisplayTitle = Graphic.DisplayTitle;
+ AccessibleName = Graphic.AccessibleName;
+ }
+}
diff --git a/src/spellcheckerexclusion.dic b/src/spellcheckerexclusion.dic
index 4eb0fa0d0..7750f71ee 100644
--- a/src/spellcheckerexclusion.dic
+++ b/src/spellcheckerexclusion.dic
@@ -18,3 +18,6 @@ jtoken
webp
hmac
Blazor
+Brettel
+bgra
+colorblindsimulator