Esempio n. 1
0
        /**
         * <summary>Gets the color corresponding to the specified components.</summary>
         * <param name="components">Color components to convert.</param>
         */
        public static DeviceColor Get(PdfArray components)
        {
            if (components == null)
            {
                return(null);
            }
            if (components.Wrapper is DeviceColor wrapped)
            {
                return(wrapped);
            }

            switch (components.Count)
            {
            case 1:
                return(DeviceGrayColor.Get(components));

            case 3:
                return(DeviceRGBColor.Get(components));

            case 4:
                return(DeviceCMYKColor.Get(components));

            default:
                return(null);
            }
        }
Esempio n. 2
0
        public override SKColor GetColor(Color color, double?alpha = null)
        {
            DeviceCMYKColor spaceColor = (DeviceCMYKColor)color;

            /*
             * NOTE: This convertion algorithm was from Apache FOP.
             */
            //FIXME: verify whether this algorithm is effective (limit checking seems quite ugly to me!).
            //float keyCorrection = (float)spaceColor.K;// / 2.5f;
            //int r = (int)((1 - Math.Min(1, spaceColor.C + keyCorrection)) * 255); if (r < 0) { r = 0; }
            //int g = (int)((1 - Math.Min(1, spaceColor.M + keyCorrection)) * 255); if (g < 0) { g = 0; }
            //int b = (int)((1 - Math.Min(1, spaceColor.Y + keyCorrection)) * 255); if (b < 0) { b = 0; }
            var r       = (int)(255 * (1 - spaceColor.C) * (1 - spaceColor.K));
            var g       = (int)(255 * (1 - spaceColor.M) * (1 - spaceColor.K));
            var b       = (int)(255 * (1 - spaceColor.Y) * (1 - spaceColor.K));
            var skColor = new SKColor((byte)r, (byte)g, (byte)b);

            if (alpha != null)
            {
                skColor = skColor.WithAlpha((byte)(alpha.Value * 255));
            }
            return(skColor);
        }