Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit d2ab119

Browse files
committed
Added CIE's 1960 UVW color space
1 parent 761d7aa commit d2ab119

File tree

12 files changed

+204
-42
lines changed

12 files changed

+204
-42
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
ColorSharp's Changelog
22
======================
33

4+
## 2015-01-13 : 0.9.0 Release
5+
6+
### Contributors
7+
* Andrés Correa Casablanca <castarco@gmail.com , castarco@litipk.com>
8+
9+
### Changes
10+
* Added CIE's 1960 UVW color space
11+
* Less destructive conversions (now the data is better preserved)
12+
* Now ToSRGB, ToCIExyY and ToCIEUVW are virtual methods, not abstract.
13+
14+
415
## 2014-12-19 : 0.8.3 Release
516

617
### Contributors

ColorSharp.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ Global
3434
$0.VersionControlPolicy = $2
3535
$2.inheritsSet = Mono
3636
description = A .Net/Mono library to handle color spaces (and light spectrums!)
37-
version = 0.8.3
37+
version = 0.9.0
3838
EndGlobalSection
3939
EndGlobal

ColorSharp/ColorSharp.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<SignAssembly>true</SignAssembly>
1212
<DelaySign>false</DelaySign>
1313
<AssemblyOriginatorKeyFile>colorsharp.snk</AssemblyOriginatorKeyFile>
14-
<ReleaseVersion>0.8.3</ReleaseVersion>
14+
<ReleaseVersion>0.9.0</ReleaseVersion>
1515
</PropertyGroup>
1616
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1717
<DebugSymbols>true</DebugSymbols>
@@ -70,6 +70,7 @@
7070
<Compile Include="src\MatchingFunctions\CIE1931XYZ1NmMatchingFunctionX.cs" />
7171
<Compile Include="src\MatchingFunctions\CIE1931XYZ1NmMatchingFunctionY.cs" />
7272
<Compile Include="src\MatchingFunctions\CIE1931XYZ1NmMatchingFunctionZ.cs" />
73+
<Compile Include="src\ColorSpaces\CIEUVW.cs" />
7374
</ItemGroup>
7475
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
7576
<ItemGroup>

ColorSharp/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
4747
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
4848

49-
[assembly: AssemblyVersion ("0.8.3.*")]
49+
[assembly: AssemblyVersion ("0.9.0.*")]
5050

5151
// The following attributes are used to specify the signing key for the assembly,
5252
// if desired. See the Mono documentation for more information about signing.

ColorSharp/src/ColorSpaces/AConvertibleColor.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ public AConvertibleColor ConvertTo (Type t, ConversionStrategy strategy=Conversi
100100
/**
101101
* Helper method used by ConvertTo.
102102
*/
103-
private AConvertibleColor InnerConvertTo (Type t, ConversionStrategy strategy = ConversionStrategy.Default)
103+
AConvertibleColor InnerConvertTo (Type t, ConversionStrategy strategy = ConversionStrategy.Default)
104104
{
105105
if (t == typeof(CIEXYZ))
106106
return ToCIEXYZ (strategy);
107107
if (t == typeof(CIExyY))
108108
return ToCIExyY(strategy);
109+
if (t == typeof(CIEUVW))
110+
return ToCIEUVW (strategy);
109111
if (t == typeof(SRGB))
110112
return ToSRGB (strategy);
111113

@@ -130,12 +132,26 @@ private AConvertibleColor InnerConvertTo (Type t, ConversionStrategy strategy =
130132
/**
131133
* <summary>Converts the color sample to a CIE's 1931 xyY color sample.</summary>
132134
*/
133-
public abstract CIExyY ToCIExyY (ConversionStrategy strategy = ConversionStrategy.Default);
135+
public virtual CIExyY ToCIExyY (ConversionStrategy strategy = ConversionStrategy.Default)
136+
{
137+
return (DataSource as CIExyY) ?? ToCIEXYZ ().ToCIExyY ();
138+
}
139+
140+
/**
141+
* <summary>Converts the color sample to a CIE's 1960 UVW color sample.</summary>
142+
*/
143+
public virtual CIEUVW ToCIEUVW (ConversionStrategy strategy = ConversionStrategy.Default)
144+
{
145+
return (DataSource as CIEUVW) ?? ToCIEXYZ ().ToCIEUVW ();
146+
}
134147

135148
/**
136149
* <summary>Converts the color sample to an HP's and Microsoft's 1996 sRGB sample.</summary>
137150
*/
138-
public abstract SRGB ToSRGB(ConversionStrategy strategy = ConversionStrategy.Default);
151+
public virtual SRGB ToSRGB(ConversionStrategy strategy = ConversionStrategy.Default)
152+
{
153+
return (DataSource as SRGB) ?? ToCIEXYZ ().ToSRGB ();
154+
}
139155

140156
#endregion
141157
}

ColorSharp/src/ColorSpaces/CIEUVW.cs

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
/*
2+
* The MIT License (MIT)
3+
* Copyright (c) 2014 Andrés Correa Casablanca
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in all
13+
* copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
* SOFTWARE.
22+
*/
23+
24+
/*
25+
* Contributors:
26+
* - Andrés Correa Casablanca <castarco@gmail.com , castarco@litipk.com>
27+
*/
28+
29+
30+
using System;
31+
32+
33+
namespace Litipk.ColorSharp
34+
{
35+
namespace ColorSpaces
36+
{
37+
/**
38+
* <summary>CIE's 1960 UVW Color Space.</summary>
39+
*/
40+
public sealed class CIEUVW : AConvertibleColor
41+
{
42+
#region properties
43+
44+
/**
45+
* <value>U component of the CIE's 1960 UVW color space.</value>
46+
*/
47+
public readonly double U;
48+
49+
/**
50+
* <value>V component of the CIE's 1960 UVW color space.</value>
51+
*/
52+
public readonly double V;
53+
54+
/**
55+
* <value>W component of the CIE's 1960 UVW color space.</value>
56+
*/
57+
public readonly double W;
58+
59+
#endregion
60+
61+
62+
#region constructors
63+
64+
public CIEUVW (double U, double V, double W, AConvertibleColor dataSource=null) : base(dataSource)
65+
{
66+
this.U = U;
67+
this.V = V;
68+
this.W = W;
69+
}
70+
71+
#endregion
72+
73+
74+
#region AConvertibleColor methods
75+
76+
/**
77+
* <inheritdoc />
78+
*/
79+
public override bool IsInsideColorSpace()
80+
{
81+
// TODO : Improve ?
82+
return ToCIExyY ().IsInsideColorSpace ();
83+
}
84+
85+
/**
86+
* <inheritdoc />
87+
*/
88+
public override CIEXYZ ToCIEXYZ (ConversionStrategy strategy=ConversionStrategy.Default)
89+
{
90+
return (DataSource as CIEXYZ) ?? new CIEXYZ (
91+
1.5 * U, V, 1.5 * U - 3 * V + 2 * W, DataSource ?? this
92+
);
93+
}
94+
95+
/**
96+
* <inheritdoc />
97+
*/
98+
public override CIEUVW ToCIEUVW (ConversionStrategy strategy = ConversionStrategy.Default)
99+
{
100+
return this;
101+
}
102+
103+
#endregion
104+
105+
106+
#region Object methods
107+
108+
/**
109+
* <inheritdoc />
110+
*/
111+
public override bool Equals(Object obj)
112+
{
113+
CIEUVW uvwObj = obj as CIEUVW;
114+
115+
if (uvwObj == this) {
116+
return true;
117+
}
118+
if (uvwObj == null || GetHashCode () != obj.GetHashCode ()) {
119+
return false;
120+
}
121+
122+
return (U == uvwObj.U && V == uvwObj.V && W == uvwObj.W);
123+
}
124+
125+
/**
126+
* <inheritdoc />
127+
*/
128+
public override int GetHashCode ()
129+
{
130+
int hash = 77837 + U.GetHashCode (); // 77837 == 277 * 281
131+
132+
hash = hash * 281 + V.GetHashCode ();
133+
134+
return hash * 281 + W.GetHashCode ();
135+
}
136+
137+
#endregion
138+
}
139+
}
140+
}

ColorSharp/src/ColorSpaces/CIEXYZ.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828

2929

3030
using System;
31-
using System.Collections.Generic;
3231

3332

3433
namespace Litipk.ColorSharp
@@ -102,15 +101,35 @@ public override CIEXYZ ToCIEXYZ (ConversionStrategy strategy=ConversionStrategy.
102101
*/
103102
public override CIExyY ToCIExyY (ConversionStrategy strategy=ConversionStrategy.Default)
104103
{
104+
CIExyY xyYDS = DataSource as CIExyY;
105+
if (xyYDS != null) {
106+
return xyYDS;
107+
}
108+
105109
double XYZ = X + Y + Z;
106110
return new CIExyY (X / XYZ, Y / XYZ, Y, DataSource ?? this);
107111
}
108112

113+
/**
114+
* <inheritdoc />
115+
*/
116+
public override CIEUVW ToCIEUVW (ConversionStrategy strategy = ConversionStrategy.Default)
117+
{
118+
return (DataSource as CIEUVW) ?? new CIEUVW (
119+
2.0 * X / 3.0, Y, 0.5 * (-X + 3 * Y + Z), DataSource ?? this
120+
);
121+
}
122+
109123
/**
110124
* <inheritdoc />
111125
*/
112126
public override SRGB ToSRGB (ConversionStrategy strategy=ConversionStrategy.ForceLowTruncate|ConversionStrategy.ForceHighStretch)
113127
{
128+
SRGB srgbDS = DataSource as SRGB;
129+
if (srgbDS != null) {
130+
return srgbDS;
131+
}
132+
114133
// Linear transformation
115134
double r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
116135
double g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;

ColorSharp/src/ColorSpaces/CIExyY.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public override bool IsInsideColorSpace()
165165
*/
166166
public override CIEXYZ ToCIEXYZ (ConversionStrategy strategy=ConversionStrategy.Default)
167167
{
168-
return new CIEXYZ (x*Y/y, Y, Y*(1.0 - x - y)/y, DataSource ?? this);
168+
return (DataSource as CIEXYZ) ?? new CIEXYZ (x*Y/y, Y, Y*(1.0 - x - y)/y, DataSource ?? this);
169169
}
170170

171171
/**
@@ -176,14 +176,6 @@ public override CIExyY ToCIExyY (ConversionStrategy strategy = ConversionStrateg
176176
return this;
177177
}
178178

179-
/**
180-
* <inheritdoc />
181-
*/
182-
public override SRGB ToSRGB (ConversionStrategy strategy = ConversionStrategy.ForceLowTruncate|ConversionStrategy.ForceHighStretch)
183-
{
184-
return ToCIEXYZ ().ToSRGB (strategy);
185-
}
186-
187179
#endregion
188180

189181

ColorSharp/src/ColorSpaces/SRGB.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ public override bool IsInsideColorSpace()
9898
*/
9999
public override CIEXYZ ToCIEXYZ (ConversionStrategy strategy=ConversionStrategy.Default)
100100
{
101+
CIEXYZ xyzDS = DataSource as CIEXYZ;
102+
if (xyzDS != null) {
103+
return xyzDS;
104+
}
105+
101106
// Gamma correction
102107
double r = R > 0.04045 ? Math.Pow((R+0.055)/1.055, 2.4) : R/12.92 ;
103108
double g = G > 0.04045 ? Math.Pow((G+0.055)/1.055, 2.4) : G/12.92 ;
@@ -112,14 +117,6 @@ public override CIEXYZ ToCIEXYZ (ConversionStrategy strategy=ConversionStrategy.
112117
);
113118
}
114119

115-
/**
116-
* <inheritdoc />
117-
*/
118-
public override CIExyY ToCIExyY (ConversionStrategy strategy = ConversionStrategy.Default)
119-
{
120-
return ToCIEXYZ ().ToCIExyY ();
121-
}
122-
123120
/**
124121
* <inheritdoc />
125122
*/

ColorSharp/src/LightSpectrums/ALightSpectrum.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,6 @@ MFs [0].DoConvolution (this), MFs [1].DoConvolution (this), MFs [2].DoConvolutio
116116
);
117117
}
118118

119-
/**
120-
* <inheritdoc />
121-
*/
122-
public override CIExyY ToCIExyY (ConversionStrategy strategy = ConversionStrategy.Default)
123-
{
124-
return ToCIEXYZ ().ToCIExyY (strategy);
125-
}
126-
127-
/**
128-
* <inheritdoc />
129-
*/
130-
public override SRGB ToSRGB(ConversionStrategy strategy = ConversionStrategy.ForceLowTruncate|ConversionStrategy.ForceHighStretch)
131-
{
132-
return ToCIEXYZ ().ToSRGB (strategy);
133-
}
134-
135119
#endregion
136120
}
137121
}

0 commit comments

Comments
 (0)