From dc4abe6245a55f48d353040dde7db2299311a29b Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Tue, 13 Jan 2009 23:48:33 +0000 Subject: [PATCH] Added palette constraint modes: Run the program with command-line option "/rgb " to force RGB components have N levels instead of 256. Ex: /rgb 16 enforces a classic Amiga 4096 color palette, 64 is PC VGA, /rgb 3 is Amstrad CPC...) Added missing messages for /wide and /tall command-line arguments. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@477 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- Makefile.dep | 27 +++++++++++++++++---------- divers.c | 7 ++++--- main.c | 43 +++++++++++++++++++++++++++++++++++-------- palette.c | 34 +++++++++++++++++++++++----------- palette.h | 8 ++++++++ 5 files changed, 87 insertions(+), 32 deletions(-) diff --git a/Makefile.dep b/Makefile.dep index 651d2e83..ae1f57c3 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -3,11 +3,14 @@ $(OBJDIR)/aide.o: aide.c const.h struct.h global.h loadsave.h divers.h graph.h \ moteur.h tables_aide.h aide.h sdlscreen.h texte.h clavier.h windows.h $(OBJDIR)/boutons.o: boutons.c const.h struct.h global.h loadsave.h divers.h \ graph.h moteur.h readline.h files.h init.h boutons.h operatio.h pages.h \ - erreurs.h readini.h saveini.h shade.h io.h aide.h texte.h sdlscreen.h windows.h brush.h -$(OBJDIR)/brush.o: brush.c brush.h erreurs.h windows.h sdlscreen.h + erreurs.h readini.h saveini.h shade.h io.h aide.h texte.h sdlscreen.h \ + windows.h brush.h +$(OBJDIR)/brush.o: brush.c global.h struct.h const.h loadsave.h graph.h divers.h \ + erreurs.h windows.h sdlscreen.h $(OBJDIR)/clavier.o: clavier.c global.h struct.h const.h loadsave.h $(OBJDIR)/divers.o: divers.c struct.h const.h sdlscreen.h global.h loadsave.h \ - graph.h erreurs.h boutons.h moteur.h divers.h clavier.h windows.h + graph.h erreurs.h boutons.h moteur.h divers.h clavier.h windows.h \ + palette.h $(OBJDIR)/files.o: files.c const.h struct.h global.h loadsave.h graph.h divers.h \ erreurs.h io.h windows.h $(OBJDIR)/gfxcfg.o: gfxcfg.c SFont.h struct.h const.h clavier.h io.h hotkeys.h \ @@ -17,19 +20,21 @@ $(OBJDIR)/graph.o: graph.c global.h struct.h const.h loadsave.h moteur.h boutons pxwide.h windows.h $(OBJDIR)/init.o: init.c const.h struct.h global.h loadsave.h graph.h boutons.h \ palette.h aide.h operatio.h divers.h erreurs.h clavier.h io.h hotkeys.h \ - files.h setup.h windows.h + files.h setup.h windows.h mountlist.h $(OBJDIR)/io.o: io.c struct.h const.h io.h $(OBJDIR)/loadsave.o: loadsave.c const.h struct.h global.h loadsave.h graph.h \ divers.h pages.h op_c.h boutons.h erreurs.h io.h sdlscreen.h windows.h $(OBJDIR)/main.o: main.c const.h struct.h global.h loadsave.h graph.h divers.h \ init.h boutons.h moteur.h pages.h files.h sdlscreen.h erreurs.h \ - readini.h saveini.h io.h texte.h setup.h windows.h brush.h realpath.h + readini.h saveini.h io.h texte.h setup.h windows.h brush.h palette.h $(OBJDIR)/moteur.o: moteur.c const.h struct.h global.h loadsave.h graph.h divers.h \ - special.h boutons.h operatio.h shade.h erreurs.h sdlscreen.h windows.h brush.h -$(OBJDIR)/mountlist.o: mountlist.h mountlist.c + special.h boutons.h operatio.h shade.h erreurs.h sdlscreen.h windows.h \ + brush.h +$(OBJDIR)/mountlist.o: mountlist.c $(OBJDIR)/op_c.o: op_c.c op_c.h struct.h const.h erreurs.h graph.h $(OBJDIR)/operatio.o: operatio.c const.h struct.h global.h loadsave.h divers.h \ - moteur.h graph.h operatio.h boutons.h pages.h erreurs.h sdlscreen.h brush.h windows.h + moteur.h graph.h operatio.h boutons.h pages.h erreurs.h sdlscreen.h \ + brush.h windows.h $(OBJDIR)/pages.o: pages.c global.h struct.h const.h loadsave.h pages.h graph.h \ erreurs.h divers.h windows.h $(OBJDIR)/palette.o: palette.c const.h struct.h global.h loadsave.h divers.h \ @@ -41,7 +46,8 @@ $(OBJDIR)/pxtall.o: pxtall.c global.h struct.h const.h loadsave.h sdlscreen.h \ divers.h pxsimple.h $(OBJDIR)/pxwide.o: pxwide.c global.h struct.h const.h loadsave.h sdlscreen.h \ divers.h -$(OBJDIR)/readini.o: readini.c const.h global.h struct.h loadsave.h graph.h divers.h +$(OBJDIR)/readini.o: readini.c const.h global.h struct.h loadsave.h graph.h \ + windows.h divers.h $(OBJDIR)/readline.o: readline.c const.h struct.h global.h loadsave.h graph.h \ divers.h erreurs.h sdlscreen.h readline.h windows.h $(OBJDIR)/realpath.o: realpath.c @@ -57,4 +63,5 @@ $(OBJDIR)/special.o: special.c const.h struct.h global.h loadsave.h graph.h \ $(OBJDIR)/texte.o: texte.c SFont.h struct.h const.h global.h loadsave.h sdlscreen.h \ io.h files.h $(OBJDIR)/version.o: version.c -$(OBJDIR)/windows.o: windows.c windows.h graph.h moteur.h divers.h struct.h sdlscreen.h +$(OBJDIR)/windows.o: windows.c windows.h struct.h const.h global.h loadsave.h \ + graph.h moteur.h divers.h sdlscreen.h erreurs.h diff --git a/divers.c b/divers.c index e184bc5b..b6e358ca 100644 --- a/divers.c +++ b/divers.c @@ -35,6 +35,7 @@ #include "clavier.h" #include "sdlscreen.h" #include "windows.h" +#include "palette.h" word Palette_Compter_nb_couleurs_utilisees(dword* Tableau) { @@ -76,9 +77,9 @@ void Set_palette(T_Palette Palette) SDL_Color PaletteSDL[256]; for(i=0;i<256;i++) { - PaletteSDL[i].r=Palette[i].R; - PaletteSDL[i].g=Palette[i].V; - PaletteSDL[i].b=Palette[i].B; + PaletteSDL[i].r=(Palette[i].R=Palette_Scale_Component(Palette[i].R)); + PaletteSDL[i].g=(Palette[i].V=Palette_Scale_Component(Palette[i].V)); + PaletteSDL[i].b=(Palette[i].B=Palette_Scale_Component(Palette[i].B)); } SDL_SetPalette(Ecran_SDL, SDL_PHYSPAL | SDL_LOGPAL, PaletteSDL,0,256); } diff --git a/main.c b/main.c index 62e34801..24f86ddc 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,15 @@ */ #define VARIABLES_GLOBALES +#include +#include +#include +#include +#include +#include +#include +#include + #include "const.h" #include "struct.h" #include "global.h" @@ -30,14 +39,6 @@ #include "init.h" #include "boutons.h" #include "moteur.h" -#include -#include -#include -#include -#include -#include -#include -#include #include "pages.h" #include "files.h" #include "loadsave.h" @@ -50,6 +51,7 @@ #include "setup.h" #include "windows.h" #include "brush.h" +#include "palette.h" #if defined(__WIN32__) #include @@ -72,6 +74,8 @@ void Afficher_syntaxe(void) printf("Syntax: GFX2 [] []\n\n"); printf(" can be:]\n"); printf("\t/? /h /help for this help screen\n"); + printf("\t/wide to emulate a video mode with wide pixels (2x1)\n"); + printf("\t/tall to emulate a video mode with tall pixels (1x2)\n"); printf("\t/mode to set a video mode\n\n"); printf("Available video modes:\n\n"); for (Indice_mode=0; Indice_mode 256) + { + Erreur(ERREUR_LIGNE_COMMANDE); + Afficher_syntaxe(); + exit(0); + } + Set_Palette_RGB_Scale(Grad); + } + else + { + Erreur(ERREUR_LIGNE_COMMANDE); + Afficher_syntaxe(); + exit(0); + } + } else { // Si ce n'est pas un paramètre, c'est le nom du fichier à ouvrir diff --git a/palette.c b/palette.c index 98aac47b..116c5613 100644 --- a/palette.c +++ b/palette.c @@ -45,19 +45,31 @@ char * Libelle_reduction_palette[7]= }; // 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 - +int Graduations_RGB = 256; // 24bit +//int Graduations_RGB = 64; // VGA +//int Graduations_RGB = 16; // Amiga +//int Graduations_RGB = 4; // MSX2 +//int Graduations_RGB = 3; // Amstrad CPC // Nombre de graduations pour une composante dans le mode actuel -int Color_Count; +int Color_Count=256; // Les composantes vont de 0 à (Color_Count-1) -int Color_Max; +int Color_Max=255; // Le demi-pas est une quantité que l'on ajoute à une composante // avant de faire un arrondi par division. -int Color_DemiPas; +int Color_DemiPas=0; + + +void Set_Palette_RGB_Scale(int Grad) +{ + if (Grad>= 2 && Grad <= 256) + Graduations_RGB = Grad; +} + +byte Palette_Scale_Component(byte Comp) +{ + return ((Comp+128/Graduations_RGB)*(Graduations_RGB-1)/255*255+(Graduations_RGB&1?1:0))/(Graduations_RGB-1); +} // Définir les unités pour les graduationss R G B ou H S V void Unite_Composantes(int Count) @@ -93,7 +105,7 @@ void Modifier_Rouge(byte Couleur, short Nouvelle_teinte, T_Palette Palette) if (Nouvelle_teinte>255) Nouvelle_teinte=255; // Arrondi - Nouvelle_teinte=255*((Nouvelle_teinte+Color_DemiPas)*Color_Max/255)/Color_Max; + Nouvelle_teinte=Palette_Scale_Component(Nouvelle_teinte); Palette[Couleur].R=Nouvelle_teinte; Set_color(Couleur,Palette[Couleur].R,Palette[Couleur].V,Palette[Couleur].B); @@ -107,7 +119,7 @@ void Modifier_Vert(byte Couleur, short Nouvelle_teinte, T_Palette Palette) if (Nouvelle_teinte>255) Nouvelle_teinte=255; // Arrondi - Nouvelle_teinte=255*((Nouvelle_teinte+Color_DemiPas)*Color_Max/255)/Color_Max; + Nouvelle_teinte=Palette_Scale_Component(Nouvelle_teinte); Palette[Couleur].V=Nouvelle_teinte; Set_color(Couleur,Palette[Couleur].R,Palette[Couleur].V,Palette[Couleur].B); @@ -121,7 +133,7 @@ void Modifier_Bleu(byte Couleur, short Nouvelle_teinte, T_Palette Palette) if (Nouvelle_teinte>255) Nouvelle_teinte=255; // Arrondi - Nouvelle_teinte=255*((Nouvelle_teinte+Color_DemiPas)*Color_Max/255)/Color_Max; + Nouvelle_teinte=Palette_Scale_Component(Nouvelle_teinte); Palette[Couleur].B=Nouvelle_teinte; Set_color(Couleur,Palette[Couleur].R,Palette[Couleur].V,Palette[Couleur].B); diff --git a/palette.h b/palette.h index 51b94b0c..7dc862f1 100644 --- a/palette.h +++ b/palette.h @@ -20,3 +20,11 @@ */ void Bouton_Palette(void); void Bouton_Palette_secondaire(void); + +// Choose the number of graduations for RGB components, from 2 to 256. +void Set_Palette_RGB_Scale(int); + +// Scale a component (R, G or B) according to the current RGB graduations +// The resulting range is [0-255] +byte Palette_Scale_Component(byte Comp); +