~ubuntu-branches/ubuntu/trusty/pdfmod/trusty

« back to all changes in this revision

Viewing changes to lib/PdfSharp/PdfSharp.Drawing/XColor.cs

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-06-18 03:44:46 UTC
  • Revision ID: james.westby@ubuntu.com-20100618034446-bogifrsscpayp361
Tags: upstream-0.8.3
ImportĀ upstreamĀ versionĀ 0.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#region PDFsharp - A .NET library for processing PDF
 
2
//
 
3
// Authors:
 
4
//   Stefan Lange (mailto:Stefan.Lange@pdfsharp.com)
 
5
//
 
6
// Copyright (c) 2005-2008 empira Software GmbH, Cologne (Germany)
 
7
//
 
8
// http://www.pdfsharp.com
 
9
// http://sourceforge.net/projects/pdfsharp
 
10
//
 
11
// Permission is hereby granted, free of charge, to any person obtaining a
 
12
// copy of this software and associated documentation files (the "Software"),
 
13
// to deal in the Software without restriction, including without limitation
 
14
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
 
15
// and/or sell copies of the Software, and to permit persons to whom the
 
16
// Software is furnished to do so, subject to the following conditions:
 
17
//
 
18
// The above copyright notice and this permission notice shall be included
 
19
// in all copies or substantial portions of the Software.
 
20
//
 
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 
24
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
26
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 
27
// DEALINGS IN THE SOFTWARE.
 
28
#endregion
 
29
 
 
30
using System;
 
31
using System.Diagnostics;
 
32
using System.Globalization;
 
33
using System.ComponentModel;
 
34
#if GDI
 
35
using System.Drawing;
 
36
#endif
 
37
#if WPF
 
38
using System.Windows.Media;
 
39
#endif
 
40
using PdfSharp.Internal;
 
41
 
 
42
namespace PdfSharp.Drawing
 
43
{
 
44
  ///<summary>
 
45
  /// Represents a RGB, CMYK, or gray scale color.
 
46
  /// </summary>
 
47
  [DebuggerDisplay("(A={A}, R={R}, G={G}, B={B} C={C}, M={M}, Y={Y}, K={K})")]
 
48
  public struct XColor
 
49
  {
 
50
    XColor(uint argb)
 
51
    {
 
52
      this.cs = XColorSpace.Rgb;
 
53
      this.a = (byte)((argb >> 24) & 0xff) / 255f;
 
54
      this.r = (byte)((argb >> 16) & 0xff);
 
55
      this.g = (byte)((argb >> 8) & 0xff);
 
56
      this.b = (byte)(argb & 0xff);
 
57
      this.c = 0;
 
58
      this.m = 0;
 
59
      this.y = 0;
 
60
      this.k = 0;
 
61
      this.gs = 0;
 
62
      RgbChanged();
 
63
      cs.GetType(); // Suppress warning
 
64
    }
 
65
 
 
66
    XColor(byte alpha, byte red, byte green, byte blue)
 
67
    {
 
68
      this.cs = XColorSpace.Rgb;
 
69
      this.a = alpha / 255f;
 
70
      this.r = red;
 
71
      this.g = green;
 
72
      this.b = blue;
 
73
      this.c = 0;
 
74
      this.m = 0;
 
75
      this.y = 0;
 
76
      this.k = 0;
 
77
      this.gs = 0;
 
78
      RgbChanged();
 
79
      cs.GetType(); // Suppress warning
 
80
    }
 
81
 
 
82
    XColor(double alpha, double cyan, double magenta, double yellow, double black)
 
83
    {
 
84
      this.cs = XColorSpace.Cmyk;
 
85
      this.a = (float)(alpha > 1 ? 1 : (alpha < 0 ? 0 : alpha));
 
86
      this.c = (float)(cyan > 1 ? 1 : (cyan < 0 ? 0 : cyan));
 
87
      this.m = (float)(magenta > 1 ? 1 : (magenta < 0 ? 0 : magenta));
 
88
      this.y = (float)(yellow > 1 ? 1 : (yellow < 0 ? 0 : yellow));
 
89
      this.k = (float)(black > 1 ? 1 : (black < 0 ? 0 : black));
 
90
      this.r = 0;
 
91
      this.g = 0;
 
92
      this.b = 0;
 
93
      this.gs = 0f;
 
94
      CmykChanged();
 
95
    }
 
96
 
 
97
    XColor(double cyan, double magenta, double yellow, double black)
 
98
      : this(1.0, cyan, magenta, yellow, black)
 
99
    { }
 
100
 
 
101
    XColor(double gray)
 
102
    {
 
103
      this.cs = XColorSpace.GrayScale;
 
104
      if (gray < 0)
 
105
        this.gs = 0;
 
106
      else if (gray > 1)
 
107
        this.gs = 1;
 
108
      this.gs = (float)gray;
 
109
 
 
110
      this.a = 1;
 
111
      this.r = 0;
 
112
      this.g = 0;
 
113
      this.b = 0;
 
114
      this.c = 0;
 
115
      this.m = 0;
 
116
      this.y = 0;
 
117
      this.k = 0;
 
118
      GrayChanged();
 
119
    }
 
120
 
 
121
#if GDI
 
122
    XColor(System.Drawing.Color color)
 
123
      : this(color.A, color.R, color.G, color.B)
 
124
    { }
 
125
#endif
 
126
 
 
127
#if WPF
 
128
    XColor(System.Windows.Media.Color color)
 
129
      : this(color.A, color.R, color.G, color.B)
 
130
    { }
 
131
#endif
 
132
 
 
133
#if GDI
 
134
    XColor(KnownColor knownColor)
 
135
      : this(System.Drawing.Color.FromKnownColor((System.Drawing.KnownColor)knownColor))
 
136
    { }
 
137
#endif
 
138
 
 
139
    internal XColor(XKnownColor knownColor)
 
140
      : this(XKnownColorTable.KnownColorToArgb(knownColor))
 
141
    { }
 
142
 
 
143
    /// <summary>
 
144
    /// Creates an XColor structure from a 32-bit ARGB value.
 
145
    /// </summary>
 
146
    public static XColor FromArgb(int argb)
 
147
    {
 
148
      return new XColor((byte)(argb >> 24), (byte)(argb >> 16), (byte)(argb >> 8), (byte)(argb));
 
149
    }
 
150
 
 
151
    /// <summary>
 
152
    /// Creates an XColor structure from a 32-bit ARGB value.
 
153
    /// </summary>
 
154
    public static XColor FromArgb(uint argb)
 
155
    {
 
156
      return new XColor((byte)(argb >> 24), (byte)(argb >> 16), (byte)(argb >> 8), (byte)(argb));
 
157
    }
 
158
 
 
159
    // from System.Drawing.Color
 
160
    //public static XColor FromArgb(int alpha, Color baseColor);
 
161
    //public static XColor FromArgb(int red, int green, int blue);
 
162
    //public static XColor FromArgb(int alpha, int red, int green, int blue);
 
163
    //public static XColor FromKnownColor(KnownColor color);
 
164
    //public static XColor FromName(string name);
 
165
 
 
166
    /// <summary>
 
167
    /// Creates an XColor structure from the specified 8-bit color values (red, green, and blue).
 
168
    /// The alpha value is implicitly 255 (fully opaque).
 
169
    /// </summary>
 
170
    public static XColor FromArgb(int red, int green, int blue)
 
171
    {
 
172
      CheckByte(red, "red");
 
173
      CheckByte(green, "green");
 
174
      CheckByte(blue, "blue");
 
175
      return new XColor((byte)255, (byte)red, (byte)green, (byte)blue);
 
176
    }
 
177
 
 
178
    /// <summary>
 
179
    /// Creates an XColor structure from the four ARGB component (alpha, red, green, and blue) values.
 
180
    /// </summary>
 
181
    public static XColor FromArgb(int alpha, int red, int green, int blue)
 
182
    {
 
183
      CheckByte(alpha, "alpha");
 
184
      CheckByte(red, "red");
 
185
      CheckByte(green, "green");
 
186
      CheckByte(blue, "blue");
 
187
      return new XColor((byte)alpha, (byte)red, (byte)green, (byte)blue);
 
188
    }
 
189
 
 
190
#if GDI
 
191
    /// <summary>
 
192
    /// Creates an XColor structure from the specified System.Drawing.Color.
 
193
    /// </summary>
 
194
    public static XColor FromArgb(System.Drawing.Color color)
 
195
    {
 
196
      return new XColor(color);
 
197
    }
 
198
#endif
 
199
 
 
200
#if WPF
 
201
    /// <summary>
 
202
    /// Creates an XColor structure from the specified System.Drawing.Color.
 
203
    /// </summary>
 
204
    public static XColor FromArgb(System.Windows.Media.Color color)
 
205
    {
 
206
      return new XColor(color);
 
207
    }
 
208
#endif
 
209
 
 
210
    /// <summary>
 
211
    /// Creates an XColor structure from the specified alpha value and color.
 
212
    /// </summary>
 
213
    public static XColor FromArgb(int alpha, XColor color)
 
214
    {
 
215
      color.A = ((byte)alpha) / 255.0;
 
216
      return color;
 
217
    }
 
218
 
 
219
#if GDI
 
220
    /// <summary>
 
221
    /// Creates an XColor structure from the specified alpha value and color.
 
222
    /// </summary>
 
223
    public static XColor FromArgb(int alpha, System.Drawing.Color color)
 
224
    {
 
225
      return new XColor(alpha, color.R, color.G, color.B);
 
226
    }
 
227
#endif
 
228
 
 
229
#if WPF
 
230
    /// <summary>
 
231
    /// Creates an XColor structure from the specified alpha value and color.
 
232
    /// </summary>
 
233
    public static XColor FromArgb(int alpha, System.Windows.Media.Color color)
 
234
    {
 
235
      return new XColor(alpha, color.R, color.G, color.B);
 
236
    }
 
237
#endif
 
238
 
 
239
    /// <summary>
 
240
    /// Creates an XColor structure from the specified CMYK values.
 
241
    /// </summary>
 
242
    public static XColor FromCmyk(double cyan, double magenta, double yellow, double black)
 
243
    {
 
244
      return new XColor(cyan, magenta, yellow, black);
 
245
    }
 
246
 
 
247
    /// <summary>
 
248
    /// Creates an XColor structure from the specified CMYK values.
 
249
    /// </summary>
 
250
    public static XColor FromCmyk(double alpha, double cyan, double magenta, double yellow, double black)
 
251
    {
 
252
      return new XColor(alpha, cyan, magenta, yellow, black);
 
253
    }
 
254
 
 
255
    /// <summary>
 
256
    /// Creates an XColor structure from the specified gray value.
 
257
    /// </summary>
 
258
    public static XColor FromGrayScale(double grayScale)
 
259
    {
 
260
      return new XColor(grayScale);
 
261
    }
 
262
 
 
263
    /// <summary>
 
264
    /// Creates an XColor from the specified pre-defined color.
 
265
    /// </summary>
 
266
    public static XColor FromKnownColor(XKnownColor color)
 
267
    {
 
268
      return new XColor(color);
 
269
    }
 
270
 
 
271
#if GDI
 
272
    /// <summary>
 
273
    /// Creates an XColor from the specified pre-defined color.
 
274
    /// </summary>
 
275
    public static XColor FromKnownColor(KnownColor color)
 
276
    {
 
277
      return new XColor(color);
 
278
    }
 
279
#endif
 
280
 
 
281
    /// <summary>
 
282
    /// Creates an XColor from the specified name of a pre-defined color.
 
283
    /// </summary>
 
284
    public static XColor FromName(string name)
 
285
    {
 
286
#if GDI
 
287
      // The implementation in System.Drawing.dll is interesting. It uses a ColorConverter
 
288
      // with hash tables, locking mechanisms etc. I'm not sure what problems that solves.
 
289
      // So I don't use the source, but the reflection.
 
290
      try
 
291
      {
 
292
        return new XColor((KnownColor)Enum.Parse(typeof(KnownColor), name, true));
 
293
      }
 
294
      catch { }
 
295
#endif
 
296
      return XColor.Empty;
 
297
    }
 
298
 
 
299
    /// <summary>
 
300
    /// Gets or sets the color space to be used for PDF generation.
 
301
    /// </summary>
 
302
    public XColorSpace ColorSpace
 
303
    {
 
304
      get { return this.cs; }
 
305
      set
 
306
      {
 
307
        if (!Enum.IsDefined(typeof(XColorSpace), value))
 
308
          throw new InvalidEnumArgumentException("value", (int)value, typeof(XColorSpace));
 
309
        this.cs = value;
 
310
      }
 
311
    }
 
312
 
 
313
    /// <summary>
 
314
    /// Indicates whether this XColor structure is uninitialized.
 
315
    /// </summary>
 
316
    public bool IsEmpty
 
317
    {
 
318
      get { return this == XColor.Empty; }
 
319
    }
 
320
 
 
321
#if GDI
 
322
#if UseGdiObjects
 
323
    /// <summary>
 
324
    /// Implicit conversion from Color to XColor
 
325
    /// </summary>
 
326
    public static implicit operator XColor(Color color)
 
327
    {
 
328
      return new XColor(color);
 
329
    }
 
330
#endif
 
331
 
 
332
    ///<summary>
 
333
    /// Creates a System.Drawing.Color object from this color.
 
334
    /// </summary>
 
335
    public System.Drawing.Color ToGdiColor()
 
336
    {
 
337
      return System.Drawing.Color.FromArgb((int)(this.a * 255), this.r, this.g, this.b);
 
338
    }
 
339
#endif
 
340
 
 
341
#if WPF
 
342
    ///<summary>
 
343
    /// Creates a System.Windows.Media.Color object from this color.
 
344
    /// </summary>
 
345
    public System.Windows.Media.Color ToWpfColor()
 
346
    {
 
347
      return System.Windows.Media.Color.FromArgb((byte)(this.a * 255), this.r, this.g, this.b);
 
348
    }
 
349
#endif
 
350
 
 
351
    /// <summary>
 
352
    /// Determines whether the specified object is a Color structure and is equivalent to this 
 
353
    /// Color structure.
 
354
    /// </summary>
 
355
    public override bool Equals(object obj)
 
356
    {
 
357
      if (obj is XColor)
 
358
      {
 
359
        XColor color = (XColor)obj;
 
360
        if (this.r == color.r && this.g == color.g && this.b == color.b &&
 
361
          this.c == color.c && this.m == color.m && this.y == color.y && this.k == color.k &&
 
362
          this.gs == color.gs)
 
363
        {
 
364
          return this.a == color.a;
 
365
        }
 
366
      }
 
367
      return false;
 
368
    }
 
369
 
 
370
    /// <summary>
 
371
    /// Returns the hash code for this instance.
 
372
    /// </summary>
 
373
    public override int GetHashCode()
 
374
    {
 
375
      return ((byte)(this.a * 255)) ^ this.r ^ this.g ^ this.b;
 
376
      // ^ *(int*)&this.c ^ *(int*)&this.m ^ *(int*)&this.y ^ *(int*)&this.k;
 
377
    }
 
378
 
 
379
    /// <summary>
 
380
    /// Determines whether two colors are equal.
 
381
    /// </summary>
 
382
    public static bool operator ==(XColor left, XColor right)
 
383
    {
 
384
      if (left.r == right.r && left.g == right.g && left.b == right.b &&
 
385
          left.c == right.c && left.m == right.m && left.y == right.y && left.k == right.k &&
 
386
          left.gs == right.gs)
 
387
      {
 
388
        return left.a == right.a;
 
389
      }
 
390
      return false;
 
391
    }
 
392
 
 
393
    /// <summary>
 
394
    /// Determines whether two colors are not equal.
 
395
    /// </summary>
 
396
    public static bool operator !=(XColor left, XColor right)
 
397
    {
 
398
      return !(left == right);
 
399
    }
 
400
 
 
401
    /// <summary>
 
402
    /// Gets a value indicating whether this color is a known color.
 
403
    /// </summary>
 
404
    public bool IsKnownColor
 
405
    {
 
406
      get { return XKnownColorTable.IsKnownColor(Argb); }
 
407
    }
 
408
 
 
409
    //public bool IsNamedColor { get; }
 
410
    //public bool IsSystemColor { get; }
 
411
 
 
412
    /// <summary>
 
413
    /// Gets the hue-saturation-brightness (HSB) hue value, in degrees, for this color.
 
414
    /// </summary>
 
415
    /// <returns>The hue, in degrees, of this color. The hue is measured in degrees, ranging from 0 through 360, in HSB color space.</returns>
 
416
    public double GetHue()
 
417
    {
 
418
      if ((this.r == this.g) && (this.g == this.b))
 
419
        return 0;
 
420
 
 
421
      double value1 = this.r / 255.0;
 
422
      double value2 = this.g / 255.0;
 
423
      double value3 = this.b / 255.0;
 
424
      double value7 = 0;
 
425
      double value4 = value1;
 
426
      double value5 = value1;
 
427
      if (value2 > value4)
 
428
        value4 = value2;
 
429
 
 
430
      if (value3 > value4)
 
431
        value4 = value3;
 
432
 
 
433
      if (value2 < value5)
 
434
        value5 = value2;
 
435
 
 
436
      if (value3 < value5)
 
437
        value5 = value3;
 
438
 
 
439
      double value6 = value4 - value5;
 
440
      if (value1 == value4)
 
441
        value7 = (value2 - value3) / value6;
 
442
      else if (value2 == value4)
 
443
        value7 = 2f + ((value3 - value1) / value6);
 
444
      else if (value3 == value4)
 
445
        value7 = 4f + ((value1 - value2) / value6);
 
446
 
 
447
      value7 *= 60;
 
448
      if (value7 < 0)
 
449
        value7 += 360;
 
450
      return value7;
 
451
    }
 
452
 
 
453
    /// <summary>
 
454
    /// Gets the hue-saturation-brightness (HSB) saturation value for this color.
 
455
    /// </summary>
 
456
    /// <returns>The saturation of this color. The saturation ranges from 0 through 1, where 0 is grayscale and 1 is the most saturated.</returns>
 
457
    public double GetSaturation()
 
458
    {
 
459
      double value1 = this.r / 255.0;
 
460
      double value2 = this.g / 255.0;
 
461
      double value3 = this.b / 255.0;
 
462
      double value7 = 0;
 
463
      double value4 = value1;
 
464
      double value5 = value1;
 
465
      if (value2 > value4)
 
466
        value4 = value2;
 
467
 
 
468
      if (value3 > value4)
 
469
        value4 = value3;
 
470
 
 
471
      if (value2 < value5)
 
472
        value5 = value2;
 
473
 
 
474
      if (value3 < value5)
 
475
        value5 = value3;
 
476
 
 
477
      if (value4 == value5)
 
478
        return value7;
 
479
 
 
480
      double value6 = (value4 + value5) / 2;
 
481
      if (value6 <= 0.5)
 
482
        return (value4 - value5) / (value4 + value5);
 
483
      return (value4 - value5) / ((2f - value4) - value5);
 
484
    }
 
485
 
 
486
    /// <summary>
 
487
    /// Gets the hue-saturation-brightness (HSB) brightness value for this color.
 
488
    /// </summary>
 
489
    /// <returns>The brightness of this color. The brightness ranges from 0 through 1, where 0 represents black and 1 represents white.</returns>
 
490
    public double GetBrightness()
 
491
    {
 
492
      double value1 = this.r / 255.0;
 
493
      double value2 = this.g / 255.0;
 
494
      double value3 = this.b / 255.0;
 
495
      double value4 = value1;
 
496
      double value5 = value1;
 
497
      if (value2 > value4)
 
498
        value4 = value2;
 
499
 
 
500
      if (value3 > value4)
 
501
        value4 = value3;
 
502
 
 
503
      if (value2 < value5)
 
504
        value5 = value2;
 
505
 
 
506
      if (value3 < value5)
 
507
        value5 = value3;
 
508
 
 
509
      return (value4 + value5) / 2;
 
510
    }
 
511
 
 
512
    ///<summary>
 
513
    /// One of the RGB values changed; recalculate other color representations.
 
514
    /// </summary>
 
515
    void RgbChanged()
 
516
    {
 
517
      this.cs = XColorSpace.Rgb;
 
518
      int c = 255 - this.r;
 
519
      int m = 255 - this.g;
 
520
      int y = 255 - this.b;
 
521
      int k = Math.Min(c, Math.Min(m, y));
 
522
      if (k == 255)
 
523
        this.c = this.m = this.y = 0;
 
524
      else
 
525
      {
 
526
        float black = 255f - k;
 
527
        this.c = (c - k) / black;
 
528
        this.m = (m - k) / black;
 
529
        this.y = (y - k) / black;
 
530
      }
 
531
      this.k = this.gs = k / 255f;
 
532
    }
 
533
 
 
534
    ///<summary>
 
535
    /// One of the CMYK values changed; recalculate other color representations.
 
536
    /// </summary>
 
537
    void CmykChanged()
 
538
    {
 
539
      this.cs = XColorSpace.Cmyk;
 
540
      float black = this.k * 255;
 
541
      float factor = 255f - black;
 
542
      this.r = (byte)(255 - Math.Min(255f, this.c * factor + black));
 
543
      this.g = (byte)(255 - Math.Min(255f, this.m * factor + black));
 
544
      this.b = (byte)(255 - Math.Min(255f, this.y * factor + black));
 
545
      this.gs = (float)(1 - Math.Min(1.0, 0.3f * this.c + 0.59f * this.m + 0.11 * this.y + this.k));
 
546
    }
 
547
 
 
548
    ///<summary>
 
549
    /// The gray scale value changed; recalculate other color representations.
 
550
    /// </summary>
 
551
    void GrayChanged()
 
552
    {
 
553
      this.cs = XColorSpace.GrayScale;
 
554
      this.r = (byte)(this.gs * 255);
 
555
      this.g = (byte)(this.gs * 255);
 
556
      this.b = (byte)(this.gs * 255);
 
557
      this.c = 0;
 
558
      this.m = 0;
 
559
      this.y = 0;
 
560
      this.k = 1 - this.gs;
 
561
    }
 
562
 
 
563
    // Properties
 
564
 
 
565
    /// <summary>
 
566
    /// Gets or sets the alpha value the specifies the transparency. 
 
567
    /// The value is in the range from 1 (opaque) to 0 (completely transparent).
 
568
    /// </summary>
 
569
    public double A
 
570
    {
 
571
      get { return this.a; }
 
572
      set
 
573
      {
 
574
        if (value < 0)
 
575
          this.a = 0;
 
576
        else if (value > 1)
 
577
          this.a = 1;
 
578
        else
 
579
          this.a = (float)value;
 
580
      }
 
581
    }
 
582
 
 
583
    /// <summary>
 
584
    /// Gets or sets the red value.
 
585
    /// </summary>
 
586
    public byte R
 
587
    {
 
588
      get { return this.r; }
 
589
      set { this.r = value; RgbChanged(); }
 
590
    }
 
591
 
 
592
    /// <summary>
 
593
    /// Gets or sets the green value.
 
594
    /// </summary>
 
595
    public byte G
 
596
    {
 
597
      get { return this.g; }
 
598
      set { this.g = value; RgbChanged(); }
 
599
    }
 
600
 
 
601
    /// <summary>
 
602
    /// Gets or sets the blue value.
 
603
    /// </summary>
 
604
    public byte B
 
605
    {
 
606
      get { return this.b; }
 
607
      set { this.b = value; RgbChanged(); }
 
608
    }
 
609
 
 
610
    /// <summary>
 
611
    /// Gets the RGB part value of the color. Internal helper function.
 
612
    /// </summary>
 
613
    internal uint Rgb
 
614
    {
 
615
      get { return ((uint)this.r << 16) | ((uint)this.g << 8) | (uint)this.b; }
 
616
    }
 
617
 
 
618
    /// <summary>
 
619
    /// Gets the ARGB part value of the color. Internal helper function.
 
620
    /// </summary>
 
621
    internal uint Argb
 
622
    {
 
623
      get { return ((uint)(this.a * 255) << 24) | ((uint)this.r << 16) | ((uint)this.g << 8) | (uint)this.b; }
 
624
    }
 
625
 
 
626
    /// <summary>
 
627
    /// Gets or sets the cyan value.
 
628
    /// </summary>
 
629
    public double C
 
630
    {
 
631
      get { return this.c; }
 
632
      set
 
633
      {
 
634
        if (value < 0)
 
635
          this.c = 0;
 
636
        else if (value > 1)
 
637
          this.c = 1;
 
638
        else
 
639
          this.c = (float)value;
 
640
        CmykChanged();
 
641
      }
 
642
    }
 
643
 
 
644
    /// <summary>
 
645
    /// Gets or sets the magenta value.
 
646
    /// </summary>
 
647
    public double M
 
648
    {
 
649
      get { return this.m; }
 
650
      set
 
651
      {
 
652
        if (value < 0)
 
653
          this.m = 0;
 
654
        else if (value > 1)
 
655
          this.m = 1;
 
656
        else
 
657
          this.m = (float)value;
 
658
        CmykChanged();
 
659
      }
 
660
    }
 
661
 
 
662
    /// <summary>
 
663
    /// Gets or sets the yellow value.
 
664
    /// </summary>
 
665
    public double Y
 
666
    {
 
667
      get { return this.y; }
 
668
      set
 
669
      {
 
670
        if (value < 0)
 
671
          this.y = 0;
 
672
        else if (value > 1)
 
673
          this.y = 1;
 
674
        else
 
675
          this.y = (float)value;
 
676
        CmykChanged();
 
677
      }
 
678
    }
 
679
 
 
680
    /// <summary>
 
681
    /// Gets or sets the black (or key) value.
 
682
    /// </summary>
 
683
    public double K
 
684
    {
 
685
      get { return this.k; }
 
686
      set
 
687
      {
 
688
        if (value < 0)
 
689
          this.k = 0;
 
690
        else if (value > 1)
 
691
          this.k = 1;
 
692
        else
 
693
          this.k = (float)value;
 
694
        CmykChanged();
 
695
      }
 
696
    }
 
697
 
 
698
    /// <summary>
 
699
    /// Gets or sets the gray scale value.
 
700
    /// </summary>
 
701
    public double GS
 
702
    {
 
703
      get { return this.gs; }
 
704
      set
 
705
      {
 
706
        if (value < 0)
 
707
          this.gs = 0;
 
708
        else if (value > 1)
 
709
          this.gs = 1;
 
710
        else
 
711
          this.gs = (float)value;
 
712
        GrayChanged();
 
713
      }
 
714
    }
 
715
 
 
716
    /// <summary>
 
717
    /// Represents the null color.
 
718
    /// </summary>
 
719
    public static XColor Empty;
 
720
 
 
721
    ///<summary>
 
722
    /// Special property for XmlSerializer only.
 
723
    /// </summary>
 
724
    public string RgbCmykG
 
725
    {
 
726
      get
 
727
      {
 
728
        return String.Format(CultureInfo.InvariantCulture,
 
729
          "{0};{1};{2};{3};{4};{5};{6};{7};{8}", this.r, this.g, this.b, this.c, this.m, this.y, this.k, this.gs, this.a);
 
730
      }
 
731
      set
 
732
      {
 
733
        string[] values = value.Split(';');
 
734
        this.r = byte.Parse(values[0], CultureInfo.InvariantCulture);
 
735
        this.g = byte.Parse(values[1], CultureInfo.InvariantCulture);
 
736
        this.b = byte.Parse(values[2], CultureInfo.InvariantCulture);
 
737
        this.c = float.Parse(values[3], CultureInfo.InvariantCulture);
 
738
        this.m = float.Parse(values[4], CultureInfo.InvariantCulture);
 
739
        this.y = float.Parse(values[5], CultureInfo.InvariantCulture);
 
740
        this.k = float.Parse(values[6], CultureInfo.InvariantCulture);
 
741
        this.gs = float.Parse(values[7], CultureInfo.InvariantCulture);
 
742
        this.a = float.Parse(values[8], CultureInfo.InvariantCulture);
 
743
      }
 
744
    }
 
745
 
 
746
    static void CheckByte(int val, string name)
 
747
    {
 
748
      if (val < 0 || val > 0xFF)
 
749
        throw new ArgumentException(PSSR.InvalidValue(val, name, 0, 255));
 
750
    }
 
751
 
 
752
    private XColorSpace cs;
 
753
 
 
754
    private float a;  // alpha
 
755
 
 
756
    private byte r;   // \
 
757
    private byte g;   // |--- RGB
 
758
    private byte b;   // /
 
759
 
 
760
    private float c;  // \
 
761
    private float m;  // |--- CMYK
 
762
    private float y;  // |
 
763
    private float k;  // /
 
764
 
 
765
    private float gs; // >--- gray scale
 
766
  }
 
767
}
 
 
b'\\ No newline at end of file'