From e31b88ceede8a573b964519901d57e639f1f42b9 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Mon, 20 Oct 2008 18:14:10 +0000 Subject: [PATCH] Palette sorting works -still slow -seems there is a bug in the HSL calculation for green and blue, they get sorted incorrectly -maybe the new S parameter should be used in clustersets, because now we are not differenciating grey from red !! maybe it's done elsewhere, we'll have to check. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@291 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- op_c.c | 7 ++++--- op_c.h | 2 +- palette.c | 23 ++++++++++------------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/op_c.c b/op_c.c index 52e2f49e..76b59d2c 100644 --- a/op_c.c +++ b/op_c.c @@ -33,7 +33,7 @@ -void rgb2hl(int r,int g,int b,byte * hr,byte * lr) +void rgb2hl(int r,int g,int b,byte * hr,byte * lr,byte* sr) { double rd,gd,bd,h,s,v,l,max,min,del,rc,gc,bc; @@ -100,6 +100,7 @@ void rgb2hl(int r,int g,int b,byte * hr,byte * lr) *hr = (h*255.0)/360; *lr = (l*255.0); + *sr = (s*255.0); } @@ -559,7 +560,7 @@ void Cluster_Split(Cluster * c,Cluster * c1,Cluster * c2,int teinte,Table_occure void Cluster_Calculer_teinte(Cluster * c,Table_occurence * to) { int cumulR,cumulV,cumulB; - int r,v,b; + int r,v,b,s=0; int nbocc; cumulR=cumulV=cumulB=0; @@ -579,7 +580,7 @@ void Cluster_Calculer_teinte(Cluster * c,Table_occurence * to) c->r=(cumulR<red_r)/c->occurences; c->v=(cumulV<red_v)/c->occurences; c->b=(cumulB<red_b)/c->occurences; - rgb2hl(c->r,c->v,c->b,&c->h,&c->l); + rgb2hl(c->r,c->v,c->b,&c->h,&c->l,&s); } diff --git a/op_c.h b/op_c.h index 0b4ee842..867b5ca4 100644 --- a/op_c.h +++ b/op_c.h @@ -147,7 +147,7 @@ void TC_Delete(Table_conversion * t); byte TC_Get(Table_conversion * t,int r,int v,int b); void TC_Set(Table_conversion * t,int r,int v,int b,byte i); -void rgb2hl(int r, int v,int b, byte* h, byte*l); +void rgb2hl(int r, int v,int b, byte* h, byte*l, byte* s); ///////////////////////////////////////////////////////////////////////////// diff --git a/palette.c b/palette.c index 3b9a98cb..33b90b92 100644 --- a/palette.c +++ b/palette.c @@ -1646,37 +1646,34 @@ void Bouton_Palette(void) case 25 : // Sort palette { - int h = 0, l = 0; - int oh=0,ol=0; // Valeur pour la couleur précédente + byte h = 0, l = 0, s=0; + byte oh=0,ol=0,os=0; // Valeur pour la couleur précédente int swap=1; while(swap==1) { swap=0; - h=0;l=0; + h=0;l=0;s=0; for(Couleur_temporaire=0;Couleur_temporaire<256;Couleur_temporaire++) { - oh=h; ol=l; + oh=h; ol=l; os=s; // On trie par Chrominance (H) et Luminance (L) rgb2hl(Palette_de_travail[Couleur_temporaire].R, Palette_de_travail[Couleur_temporaire].V, - Palette_de_travail[Couleur_temporaire].B,&h,&l); + Palette_de_travail[Couleur_temporaire].B,&h,&l,&s); - // Note : comparer seulement H et L ne suffit pas toujours à trancher... - // donc on regarde aussi les composantes R G B s'il y a un doute - if((h0)) // Un gris passe devant une couleur saturée + || (((s>0 && os > 0) || (s==os && s==0)) // Deux couleurs saturées ou deux gris... + && (h