Some more work on HLS colors. Broken...

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@347 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Adrien Destugues 2008-11-15 22:43:12 +00:00
parent 48979bf251
commit a60b2bfd01
3 changed files with 66 additions and 4 deletions

36
op_c.c
View File

@ -24,6 +24,7 @@
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <math.h>
#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);
}
/////////////////////////////////////////////////////////////////////////////
///////////////////////////// Mthodes 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)

1
op_c.h
View File

@ -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);
/////////////////////////////////////////////////////////////////////////////

View File

@ -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);
}