-Use nearest neighbour and no error diffusion when loading 24bit images

-Some cleanup to the palette computing function, but no real improvement. I can't get it to perform better ...


git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@987 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Adrien Destugues 2009-08-09 20:26:10 +00:00
parent d5b5ba6de3
commit 6cdc5e3042
2 changed files with 52 additions and 54 deletions

40
op_c.c
View File

@ -345,7 +345,7 @@ int OT_count_colors(T_Occurrence_table * t)
///////////////////////////////////////// Mthodes de gestion des clusters // ///////////////////////////////////////// Mthodes de gestion des clusters //
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
void Cluster_analyser(T_Cluster * c,T_Occurrence_table * to) void Cluster_pack(T_Cluster * c,T_Occurrence_table * to)
{ {
int rmin,rmax,vmin,vmax,bmin,bmax; int rmin,rmax,vmin,vmax,bmin,bmax;
int r,g,b; int r,g,b;
@ -667,7 +667,7 @@ void CS_Init(T_Cluster_set * cs,T_Occurrence_table * to)
cs->clusters->Vmax = cs->clusters->vmax = to->rng_g-1; cs->clusters->Vmax = cs->clusters->vmax = to->rng_g-1;
cs->clusters->Bmax = cs->clusters->bmax = to->rng_b-1; cs->clusters->Bmax = cs->clusters->bmax = to->rng_b-1;
cs->clusters->next = NULL; cs->clusters->next = NULL;
Cluster_analyser(cs->clusters,to); Cluster_pack(cs->clusters,to);
cs->nb=1; cs->nb=1;
} }
@ -798,13 +798,11 @@ void CS_Generate(T_Cluster_set * cs,T_Occurrence_table * to)
Cluster_split(&current,&Nouveau1,&Nouveau2,current.plus_large,to); Cluster_split(&current,&Nouveau1,&Nouveau2,current.plus_large,to);
// On compacte ces deux nouveaux (il peut y avoir un espace entre l'endroit de la coupure et les premiers pixels du cluster) // On compacte ces deux nouveaux (il peut y avoir un espace entre l'endroit de la coupure et les premiers pixels du cluster)
Cluster_analyser(&Nouveau1,to); Cluster_pack(&Nouveau1,to);
Cluster_analyser(&Nouveau2,to); Cluster_pack(&Nouveau2,to);
// On met ces deux nouveaux clusters dans le clusterSet... sauf s'ils sont vides // On les remet dans le set
if(Nouveau1.occurences>0)
CS_Set(cs,&Nouveau1); CS_Set(cs,&Nouveau1);
if(Nouveau2.occurences>0)
CS_Set(cs,&Nouveau2); CS_Set(cs,&Nouveau2);
} }
} }
@ -1020,18 +1018,26 @@ T_Conversion_table * Optimize_palette(T_Bitmap24B image,int size,T_Components *
to=0; tc=0; cs=0; ds=0; to=0; tc=0; cs=0; ds=0;
to=OT_new(r,g,b); to=OT_new(r,g,b);
if (to!=0) if (to == NULL)
{ return 0;
tc=CT_new(r,g,b); tc=CT_new(r,g,b);
if (tc!=0) if (tc == NULL)
{ {
OT_delete(to);
return 0;
}
// Première étape : on compte les pixels de chaque couleur pour pouvoir trier là dessus // Première étape : on compte les pixels de chaque couleur pour pouvoir trier là dessus
OT_count_occurrences(to,image,size); OT_count_occurrences(to,image,size);
cs=CS_New(256,to); cs=CS_New(256,to);
if (cs!=0) if (cs == NULL)
{ {
CT_delete(tc);
OT_delete(to);
return 0;
}
// C'est bon, on a pu tout allouer // C'est bon, on a pu tout allouer
// On génère les clusters (avec l'algo du median cut) // On génère les clusters (avec l'algo du median cut)
@ -1056,14 +1062,6 @@ T_Conversion_table * Optimize_palette(T_Bitmap24B image,int size,T_Components *
CS_Delete(cs); CS_Delete(cs);
OT_delete(to); OT_delete(to);
return tc; return tc;
}
CT_delete(tc);
}
OT_delete(to);
}
// Si on arrive ici c'est que l'allocation n'a pas réussi,
// l'appelant devra recommencer avec une précision plus faible (3 derniers paramètres)
return 0;
} }
int Modified_value(int value,int modif) int Modified_value(int value,int modif)
@ -1173,7 +1171,6 @@ void Convert_24b_bitmap_to_256_Floyd_Steinberg(T_Bitmap256 dest,T_Bitmap24B sour
d++; d++;
} }
} }
} }
void Convert_24b_bitmap_to_256_nearest_neighbor(T_Bitmap256 dest,T_Bitmap24B source,int width,int height,T_Components * palette,T_Conversion_table * tc) void Convert_24b_bitmap_to_256_nearest_neighbor(T_Bitmap256 dest,T_Bitmap24B source,int width,int height,T_Components * palette,T_Conversion_table * tc)
@ -1247,7 +1244,8 @@ int Convert_24b_bitmap_to_256(T_Bitmap256 dest,T_Bitmap24B source,int width,int
if (table!=0) if (table!=0)
{ {
Convert_24b_bitmap_to_256_Floyd_Steinberg(dest,source,width,height,palette,table); //Convert_24b_bitmap_to_256_Floyd_Steinberg(dest,source,width,height,palette,table);
Convert_24b_bitmap_to_256_nearest_neighbor(dest,source,width,height,palette,table);
CT_delete(table); CT_delete(table);
return 0; return 0;
} }

2
op_c.h
View File

@ -176,7 +176,7 @@ void OT_count_occurrences(T_Occurrence_table * t,T_Bitmap24B image,int size);
///////////////////////////////////////// Méthodes de gestion des clusters // ///////////////////////////////////////// Méthodes de gestion des clusters //
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
void Cluster_analyser(T_Cluster * c,T_Occurrence_table * to); void Cluster_pack(T_Cluster * c,T_Occurrence_table * to);
void Cluster_split(T_Cluster * c,T_Cluster * c1,T_Cluster * c2,int hue,T_Occurrence_table * to); void Cluster_split(T_Cluster * c,T_Cluster * c1,T_Cluster * c2,int hue,T_Occurrence_table * to);
void Cluster_compute_hue(T_Cluster * c,T_Occurrence_table * to); void Cluster_compute_hue(T_Cluster * c,T_Occurrence_table * to);