Implemented palette sorting. There are problems as we're sortig with HSL color system and the rgb2hl function doesn't return s... we'll have to add that as we can't say if we're looking at red or grey (both have H=0).

Also, there is a problem with the makefile under linux. The .dep is set for checking the .o in the win32 folder. It still works but recompiles everything at each change.

Also added a button to enable HSL color editing in the palette screen. We'll need a hls2rgb function, and some other tweaks and reworks to the palette screen.


git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@290 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Adrien Destugues 2008-10-19 18:52:10 +00:00
parent 4a3b324a52
commit fc41bbe89d
5 changed files with 152 additions and 90 deletions

View File

@ -44,7 +44,7 @@ else
else
BIN = grafx2
CFGBIN = gfxcfg
COPT = -Wall -c -g `sdl-config --cflags`
COPT = -W -Wall -c -g `sdl-config --cflags`
LOPT = `sdl-config --libs`
CC = gcc
OBJDIR = obj/unix

View File

@ -1,44 +1,44 @@
obj/win32/SFont.o: SFont.c SFont.h
obj/win32/aide.o: aide.c const.h struct.h global.h loadsave.h divers.h graph.h \
$(OBJDIR)/SFont.o: SFont.c SFont.h
$(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
obj/win32/boutons.o: boutons.c const.h struct.h global.h loadsave.h divers.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 sdlscreen.h
obj/win32/clavier.o: clavier.c global.h struct.h const.h loadsave.h
obj/win32/divers.o: divers.c struct.h const.h sdlscreen.h global.h loadsave.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
obj/win32/files.o: files.c const.h struct.h global.h loadsave.h graph.h divers.h \
$(OBJDIR)/files.o: files.c const.h struct.h global.h loadsave.h graph.h divers.h \
erreurs.h linux.h
obj/win32/gfxcfg.o: gfxcfg.c SFont.h struct.h const.h clavier.h io.h hotkeys.h
obj/win32/graph.o: graph.c sdlscreen.h struct.h const.h graph.h divers.h moteur.h \
$(OBJDIR)/gfxcfg.o: gfxcfg.c SFont.h struct.h const.h clavier.h io.h hotkeys.h
$(OBJDIR)/graph.o: graph.c sdlscreen.h struct.h const.h graph.h divers.h moteur.h \
boutons.h pages.h global.h loadsave.h erreurs.h
obj/win32/init.o: init.c const.h struct.h global.h loadsave.h graph.h boutons.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
obj/win32/io.o: io.c struct.h const.h io.h
obj/win32/linux.o: linux.c
obj/win32/loadsave.o: loadsave.c const.h struct.h global.h loadsave.h graph.h \
$(OBJDIR)/io.o: io.c struct.h const.h io.h
$(OBJDIR)/linux.o: linux.c
$(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 linux.h io.h sdlscreen.h
obj/win32/main.o: main.c const.h struct.h global.h loadsave.h graph.h divers.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 linux.h io.h
obj/win32/moteur.o: moteur.c const.h struct.h global.h loadsave.h graph.h divers.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 linux.h sdlscreen.h
obj/win32/op_c.o: op_c.c op_c.h struct.h const.h erreurs.h
obj/win32/operatio.o: operatio.c const.h struct.h global.h loadsave.h divers.h \
$(OBJDIR)/op_c.o: op_c.c op_c.h struct.h const.h erreurs.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
obj/win32/pages.o: pages.c global.h struct.h const.h loadsave.h pages.h graph.h \
$(OBJDIR)/pages.o: pages.c global.h struct.h const.h loadsave.h pages.h graph.h \
erreurs.h linux.h
obj/win32/palette.o: palette.c const.h struct.h global.h loadsave.h divers.h \
$(OBJDIR)/palette.o: palette.c const.h struct.h global.h loadsave.h divers.h \
graph.h moteur.h readline.h boutons.h pages.h aide.h sdlscreen.h
obj/win32/readini.o: readini.c const.h global.h struct.h loadsave.h graph.h
obj/win32/readline.o: readline.c const.h struct.h global.h loadsave.h graph.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 linux.h sdlscreen.h
obj/win32/saveini.o: saveini.c const.h global.h struct.h loadsave.h readini.h \
$(OBJDIR)/saveini.o: saveini.c const.h global.h struct.h loadsave.h readini.h \
files.h erreurs.h graph.h
obj/win32/sdlscreen.o: sdlscreen.c global.h struct.h const.h loadsave.h sdlscreen.h \
$(OBJDIR)/sdlscreen.o: sdlscreen.c global.h struct.h const.h loadsave.h sdlscreen.h \
divers.h erreurs.h graph.h
obj/win32/shade.o: shade.c global.h struct.h const.h loadsave.h graph.h moteur.h \
$(OBJDIR)/shade.o: shade.c global.h struct.h const.h loadsave.h graph.h moteur.h \
divers.h readline.h aide.h sdlscreen.h
obj/win32/special.o: special.c const.h struct.h global.h loadsave.h graph.h \
$(OBJDIR)/special.o: special.c const.h struct.h global.h loadsave.h graph.h \
moteur.h
obj/win32/version.o: version.c
$(OBJDIR)/version.o: version.c

100
op_c.c
View File

@ -24,8 +24,10 @@
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "op_c.h"
#include "erreurs.h"
#include "graph.h"
#undef OPTIMISATIONS_ASSEMBLEUR
@ -807,79 +809,77 @@ void CS_Generer_TC_et_Palette(ClusterSet * cs,Table_conversion * tc,struct Compo
}
}
/////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////// Mthodes de gestion des dgrads //
///////////////////////////////////////// Méthodes de gestion des dégradés //
/////////////////////////////////////////////////////////////////////////////
void DS_Init(DegradeSet * ds,ClusterSet * cs)
{
ds->degrades[0].nbcouleurs=1;
ds->degrades[0].min=cs->clusters[0].h;
ds->degrades[0].max=cs->clusters[0].h;
ds->degrades[0].hue=cs->clusters[0].h;
// Et hop : le 1er ensemble de dgrads est initialis
ds->nb=1;
ds->degrades[0].nbcouleurs=1;
ds->degrades[0].min=cs->clusters[0].h;
ds->degrades[0].max=cs->clusters[0].h;
ds->degrades[0].hue=cs->clusters[0].h;
// Et hop : le 1er ensemble de dgrads est initialis
ds->nb=1;
}
DegradeSet * DS_New(ClusterSet * cs)
{
DegradeSet * n;
DegradeSet * n;
n=(DegradeSet *)malloc(sizeof(DegradeSet));
if (n!=0)
{
// On recopie les paramŠtres demands
n->nbmax=cs->nbmax;
// On tente d'allouer la table
n->degrades=(Degrade *)malloc((n->nbmax)*sizeof(Degrade));
if (n->degrades!=0)
// C'est bon! On initialise
DS_Init(n,cs);
else
n=(DegradeSet *)malloc(sizeof(DegradeSet));
if (n!=0)
{
// Table impossible … allouer
free(n);
n=0;
}
}
// On recopie les paramŠtres demands
n->nbmax=cs->nbmax;
return n;
// On tente d'allouer la table
n->degrades=(Degrade *)malloc((n->nbmax)*sizeof(Degrade));
if (n->degrades!=0)
// C'est bon! On initialise
DS_Init(n,cs);
else
{
// Table impossible … allouer
free(n);
n=0;
}
}
return n;
}
void DS_Delete(DegradeSet * ds)
{
free(ds->degrades);
free(ds);
free(ds->degrades);
free(ds);
}
void DS_Generer(DegradeSet * ds,ClusterSet * cs)
{
int ic,id; // Les indices de parcours des ensembles
int mdegr; // Meilleur dgrad
int mdiff; // Meilleure diffrence de chrominance
int diff; // Diffrence de chrominance courante
int ic,id; // Les indices de parcours des ensembles
int mdegr; // Meilleur dgrad
int mdiff; // Meilleure diffrence de chrominance
int diff; // Diffrence de chrominance courante
// Pour chacun des clusters … traiter
for (ic=1;ic<cs->nb;ic++)
{
// On recherche le dgrad le plus proche de la chrominance du cluster
mdegr=-1;
mdiff=99999999;
for (id=0;id<ds->nb;id++)
// Pour chacun des clusters … traiter
for (ic=1;ic<cs->nb;ic++)
{
diff=abs(cs->clusters[ic].h - ds->degrades[id].hue);
if ((mdiff>diff) && (diff<16))
{
mdegr=id;
mdiff=diff;
}
}
// On recherche le dgrad le plus proche de la chrominance du cluster
mdegr=-1;
mdiff=99999999;
for (id=0;id<ds->nb;id++)
{
diff=abs(cs->clusters[ic].h - ds->degrades[id].hue);
if ((mdiff>diff) && (diff<16))
{
mdegr=id;
mdiff=diff;
}
}
// Si on a trouv un dgrad dans lequel inclure le cluster
if (mdegr!=-1)
// Si on a trouv un dgrad dans lequel inclure le cluster
if (mdegr!=-1)
{
// On met … jour le dgrad
if (cs->clusters[ic].h < ds->degrades[mdegr].min)

3
op_c.h
View File

@ -147,6 +147,7 @@ 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);
/////////////////////////////////////////////////////////////////////////////
@ -186,8 +187,6 @@ void CS_Generer(ClusterSet * cs,Table_occurence * to);
void CS_Calculer_teintes(ClusterSet * cs,Table_occurence * to);
void CS_Generer_TC_et_Palette(ClusterSet * cs,Table_conversion * tc,struct Composantes * palette);
/////////////////////////////////////////////////////////////////////////////
//////////////////////////// Mthodes de gestion des ensembles de dgrads //
/////////////////////////////////////////////////////////////////////////////

View File

@ -32,6 +32,10 @@
#include "pages.h"
#include "aide.h"
#include "sdlscreen.h"
#include "erreurs.h"
#include "op_c.h"
byte Palette_mode_RGB = 1; // Indique si on est en HSV ou en RGB
// --------------------------- Menu des palettes -----------------------------
char * Libelle_reduction_palette[7]=
@ -763,10 +767,10 @@ void Bouton_Palette(void)
Fenetre_Definir_bouton_normal( 6,17,59,14,"Default",3,1,SDLK_f); // 5
Fenetre_Definir_bouton_normal(66,17,29,14,"Gry" ,1,1,SDLK_g); // 6
Fenetre_Definir_bouton_normal( 6,47,59,14,"Swap" ,1,1,SDLK_s); // 7
Fenetre_Definir_bouton_normal(66,47,59,14,"X-Swap" ,1,1,SDLK_x); // 8
Fenetre_Definir_bouton_normal( 6,62,59,14,"Copy" ,1,1,SDLK_c); // 9
Fenetre_Definir_bouton_normal(66,62,59,14,"Spread" ,4,1,SDLK_e); // 10
Fenetre_Definir_bouton_normal(66,47,29,14,"Swp" ,1,1,SDLK_s); // 7
Fenetre_Definir_bouton_normal( 6,47,59,14,"X-Swap" ,1,1,SDLK_x); // 8
Fenetre_Definir_bouton_normal(66,32,29,14,"Cpy" ,1,1,SDLK_c); // 9
Fenetre_Definir_bouton_normal( 6,32,59,14,"Spread" ,4,1,SDLK_e); // 10
Fenetre_Definir_bouton_normal(239,20,51,14,"Reduce" ,1,1,SDLK_r); // 11
Print_dans_fenetre(241,41,"to",CM_Fonce,CM_Clair);
@ -787,10 +791,13 @@ void Bouton_Palette(void)
Fenetre_Definir_bouton_normal(266,165,12,11,"-",0,1,SDLK_KP_MINUS); // 19
Fenetre_Definir_bouton_normal(96,17,29,14,"Neg" ,1,1,SDLK_n); // 20
Fenetre_Definir_bouton_normal( 6,32,59,14,"Invert" ,1,1,SDLK_i); // 21
Fenetre_Definir_bouton_normal(66,32,59,14,"X-Inv." ,5,1,SDLK_v); // 22
Fenetre_Definir_bouton_normal(66,62,29,14,"Inv" ,1,1,SDLK_i); // 21
Fenetre_Definir_bouton_normal( 6,62,59,14,"X-Inv." ,5,1,SDLK_v); // 22
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,47,29,14,"Sort" ,1,1,SDLK_o); // 25
// Affichage du facteur de réduction de la palette
Num2str(Reduce_Nb_couleurs,Chaine,3);
Print_dans_fenetre(265,41,Chaine,CM_Noir,CM_Clair);
@ -1616,17 +1623,73 @@ 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);
}
Palette_mode_RGB = !Palette_mode_RGB ;
break;
case 25 : // Sort palette
{
int h = 0, l = 0;
int oh=0,ol=0; // Valeur pour la couleur précédente
int swap=1;
while(swap==1)
{
swap=0;
h=0;l=0;
for(Couleur_temporaire=0;Couleur_temporaire<256;Couleur_temporaire++)
{
oh=h; ol=l;
// 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);
// Note : comparer seulement H et L ne suffit pas toujours à trancher...
// donc on regarde aussi les composantes R G B s'il y a un doute
if((h<oh) || (h==oh && (l<ol
|| ( l==ol && (Palette_de_travail[Couleur_temporaire].V < Palette_de_travail[Couleur_temporaire-1].V
|| (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
Swap(0,Couleur_temporaire,Couleur_temporaire-1,1,Palette_de_travail,Utilisation_couleur);
swap=1;
DEBUG("swap",Couleur_temporaire);
}
}
}
}
break;
}
if (!Mouse_K)
{
switch (Touche)
{
case SDLK_LEFTBRACKET : // Décaler Forecolor vers la gauche
if (Debut_block==Fin_block)
{
Fore_color--;
switch (Touche)
{
case SDLK_LEFTBRACKET : // Décaler Forecolor vers la gauche
if (Debut_block==Fin_block)
{
Fore_color--;
Premiere_couleur--;
Derniere_couleur--;
Debut_block--;