예제 #1
0
            /**
             * <inheritdoc />
             */
            public override SRGB ToSRGB(ToSmallSpaceStrategy strategy = ToSmallSpaceStrategy.ForceLowTruncate | ToSmallSpaceStrategy.ForceHighStretch)
            {
                SRGB srgbDS = DataSource as SRGB;

                if (srgbDS != null)
                {
                    return(srgbDS);
                }

                // Linear transformation
                double r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
                double g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
                double b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;

                // Gamma correction
                r = r > 0.0031308 ? 1.055 * Math.Pow(r, 1 / 2.4) - 0.055 : 12.92 * r;
                g = g > 0.0031308 ? 1.055 * Math.Pow(g, 1 / 2.4) - 0.055 : 12.92 * g;
                b = b > 0.0031308 ? 1.055 * Math.Pow(b, 1 / 2.4) - 0.055 : 12.92 * b;

                if ((strategy & ToSmallSpaceStrategy.ForceLowStretch) != 0)
                {
                    double minChannelValue = Math.Min(r, Math.Min(g, b));

                    if (minChannelValue < 0.0)
                    {
                        r -= minChannelValue;
                        g -= minChannelValue;
                        b -= minChannelValue;
                    }
                }
                else if ((strategy & ToSmallSpaceStrategy.ForceLowTruncate) != 0)
                {
                    r = Math.Max(0.0, r);
                    g = Math.Max(0.0, g);
                    b = Math.Max(0.0, b);
                }

                if ((strategy & ToSmallSpaceStrategy.ForceHighStretch) != 0)
                {
                    double maxChannelValue = Math.Max(r, Math.Max(g, b));

                    if (maxChannelValue > 1.0)
                    {
                        r = r / maxChannelValue;
                        g = g / maxChannelValue;
                        b = b / maxChannelValue;
                    }
                }
                else if ((strategy & ToSmallSpaceStrategy.ForceHighTruncate) != 0)
                {
                    r = Math.Min(1.0, r);
                    g = Math.Min(1.0, g);
                    b = Math.Min(1.0, b);
                }

                return(new SRGB(r, g, b, DataSource ?? this));
            }
예제 #2
0
            /**
            * <inheritdoc />
            */
            public override SRGB ToSRGB(ToSmallSpaceStrategy strategy=ToSmallSpaceStrategy.ForceLowTruncate|ToSmallSpaceStrategy.ForceHighStretch)
            {
                SRGB srgbDS = DataSource as SRGB;
                if (srgbDS != null) {
                    return srgbDS;
                }

                // Linear transformation
                double r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
                double g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
                double b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;

                // Gamma correction
                r = r > 0.0031308 ? 1.055 * Math.Pow(r, 1 / 2.4) - 0.055 : 12.92 * r;
                g = g > 0.0031308 ? 1.055 * Math.Pow(g, 1 / 2.4) - 0.055 : 12.92 * g;
                b = b > 0.0031308 ? 1.055 * Math.Pow(b, 1 / 2.4) - 0.055 : 12.92 * b;

                if ((strategy & ToSmallSpaceStrategy.ForceLowStretch) != 0) {
                    double minChannelValue = Math.Min (r, Math.Min (g, b));

                    if (minChannelValue < 0.0) {
                        r -= minChannelValue;
                        g -= minChannelValue;
                        b -= minChannelValue;
                    }
                } else if ((strategy & ToSmallSpaceStrategy.ForceLowTruncate) != 0) {
                    r = Math.Max (0.0, r);
                    g = Math.Max (0.0, g);
                    b = Math.Max (0.0, b);
                }

                if ((strategy & ToSmallSpaceStrategy.ForceHighStretch) != 0) {
                    double maxChannelValue = Math.Max (r, Math.Max (g, b));

                    if (maxChannelValue > 1.0) {
                        r = r / maxChannelValue;
                        g = g / maxChannelValue;
                        b = b / maxChannelValue;
                    }
                } else if ((strategy & ToSmallSpaceStrategy.ForceHighTruncate) != 0) {
                    r = Math.Min (1.0, r);
                    g = Math.Min (1.0, g);
                    b = Math.Min (1.0, b);
                }

                return new SRGB(r, g, b, DataSource ?? this);
            }
예제 #3
0
 /**
  * <summary>Converts the color sample to an HP's and Microsoft's 1996 sRGB sample.</summary>
  */
 public virtual SRGB ToSRGB(ToSmallSpaceStrategy strategy = ToSmallSpaceStrategy.ForceLowTruncate | ToSmallSpaceStrategy.ForceHighStretch)
 {
     return((DataSource as SRGB) ?? ToCIEXYZ().ToSRGB(strategy));
 }
예제 #4
0
 /**
  * <inheritdoc />
  */
 public override SRGB ToSRGB(ToSmallSpaceStrategy strategy = ToSmallSpaceStrategy.Default)
 {
     return(this);
 }
예제 #5
0
 /**
  * <inheritdoc />
  */
 public override SRGB ToSRGB(ToSmallSpaceStrategy strategy = ToSmallSpaceStrategy.Default)
 {
     return this;
 }