예제 #1
0
        public static int DXFColor2Index(DXFColor _color)
        {
            if (DXFColor.EqualRGB(_color, new DXFColor(0f, 1f), 0.05f))
            {
                return(7);
            }

            for (int i = 0; i < 10; i++)
            {
                if (DXFColor.EqualRGB(_color, DXFColor.IndexColors_FirstTen[i], 0.05f))
                {
                    return(i);
                }
            }
            for (int i = 0; i < 6; i++)
            {
                if (DXFColor.EqualRGB(_color, DXFColor.IndexColors_LastSix[i], 0.05f))
                {
                    return(250 + i);
                }
            }
            for (int i = 10; i < 250; i++)
            {
                if (DXFColor.EqualRGB(_color, DXFColor.IndexColors_10_249[i - 10], 0.05f))
                {
                    return(i);
                }
            }

            return(7); // black
        }
예제 #2
0
        public static int DXFColor2TrueColor(DXFColor _color)
        {
            int red   = (int)(_color.r * 255);
            int green = (int)(_color.g * 255);
            int blue  = (int)(_color.b * 255);
            int tc    = (195 << 24) + (red << 16) + (green << 8) + blue;

            return(tc);
        }
예제 #3
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // ============================================= METHOD OVERRIDES ========================================= //
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public override bool Equals(object obj)
        {
            DXFColor col = obj as DXFColor;

            if (col == null)
            {
                return(false);
            }

            return((Math.Abs(this.R - col.R) < DXFColor.COMP_TOLERANCE) &&
                   (Math.Abs(this.G - col.G) < DXFColor.COMP_TOLERANCE) &&
                   (Math.Abs(this.B - col.B) < DXFColor.COMP_TOLERANCE) &&
                   (Math.Abs(this.A - col.A) < DXFColor.COMP_TOLERANCE));
        }
예제 #4
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // ========================================== STATIC CONSTRUCTOR ========================================== //
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        static DXFColor()
        {
            IndexColors_10_249 = new DXFColor[240];
            for (int i = 10; i < 250; i++)
            {
                int iHue        = ((i / 10) - 1) * DXFColor.HueStep; // 0 - 345
                int iSaturation = DXFColor.Saturation[i % 10];       // 0 - 100
                int iLuminance  = DXFColor.Luminance[i % 10];        // 0 - 100

                float fHue        = (float)iHue / 360f;              // 0.0416 - 1.0
                float fSaturation = (float)iSaturation / 100f;       // 0.0 - 1.0
                float fLuminance  = (float)iLuminance / 100f;        // 0.0 - 1.0

                float r, g, b;
                HLS2RGB(fHue, fSaturation, fLuminance, out r, out g, out b);

                IndexColors_10_249[i - 10] = new DXFColor(r, g, b, 1f);
            }
        }
예제 #5
0
        public static bool EqualRGB(DXFColor _c1, DXFColor _c2, float _tolerance)
        {
            if ((object)_c1 == null && (object)_c2 != null)
            {
                return(false);
            }
            if ((object)_c1 != null && (object)_c2 == null)
            {
                return(false);
            }
            if ((object)_c1 == null && (object)_c2 == null)
            {
                return(true);
            }

            return((Math.Abs(_c1.R - _c2.R) < _tolerance) &&
                   (Math.Abs(_c1.G - _c2.G) < _tolerance) &&
                   (Math.Abs(_c1.B - _c2.B) < _tolerance));
        }