Permalink
Browse files

Project

  • Loading branch information...
Silverfeelin committed Sep 26, 2016
1 parent e880119 commit 4f735bb53edbe6df487d9e6a9fa8b04c9b6e8fda
View
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30501.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DirectiveGenerator", "DirectiveGenerator\DirectiveGenerator.csproj", "{2EEEFD28-549F-4B53-8A7E-3FC49B75EBDB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2EEEFD28-549F-4B53-8A7E-3FC49B75EBDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2EEEFD28-549F-4B53-8A7E-3FC49B75EBDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2EEEFD28-549F-4B53-8A7E-3FC49B75EBDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2EEEFD28-549F-4B53-8A7E-3FC49B75EBDB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2EEEFD28-549F-4B53-8A7E-3FC49B75EBDB}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DirectiveGenerator</RootNamespace>
<AssemblyName>DirectiveGenerator</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
@@ -0,0 +1,123 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DirectiveGenerator
{
class Program
{
[STAThread]
static void Main(string[] args)
{
// Parameter checkng
if (args.Count() != 2)
WaitAndExit("Improper usage! Expected parameters: <image_one_path> <image_two_path>\n" +
"Try dragging two image files directly on top of the application!");
// Image checking
Bitmap b1 = null, b2 = null;
try
{
b1 = new Bitmap(args[0]);
}
catch (ArgumentException)
{
WaitAndExit("The first file ({0}) is not a valid image or does not exist.", args[0]);
}
try
{
b2 = new Bitmap(args[1]);
}
catch (ArgumentException)
{
WaitAndExit("The second file \"{0}\" is not a valid image or does not exist.", args[1]);
}
if (!b1.Size.Equals(b2.Size))
WaitAndExit("Image resolutions do not match.\n\"{0}\": {1}\n\"{2}\": {3}\nThat'd make comparing colors quite difficult!", args[0], b1.Size, args[1], b2.Size);
// Conversion order
while (true)
{
Console.WriteLine("Convert \"{0}\" to \"{1}\"?", args[0], args[1]);
Console.WriteLine("Y: Start. N: Switch order. ESC: Abort.");
ConsoleKeyInfo cki = Console.ReadKey();
Console.WriteLine();
if (cki.Key == ConsoleKey.Escape)
WaitAndExit();
else if (cki.Key == ConsoleKey.Y)
break;
else if (cki.Key == ConsoleKey.N)
{
string temp = args[0];
args[0] = args[1];
args[1] = temp;
break;
}
}
// Comparing images
Dictionary<Color, Color> conversions = new Dictionary<Color, Color>();
Console.WriteLine("Starting comparison from \"{0}\" to \"{1}\".", args[0], args[1]);
for (int y = b1.Height - 1; y >= 0; y--)
{
for (int x = b1.Width - 1; x >= 0; x--)
{
Color cFrom = b1.GetPixel(x, y),
cTo = b2.GetPixel(x, y);
if (!cFrom.Equals(cTo))
conversions[cFrom] = cTo;
}
}
// Copy results to clipboard
Clipboard.SetText(CreateDirectives(conversions));
WaitAndExit("Directives copied to clipboard!");
}
static void WaitAndExit(string message = null, params object[] args)
{
if (!string.IsNullOrEmpty(message))
Console.WriteLine(message, args);
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
Environment.Exit(0);
}
static string ColorToString(Color c)
{
string r = c.R.ToString("X2"),
g = c.G.ToString("X2"),
b = c.B.ToString("X2"),
a = c.A.ToString("X2");
return (r + g + b + a).ToLower();
}
static string CreateDirectives(Dictionary<Color, Color> conversions)
{
string directives = "?replace";
foreach (KeyValuePair<Color, Color> conversion in conversions)
{
directives += string.Format(";{0}={1}", ColorToString(conversion.Key), ColorToString(conversion.Value));
}
Console.WriteLine(directives);
return directives;
}
}
}
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("DirectiveGenerator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DirectiveGenerator")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("88eb4591-d633-4bcb-af1a-d5ae0faede4d")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

0 comments on commit 4f735bb

Please sign in to comment.