OSDN Git Service

CIEColor.cs
authorHOSOKAWA Kenchi <hskwk@users.sourceforge.jp>
Fri, 7 Jan 2011 11:47:34 +0000 (20:47 +0900)
committerHOSOKAWA Kenchi <hskwk@users.sourceforge.jp>
Fri, 7 Jan 2011 11:47:34 +0000 (20:47 +0900)
dev4/PsychlopsSilverlight4.csproj
dev4/psychlops/extention/standard/CIEColor.cs [new file with mode: 0644]
test4/PsychlopsMain.cs
test4/PsychlopsSilverlight4test.csproj

index 2ee575b..e2f0ade 100644 (file)
@@ -87,6 +87,7 @@
     <Compile Include="psychlops\extention\math\solver.cs" />\r
     <Compile Include="psychlops\extention\media\dom.cs" />\r
     <Compile Include="psychlops\extention\media\svg.cs" />\r
+    <Compile Include="psychlops\extention\standard\CIEColor.cs" />\r
     <Compile Include="psychlops\extention\standard\figures.cs" />\r
     <Compile Include="psychlops\extention\standard\widget.cs" />\r
     <Compile Include="psychlops\psychlops.cs" />\r
diff --git a/dev4/psychlops/extention/standard/CIEColor.cs b/dev4/psychlops/extention/standard/CIEColor.cs
new file mode 100644 (file)
index 0000000..50df53c
--- /dev/null
@@ -0,0 +1,108 @@
+using System;\r
+\r
+namespace Psychlops\r
+{\r
+       namespace ColorSpaces\r
+       {\r
+               /*\r
+                * CIE 1931\r
+                * R: 700 nm\r
+                * G: 546.1 nm\r
+                * B: 435.8 nm\r
+                * White Point: Illuminant E\r
+                */\r
+               public struct CIERGB\r
+               {\r
+                       public double R, G, B;\r
+\r
+                       public CIEXYZ convertToCIEXYZ()\r
+                       {\r
+                               double[,] b =\r
+                       { \r
+                               { 0.49, 0.31, 0.20 },\r
+                               { 0.17697, 0.81240, 0.01063 },\r
+                               { 0.00, 0.01, 0.99 }\r
+                       };\r
+\r
+                               CIEXYZ v;\r
+\r
+                               v.X = b[0, 0] * R + b[0, 1] * G + b[0, 2] * B;\r
+                               v.Y = b[1, 0] * R + b[1, 1] * G + b[1, 2] * B;\r
+                               v.Z = b[2, 0] * R + b[2, 1] * G + b[2, 2] * B;\r
+\r
+                               return v;\r
+                       }\r
+               }\r
+\r
+               /*\r
+                * CIE 1931\r
+                */\r
+               public struct CIEXYZ\r
+               {\r
+                       public double X, Y, Z;\r
+\r
+                       public CIExyY convertToCIExyY()\r
+                       {\r
+                               CIExyY v;\r
+\r
+                               double denominator = X + Y + Z;\r
+                               v.x = X / denominator;\r
+                               v.y = Y / denominator;\r
+                               v.Y = Y;\r
+\r
+                               return v;\r
+                       }\r
+               }\r
+\r
+               public struct CIExyY\r
+               {\r
+                       public double x, y, Y;\r
+\r
+                       public CIEXYZ convertToCIEXYZ()\r
+                       {\r
+                               CIEXYZ v;\r
+\r
+                               v.X = Y / y * x;\r
+                               v.Y = Y;\r
+                               v.Z = Y / y * (1 - x - y);\r
+\r
+                               return v;\r
+                       }\r
+\r
+                       // Yn = 1.0 when RGB of white point is { 1, 1, 1 }\r
+                       public CIELuv convertToCIELuv(double Yn = 1.0)\r
+                       {\r
+\r
+                               CIELuv v;\r
+\r
+                               double denominator = (-2 * x + 12 * y + 3);\r
+                               double up = 4 * x / denominator;\r
+                               double vp = 9 * y / denominator;\r
+\r
+                               double Yd = Y / Yn;\r
+                               v.L = Yd > System.Math.Pow(6 / 29, 3) ? 116 * System.Math.Pow(Yd, 3) : System.Math.Pow(29 / 3, 3) * Yd;\r
+                               v.u = 13 * v.L * (up - 0.2009);\r
+                               v.v = 13 * v.L * (vp - 0.4610);\r
+\r
+                               return v;\r
+                       }\r
+               }\r
+\r
+               /* L*u*v*\r
+                * CIE 1976\r
+                * standard illuminant C\r
+                */\r
+               public struct CIELuv\r
+               {\r
+                       public double L, u, v;\r
+\r
+               }\r
+\r
+               public struct CIELab\r
+               {\r
+                       public double L, a, b;\r
+\r
+               }\r
+\r
+       }\r
+}
\ No newline at end of file
index ad9a4c1..71d18a5 100644 (file)
@@ -9,6 +9,9 @@ namespace PsychlopsSilverlightApp
 \r
                public void psychlops_main()\r
                {\r
+                       Psychlops.ColorSpaces.CIERGB rgb = new Psychlops.ColorSpaces.CIERGB { R = 1, G = 1, B = 1 };\r
+                       var xyz = rgb.convertToCIEXYZ();\r
+\r
                        Canvas window = new Canvas(300,300);\r
 \r
                        Rectangle figure = new Rectangle();\r
@@ -38,6 +41,8 @@ namespace PsychlopsSilverlightApp
                                figure.shift(motion_dir * 1, motion_dir * 0);\r
 \r
                                figure.draw();\r
+\r
+                               window.msg(xyz.Y.ToString(), 100, 100);\r
                                window.flip();\r
 \r
                                frame++;\r
index 44c62e0..9d816f2 100644 (file)
@@ -62,9 +62,6 @@
     <WarningLevel>4</WarningLevel>\r
   </PropertyGroup>\r
   <ItemGroup>\r
-    <Reference Include="PsychlopsSilverlight4">\r
-      <HintPath>..\dev4\Bin\Release\PsychlopsSilverlight4.dll</HintPath>\r
-    </Reference>\r
     <Reference Include="System.Windows" />\r
     <Reference Include="mscorlib" />\r
     <Reference Include="system" />\r
   <ItemGroup>\r
     <Folder Include="Resources\" />\r
   </ItemGroup>\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\dev4\PsychlopsSilverlight4.csproj">\r
+      <Project>{58F3CEF1-8123-4105-9525-B7E2C7F188AC}</Project>\r
+      <Name>PsychlopsSilverlight4</Name>\r
+    </ProjectReference>\r
+  </ItemGroup>\r
   <Import Project="$(MSBuildExtensionsPath32)\Microsoft\Silverlight\$(SilverlightVersion)\Microsoft.Silverlight.CSharp.targets" />\r
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
        Other similar extension points exist, see Microsoft.Common.targets.\r