Example #1
0
 Gdk.Color render_foreground(ContrastPaletteColor symbol)
 {
     return(Contrast.RenderForegroundColor(get_background(), symbol));
 }
Example #2
0
		Gdk.Color render_foreground(ContrastPaletteColor symbol)
		{
			return Contrast.RenderForegroundColor(get_background(), symbol);
		}
Example #3
0
		/* Creates a specific color value for a foreground color, optimizing for
		 * maximum readability against the background.
		 */
		
		public static Gdk.Color RenderForegroundColor(Gdk.Color background, ContrastPaletteColor color)
		{
			float L, a, b;
			int max_color;
			float max_dist;
			float[,] points = new float[8,3];
			float ld, cd;
			int i;
			Gdk.Color rcolor = new Gdk.Color();
			
			rgb_to_lab(background.Red, background.Green, background.Blue, out L, out a, out b);
			
			points[0,0] = color_regions[(int)color,0];
			points[0,1] = color_regions[(int)color,2];
			points[0,2] = color_regions[(int)color,4];
			
			points[1,0] = color_regions[(int)color,0];
			points[1,1] = color_regions[(int)color,2];
			points[1,2] = color_regions[(int)color,5];
			
			points[2,0] = color_regions[(int)color,0];
			points[2,1] = color_regions[(int)color,3];
			points[2,2] = color_regions[(int)color,4];

			points[3,0] = color_regions[(int)color,0];
			points[3,1] = color_regions[(int)color,3];
			points[3,2] = color_regions[(int)color,5];

			points[4,0] = color_regions[(int)color,1];
			points[4,1] = color_regions[(int)color,2];
			points[4,2] = color_regions[(int)color,4];

			points[5,0] = color_regions[(int)color,1];
			points[5,1] = color_regions[(int)color,2];
			points[5,2] = color_regions[(int)color,5];

			points[6,0] = color_regions[(int)color,1];
			points[6,1] = color_regions[(int)color,3];
			points[6,2] = color_regions[(int)color,4];
			
			points[7,0] = color_regions[(int)color,1];
			points[7,1] = color_regions[(int)color,3];
			points[7,2] = color_regions[(int)color,5];
			
			max_dist = 0;
			max_color = 0;
			
			for (i = 0; i < 8; i++) {
				float dist = lab_distance(L, a, b, points[i,0], points[i,1], points[i,2]);
				
				if (dist > max_dist) {
					max_dist = dist;
					max_color = i;
				}
			}

			/* If the luminosity distance is really short, extend the vector further
			 * out.  This may push it outside the bounds of the region that a color
			 * is specified in, but it keeps things readable when the background and
			 * foreground are really close.
			 */
			
			ld = Math.Abs(L - points[max_color,0]);
			cd = (float) Math.Sqrt (Math.Pow (Math.Abs (a - points[max_color,1]), 2.0f) + Math.Pow (Math.Abs (b - points[max_color,2]), 2.0f));
			
			if ((ld < 10.0f) && (cd < 60.0f)) {
				float dL, da, db;
				
				dL = points[max_color,0] - L;
				da = points[max_color,1] - a;
				db = points[max_color,2] - b;
				points[max_color,0] = L + (dL * 4.0f);
				points[max_color,1] = a + (da * 1.5f);
				points[max_color,2] = b + (db * 1.5f);
			}

			rcolor.Pixel = 0;
			lab_to_rgb(points[max_color,0], points[max_color,1], points[max_color,2], out rcolor.Red, out rcolor.Green, out rcolor.Blue);
			
			return rcolor;
		}
        /* Creates a specific color value for a foreground color, optimizing for
         * maximum readability against the background.
         */

        public static Color RenderForegroundColor(Color background, ContrastPaletteColor color)
        {
            float L, a, b;
            int   max_color;
            float max_dist;

            float[,] points = new float[8, 3];
            float ld, cd;
            int   i;

            rgb_to_lab((ushort)(background.R * 255), (ushort)(background.G * 255),
                       (ushort)(background.B * 255), out L, out a, out b);

            points[0, 0] = color_regions[(int)color, 0];
            points[0, 1] = color_regions[(int)color, 2];
            points[0, 2] = color_regions[(int)color, 4];

            points[1, 0] = color_regions[(int)color, 0];
            points[1, 1] = color_regions[(int)color, 2];
            points[1, 2] = color_regions[(int)color, 5];

            points[2, 0] = color_regions[(int)color, 0];
            points[2, 1] = color_regions[(int)color, 3];
            points[2, 2] = color_regions[(int)color, 4];

            points[3, 0] = color_regions[(int)color, 0];
            points[3, 1] = color_regions[(int)color, 3];
            points[3, 2] = color_regions[(int)color, 5];

            points[4, 0] = color_regions[(int)color, 1];
            points[4, 1] = color_regions[(int)color, 2];
            points[4, 2] = color_regions[(int)color, 4];

            points[5, 0] = color_regions[(int)color, 1];
            points[5, 1] = color_regions[(int)color, 2];
            points[5, 2] = color_regions[(int)color, 5];

            points[6, 0] = color_regions[(int)color, 1];
            points[6, 1] = color_regions[(int)color, 3];
            points[6, 2] = color_regions[(int)color, 4];

            points[7, 0] = color_regions[(int)color, 1];
            points[7, 1] = color_regions[(int)color, 3];
            points[7, 2] = color_regions[(int)color, 5];

            max_dist  = 0;
            max_color = 0;

            for (i = 0; i < 8; i++)
            {
                float dist = lab_distance(L, a, b, points[i, 0], points[i, 1], points[i, 2]);

                if (dist > max_dist)
                {
                    max_dist  = dist;
                    max_color = i;
                }
            }

            /* If the luminosity distance is really short, extend the vector further
             * out.  This may push it outside the bounds of the region that a color
             * is specified in, but it keeps things readable when the background and
             * foreground are really close.
             */

            ld = Math.Abs(L - points[max_color, 0]);
            cd = (float)Math.Sqrt(Math.Pow(Math.Abs(a - points[max_color, 1]), 2.0f) + Math.Pow(Math.Abs(b - points[max_color, 2]), 2.0f));

            if ((ld < 10.0f) && (cd < 60.0f))
            {
                float dL, da, db;

                dL = points[max_color, 0] - L;
                da = points[max_color, 1] - a;
                db = points[max_color, 2] - b;
                points[max_color, 0] = L + (dL * 4.0f);
                points[max_color, 1] = a + (da * 1.5f);
                points[max_color, 2] = b + (db * 1.5f);
            }

            ushort red, green, blue;

            lab_to_rgb(points[max_color, 0], points[max_color, 1], points[max_color, 2], out red, out green, out blue);

            return(new Color(red / 255.0, green / 255.0, blue / 255.0));
        }