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
This commit is contained in:
Adrien Destugues 2008-10-20 18:14:10 +00:00
parent fc41bbe89d
commit e31b88ceed
3 changed files with 15 additions and 17 deletions

7
op_c.c
View File

@ -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; 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; *hr = (h*255.0)/360;
*lr = (l*255.0); *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) void Cluster_Calculer_teinte(Cluster * c,Table_occurence * to)
{ {
int cumulR,cumulV,cumulB; int cumulR,cumulV,cumulB;
int r,v,b; int r,v,b,s=0;
int nbocc; int nbocc;
cumulR=cumulV=cumulB=0; cumulR=cumulV=cumulB=0;
@ -579,7 +580,7 @@ void Cluster_Calculer_teinte(Cluster * c,Table_occurence * to)
c->r=(cumulR<<to->red_r)/c->occurences; c->r=(cumulR<<to->red_r)/c->occurences;
c->v=(cumulV<<to->red_v)/c->occurences; c->v=(cumulV<<to->red_v)/c->occurences;
c->b=(cumulB<<to->red_b)/c->occurences; c->b=(cumulB<<to->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);
} }

2
op_c.h
View File

@ -147,7 +147,7 @@ void TC_Delete(Table_conversion * t);
byte TC_Get(Table_conversion * t,int r,int v,int b); 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 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);
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

View File

@ -1646,37 +1646,34 @@ void Bouton_Palette(void)
case 25 : // Sort palette case 25 : // Sort palette
{ {
int h = 0, l = 0; byte h = 0, l = 0, s=0;
int oh=0,ol=0; // Valeur pour la couleur précédente byte oh=0,ol=0,os=0; // Valeur pour la couleur précédente
int swap=1; int swap=1;
while(swap==1) while(swap==1)
{ {
swap=0; swap=0;
h=0;l=0; h=0;l=0;s=0;
for(Couleur_temporaire=0;Couleur_temporaire<256;Couleur_temporaire++) 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) // On trie par Chrominance (H) et Luminance (L)
rgb2hl(Palette_de_travail[Couleur_temporaire].R, rgb2hl(Palette_de_travail[Couleur_temporaire].R,
Palette_de_travail[Couleur_temporaire].V, 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... if(
// donc on regarde aussi les composantes R G B s'il y a un doute ((s==0) && (os>0)) // Un gris passe devant une couleur saturée
if((h<oh) || (h==oh && (l<ol || (((s>0 && os > 0) || (s==os && s==0)) // Deux couleurs saturées ou deux gris...
|| ( l==ol && (Palette_de_travail[Couleur_temporaire].V < Palette_de_travail[Couleur_temporaire-1].V && (h<oh || (h==oh && l<ol)))) // Dans ce cas on décide avec chroma puis lumi
|| (Palette_de_travail[Couleur_temporaire].V == Palette_de_travail[Couleur_temporaire-1].V && Palette_de_travail[Couleur_temporaire].R < Palette_de_travail[Couleur_temporaire-1].R)
|| (Palette_de_travail[Couleur_temporaire].V == Palette_de_travail[Couleur_temporaire-1].V && Palette_de_travail[Couleur_temporaire].R < Palette_de_travail[Couleur_temporaire-1].R && Palette_de_travail[Couleur_temporaire].B < Palette_de_travail[Couleur_temporaire-1].B)))))
)
{ {
// On échange la couleur avec la précédente // On échange la couleur avec la précédente
Swap(0,Couleur_temporaire,Couleur_temporaire-1,1,Palette_de_travail,Utilisation_couleur); Swap(0,Couleur_temporaire,Couleur_temporaire-1,1,Palette_de_travail,Utilisation_couleur);
swap=1; swap=1;
DEBUG("swap",Couleur_temporaire);
} }
} }
} }
Il_faut_remapper=1;
} }
break; break;
} }