diff --git a/Makefile b/Makefile index b22e23d7..43578a37 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ # Windows specific ifdef COMSPEC DELCOMMAND = rm -f - MKDIR = mkdir + MKDIR = mkdir -p RMDIR = rmdir CP = cp BIN = grafx2.exe diff --git a/Makefile.dep b/Makefile.dep index bffac602..cae63e4b 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -35,8 +35,8 @@ $(OBJDIR)/palette.o: palette.c const.h struct.h global.h loadsave.h divers.h \ $(OBJDIR)/readini.o: readini.c const.h global.h struct.h loadsave.h graph.h $(OBJDIR)/readline.o: readline.c const.h struct.h global.h loadsave.h graph.h \ divers.h erreurs.h sdlscreen.h readline.h -$(OBJDIR)/saveini.o: saveini.c const.h global.h struct.h loadsave.h readini.h \ - files.h erreurs.h graph.h +$(OBJDIR)/saveini.o: saveini.c const.h global.h struct.h loadsave.h readini.h io.h \ + erreurs.h graph.h $(OBJDIR)/sdlscreen.o: sdlscreen.c global.h struct.h const.h loadsave.h sdlscreen.h \ divers.h erreurs.h graph.h $(OBJDIR)/setup.o: setup.c struct.h const.h io.h files.h diff --git a/boutons.c b/boutons.c index 578292db..9355ba68 100644 --- a/boutons.c +++ b/boutons.c @@ -4362,7 +4362,7 @@ void Calculer_les_tables_de_Colorize(void) Facteur_A=256*(100-Colorize_Opacite)/100; Facteur_B=256*( Colorize_Opacite)/100; - for (Indice=0;Indice<64;Indice++) + for (Indice=0;Indice<256;Indice++) { Table_de_multiplication_par_Facteur_A[Indice]=Indice*Facteur_A; Table_de_multiplication_par_Facteur_B[Indice]=Indice*Facteur_B; diff --git a/divers.c b/divers.c index e0c975f0..d7d364c1 100644 --- a/divers.c +++ b/divers.c @@ -81,9 +81,9 @@ void Set_palette(T_Palette Palette) SDL_Color PaletteSDL[256]; for(i=0;i<256;i++) { - PaletteSDL[i].r=(Palette[i].R<<2) + (Palette[i].R>>4); //Les couleurs VGA ne vont que de 0 à 63 - PaletteSDL[i].g=(Palette[i].V<<2) + (Palette[i].V>>4); - PaletteSDL[i].b=(Palette[i].B<<2) + (Palette[i].B>>4); + PaletteSDL[i].r=Palette[i].R; + PaletteSDL[i].g=Palette[i].V; + PaletteSDL[i].b=Palette[i].B; } //SDL_PHYSPAL| SDL_SetPalette(Ecran_SDL, SDL_PHYSPAL | SDL_LOGPAL, PaletteSDL,0,256); @@ -92,9 +92,9 @@ void Set_palette(T_Palette Palette) void Set_color(byte Couleur, byte Rouge, byte Vert, byte Bleu) { SDL_Color comp; - comp.r=Rouge << 2; - comp.g=Vert << 2; - comp.b=Bleu << 2; + comp.r=Rouge; + comp.g=Vert; + comp.b=Bleu; SDL_SetPalette(Ecran_SDL, SDL_LOGPAL, &comp, Couleur, 1); } @@ -638,9 +638,9 @@ void Palette_64_to_256(T_Palette Palette) int i; for(i=0;i<256;i++) { - Palette[i].R = Palette[i].R << 2; - Palette[i].V = Palette[i].V << 2; - Palette[i].B = Palette[i].B << 2; + Palette[i].R = (Palette[i].R << 2)|(Palette[i].R >> 4); + Palette[i].V = (Palette[i].V << 2)|(Palette[i].V >> 4); + Palette[i].B = (Palette[i].B << 2)|(Palette[i].B >> 4); } } diff --git a/global.h b/global.h index 5f00e734..c5b1c586 100644 --- a/global.h +++ b/global.h @@ -445,8 +445,8 @@ GLOBAL short Trame_Hauteur; // Hauteur de la trame GLOBAL byte Colorize_Mode; // Le mode Colorize est enclenché GLOBAL byte Colorize_Opacite; // Intensité du Colorize GLOBAL byte Colorize_Mode_en_cours; // Le type de Colorize en cours (0-2) -GLOBAL word Table_de_multiplication_par_Facteur_A[64]; -GLOBAL word Table_de_multiplication_par_Facteur_B[64]; +GLOBAL word Table_de_multiplication_par_Facteur_A[256]; +GLOBAL word Table_de_multiplication_par_Facteur_B[256]; // Mode smooth: diff --git a/graph.c b/graph.c index 8049848b..406a9e3f 100644 --- a/graph.c +++ b/graph.c @@ -1668,6 +1668,203 @@ void Print_nom_fichier(void) } } +// Fonction d'affichage d'une chaine numérique avec une fonte très fine +// Spécialisée pour les compteurs RGB +void Print_compteur(short X,short Y,char * Chaine,byte Couleur_texte,byte Couleur_fond) +{ + // Macros pour écrire des litteraux binaires. + // Ex: Ob(11110000) == 0xF0 + #define Ob(x) ((unsigned)Ob_(0 ## x ## uL)) + #define Ob_(x) ((x & 1) | (x >> 2 & 2) | (x >> 4 & 4) | (x >> 6 & 8) | \ + (x >> 8 & 16) | (x >> 10 & 32) | (x >> 12 & 64) | (x >> 14 & 128)) + + byte Caractere[14][8] = { + { // 0 + Ob(00011100), + Ob(00110110), + Ob(00110110), + Ob(00110110), + Ob(00110110), + Ob(00110110), + Ob(00110110), + Ob(00011100) + }, + { // 1 + Ob(00001100), + Ob(00011100), + Ob(00111100), + Ob(00001100), + Ob(00001100), + Ob(00001100), + Ob(00001100), + Ob(00001100) + }, + { // 2 + Ob(00011100), + Ob(00110110), + Ob(00000110), + Ob(00000110), + Ob(00000110), + Ob(00001100), + Ob(00011000), + Ob(00111110) + }, + { // 3 + Ob(00011100), + Ob(00110110), + Ob(00000110), + Ob(00001100), + Ob(00000110), + Ob(00000110), + Ob(00110110), + Ob(00011100) + }, + { // 4 + Ob(00001100), + Ob(00001100), + Ob(00011000), + Ob(00011000), + Ob(00110000), + Ob(00110100), + Ob(00111110), + Ob(00000100) + }, + { // 5 + Ob(00111110), + Ob(00110000), + Ob(00110000), + Ob(00111100), + Ob(00000110), + Ob(00000110), + Ob(00110110), + Ob(00011100) + }, + { // 6 + Ob(00011100), + Ob(00110110), + Ob(00110000), + Ob(00111100), + Ob(00110110), + Ob(00110110), + Ob(00110110), + Ob(00011100) + }, + { // 7 + Ob(00111110), + Ob(00000110), + Ob(00000110), + Ob(00001100), + Ob(00011000), + Ob(00011000), + Ob(00011000), + Ob(00011000) + }, + { // 8 + Ob(00011100), + Ob(00110110), + Ob(00110110), + Ob(00011100), + Ob(00110110), + Ob(00110110), + Ob(00110110), + Ob(00011100) + }, + { // 9 + Ob(00011100), + Ob(00110110), + Ob(00110110), + Ob(00011110), + Ob(00000110), + Ob(00000110), + Ob(00110110), + Ob(00011100) + }, + { // (espace) + Ob(00000000), + Ob(00000000), + Ob(00000000), + Ob(00000000), + Ob(00000000), + Ob(00000000), + Ob(00000000), + Ob(00000000) + }, + { // + + Ob(00000000), + Ob(00001000), + Ob(00001000), + Ob(00111110), + Ob(00001000), + Ob(00001000), + Ob(00000000), + Ob(00000000) + }, + { // - + Ob(00000000), + Ob(00000000), + Ob(00000000), + Ob(00111110), + Ob(00000000), + Ob(00000000), + Ob(00000000), + Ob(00000000) + }, + { // +- + Ob(00001000), + Ob(00001000), + Ob(00111110), + Ob(00001000), + Ob(00001000), + Ob(00000000), + Ob(00111110), + Ob(00000000) + } }; + + word Indice; + short Pos_X; + short Pos_Y; + for (Indice=0;Chaine[Indice]!='\0';Indice++) + { + int Numero_car; + switch(Chaine[Indice]) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + Numero_car=Chaine[Indice]-'0'; + break; + case ' ': + default: + Numero_car=10; + break; + case '+': + Numero_car=11; + break; + case '-': + Numero_car=12; + break; + case '±': + Numero_car=13; + break; + } + for (Pos_Y=0;Pos_Y<8;Pos_Y++) + { + for (Pos_X=0;Pos_X<6;Pos_X++) + { + byte Couleur = (Caractere[Numero_car][Pos_Y] & (1 << (6-Pos_X))) ? Couleur_texte:Couleur_fond; + Pixel_dans_fenetre(X+(Indice*6+Pos_X),Y+Pos_Y,Couleur); + } + } + } + UpdateRect(Fenetre_Pos_X+X*Menu_Facteur_X,Fenetre_Pos_Y+Y*Menu_Facteur_Y,strlen(Chaine)*Menu_Facteur_X*6,8*Menu_Facteur_Y); +} // -- Calcul des différents effets ------------------------------------------- diff --git a/graph.h b/graph.h index ec76af88..ca23ed55 100644 --- a/graph.h +++ b/graph.h @@ -65,6 +65,7 @@ void Print_char_transparent_dans_fenetre(short Pos_X,short Pos_Y,unsigned char C void Print_dans_menu(char * Chaine, short Position); void Print_coordonnees(void); void Print_nom_fichier(void); +void Print_compteur(short X,short Y,char * Chaine,byte Couleur_texte,byte Couleur_fond); byte Aucun_effet(word X,word Y,byte Couleur); byte Effet_Shade(word X,word Y,byte Couleur); diff --git a/init.c b/init.c index b5b094b7..ec0dd59b 100644 --- a/init.c +++ b/init.c @@ -185,6 +185,7 @@ void Charger_DAT(void) if (!read_bytes(Handle, Palette_defaut,sizeof(T_Palette))) Erreur(ERREUR_DAT_CORROMPU); + Palette_64_to_256(Palette_defaut); if (!read_bytes(Handle, BLOCK_MENU,LARGEUR_MENU*HAUTEUR_MENU)) Erreur(ERREUR_DAT_CORROMPU); diff --git a/loadsave.c b/loadsave.c index ddaafa2f..d05b61c1 100644 --- a/loadsave.c +++ b/loadsave.c @@ -148,9 +148,9 @@ void Palette_fake_24b(T_Palette Palette) // Génération de la palette for (Couleur=0;Couleur<256;Couleur++) { - Palette[Couleur].R=((Couleur & 0xE0)>>5)<<3; - Palette[Couleur].V=((Couleur & 0x1C)>>2)<<3; - Palette[Couleur].B=((Couleur & 0x03)>>0)<<4; + Palette[Couleur].R=((Couleur & 0xE0)>>5)<<5; + Palette[Couleur].V=((Couleur & 0x1C)>>2)<<5; + Palette[Couleur].B=((Couleur & 0x03)>>0)<<6; } } @@ -512,8 +512,10 @@ void Charger_image(byte Image) if (Convert_bitmap_24B_to_256(Brosse,Buffer_image_24b,Brosse_Largeur,Brosse_Hauteur,Principal_Palette)) Erreur_fichier=2; } - if (!Erreur_fichier) - Palette_256_to_64(Principal_Palette); + //if (!Erreur_fichier) + // Palette_256_to_64(Principal_Palette); + // Normalement plus besoin car 256 color natif, et c'etait probablement + // un bug - yr } free(Buffer_image_24b); @@ -625,11 +627,14 @@ void Load_PAL(void) // Ouverture du fichier if ((Fichier=fopen(Nom_du_fichier, "rb"))) { + T_Palette Palette_64; // Initialiser_preview(???); // Pas possible... pas d'image... // Lecture du fichier dans Principal_Palette - if (read_bytes(Fichier,Principal_Palette,sizeof(T_Palette))) + if (read_bytes(Fichier,Palette_64,sizeof(T_Palette))) { + Palette_64_to_256(Palette_64); + memcpy(Principal_Palette,Palette_64,sizeof(T_Palette)); Set_palette(Principal_Palette); Remapper_fileselect(); @@ -662,8 +667,11 @@ void Save_PAL(void) // Ouverture du fichier if ((Fichier=fopen(Nom_du_fichier,"wb"))) { + T_Palette Palette_64; + memcpy(Palette_64,Principal_Palette,sizeof(T_Palette)); + Palette_256_to_64(Palette_64); // Enregistrement de Principal_Palette dans le fichier - if (! write_bytes(Fichier,Principal_Palette,sizeof(T_Palette))) + if (! write_bytes(Fichier,Palette_64,sizeof(T_Palette))) { Erreur_fichier=1; fclose(Fichier); @@ -763,13 +771,7 @@ void Load_IMG(void) Initialiser_preview(IMG_Header.Largeur,IMG_Header.Hauteur,Taille_du_fichier,FORMAT_IMG); if (Erreur_fichier==0) { - // On commence par passer la palette en 256 comme ça, si la nouvelle - // palette a moins de 256 coul, la précédente ne souffrira pas d'un - // assombrissement préjudiciable. - Palette_64_to_256(Principal_Palette); - // On peut maintenant transférer la nouvelle palette memcpy(Principal_Palette,IMG_Header.Palette,sizeof(T_Palette)); - Palette_256_to_64(Principal_Palette); Set_palette(Principal_Palette); Remapper_fileselect(); @@ -827,9 +829,7 @@ void Save_IMG(void) IMG_Header.Filler2[23]=0; // Hi(Longueur de la signature) memcpy(IMG_Header.Filler2+23,"GRAFX2 by SunsetDesign (IMG format taken from PV (c)W.Wiedmann)",64); - Palette_64_to_256(Principal_Palette); memcpy(IMG_Header.Palette,Principal_Palette,sizeof(T_Palette)); - Palette_256_to_64(Principal_Palette); #if SDL_BYTEORDER == SDL_BIG_ENDIAN IMG_Header.Largeur = SDL_Swap16(IMG_Header.Largeur); @@ -1047,11 +1047,13 @@ void Load_PKM(void) Initialiser_preview(Head.Largeur,Head.Hauteur,Taille_du_fichier,FORMAT_PKM); if (Erreur_fichier==0) { + Principal_Largeur_image=Head.Largeur; Principal_Hauteur_image=Head.Hauteur; Taille_image=(dword)(Principal_Largeur_image*Principal_Hauteur_image); - + // Palette lue en 64 memcpy(Principal_Palette,Head.Palette,sizeof(T_Palette)); + Palette_64_to_256(Principal_Palette); Set_palette(Principal_Palette); Remapper_fileselect(); @@ -1174,6 +1176,7 @@ void Save_PKM(void) Head.Largeur=Principal_Largeur_image; Head.Hauteur=Principal_Hauteur_image; memcpy(Head.Palette,Principal_Palette,sizeof(T_Palette)); + Palette_256_to_64(Head.Palette); // Calcul de la taille du Post-Header Head.Jump=9; // 6 pour les dimensions de l'ecran + 3 pour la back-color @@ -1679,6 +1682,7 @@ void Load_LBM(void) Palette_256_to_64(Principal_Palette); if (Image_HAM) Adapter_Palette_HAM(); + Palette_64_to_256(Principal_Palette); Set_palette(Principal_Palette); Remapper_fileselect(); @@ -1818,9 +1822,6 @@ void Load_LBM(void) } else { - // On restore l'ancienne palette en cas d'erreur... - Palette_256_to_64(Principal_Palette); - // ... ce qui permet de ne renvoyer qu'une erreur 1 (pas de modif) Erreur_fichier=1; } } @@ -1988,9 +1989,7 @@ void Save_LBM(void) write_bytes(LBM_Fichier,"CMAP",4); write_dword_be(LBM_Fichier,sizeof(T_Palette)); - Palette_64_to_256(Principal_Palette); write_bytes(LBM_Fichier,Principal_Palette,sizeof(T_Palette)); - Palette_256_to_64(Principal_Palette); write_bytes(LBM_Fichier,"BODY",4); write_dword_be(LBM_Fichier,0); // On mettra la taille à jour à la fin @@ -2199,8 +2198,6 @@ void Load_BMP(void) // assombrissement préjudiciable. if (Config.Clear_palette) memset(Principal_Palette,0,sizeof(T_Palette)); - else - Palette_64_to_256(Principal_Palette); // On peut maintenant transférer la nouvelle palette for (Indice=0; Indice4) @@ -3538,7 +3513,6 @@ void Load_PCX(void) } } } - Palette_256_to_64(Principal_Palette); Set_palette(Principal_Palette); Remapper_fileselect(); @@ -3768,8 +3742,6 @@ void Save_PCX(void) if ((Fichier=fopen(Nom_du_fichier,"wb"))) { - // On prépare la palette pour écrire les 16 premieres valeurs - Palette_64_to_256(Principal_Palette); PCX_Header.Manufacturer=10; PCX_Header.Version=5; @@ -3859,8 +3831,6 @@ void Save_PCX(void) if (Erreur_fichier) remove(Nom_du_fichier); - // On remet la palette à son état normal - Palette_256_to_64(Principal_Palette); } else Erreur_fichier=1; @@ -4284,9 +4254,9 @@ void Load_KCF(void) for (Indice_couleur=0;Indice_couleur<16;Indice_couleur++) { Indice=16+(Indice_palette*16)+Indice_couleur; - Principal_Palette[Indice].R=((Buffer.Palette[Indice_palette].Couleur[Indice_couleur].Octet1 >> 4) << 2); - Principal_Palette[Indice].B=((Buffer.Palette[Indice_palette].Couleur[Indice_couleur].Octet1 & 15) << 2); - Principal_Palette[Indice].V=((Buffer.Palette[Indice_palette].Couleur[Indice_couleur].Octet2 & 15) << 2); + Principal_Palette[Indice].R=((Buffer.Palette[Indice_palette].Couleur[Indice_couleur].Octet1 >> 4) << 4); + Principal_Palette[Indice].B=((Buffer.Palette[Indice_palette].Couleur[Indice_couleur].Octet1 & 15) << 4); + Principal_Palette[Indice].V=((Buffer.Palette[Indice_palette].Couleur[Indice_couleur].Octet2 & 15) << 4); } for (Indice=0;Indice<16;Indice++) @@ -4323,16 +4293,16 @@ void Load_KCF(void) { case 12: // RRRR BBBB | 0000 VVVV read_bytes(Fichier,Octet,2); - Principal_Palette[Indice].R=(Octet[0] >> 4) << 2; - Principal_Palette[Indice].B=(Octet[0] & 15) << 2; - Principal_Palette[Indice].V=(Octet[1] & 15) << 2; + Principal_Palette[Indice].R=(Octet[0] >> 4) << 4; + Principal_Palette[Indice].B=(Octet[0] & 15) << 4; + Principal_Palette[Indice].V=(Octet[1] & 15) << 4; break; case 24: // RRRR RRRR | VVVV VVVV | BBBB BBBB read_bytes(Fichier,Octet,3); - Principal_Palette[Indice].R=Octet[0]>>2; - Principal_Palette[Indice].V=Octet[1]>>2; - Principal_Palette[Indice].B=Octet[2]>>2; + Principal_Palette[Indice].R=Octet[0]; + Principal_Palette[Indice].V=Octet[1]; + Principal_Palette[Indice].B=Octet[2]; } Indice++; @@ -4396,8 +4366,8 @@ void Save_KCF(void) for (Indice_couleur=0;Indice_couleur<16;Indice_couleur++) { Indice=16+(Indice_palette*16)+Indice_couleur; - Buffer.Palette[Indice_palette].Couleur[Indice_couleur].Octet1=((Principal_Palette[Indice].R>>2)<<4) | (Principal_Palette[Indice].B>>2); - Buffer.Palette[Indice_palette].Couleur[Indice_couleur].Octet2=Principal_Palette[Indice].V>>2; + Buffer.Palette[Indice_palette].Couleur[Indice_couleur].Octet1=((Principal_Palette[Indice].R>>4)<<4) | (Principal_Palette[Indice].B>>4); + Buffer.Palette[Indice_palette].Couleur[Indice_couleur].Octet2=Principal_Palette[Indice].V>>4; } if (! write_bytes(Fichier,&Buffer,sizeof(T_KCF_Header))) @@ -4423,9 +4393,9 @@ void Save_KCF(void) for (Indice=0;(Indice<256) && (!Erreur_fichier);Indice++) { - Octet[0]=Principal_Palette[Indice].R<<2; - Octet[1]=Principal_Palette[Indice].V<<2; - Octet[2]=Principal_Palette[Indice].B<<2; + Octet[0]=Principal_Palette[Indice].R; + Octet[1]=Principal_Palette[Indice].V; + Octet[2]=Principal_Palette[Indice].B; if (! write_bytes(Fichier,Octet,3)) Erreur_fichier=1; } @@ -4521,6 +4491,7 @@ void Load_SCx(void) if (Config.Clear_palette) memset(Principal_Palette,0,sizeof(T_Palette)); + Palette_64_to_256(SCx_Palette); memcpy(Principal_Palette,SCx_Palette,Taille); Set_palette(Principal_Palette); Remapper_fileselect(); @@ -4587,6 +4558,10 @@ void Save_SCx(void) // Ouverture du fichier if ((Fichier=fopen(Nom_du_fichier,"wb"))) { + T_Palette Palette_64; + memcpy(Palette_64,Principal_Palette,sizeof(T_Palette)); + Palette_256_to_64(Palette_64); + memcpy(SCx_Header.Filler1,"RIX3",4); SCx_Header.Largeur=Principal_Largeur_image; SCx_Header.Hauteur=Principal_Hauteur_image; @@ -4594,7 +4569,7 @@ void Save_SCx(void) SCx_Header.Plans=0x00; if (write_bytes(Fichier,&SCx_Header,sizeof(T_SCx_Header)) && - write_bytes(Fichier,&Principal_Palette,sizeof(T_Palette))) + write_bytes(Fichier,&Palette_64,sizeof(T_Palette))) { Init_ecriture(); @@ -4711,9 +4686,9 @@ void PI1_Decoder_palette(byte * Src,byte * Pal) w=((word)Src[(i*2)+1]<<8) | Src[(i*2)+0]; // Traitement des couleurs rouge, verte et bleue: - Pal[ip++]=(((w & 0x0007) << 1) | ((w & 0x0008) >> 3)) << 2; - Pal[ip++]=(((w & 0x7000) >> 11) | ((w & 0x8000) >> 15)) << 2; - Pal[ip++]=(((w & 0x0700) >> 7) | ((w & 0x0800) >> 11)) << 2; + Pal[ip++]=(((w & 0x0007) << 1) | ((w & 0x0008) >> 3)) << 4; + Pal[ip++]=(((w & 0x7000) >> 11) | ((w & 0x8000) >> 15)) << 4; + Pal[ip++]=(((w & 0x0700) >> 7) | ((w & 0x0800) >> 11)) << 4; } } @@ -4735,9 +4710,9 @@ void PI1_Coder_palette(byte * Pal,byte * Dst) for (i=0;i<16;i++) { // Traitement des couleurs rouge, verte et bleue: - w =(((word)Pal[ip] & 0x38) >> 3) | (((word)Pal[ip] & 0x04) << 1); ip++; - w|=(((word)Pal[ip] & 0x38) << 9) | (((word)Pal[ip] & 0x04) << 13); ip++; - w|=(((word)Pal[ip] & 0x38) << 5) | (((word)Pal[ip] & 0x04) << 9); ip++; + w =(((word)(Pal[ip]>>2) & 0x38) >> 3) | (((word)(Pal[ip]>>2) & 0x04) << 1); ip++; + w|=(((word)(Pal[ip]>>2) & 0x38) << 9) | (((word)(Pal[ip]>>2) & 0x04) << 13); ip++; + w|=(((word)(Pal[ip]>>2) & 0x38) << 5) | (((word)(Pal[ip]>>2) & 0x04) << 9); ip++; Dst[(i*2)+0]=w & 0x00FF; Dst[(i*2)+1]=(w>>8); diff --git a/op_c.c b/op_c.c index b925b414..87420485 100644 --- a/op_c.c +++ b/op_c.c @@ -34,7 +34,7 @@ -void rgb2hl(int r,int g,int b,byte * hr,byte * lr,byte* sr) +void RGBtoHSL(int r,int g,int b,byte * hr,byte * sr,byte* lr) { double rd,gd,bd,h,s,l,max,min; @@ -103,7 +103,7 @@ 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) +void HSLtoRGB(byte H,byte S,byte L, byte* R, byte* G, byte* B) { float rf =0 ,gf = 0,bf = 0; float hf,lf,sf; @@ -156,7 +156,7 @@ void HLStoRGB(byte H,byte L,byte S, byte* R, byte* G, byte* B) if (bf < 1/6.0) bf = p + ((q-p)*6*bf); - else if(rf < 0.5) + else if(bf < 0.5) bf = q; else if(bf < 2/3.0) bf = p + ((q-p)*6*(2/3.0-bf)); @@ -632,7 +632,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,&s); + RGBtoHSL(c->r,c->v,c->b,&c->h,&s,&c->l); } diff --git a/op_c.h b/op_c.h index 1a8f965b..d61bd1f2 100644 --- a/op_c.h +++ b/op_c.h @@ -147,8 +147,8 @@ 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, byte* s); -void HLStoRGB(byte h, byte l, byte s, byte* r, byte* g, byte* b); +void RGBtoHSL(int r, int v,int b, byte* h, byte*s, byte* l); +void HSLtoRGB(byte h, byte s, byte l, byte* r, byte* g, byte* b); ///////////////////////////////////////////////////////////////////////////// diff --git a/palette.c b/palette.c index 885c128b..e84eaff1 100644 --- a/palette.c +++ b/palette.c @@ -35,7 +35,7 @@ #include "erreurs.h" #include "op_c.h" -byte Palette_mode_RGB = 1; // Indique si on est en HSV ou en RGB +byte Palette_mode_RGB = 1; // Indique si on est en HSL ou en RGB // --------------------------- Menu des palettes ----------------------------- char * Libelle_reduction_palette[7]= @@ -43,13 +43,56 @@ char * Libelle_reduction_palette[7]= "128"," 64"," 32"," 16"," 8"," 4"," 2" }; +// Nombre de graduations pour une composante RGB +const int Graduations_RGB =256; // 24bit +//const int Graduations_RGB = 64; // VGA +//const int Graduations_RGB = 16; // Amiga +//const int Graduations_RGB = 3; // Amstrad CPC + + +// Nombre de graduations pour une composante dans le mode actuel +int Color_Count; +// Les composantes vont de 0 à (Color_Count-1) +int Color_Max; +// Le demi-pas est une quantité que l'on ajoute à une composante +// avant de faire un arrondi par division. +int Color_DemiPas; + +// Définir les unités pour les graduationss R G B ou H S V +void Unite_Composantes(int Count) +{ + Color_Count = Count; + Color_Max = Count-1; + Color_DemiPas = 256/Count/2; +} + +void Modifier_HSL(T_Palette Palette_depart, T_Palette Palette_arrivee, byte Couleur, short Difference_H, short Difference_S, short Difference_L) +{ + byte H, S, L; + RGBtoHSL(Palette_depart[Couleur].R,Palette_depart[Couleur].V,Palette_depart[Couleur].B,&H,&S,&L); + // La teinte (Hue) est cyclique + H=(Difference_H+256+H); + // Pour les autres (Saturation, Lightness), au lieu d'additionner, + // on va faire un ratio, cela utilise mieux la plage de valeurs 0-255 + if (Difference_S<0) + S=(255+Difference_S)*S/255; + else if (Difference_S>0) + S=255-(255-Difference_S)*(255-S)/255; + if (Difference_L<0) + L=(255+Difference_L)*L/255; + else if (Difference_L>0) + L=255-(255-Difference_L)*(255-L)/255; + HSLtoRGB(H,S,L,&Palette_arrivee[Couleur].R,&Palette_arrivee[Couleur].V,&Palette_arrivee[Couleur].B); +} void Modifier_Rouge(byte Couleur, short Nouvelle_teinte, T_Palette Palette) { if (Nouvelle_teinte< 0) Nouvelle_teinte= 0; - if (Nouvelle_teinte>63) - Nouvelle_teinte=63; + if (Nouvelle_teinte>255) + Nouvelle_teinte=255; + // Arrondi + Nouvelle_teinte=255*((Nouvelle_teinte+Color_DemiPas)*Color_Max/255)/Color_Max; Palette[Couleur].R=Nouvelle_teinte; Set_color(Couleur,Palette[Couleur].R,Palette[Couleur].V,Palette[Couleur].B); @@ -60,8 +103,10 @@ void Modifier_Vert(byte Couleur, short Nouvelle_teinte, T_Palette Palette) { if (Nouvelle_teinte< 0) Nouvelle_teinte= 0; - if (Nouvelle_teinte>63) - Nouvelle_teinte=63; + if (Nouvelle_teinte>255) + Nouvelle_teinte=255; + // Arrondi + Nouvelle_teinte=255*((Nouvelle_teinte+Color_DemiPas)*Color_Max/255)/Color_Max; Palette[Couleur].V=Nouvelle_teinte; Set_color(Couleur,Palette[Couleur].R,Palette[Couleur].V,Palette[Couleur].B); @@ -72,13 +117,22 @@ void Modifier_Bleu(byte Couleur, short Nouvelle_teinte, T_Palette Palette) { if (Nouvelle_teinte< 0) Nouvelle_teinte= 0; - if (Nouvelle_teinte>63) - Nouvelle_teinte=63; + if (Nouvelle_teinte>255) + Nouvelle_teinte=255; + // Arrondi + Nouvelle_teinte=255*((Nouvelle_teinte+Color_DemiPas)*Color_Max/255)/Color_Max; Palette[Couleur].B=Nouvelle_teinte; Set_color(Couleur,Palette[Couleur].R,Palette[Couleur].V,Palette[Couleur].B); } +void Formate_composante(byte Valeur, char *Chaine) +// Formate une chaine de 4 caractères+\0 : "nnn " +{ + Num2str(Valeur,Chaine,3); + Chaine[3]=' '; + Chaine[4]='\0'; +} void Degrader_palette(short Debut,short Fin,T_Palette Palette) // Modifie la palette pour obtenir un dégradé de couleur entre les deux bornes @@ -387,7 +441,7 @@ void Remettre_proprement_les_couleurs_du_menu(dword * Utilisation_couleur) void Reduce_palette(short * Nb_couleurs_utilisees,int Nb_couleurs_demandees,T_Palette Palette,dword * Utilisation_couleur) { - char Chaine[4]; // Buffer d'affichage du compteur + char Chaine[5]; // Buffer d'affichage du compteur byte Table_de_conversion[256]; // Table de conversion int Couleur_1; // |_ Variables de balayages int Couleur_2; // | de la palette @@ -581,7 +635,7 @@ void Palette_Modifier_jauge(struct Fenetre_Bouton_scroller * Jauge, Jauge->Position=Position; Calculer_hauteur_curseur_jauge(Jauge); Fenetre_Dessiner_jauge(Jauge); - Print_dans_fenetre(Pos_X,172,Valeur,CM_Noir,CM_Clair); + Print_compteur(Pos_X,172,Valeur,CM_Noir,CM_Clair); } @@ -591,22 +645,31 @@ void Afficher_les_jauges(struct Fenetre_Bouton_scroller * Jauge_rouge, struct Fenetre_Bouton_scroller * Jauge_bleue, byte Bloc_selectionne, struct Composantes * Palette) { - char Chaine[3]; + char Chaine[5]; if (Bloc_selectionne) { - Palette_Modifier_jauge(Jauge_rouge,127,63,"± 0",176); - Palette_Modifier_jauge(Jauge_verte,127,63,"± 0",203); - Palette_Modifier_jauge(Jauge_bleue,127,63,"± 0",230); + Palette_Modifier_jauge(Jauge_rouge,Color_Max*2+1,Color_Max,"± 0",176); + Palette_Modifier_jauge(Jauge_verte,Color_Max*2+1,Color_Max,"± 0",203); + Palette_Modifier_jauge(Jauge_bleue,Color_Max*2+1,Color_Max,"± 0",230); } else { - Num2str(Palette[Fore_color].R,Chaine,2); - Palette_Modifier_jauge(Jauge_rouge,64,63-Palette[Fore_color].R,Chaine,180); - Num2str(Palette[Fore_color].V,Chaine,2); - Palette_Modifier_jauge(Jauge_verte,64,63-Palette[Fore_color].V,Chaine,207); - Num2str(Palette[Fore_color].B,Chaine,2); - Palette_Modifier_jauge(Jauge_bleue,64,63-Palette[Fore_color].B,Chaine,234); + byte j1, j2, j3; + j1= Palette[Fore_color].R; + j2= Palette[Fore_color].V; + j3= Palette[Fore_color].B; + if (!Palette_mode_RGB) + { + RGBtoHSL(j1,j2,j3,&j1,&j2,&j3); + } + + Formate_composante(j1*Color_Max/255,Chaine); + Palette_Modifier_jauge(Jauge_rouge,Color_Count,Color_Max-j1*Color_Max/255,Chaine,176); + Formate_composante(j2*Color_Max/255,Chaine); + Palette_Modifier_jauge(Jauge_verte,Color_Count,Color_Max-j2*Color_Max/255,Chaine,203); + Formate_composante(j3*Color_Max/255,Chaine); + Palette_Modifier_jauge(Jauge_bleue,Color_Count,Color_Max-j3*Color_Max/255,Chaine,230); } } @@ -617,46 +680,50 @@ void Palette_Reafficher_jauges(struct Fenetre_Bouton_scroller * Jauge_rouge, struct Fenetre_Bouton_scroller * Jauge_bleue, T_Palette Palette,byte Debut,byte Fin) { - byte Couleur; - char Chaine[3]; + char Chaine[5]; Effacer_curseur(); // Réaffichage des jauges: if (Debut!=Fin) { // Dans le cas d'un bloc, tout à 0. - Jauge_rouge->Position =63; + Jauge_rouge->Position =Color_Max; Fenetre_Dessiner_jauge(Jauge_rouge); - Print_dans_fenetre(176,172,"± 0",CM_Noir,CM_Clair); + Print_compteur(176,172,"± 0",CM_Noir,CM_Clair); - Jauge_verte->Position =63; + Jauge_verte->Position =Color_Max; Fenetre_Dessiner_jauge(Jauge_verte); - Print_dans_fenetre(203,172,"± 0",CM_Noir,CM_Clair); + Print_compteur(203,172,"± 0",CM_Noir,CM_Clair); - Jauge_bleue->Position =63; + Jauge_bleue->Position =Color_Max; Fenetre_Dessiner_jauge(Jauge_bleue); - Print_dans_fenetre(230,172,"± 0",CM_Noir,CM_Clair); + Print_compteur(230,172,"± 0",CM_Noir,CM_Clair); } else { // Dans le cas d'une seule couleur, composantes. - Couleur=Palette[Debut].R; - Num2str(Couleur,Chaine,2); - Jauge_rouge->Position=63-Couleur; + byte j1, j2, j3; + j1= Palette[Debut].R; + j2= Palette[Debut].V; + j3= Palette[Debut].B; + if (!Palette_mode_RGB) + { + RGBtoHSL(j1,j2,j3,&j1,&j2,&j3); + } + Formate_composante(j1*Color_Max/255,Chaine); + Jauge_rouge->Position=Color_Max-j1*Color_Max/255; Fenetre_Dessiner_jauge(Jauge_rouge); - Print_dans_fenetre(180,172,Chaine,CM_Noir,CM_Clair); + Print_compteur(176,172,Chaine,CM_Noir,CM_Clair); - Couleur=Palette[Debut].V; - Num2str(Couleur,Chaine,2); - Jauge_verte->Position=63-Couleur; + Formate_composante(j2*Color_Max/255,Chaine); + Jauge_verte->Position=Color_Max-j2*Color_Max/255; Fenetre_Dessiner_jauge(Jauge_verte); - Print_dans_fenetre(207,172,Chaine,CM_Noir,CM_Clair); + Print_compteur(203,172,Chaine,CM_Noir,CM_Clair); - Couleur=Palette[Debut].B; - Num2str(Couleur,Chaine,2); - Jauge_bleue->Position=63-Couleur; + Formate_composante(j3*Color_Max/255,Chaine); + Jauge_bleue->Position=Color_Max-j3*Color_Max/255; Fenetre_Dessiner_jauge(Jauge_bleue); - Print_dans_fenetre(234,172,Chaine,CM_Noir,CM_Clair); + Print_compteur(230,172,Chaine,CM_Noir,CM_Clair); } Afficher_curseur(); } @@ -696,11 +763,12 @@ void Bouton_Palette(void) struct Composantes * Palette_temporaire; struct Composantes * Palette_de_travail; - Palette_backup =(struct Composantes *)malloc(sizeof(T_Palette)); Palette_temporaire=(struct Composantes *)malloc(sizeof(T_Palette)); Palette_de_travail=(struct Composantes *)malloc(sizeof(T_Palette)); + Unite_Composantes(Graduations_RGB); + Ouvrir_fenetre(299,188,"Palette"); memcpy(Palette_de_travail,Principal_Palette,sizeof(T_Palette)); @@ -726,11 +794,11 @@ void Bouton_Palette(void) Block(Fenetre_Pos_X+(Menu_Facteur_X*206),Fenetre_Pos_Y+(Menu_Facteur_Y*141),Menu_Facteur_X*17,Menu_Facteur_Y,CM_Fonce); Block(Fenetre_Pos_X+(Menu_Facteur_X*233),Fenetre_Pos_Y+(Menu_Facteur_Y*141),Menu_Facteur_X*17,Menu_Facteur_Y,CM_Fonce); // Jauges de couleur - Fenetre_Definir_bouton_scroller(182, 81, 88,64,1,63-Palette_de_travail[Fore_color].R);// 2 + Fenetre_Definir_bouton_scroller(182, 81, 88,Color_Count,1,Color_Max-Palette_de_travail[Fore_color].R*Color_Max/255);// 2 Jauge_rouge=Fenetre_Liste_boutons_scroller; - Fenetre_Definir_bouton_scroller(209, 81, 88,64,1,63-Palette_de_travail[Fore_color].V);// 3 + Fenetre_Definir_bouton_scroller(209, 81, 88,Color_Count,1,Color_Max-Palette_de_travail[Fore_color].V*Color_Max/255);// 3 Jauge_verte=Fenetre_Liste_boutons_scroller; - Fenetre_Definir_bouton_scroller(236, 81, 88,64,1,63-Palette_de_travail[Fore_color].B);// 4 + Fenetre_Definir_bouton_scroller(236, 81, 88,Color_Count,1,Color_Max-Palette_de_travail[Fore_color].B*Color_Max/255);// 4 Jauge_bleue=Fenetre_Liste_boutons_scroller; Print_dans_fenetre(184,71,"R",CM_Fonce,CM_Clair); Print_dans_fenetre(211,71,"G",CM_Fonce,CM_Clair); @@ -744,12 +812,12 @@ void Bouton_Palette(void) Block(Fenetre_Pos_X+(Menu_Facteur_X*264),Fenetre_Pos_Y+(Menu_Facteur_Y*93),Menu_Facteur_X<<4,Menu_Facteur_Y*64,Fore_color); // Affichage des valeurs de la couleur courante (pour 1 couleur) - Num2str(Principal_Palette[Fore_color].R,Chaine,2); - Print_dans_fenetre(180,172,Chaine,CM_Noir,CM_Clair); - Num2str(Principal_Palette[Fore_color].V,Chaine,2); - Print_dans_fenetre(207,172,Chaine,CM_Noir,CM_Clair); - Num2str(Principal_Palette[Fore_color].B,Chaine,2); - Print_dans_fenetre(234,172,Chaine,CM_Noir,CM_Clair); + Formate_composante(Principal_Palette[Fore_color].R*Color_Max/255,Chaine); + Print_compteur(176,172,Chaine,CM_Noir,CM_Clair); + Formate_composante(Principal_Palette[Fore_color].V*Color_Max/255,Chaine); + Print_compteur(203,172,Chaine,CM_Noir,CM_Clair); + Formate_composante(Principal_Palette[Fore_color].B*Color_Max/255,Chaine); + Print_compteur(230,172,Chaine,CM_Noir,CM_Clair); Print_dans_fenetre(129,58,"Color number:",CM_Fonce,CM_Clair); Num2str(Fore_color,Chaine,3); @@ -787,7 +855,7 @@ void Bouton_Palette(void) Fenetre_Definir_bouton_saisie(263,39,3); // 23 - Fenetre_Definir_bouton_normal(96,32,29,14,"HSV" ,1,1,SDLK_n); // 24 + Fenetre_Definir_bouton_normal(96,32,29,14,"HSL" ,1,1,SDLK_n); // 24 Fenetre_Definir_bouton_normal(96,47,29,14,"Srt" ,1,1,SDLK_o); // 25 // Affichage du facteur de réduction de la palette Num2str(Reduce_Nb_couleurs,Chaine,3); @@ -922,6 +990,7 @@ void Bouton_Palette(void) // Affichage dans le block de visu de la couleur en cours Block(Fenetre_Pos_X+(Menu_Facteur_X*264),Fenetre_Pos_Y+(Menu_Facteur_Y*93),Menu_Facteur_X<<4,Menu_Facteur_Y*64,Fore_color); + UpdateRect(Fenetre_Pos_X+(Menu_Facteur_X*264),Fenetre_Pos_Y+(Menu_Facteur_Y*93),Menu_Facteur_X<<4,Menu_Facteur_Y*64); } // On tagge le bloc (ou la couleur) @@ -938,112 +1007,130 @@ void Bouton_Palette(void) Effacer_curseur(); if (Debut_block==Fin_block) { - 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; - - DEBUG("ra",Palette_de_travail[Fore_color].R); - DEBUG("ga",Palette_de_travail[Fore_color].V); - DEBUG("ba",Palette_de_travail[Fore_color].B); - rgb2hl(Palette_de_travail[Fore_color].R*4,Palette_de_travail[Fore_color].V*4,Palette_de_travail[Fore_color].B*4,&h,&l,&s); - DEBUG("h",h); - DEBUG("l",l); - DEBUG("s",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); - - Palette_de_travail[Fore_color].R /= 4; // On ne compte que de 0 à 63 ici - Palette_de_travail[Fore_color].V /= 4; // On ne compte que de 0 à 63 ici - Palette_de_travail[Fore_color].B /= 4; // On ne compte que de 0 à 63 ici - - DEBUG("rb",Palette_de_travail[Fore_color].R); - DEBUG("gb",Palette_de_travail[Fore_color].V); - DEBUG("bb",Palette_de_travail[Fore_color].B); - Num2str((int)h>>2,Chaine,2); - } - Print_dans_fenetre(180,172,Chaine,CM_Noir,CM_Clair); + if(Palette_mode_RGB) + { + Modifier_Rouge(Fore_color,(Color_Max-Jauge_rouge->Position)*255/Color_Max,Palette_de_travail); + Formate_composante(Palette_de_travail[Fore_color].R*Color_Max/255,Chaine); + } + else + { + HSLtoRGB( + 255-Jauge_rouge->Position, + 255-Jauge_verte->Position, + 255-Jauge_bleue->Position, + &Palette_de_travail[Fore_color].R, + &Palette_de_travail[Fore_color].V, + &Palette_de_travail[Fore_color].B); + Formate_composante((int)255-Jauge_rouge->Position,Chaine); + } + Print_compteur(176,172,Chaine,CM_Noir,CM_Clair); } else { + if(Palette_mode_RGB) + { for (i=Debut_block; i<=Fin_block; i++) - Modifier_Rouge(i,Palette_temporaire[i].R+63-Jauge_rouge->Position,Palette_de_travail); + Modifier_Rouge(i,Palette_temporaire[i].R+(Color_Max-Jauge_rouge->Position)*255/Color_Max,Palette_de_travail); + } + else + { + for (i=Debut_block; i<=Fin_block; i++) + Modifier_HSL( + Palette_temporaire, + Palette_de_travail, + i, + Color_Max-Jauge_rouge->Position, + Color_Max-Jauge_verte->Position, + Color_Max-Jauge_bleue->Position + ); + } - if (Jauge_rouge->Position>63) + if (Jauge_rouge->Position>Color_Max) { // Jauge dans les négatifs: - Num2str(-(63-Jauge_rouge->Position),Chaine,3); + Num2str(-(Color_Max-Jauge_rouge->Position),Chaine,4); Chaine[0]='-'; } - else if (Jauge_rouge->Position<63) + else if (Jauge_rouge->PositionPosition ,Chaine,3); + Num2str( Color_Max-Jauge_rouge->Position ,Chaine,4); Chaine[0]='+'; } else { // Jauge nulle: - strcpy(Chaine,"± 0"); + strcpy(Chaine,"± 0"); } - Print_dans_fenetre(176,172,Chaine,CM_Noir,CM_Clair); + Print_compteur(176,172,Chaine,CM_Noir,CM_Clair); } Il_faut_remapper=1; Afficher_curseur(); - Set_palette(Palette_de_travail); + Set_palette(Palette_de_travail); break; case 3 : // Jauge verte Effacer_curseur(); if (Debut_block==Fin_block) { - 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); + if(Palette_mode_RGB) + { + Modifier_Vert (Fore_color,(Color_Max-Jauge_verte->Position)*255/Color_Max,Palette_de_travail); + Formate_composante(Palette_de_travail[Fore_color].V*Color_Max/255,Chaine); + } + else + { + HSLtoRGB( + 255-Jauge_rouge->Position, + 255-Jauge_verte->Position, + 255-Jauge_bleue->Position, + &Palette_de_travail[Fore_color].R, + &Palette_de_travail[Fore_color].V, + &Palette_de_travail[Fore_color].B); + Formate_composante((int)255-Jauge_verte->Position,Chaine); + } + Print_compteur(203,172,Chaine,CM_Noir,CM_Clair); } else { + if(Palette_mode_RGB) + { + for (i=Debut_block; i<=Fin_block; i++) + Modifier_Vert (i,Palette_temporaire[i].V+(Color_Max-Jauge_verte->Position)*255/Color_Max,Palette_de_travail); + } + else + { for (i=Debut_block; i<=Fin_block; i++) - Modifier_Vert (i,Palette_temporaire[i].V+63-Jauge_verte->Position,Palette_de_travail); + Modifier_HSL( + Palette_temporaire, + Palette_de_travail, + i, + Color_Max-Jauge_rouge->Position, + Color_Max-Jauge_verte->Position, + Color_Max-Jauge_bleue->Position + ); + } - if (Jauge_verte->Position>63) + if (Jauge_verte->Position>Color_Max) { // Jauge dans les négatifs: - Num2str(-(63-Jauge_verte->Position),Chaine,3); + Num2str(-(Color_Max-Jauge_verte->Position),Chaine,4); Chaine[0]='-'; } - else if (Jauge_verte->Position<63) + else if (Jauge_verte->PositionPosition ,Chaine,3); + Num2str( Color_Max-Jauge_verte->Position ,Chaine,4); Chaine[0]='+'; } else { // Jauge nulle: - strcpy(Chaine,"± 0"); + strcpy(Chaine,"± 0"); } - Print_dans_fenetre(203,172,Chaine,CM_Noir,CM_Clair); + Print_compteur(203,172,Chaine,CM_Noir,CM_Clair); } Il_faut_remapper=1; @@ -1056,33 +1143,62 @@ void Bouton_Palette(void) Effacer_curseur(); if (Debut_block==Fin_block) { - Modifier_Bleu (Fore_color,63-Jauge_bleue->Position,Palette_de_travail); - Num2str(Palette_de_travail[Fore_color].B,Chaine,2); - Print_dans_fenetre(234,172,Chaine,CM_Noir,CM_Clair); + if(Palette_mode_RGB) + { + Modifier_Bleu (Fore_color,(Color_Max-Jauge_bleue->Position)*255/Color_Max,Palette_de_travail); + Formate_composante(Palette_de_travail[Fore_color].B*Color_Max/255,Chaine); + } + else + { + HSLtoRGB( + 255-Jauge_rouge->Position, + 255-Jauge_verte->Position, + 255-Jauge_bleue->Position, + &Palette_de_travail[Fore_color].R, + &Palette_de_travail[Fore_color].V, + &Palette_de_travail[Fore_color].B); + Formate_composante((int)255-Jauge_bleue->Position,Chaine); + } + Print_compteur(230,172,Chaine,CM_Noir,CM_Clair); } else { + if(Palette_mode_RGB) + { for (i=Debut_block; i<=Fin_block; i++) - Modifier_Bleu(i,Palette_temporaire[i].B+63-Jauge_bleue->Position,Palette_de_travail); + Modifier_Bleu(i,Palette_temporaire[i].B+(Color_Max-Jauge_bleue->Position)*255/Color_Max,Palette_de_travail); + } + else + { + for (i=Debut_block; i<=Fin_block; i++) + Modifier_HSL( + Palette_temporaire, + Palette_de_travail, + i, + Color_Max-Jauge_rouge->Position, + Color_Max-Jauge_verte->Position, + Color_Max-Jauge_bleue->Position + ); + } - if (Jauge_bleue->Position>63) + if (Jauge_bleue->Position>Color_Max) { // Jauge dans les négatifs: - Num2str(-(63-Jauge_bleue->Position),Chaine,3); + Num2str(-(Color_Max-Jauge_bleue->Position),Chaine,4); Chaine[0]='-'; } - else if (Jauge_bleue->Position<63) + else if (Jauge_bleue->PositionPosition ,Chaine,3); + Num2str( Color_Max-Jauge_bleue->Position ,Chaine,4); Chaine[0]='+'; } else { // Jauge nulle: - strcpy(Chaine,"± 0"); + strcpy(Chaine,"± 0"); } - Print_dans_fenetre(230,172,Chaine,CM_Noir,CM_Clair); + Print_compteur(230,172,Chaine,CM_Noir,CM_Clair); } Il_faut_remapper=1; @@ -1116,7 +1232,7 @@ void Bouton_Palette(void) } Palette_Reafficher_jauges(Jauge_rouge,Jauge_verte,Jauge_bleue,Palette_de_travail,Debut_block,Fin_block); // On prépare la "modifiabilité" des nouvelles couleurs - Set_palette(Palette_de_travail); + Set_palette(Palette_de_travail); memcpy(Palette_temporaire,Palette_de_travail,sizeof(T_Palette)); Il_faut_remapper=1; @@ -1174,7 +1290,7 @@ void Bouton_Palette(void) Il_faut_remapper=1; - Set_palette(Palette_de_travail); + Set_palette(Palette_de_travail); Afficher_curseur(); Palette_Reafficher_jauges(Jauge_rouge,Jauge_verte,Jauge_bleue,Palette_de_travail,Debut_block,Fin_block); @@ -1250,7 +1366,7 @@ void Bouton_Palette(void) Palette_Reafficher_jauges(Jauge_rouge,Jauge_verte,Jauge_bleue,Palette_de_travail,Debut_block,Fin_block); // On prépare la "modifiabilité" des nouvelles couleurs - Set_palette(Palette_de_travail); + Set_palette(Palette_de_travail); memcpy(Palette_temporaire,Palette_de_travail,sizeof(T_Palette)); @@ -1340,6 +1456,8 @@ void Bouton_Palette(void) break; case 18 : // [+] + if (!Palette_mode_RGB) + break; Effacer_curseur(); if (Debut_block==Fin_block) { @@ -1347,25 +1465,25 @@ void Bouton_Palette(void) { (Jauge_rouge->Position)--; Fenetre_Dessiner_jauge(Jauge_rouge); - Modifier_Rouge(Fore_color,63-Jauge_rouge->Position,Palette_de_travail); - Num2str(Palette_de_travail[Fore_color].R,Chaine,2); - Print_dans_fenetre(180,172,Chaine,CM_Noir,CM_Clair); + Modifier_Rouge(Fore_color,(Color_Max-Jauge_rouge->Position)*255/Color_Max,Palette_de_travail); + Formate_composante(Palette_de_travail[Fore_color].R*Color_Max/255,Chaine); + Print_compteur(176,172,Chaine,CM_Noir,CM_Clair); } if (Jauge_verte->Position) { (Jauge_verte->Position)--; Fenetre_Dessiner_jauge(Jauge_verte); - Modifier_Vert (Fore_color,63-Jauge_verte->Position,Palette_de_travail); - Num2str(Palette_de_travail[Fore_color].V,Chaine,2); - Print_dans_fenetre(207,172,Chaine,CM_Noir,CM_Clair); + Modifier_Vert (Fore_color,(Color_Max-Jauge_verte->Position)*255/Color_Max,Palette_de_travail); + Formate_composante(Palette_de_travail[Fore_color].V*Color_Max/255,Chaine); + Print_compteur(203,172,Chaine,CM_Noir,CM_Clair); } if (Jauge_bleue->Position) { (Jauge_bleue->Position)--; Fenetre_Dessiner_jauge(Jauge_bleue); - Modifier_Bleu (Fore_color,63-Jauge_bleue->Position,Palette_de_travail); - Num2str(Palette_de_travail[Fore_color].B,Chaine,2); - Print_dans_fenetre(234,172,Chaine,CM_Noir,CM_Clair); + Modifier_Bleu (Fore_color,(Color_Max-Jauge_bleue->Position)*255/Color_Max,Palette_de_travail); + Formate_composante(Palette_de_travail[Fore_color].B*Color_Max/255,Chaine); + Print_compteur(230,172,Chaine,CM_Noir,CM_Clair); } } else @@ -1388,122 +1506,124 @@ void Bouton_Palette(void) for (i=Debut_block; i<=Fin_block; i++) { - Modifier_Rouge(i,Palette_temporaire[i].R+63-Jauge_rouge->Position,Palette_de_travail); - Modifier_Vert (i,Palette_temporaire[i].V+63-Jauge_verte->Position,Palette_de_travail); - Modifier_Bleu (i,Palette_temporaire[i].B+63-Jauge_bleue->Position,Palette_de_travail); + Modifier_Rouge(i,Palette_temporaire[i].R+(Color_Max-Jauge_rouge->Position)*255/Color_Max,Palette_de_travail); + Modifier_Vert (i,Palette_temporaire[i].V+(Color_Max-Jauge_verte->Position)*255/Color_Max,Palette_de_travail); + Modifier_Bleu (i,Palette_temporaire[i].B+(Color_Max-Jauge_bleue->Position)*255/Color_Max,Palette_de_travail); } // -- Rouge -- - if (Jauge_rouge->Position>63) + if (Jauge_rouge->Position>Color_Max) { // Jauge dans les négatifs: - Num2str(-(63-Jauge_rouge->Position),Chaine,3); + Num2str(-(Color_Max-Jauge_rouge->Position),Chaine,4); Chaine[0]='-'; } - else if (Jauge_rouge->Position<63) + else if (Jauge_rouge->PositionPosition ,Chaine,3); + Num2str( Color_Max-Jauge_rouge->Position ,Chaine,4); Chaine[0]='+'; } else { // Jauge nulle: - strcpy(Chaine,"± 0"); + strcpy(Chaine,"± 0"); } - Print_dans_fenetre(176,172,Chaine,CM_Noir,CM_Clair); + Print_compteur(176,172,Chaine,CM_Noir,CM_Clair); // -- Vert -- - if (Jauge_verte->Position>63) + if (Jauge_verte->Position>Color_Max) { // Jauge dans les négatifs: - Num2str(-(63-Jauge_verte->Position),Chaine,3); + Num2str(-(Color_Max-Jauge_verte->Position),Chaine,4); Chaine[0]='-'; } - else if (Jauge_verte->Position<63) + else if (Jauge_verte->PositionPosition ,Chaine,3); + Num2str( Color_Max-Jauge_verte->Position ,Chaine,4); Chaine[0]='+'; } else { // Jauge nulle: - strcpy(Chaine,"± 0"); + strcpy(Chaine,"± 0"); } - Print_dans_fenetre(203,172,Chaine,CM_Noir,CM_Clair); + Print_compteur(203,172,Chaine,CM_Noir,CM_Clair); // -- Bleu -- - if (Jauge_bleue->Position>63) + if (Jauge_bleue->Position>Color_Max) { // Jauge dans les négatifs: - Num2str(-(63-Jauge_bleue->Position),Chaine,3); + Num2str(-(Color_Max-Jauge_bleue->Position),Chaine,4); Chaine[0]='-'; } - else if (Jauge_bleue->Position<63) + else if (Jauge_bleue->PositionPosition ,Chaine,3); + Num2str( Color_Max-Jauge_bleue->Position ,Chaine,4); Chaine[0]='+'; } else { // Jauge nulle: - strcpy(Chaine,"± 0"); + strcpy(Chaine,"± 0"); } - Print_dans_fenetre(230,172,Chaine,CM_Noir,CM_Clair); + Print_compteur(230,172,Chaine,CM_Noir,CM_Clair); } Il_faut_remapper=1; Afficher_curseur(); - Set_palette(Palette_de_travail); + Set_palette(Palette_de_travail); break; case 19 : // [-] + if (!Palette_mode_RGB) + break; Effacer_curseur(); if (Debut_block==Fin_block) { - if (Jauge_rouge->Position<63) + if (Jauge_rouge->PositionPosition)++; Fenetre_Dessiner_jauge(Jauge_rouge); - Modifier_Rouge(Fore_color,63-Jauge_rouge->Position,Palette_de_travail); - Num2str(Palette_de_travail[Fore_color].R,Chaine,2); - Print_dans_fenetre(180,172,Chaine,CM_Noir,CM_Clair); + Modifier_Rouge(Fore_color,(Color_Max-Jauge_rouge->Position)*255/Color_Max,Palette_de_travail); + Formate_composante(Palette_de_travail[Fore_color].R*Color_Max/255,Chaine); + Print_compteur(176,172,Chaine,CM_Noir,CM_Clair); } - if (Jauge_verte->Position<63) + if (Jauge_verte->PositionPosition)++; Fenetre_Dessiner_jauge(Jauge_verte); - Modifier_Vert (Fore_color,63-Jauge_verte->Position,Palette_de_travail); - Num2str(Palette_de_travail[Fore_color].V,Chaine,2); - Print_dans_fenetre(207,172,Chaine,CM_Noir,CM_Clair); + Modifier_Vert (Fore_color,(Color_Max-Jauge_verte->Position)*255/Color_Max,Palette_de_travail); + Formate_composante(Palette_de_travail[Fore_color].V*Color_Max/255,Chaine); + Print_compteur(203,172,Chaine,CM_Noir,CM_Clair); } - if (Jauge_bleue->Position<63) + if (Jauge_bleue->PositionPosition)++; Fenetre_Dessiner_jauge(Jauge_bleue); - Modifier_Bleu (Fore_color,63-Jauge_bleue->Position,Palette_de_travail); - Num2str(Palette_de_travail[Fore_color].B,Chaine,2); - Print_dans_fenetre(234,172,Chaine,CM_Noir,CM_Clair); + Modifier_Bleu (Fore_color,(Color_Max-Jauge_bleue->Position)*255/Color_Max,Palette_de_travail); + Formate_composante(Palette_de_travail[Fore_color].B*Color_Max/255,Chaine); + Print_compteur(230,172,Chaine,CM_Noir,CM_Clair); } } else { - if (Jauge_rouge->Position<126) + if (Jauge_rouge->Position<(Color_Max*2)) { (Jauge_rouge->Position)++; Fenetre_Dessiner_jauge(Jauge_rouge); } - if (Jauge_verte->Position<126) + if (Jauge_verte->Position<(Color_Max*2)) { (Jauge_verte->Position)++; Fenetre_Dessiner_jauge(Jauge_verte); } - if (Jauge_bleue->Position<126) + if (Jauge_bleue->Position<(Color_Max*2)) { (Jauge_bleue->Position)++; Fenetre_Dessiner_jauge(Jauge_bleue); @@ -1511,78 +1631,78 @@ void Bouton_Palette(void) for (i=Debut_block; i<=Fin_block; i++) { - Modifier_Rouge(i,Palette_temporaire[i].R+63-Jauge_rouge->Position,Palette_de_travail); - Modifier_Vert (i,Palette_temporaire[i].V+63-Jauge_verte->Position,Palette_de_travail); - Modifier_Bleu (i,Palette_temporaire[i].B+63-Jauge_bleue->Position,Palette_de_travail); + Modifier_Rouge(i,Palette_temporaire[i].R+(Color_Max-Jauge_rouge->Position)*255/Color_Max,Palette_de_travail); + Modifier_Vert (i,Palette_temporaire[i].V+(Color_Max-Jauge_verte->Position)*255/Color_Max,Palette_de_travail); + Modifier_Bleu (i,Palette_temporaire[i].B+(Color_Max-Jauge_bleue->Position)*255/Color_Max,Palette_de_travail); } // -- Rouge -- - if (Jauge_rouge->Position>63) + if (Jauge_rouge->Position>Color_Max) { // Jauge dans les négatifs: - Num2str(-(63-Jauge_rouge->Position),Chaine,3); + Num2str(-(Color_Max-Jauge_rouge->Position),Chaine,4); Chaine[0]='-'; } - else if (Jauge_rouge->Position<63) + else if (Jauge_rouge->PositionPosition ,Chaine,3); + Num2str( Color_Max-Jauge_rouge->Position ,Chaine,4); Chaine[0]='+'; } else { // Jauge nulle: - strcpy(Chaine,"± 0"); + strcpy(Chaine,"± 0"); } - Print_dans_fenetre(176,172,Chaine,CM_Noir,CM_Clair); + Print_compteur(176,172,Chaine,CM_Noir,CM_Clair); // -- Vert -- - if (Jauge_verte->Position>63) + if (Jauge_verte->Position>Color_Max) { // Jauge dans les négatifs: - Num2str(-(63-Jauge_verte->Position),Chaine,3); + Num2str(-(Color_Max-Jauge_verte->Position),Chaine,4); Chaine[0]='-'; } - else if (Jauge_verte->Position<63) + else if (Jauge_verte->PositionPosition ,Chaine,3); + Num2str( Color_Max-Jauge_verte->Position ,Chaine,4); Chaine[0]='+'; } else { // Jauge nulle: - strcpy(Chaine,"± 0"); + strcpy(Chaine,"± 0"); } - Print_dans_fenetre(203,172,Chaine,CM_Noir,CM_Clair); + Print_compteur(203,172,Chaine,CM_Noir,CM_Clair); // -- Bleu -- - if (Jauge_bleue->Position>63) + if (Jauge_bleue->Position>Color_Max) { // Jauge dans les négatifs: - Num2str(-(63-Jauge_bleue->Position),Chaine,3); + Num2str(-(Color_Max-Jauge_bleue->Position),Chaine,4); Chaine[0]='-'; } - else if (Jauge_bleue->Position<63) + else if (Jauge_bleue->PositionPosition ,Chaine,3); + Num2str( Color_Max-Jauge_bleue->Position ,Chaine,4); Chaine[0]='+'; } else { // Jauge nulle: - strcpy(Chaine,"± 0"); + strcpy(Chaine,"± 0"); } - Print_dans_fenetre(230,172,Chaine,CM_Noir,CM_Clair); + Print_compteur(230,172,Chaine,CM_Noir,CM_Clair); } Il_faut_remapper=1; Afficher_curseur(); - Set_palette(Palette_de_travail); + Set_palette(Palette_de_travail); break; case 20 : // Negative @@ -1591,12 +1711,12 @@ void Bouton_Palette(void) // Negative for (i=Debut_block;i<=Fin_block;i++) { - Modifier_Rouge(i,63-Palette_de_travail[i].R,Palette_de_travail); - Modifier_Vert (i,63-Palette_de_travail[i].V,Palette_de_travail); - Modifier_Bleu (i,63-Palette_de_travail[i].B,Palette_de_travail); + Modifier_Rouge(i,255-Palette_de_travail[i].R,Palette_de_travail); + Modifier_Vert (i,255-Palette_de_travail[i].V,Palette_de_travail); + Modifier_Bleu (i,255-Palette_de_travail[i].B,Palette_de_travail); } Palette_Reafficher_jauges(Jauge_rouge,Jauge_verte,Jauge_bleue,Palette_de_travail,Debut_block,Fin_block); - Set_palette(Palette_de_travail); + Set_palette(Palette_de_travail); // On prépare la "modifiabilité" des nouvelles couleurs memcpy(Palette_temporaire,Palette_de_travail,sizeof(T_Palette)); @@ -1641,7 +1761,7 @@ void Bouton_Palette(void) Afficher_curseur(); } // On prépare la "modifiabilité" des nouvelles couleurs - Set_palette(Palette_de_travail); + Set_palette(Palette_de_travail); memcpy(Palette_temporaire,Palette_de_travail,sizeof(T_Palette)); Il_faut_remapper=1; @@ -1671,74 +1791,81 @@ void Bouton_Palette(void) Afficher_curseur(); break; - case 24 : // HSV <> RGB - // TODO unfinished ! - if(Palette_mode_RGB) - { - // On passe en HSV - Print_dans_fenetre(184,71,"H",CM_Fonce,CM_Clair); - Print_dans_fenetre(211,71,"S",CM_Fonce,CM_Clair); - Print_dans_fenetre(238,71,"V",CM_Fonce,CM_Clair); - } - else - { - // On passe en RGB - Print_dans_fenetre(184,71,"R",CM_Fonce,CM_Clair); - Print_dans_fenetre(211,71,"G",CM_Fonce,CM_Clair); - Print_dans_fenetre(238,71,"B",CM_Fonce,CM_Clair); - } + case 24 : // HSL <> RGB + + // Acte les changements en cours sur une ou plusieurs couleurs + memcpy(Palette_temporaire,Palette_de_travail,sizeof(T_Palette)); + memcpy(Palette_backup ,Palette_de_travail,sizeof(T_Palette)); - Palette_mode_RGB = !Palette_mode_RGB ; - break; + Palette_mode_RGB = !Palette_mode_RGB; - case 25 : // Sort palette - { - byte h = 0, l = 0, s=0; - byte oh=0,ol=0,os=0; // Valeur pour la couleur précédente - int swap=1; + if(! Palette_mode_RGB) + { + // On passe en HSL + Print_dans_fenetre(184,71,"H",CM_Fonce,CM_Clair); + Print_dans_fenetre(211,71,"S",CM_Fonce,CM_Clair); + Print_dans_fenetre(238,71,"L",CM_Fonce,CM_Clair); + Unite_Composantes(256); + } + else + { + // On passe en RGB + Print_dans_fenetre(184,71,"R",CM_Fonce,CM_Clair); + Print_dans_fenetre(211,71,"G",CM_Fonce,CM_Clair); + Print_dans_fenetre(238,71,"B",CM_Fonce,CM_Clair); + Unite_Composantes(Graduations_RGB); + } + Afficher_les_jauges(Jauge_rouge,Jauge_verte,Jauge_bleue,(Debut_block!=Fin_block),Palette_de_travail); + break; - while(swap==1) - { - swap=0; - h=0;l=0;s=0; - for(Couleur_temporaire=0;Couleur_temporaire<256;Couleur_temporaire++) - { - 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,&s); - - if( - ((s==0) && (os>0)) // Un gris passe devant une couleur saturée - || (((s>0 && os > 0) || (s==os && s==0)) // Deux couleurs saturées ou deux gris... - && (h0)) // Un gris passe devant une couleur saturée + || (((s>0 && os > 0) || (s==os && s==0)) // Deux couleurs saturées ou deux gris... + && (hNb_elements=64; - Jauge_rouge->Position =63-Palette_de_travail[Fore_color].R; - Calculer_hauteur_curseur_jauge(Jauge_rouge); - Fenetre_Dessiner_jauge(Jauge_rouge); - Num2str(Palette_de_travail[Fore_color].R,Chaine,2); - Print_dans_fenetre(180,172,Chaine,CM_Noir,CM_Clair); - - Jauge_verte->Nb_elements=64; - Jauge_verte->Position =63-Palette_de_travail[Fore_color].V; - Calculer_hauteur_curseur_jauge(Jauge_verte); - Fenetre_Dessiner_jauge(Jauge_verte); - Num2str(Palette_de_travail[Fore_color].V,Chaine,2); - Print_dans_fenetre(207,172,Chaine,CM_Noir,CM_Clair); - - Jauge_bleue->Nb_elements=64; - Jauge_bleue->Position =63-Palette_de_travail[Fore_color].B; - Calculer_hauteur_curseur_jauge(Jauge_bleue); - Fenetre_Dessiner_jauge(Jauge_bleue); - Num2str(Palette_de_travail[Fore_color].B,Chaine,2); - Print_dans_fenetre(234,172,Chaine,CM_Noir,CM_Clair); + Afficher_les_jauges(Jauge_rouge,Jauge_verte,Jauge_bleue,0,Palette_de_travail); // Affichage dans le block de visu de la couleur en cours Block(Fenetre_Pos_X+(Menu_Facteur_X*264),Fenetre_Pos_Y+(Menu_Facteur_Y*93),Menu_Facteur_X<<4,Menu_Facteur_Y*64,Fore_color); - + UpdateRect(Fenetre_Pos_X+(Menu_Facteur_X*264),Fenetre_Pos_Y+(Menu_Facteur_Y*93),Menu_Facteur_X<<4,Menu_Facteur_Y*64); + memcpy(Palette_backup ,Palette_de_travail,sizeof(T_Palette)); memcpy(Palette_temporaire,Palette_de_travail,sizeof(T_Palette)); } @@ -1893,7 +2004,7 @@ void Bouton_Palette(void) Block(Fenetre_Pos_X+(Menu_Facteur_X*260),Fenetre_Pos_Y+(Menu_Facteur_Y*89),Menu_Facteur_X*24,Menu_Facteur_Y*72,Back_color); Bloc_degrade_dans_fenetre(264,93,Debut_block,Fin_block); - UpdateRect(Fenetre_Pos_X+8*Menu_Facteur_X,Fenetre_Pos_Y+82*Menu_Facteur_Y,Menu_Facteur_X*16*10,Menu_Facteur_Y*5*16); + UpdateRect(Fenetre_Pos_X+8*Menu_Facteur_X,Fenetre_Pos_Y+82*Menu_Facteur_Y,Menu_Facteur_X*16*10,Menu_Facteur_Y*5*16); Afficher_curseur(); Il_faut_remapper=0; diff --git a/readini.c b/readini.c index cfe70de7..24c5b56e 100644 --- a/readini.c +++ b/readini.c @@ -468,9 +468,9 @@ int Charger_INI(struct S_Config * Conf) Conf->Coul_menu_pref[0].R=0; Conf->Coul_menu_pref[0].V=0; Conf->Coul_menu_pref[0].B=0; - Conf->Coul_menu_pref[3].R=63; - Conf->Coul_menu_pref[3].V=63; - Conf->Coul_menu_pref[3].B=63; + Conf->Coul_menu_pref[3].R=255; + Conf->Coul_menu_pref[3].V=255; + Conf->Coul_menu_pref[3].B=255; if ((Retour=Charger_INI_Get_values (Fichier,Buffer,"Light_color",3,Valeurs))) goto Erreur_Retour; @@ -480,9 +480,9 @@ int Charger_INI(struct S_Config * Conf) goto Erreur_ERREUR_INI_CORROMPU; if ((Valeurs[2]<0) || (Valeurs[2]>63)) goto Erreur_ERREUR_INI_CORROMPU; - Conf->Coul_menu_pref[2].R=Valeurs[0]; - Conf->Coul_menu_pref[2].V=Valeurs[1]; - Conf->Coul_menu_pref[2].B=Valeurs[2]; + Conf->Coul_menu_pref[2].R=(Valeurs[0]<<2)|(Valeurs[0]>>4); + Conf->Coul_menu_pref[2].V=(Valeurs[1]<<2)|(Valeurs[1]>>4); + Conf->Coul_menu_pref[2].B=(Valeurs[2]<<2)|(Valeurs[2]>>4); if ((Retour=Charger_INI_Get_values (Fichier,Buffer,"Dark_color",3,Valeurs))) goto Erreur_Retour; @@ -492,9 +492,9 @@ int Charger_INI(struct S_Config * Conf) goto Erreur_ERREUR_INI_CORROMPU; if ((Valeurs[2]<0) || (Valeurs[2]>63)) goto Erreur_ERREUR_INI_CORROMPU; - Conf->Coul_menu_pref[1].R=Valeurs[0]; - Conf->Coul_menu_pref[1].V=Valeurs[1]; - Conf->Coul_menu_pref[1].B=Valeurs[2]; + Conf->Coul_menu_pref[1].R=(Valeurs[0]<<2)|(Valeurs[0]>>4); + Conf->Coul_menu_pref[1].V=(Valeurs[1]<<2)|(Valeurs[1]>>4); + Conf->Coul_menu_pref[1].B=(Valeurs[2]<<2)|(Valeurs[2]>>4); if ((Retour=Charger_INI_Get_values (Fichier,Buffer,"Menu_ratio",1,Valeurs))) goto Erreur_Retour; diff --git a/saveini.c b/saveini.c index e1b6dc68..6168c63c 100644 --- a/saveini.c +++ b/saveini.c @@ -461,15 +461,15 @@ int Sauver_INI(struct S_Config * Conf) if ((Retour=Sauver_INI_Reach_group(Ancien_fichier,Nouveau_fichier,Buffer,"[MENU]"))) goto Erreur_Retour; - Valeurs[0]=Conf->Coul_menu_pref[2].R; - Valeurs[1]=Conf->Coul_menu_pref[2].V; - Valeurs[2]=Conf->Coul_menu_pref[2].B; + Valeurs[0]=Conf->Coul_menu_pref[2].R>>2; + Valeurs[1]=Conf->Coul_menu_pref[2].V>>2; + Valeurs[2]=Conf->Coul_menu_pref[2].B>>2; if ((Retour=Sauver_INI_Set_values (Ancien_fichier,Nouveau_fichier,Buffer,"Light_color",3,Valeurs,0))) goto Erreur_Retour; - Valeurs[0]=Conf->Coul_menu_pref[1].R; - Valeurs[1]=Conf->Coul_menu_pref[1].V; - Valeurs[2]=Conf->Coul_menu_pref[1].B; + Valeurs[0]=Conf->Coul_menu_pref[1].R>>2; + Valeurs[1]=Conf->Coul_menu_pref[1].V>>2; + Valeurs[2]=Conf->Coul_menu_pref[1].B>>2; if ((Retour=Sauver_INI_Set_values (Ancien_fichier,Nouveau_fichier,Buffer,"Dark_color",3,Valeurs,0))) goto Erreur_Retour; diff --git a/sdlscreen.c b/sdlscreen.c index 3e41aa91..214a5ce3 100644 --- a/sdlscreen.c +++ b/sdlscreen.c @@ -633,9 +633,9 @@ byte * Surface_en_bytefield(SDL_Surface *Source, byte * Destination) SDL_Color Conversion_couleur_SDL(byte Index) { SDL_Color Couleur; - Couleur.r = (Principal_Palette[Index].R<<2) + (Principal_Palette[Index].R>>4); - Couleur.g = (Principal_Palette[Index].V<<2) + (Principal_Palette[Index].V>>4); - Couleur.b = (Principal_Palette[Index].B<<2) + (Principal_Palette[Index].B>>4); + Couleur.r = Principal_Palette[Index].R; + Couleur.g = Principal_Palette[Index].V; + Couleur.b = Principal_Palette[Index].B; Couleur.unused = 255; return Couleur; }