diff --git a/op_c.c b/op_c.c index 31726dfb..bb88cd17 100644 --- a/op_c.c +++ b/op_c.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "op_c.h" #include "erreurs.h" @@ -103,10 +104,43 @@ void rgb2hl(int r,int g,int b,byte * hr,byte * lr,byte* sr) *sr = (s*255.0); } +void HLStoRGB(byte H,byte L,byte S, byte* R, byte* G, byte* B) +{ + float OffsetSaturation; + float rf,gf,bf; + S = 255 - S; + + if(H < 85) + rf = fminf(1, (85 - H) / 42.5); + + else if(H > 170) + rf = fminf(1, (H - 170) / 42.5); + + if (H < 170) + gf = fminf(1, (85 - abs(H - 85)) / 42.5); + + if (H > 85) + bf = fminf(1, (85 - abs(H - 170)) / 42.5); + + if (S < 255) + { + rf = rf * (S / 255.0); + gf = gf * (S / 255.0); + bf = bf * (S / 255.0); + OffsetSaturation = /*128 **/ (255 - S) / 255.0; + rf += OffsetSaturation; + gf += OffsetSaturation; + bf += OffsetSaturation; + } + + *R = rf * ((255 - abs(L - 255)) / 255.0); + *G = gf * ((255 - abs(L - 255)) / 255.0); + *B = bf * ((255 - abs(L - 255)) / 255.0); +} ///////////////////////////////////////////////////////////////////////////// -///////////////////////////// M‚thodes de gestion des tables de conversion // +///////////////////////////// Méthodes de gestion des tables de conversion // ///////////////////////////////////////////////////////////////////////////// Table_conversion * TC_New(int nbb_r,int nbb_v,int nbb_b) diff --git a/op_c.h b/op_c.h index 867b5ca4..1a8f965b 100644 --- a/op_c.h +++ b/op_c.h @@ -148,6 +148,7 @@ 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, byte* s); +void HLStoRGB(byte h, byte l, byte s, byte* r, byte* g, byte* b); ///////////////////////////////////////////////////////////////////////////// diff --git a/palette.c b/palette.c index 05670cac..546a1429 100644 --- a/palette.c +++ b/palette.c @@ -937,8 +937,21 @@ void Bouton_Palette(void) Effacer_curseur(); if (Debut_block==Fin_block) { - Modifier_Rouge(Fore_color,63-Jauge_rouge->Position,Palette_de_travail); - Num2str(Palette_de_travail[Fore_color].R,Chaine,2); + if(Palette_mode_RGB) + { + Modifier_Rouge(Fore_color,63-Jauge_rouge->Position,Palette_de_travail); + Num2str(Palette_de_travail[Fore_color].R,Chaine,2); + } + else + { + byte h,l,s; + + rgb2hl(Palette_de_travail[Fore_color].R,Palette_de_travail[Fore_color].V,Palette_de_travail[Fore_color].B,&h,&l,&s); + h=(63-Jauge_rouge->Position)*4; // Enlever le *4 quand le slider ira de 0 à 255 comme il faut + HLStoRGB(h,l,s,&Palette_de_travail[Fore_color].R,&Palette_de_travail[Fore_color].V,&Palette_de_travail[Fore_color].B); + + Num2str((int)h>>2,Chaine,2); + } Print_dans_fenetre(180,172,Chaine,CM_Noir,CM_Clair); } else @@ -976,7 +989,21 @@ void Bouton_Palette(void) Effacer_curseur(); if (Debut_block==Fin_block) { - Modifier_Vert (Fore_color,63-Jauge_verte->Position,Palette_de_travail); + if(Palette_mode_RGB) + { + Modifier_Vert (Fore_color,63-Jauge_verte->Position,Palette_de_travail); + Num2str(Palette_de_travail[Fore_color].V,Chaine,2); + } + else + { + byte h,l,s; + + rgb2hl(Palette_de_travail[Fore_color].R,Palette_de_travail[Fore_color].V,Palette_de_travail[Fore_color].B,&h,&l,&s); + l=(63-Jauge_verte->Position)*4; // Mettre +1 quand on aura modifié la plage du slider + HLStoRGB(h,l,s,&Palette_de_travail[Fore_color].R,&Palette_de_travail[Fore_color].V,&Palette_de_travail[Fore_color].B); + + Num2str((int)h>>2,Chaine,2); + } Num2str(Palette_de_travail[Fore_color].V,Chaine,2); Print_dans_fenetre(207,172,Chaine,CM_Noir,CM_Clair); }