@@ -71,37 +71,36 @@ public ColorPair( Dictionary< string, object > dictionary ): this()
7171 }
7272
7373 {
74- if ( dictionary . TryGetValue ( "color" , out object o ) == false || ! ( o is Dictionary < string , object > dict ) )
74+ if ( dictionary . TryGetValue ( "color" , out object o ) && o is Dictionary < string , object > dict )
7575 {
76- throw new ArgumentException ( ) ;
76+ this . Color = this . ColorFromDictionary ( dict ) ;
7777 }
78-
79- this . Color = this . ColorFromDictionary ( dict ) ;
8078 }
8179
8280 {
83- if ( dictionary . TryGetValue ( "variant" , out object o ) == false || ! ( o is Dictionary < string , object > dict ) )
81+ if ( dictionary . TryGetValue ( "variant" , out object o ) && o is Dictionary < string , object > dict )
8482 {
85- throw new ArgumentException ( ) ;
83+ this . Variant = this . ColorFromDictionary ( dict ) ;
8684 }
87-
88- this . Variant = this . ColorFromDictionary ( dict ) ;
8985 }
9086
9187 {
92- if ( dictionary . TryGetValue ( "lightnesses" , out object o ) == false || ! ( o is List < Dictionary < string , object > > list ) )
93- {
94- throw new ArgumentException ( ) ;
95- }
96-
97- foreach ( Dictionary < string , object > l in list )
88+ if ( dictionary . TryGetValue ( "lightnesses" , out object o ) && o is List < object > list )
9889 {
99- try
90+ foreach ( object value in list )
10091 {
101- this . Lightnesses . Add ( new LightnessPair ( l ) ) ;
92+ if ( ! ( value is Dictionary < string , object > l ) )
93+ {
94+ continue ;
95+ }
96+
97+ try
98+ {
99+ this . Lightnesses . Add ( new LightnessPair ( l ) ) ;
100+ }
101+ catch
102+ { }
102103 }
103- catch
104- { }
105104 }
106105 }
107106 }
@@ -133,14 +132,14 @@ private Dictionary< string, object > ColorToDictionary( SolidColorBrush color )
133132 return null ;
134133 }
135134
136- ColorExtensions . HSLComponents hsl = color . Color . GetHSL ( ) ;
135+ ColorExtensions . RGBComponents rgb = color . Color . GetRGB ( ) ;
137136
138137 return new Dictionary < string , object >
139138 {
140- { "h " , hsl . Hue } ,
141- { "s " , hsl . Saturation } ,
142- { "l " , hsl . Lightness } ,
143- { "a" , hsl . Alpha }
139+ { "r " , rgb . Red } ,
140+ { "g " , rgb . Green } ,
141+ { "b " , rgb . Blue } ,
142+ { "a" , rgb . Alpha }
144143 } ;
145144 }
146145
@@ -151,36 +150,36 @@ private SolidColorBrush ColorFromDictionary( Dictionary< string, object > dictio
151150 return null ;
152151 }
153152
154- double h ;
155- double s ;
156- double l ;
153+ double r ;
154+ double g ;
155+ double b ;
157156 double a ;
158157
159158 {
160- if ( dictionary . TryGetValue ( "h " , out object o ) == false || ! ( o is double d ) )
159+ if ( dictionary . TryGetValue ( "r " , out object o ) == false || ! ( o is double d ) )
161160 {
162161 throw new ArgumentException ( ) ;
163162 }
164163
165- h = d ;
164+ r = d ;
166165 }
167166
168167 {
169- if ( dictionary . TryGetValue ( "s " , out object o ) == false || ! ( o is double d ) )
168+ if ( dictionary . TryGetValue ( "g " , out object o ) == false || ! ( o is double d ) )
170169 {
171170 throw new ArgumentException ( ) ;
172171 }
173172
174- s = d ;
173+ g = d ;
175174 }
176175
177176 {
178- if ( dictionary . TryGetValue ( "l " , out object o ) == false || ! ( o is double d ) )
177+ if ( dictionary . TryGetValue ( "b " , out object o ) == false || ! ( o is double d ) )
179178 {
180179 throw new ArgumentException ( ) ;
181180 }
182181
183- l = d ;
182+ b = d ;
184183 }
185184
186185 {
@@ -192,7 +191,16 @@ private SolidColorBrush ColorFromDictionary( Dictionary< string, object > dictio
192191 a = d ;
193192 }
194193
195- return new SolidColorBrush ( ColorExtensions . FromHSL ( h , s , l , a ) ) ;
194+ return new SolidColorBrush
195+ (
196+ System . Windows . Media . Color . FromArgb
197+ (
198+ ( byte ) Math . Round ( a * 255 ) ,
199+ ( byte ) Math . Round ( r * 255 ) ,
200+ ( byte ) Math . Round ( g * 255 ) ,
201+ ( byte ) Math . Round ( b * 255 )
202+ )
203+ ) ;
196204 }
197205 }
198206}
0 commit comments