From 19ac89a38f790152b62a10f46187055df75d7409 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Tue, 7 Apr 2009 17:54:52 +0000 Subject: [PATCH] New (hopefully better) method for selecting the colors in smooth and colorize. Tell me if you think it's good. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@742 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- helpfile.h | 2 +- windows.c | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/helpfile.h b/helpfile.h index b213b506..83882786 100644 --- a/helpfile.h +++ b/helpfile.h @@ -883,7 +883,7 @@ static const T_Help_table helptable_grad_rect[] = HELP_TEXT ("starting color, drag to a point where you") HELP_TEXT ("want the ending color, and release the") HELP_TEXT ("button. You can press SHIFT to enforce your") - HELP_TEXT ("line to be vertical, horizontal, or + HELP_TEXT ("line to be vertical, horizontal, or") HELP_TEXT ("diagonal.") }; static const T_Help_table helptable_grad_menu[] = diff --git a/windows.c b/windows.c index abe34d76..b95485a0 100644 --- a/windows.c +++ b/windows.c @@ -2200,6 +2200,7 @@ byte Best_color(byte r,byte g,byte b) int delta_r,delta_g,delta_b; int dist; int best_dist=0x7FFFFFFF; + int rmean; byte best_color=0; for (col=0; col<256; col++) @@ -2210,7 +2211,10 @@ byte Best_color(byte r,byte g,byte b) delta_g=(int)Main_palette[col].G-g; delta_b=(int)Main_palette[col].B-b; - if (!(dist=(delta_r*delta_r*30)+(delta_g*delta_g*59)+(delta_b*delta_b*11))) + rmean = ( Main_palette[col].R + r ) / 2; + + if (!(dist= ( ( (512+rmean) *delta_r*delta_r) >>8) + 4*delta_g*delta_g + (((767-rmean)*delta_b*delta_b)>>8))) + //if (!(dist=(delta_r*delta_r*30)+(delta_g*delta_g*59)+(delta_b*delta_b*11))) return col; if (dist>8) + 4*delta_g*delta_g + (((767-rmean)*delta_b*delta_b)>>8))) + //if (!(dist=(delta_r*delta_r*30)+(delta_g*delta_g*59)+(delta_b*delta_b*11))) return col; if (dist