Skip to content

Commit

Permalink
プロジェクト追加
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogy committed Apr 3, 2017
1 parent 1b7a478 commit 675df4a
Show file tree
Hide file tree
Showing 15 changed files with 1,395 additions and 0 deletions.
6 changes: 6 additions & 0 deletions App.config
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
28 changes: 28 additions & 0 deletions Bead.cs
@@ -0,0 +1,28 @@
using ClosedXML.Excel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeadsImageConverter
{
public class Bead
{
public readonly int No;
public readonly string Name;
public readonly XLColor Color;
public readonly XLColor FontColor;
public int Count { get; set; }
public int Total { get; set; }

public Bead(int no, string name, byte r, byte g, byte b)
{
No = no;
Name = name;
Color = XLColor.FromArgb((int)r, (int)g, (int)b);
byte grey = (byte)(0.299 * (double)r + 0.587 * (double)g + 0.114 * (double)b);
FontColor = ((grey < 186) ? XLColor.White : XLColor.Black);
}
}
}
102 changes: 102 additions & 0 deletions BeadsImageConverter.csproj
@@ -0,0 +1,102 @@
<?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>{E630D483-EA4F-409B-958B-569DD2D6054F}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BeadsImageConverter</RootNamespace>
<AssemblyName>BeadsImageConverter</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</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>
<Prefer32Bit>false</Prefer32Bit>
</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>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="ClosedXML">
<HintPath>packages\ClosedXML.0.87.0\build\net40\ClosedXML.dll</HintPath>
</Reference>
<Reference Include="DocumentFormat.OpenXml, Version=2.5.5631.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>packages\DocumentFormat.OpenXml.2.5\lib\DocumentFormat.OpenXml.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Bead.cs" />
<Compile Include="CIELAB.cs" />
<Compile Include="FormMain.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FormMain.Designer.cs">
<DependentUpon>FormMain.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="FormMain.resx">
<DependentUpon>FormMain.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</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>
22 changes: 22 additions & 0 deletions BeadsImageConverter.sln
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.40629.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeadsImageConverter", "BeadsImageConverter.csproj", "{E630D483-EA4F-409B-958B-569DD2D6054F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E630D483-EA4F-409B-958B-569DD2D6054F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E630D483-EA4F-409B-958B-569DD2D6054F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E630D483-EA4F-409B-958B-569DD2D6054F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E630D483-EA4F-409B-958B-569DD2D6054F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
90 changes: 90 additions & 0 deletions CIELAB.cs
@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BeadsImageConverter
{
public class CIELAB
{
private static readonly int[] GammaTable = CreateGammaTable();
private static readonly int[] LabTable = CreateLabTable();
public static readonly CIELAB White = FromColor(Color.White);
public static readonly CIELAB Black = FromColor(Color.Black);
private static readonly double Max = Diff(White, Black);

public readonly int L;
public readonly int A;
public readonly int B;

private static int[] CreateGammaTable()
{
int[] table = new int[256];
for (int i = 0; i < 256; i++)
{
double value = (double)i / 255.0;
table[i] = (int)(((value > 0.04045) ? Math.Pow((value + 0.055) / 1.055, 2.4) : (value / 12.92)) * 100000.0);
}
return table;
}

private static int[] CreateLabTable()
{
int[] table = new int[100001];
for (int i = 0; i < table.Count<int>(); i++)
{
double value = (double)i / 100001.0;
table[i] = (int)(((value > 0.008856) ? Math.Pow(value, 0.33333333333333331) : (7.787 * value + 0.13793103448275862)) * 1000000.0);
}
return table;
}

private static double Diff(CIELAB src, CIELAB dst)
{
double L = (double)(src.L - dst.L);
double A = (double)(src.A - dst.A);
double B = (double)(src.B - dst.B);
return Math.Sqrt(L * L + A * A + B * B);
}

public static CIELAB FromRGB(byte r, byte g, byte b)
{
return CIELAB.FromColor(Color.FromArgb((int)r, (int)g, (int)b));
}

public static CIELAB FromColor(Color color)
{
int r = GammaTable[(int)color.R];
int g = GammaTable[(int)color.G];
int b = GammaTable[(int)color.B];

int x = (4124 * r + 3576 * g + 1805 * b) / 9505;
int y = (2126 * r + 7152 * g + 722 * b) / 10000;
int z = (193 * r + 1192 * g + 9505 * b) / 10890;

x = LabTable[x];
y = LabTable[y];
z = LabTable[z];

int L = 116 * y - 16000000;
int A = 500 * (x - y);
int B = 200 * (y - z);

return new CIELAB(L, A, B);
}

public static double Difference(CIELAB src, CIELAB dst)
{
return Diff(src, dst) / Max;
}

public CIELAB(int l, int a, int b)
{
this.L = l;
this.A = a;
this.B = b;
}
}
}
140 changes: 140 additions & 0 deletions FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 675df4a

Please sign in to comment.