Some work on brush remapping
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1700 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
40a7bcf40e
commit
e01b310317
94
src/brush.c
94
src/brush.c
@ -494,10 +494,14 @@ byte Realloc_brush(word new_brush_width, word new_brush_height, byte *new_brush,
|
||||
{
|
||||
|
||||
byte *new_smear_brush;
|
||||
byte *new_brush_remapped;
|
||||
word new_smear_brush_width;
|
||||
word new_smear_brush_height;
|
||||
byte new_brush_is_provided;
|
||||
|
||||
if (new_brush==NULL)
|
||||
new_brush_is_provided = (new_brush!=NULL);
|
||||
|
||||
if (!new_brush_is_provided)
|
||||
{
|
||||
new_brush=(byte *)malloc(((long)new_brush_height)*new_brush_width);
|
||||
if (new_brush == NULL)
|
||||
@ -512,8 +516,8 @@ byte Realloc_brush(word new_brush_width, word new_brush_height, byte *new_brush,
|
||||
new_smear_brush_width=(new_brush_width>MAX_PAINTBRUSH_SIZE)?new_brush_width:MAX_PAINTBRUSH_SIZE;
|
||||
new_smear_brush_height=(new_brush_height>MAX_PAINTBRUSH_SIZE)?new_brush_height:MAX_PAINTBRUSH_SIZE;
|
||||
new_smear_brush=NULL;
|
||||
if ( (((long)Brush_height)*Brush_width) !=
|
||||
(((long)new_brush_height)*new_brush_width) )
|
||||
if ( (((long)Smear_brush_height)*Smear_brush_width) !=
|
||||
(((long)new_smear_brush_width)*new_smear_brush_height) )
|
||||
{
|
||||
new_smear_brush=(byte *)malloc(((long)new_smear_brush_height)*new_smear_brush_width);
|
||||
if (new_smear_brush == NULL)
|
||||
@ -521,13 +525,33 @@ byte Realloc_brush(word new_brush_width, word new_brush_height, byte *new_brush,
|
||||
Error(0);
|
||||
if (old_brush)
|
||||
*old_brush=NULL;
|
||||
if (!new_brush_is_provided)
|
||||
free(new_brush);
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
new_brush_remapped=NULL;
|
||||
if ( (((long)Brush_height)*Brush_width) !=
|
||||
(((long)new_brush_height)*new_brush_width) )
|
||||
{
|
||||
new_brush_remapped=(byte *)malloc(((long)new_brush_height)*new_brush_width);
|
||||
if (new_brush_remapped == NULL)
|
||||
{
|
||||
Error(0);
|
||||
free(new_smear_brush);
|
||||
if (old_brush)
|
||||
*old_brush=NULL;
|
||||
if (!new_brush_is_provided)
|
||||
free(new_brush);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
// All allocations successful: can replace globals
|
||||
Brush_width=new_brush_width;
|
||||
Brush_height=new_brush_height;
|
||||
memcpy(Brush_original_palette, Main_palette,sizeof(T_Palette));
|
||||
Brush_original_back_color=Back_color;
|
||||
|
||||
if (new_smear_brush)
|
||||
{
|
||||
@ -539,12 +563,22 @@ byte Realloc_brush(word new_brush_width, word new_brush_height, byte *new_brush,
|
||||
|
||||
// Save or free the old brush pixels
|
||||
if (old_brush)
|
||||
*old_brush=Brush;
|
||||
*old_brush=Brush_original_pixels;
|
||||
else
|
||||
free(old_brush);
|
||||
Brush_original_pixels=new_brush;
|
||||
// Assign new brush
|
||||
Brush=new_brush;
|
||||
|
||||
if (new_brush_remapped)
|
||||
{
|
||||
free(Brush);
|
||||
Brush=new_brush_remapped;
|
||||
}
|
||||
if (new_brush_is_provided)
|
||||
{
|
||||
// Copy from Brush_original_pixels to Brush, using the last defined colmap.
|
||||
Remap_general_lowlevel(Brush_colormap,Brush_original_pixels,Brush,Brush_width,Brush_height,Brush_width);
|
||||
//memcpy(Brush, Brush_original_pixels,(long)Brush_width*Brush_height);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -742,6 +776,8 @@ void Capture_brush(short start_x,short start_y,short end_x,short end_y,short cle
|
||||
}
|
||||
Update_part_of_screen(start_x,start_y,Brush_width,Brush_height);
|
||||
}
|
||||
// Copy without remap
|
||||
memcpy(Brush_original_pixels, Brush, (long)Brush_height*Brush_width);
|
||||
|
||||
// On centre la prise sur la brosse
|
||||
Brush_offset_X=(Brush_width>>1);
|
||||
@ -759,10 +795,13 @@ void Rotate_90_deg(void)
|
||||
Error(0);
|
||||
return;
|
||||
}
|
||||
Rotate_90_deg_lowlevel(old_brush,Brush,Brush_height,Brush_width);
|
||||
Rotate_90_deg_lowlevel(old_brush,Brush_original_pixels,Brush_height,Brush_width);
|
||||
|
||||
free(old_brush);
|
||||
|
||||
// Copy without remap
|
||||
memcpy(Brush, Brush_original_pixels, (long)Brush_height*Brush_width);
|
||||
|
||||
// On centre la prise sur la brosse
|
||||
Brush_offset_X=(Brush_width>>1);
|
||||
Brush_offset_Y=(Brush_height>>1);
|
||||
@ -773,34 +812,45 @@ void Remap_brush(void)
|
||||
{
|
||||
short x_pos; // Variable de balayage de la brosse
|
||||
short y_pos; // Variable de balayage de la brosse
|
||||
byte used[256]; // Tableau de booléens "La couleur est utilisée"
|
||||
int color;
|
||||
|
||||
|
||||
// On commence par initialiser le tableau de booléens à faux
|
||||
for (color=0;color<=255;color++)
|
||||
used[color]=0;
|
||||
Brush_colormap[color]=0;
|
||||
|
||||
// On calcule la table d'utilisation des couleurs
|
||||
for (y_pos=0;y_pos<Brush_height;y_pos++)
|
||||
for (x_pos=0;x_pos<Brush_width;x_pos++)
|
||||
used[Read_pixel_from_brush(x_pos,y_pos)]=1;
|
||||
Brush_colormap[*(Brush_original_pixels + y_pos * Brush_width + x_pos)]=1;
|
||||
|
||||
// On n'est pas censé remapper la couleur de transparence, sinon la brosse
|
||||
// changera de forme, donc on dit pour l'instant qu'elle n'est pas utilisée
|
||||
// ainsi on ne s'embêtera pas à la recalculer
|
||||
used[Back_color]=0;
|
||||
Brush_colormap[Back_color]=0;
|
||||
|
||||
// On va maintenant se servir de la table "used" comme table de
|
||||
// On va maintenant se servir de la table comme table de
|
||||
// conversion: pour chaque indice, la table donne une couleur de
|
||||
// remplacement.
|
||||
// Note : Seules les couleurs utilisées on besoin d'êtres recalculées: les
|
||||
// autres ne seront jamais consultées dans la nouvelle table de
|
||||
// conversion puisque elles n'existent pas dans la brosse, donc elles
|
||||
// ne seront pas utilisées par Remap_brush_LOWLEVEL.
|
||||
// ne seront pas utilisées par Remap_general_lowlevel.
|
||||
for (color=0;color<=255;color++)
|
||||
if (used[color] != 0)
|
||||
used[color]=Best_color_perceptual(Spare_palette[color].R,Spare_palette[color].G,Spare_palette[color].B);
|
||||
if (Brush_colormap[color] != 0)
|
||||
{
|
||||
byte r,g,b;
|
||||
r=Brush_original_palette[color].R;
|
||||
g=Brush_original_palette[color].G;
|
||||
b=Brush_original_palette[color].B;
|
||||
|
||||
// When remapping to same palette, ensure we keep same color index
|
||||
if (r==Main_palette[color].R && g==Main_palette[color].G && b==Main_palette[color].B)
|
||||
Brush_colormap[color]=color;
|
||||
else
|
||||
// Usual method: closest by r g b
|
||||
Brush_colormap[color]=Best_color_perceptual(r,g,b);
|
||||
}
|
||||
|
||||
// Il reste une couleur non calculée dans la table qu'il faut mettre à
|
||||
// jour: c'est la couleur de fond. On l'avait inhibée pour éviter son
|
||||
@ -808,13 +858,13 @@ void Remap_brush(void)
|
||||
// la brosse, on va mettre dans la table une relation d'équivalence entre
|
||||
// les deux palettes: comme on ne veut pas que la couleur soit remplacée,
|
||||
// on va dire qu'on veut qu'elle soit remplacée par la couleur en question.
|
||||
used[Back_color]=Back_color;
|
||||
Brush_colormap[Back_color]=Back_color;
|
||||
|
||||
// Maintenant qu'on a une super table de conversion qui n'a que le nom
|
||||
// qui craint un peu, on peut faire l'échange dans la brosse de toutes les
|
||||
// teintes.
|
||||
Remap_general_lowlevel(used,Brush,Brush_width,Brush_height,Brush_width);
|
||||
//Remap_brush_LOWLEVEL(used);
|
||||
Remap_general_lowlevel(Brush_colormap,Brush_original_pixels,Brush,Brush_width,Brush_height,Brush_width);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -898,6 +948,8 @@ void Outline_brush(void)
|
||||
Pixel_in_brush(x_pos,y_pos,Fore_color);
|
||||
}
|
||||
}
|
||||
// Copy without remap
|
||||
memcpy(Brush_original_pixels, Brush, (long)Brush_height*Brush_width);
|
||||
|
||||
// On recentre la prise sur la brosse
|
||||
Brush_offset_X=(Brush_width>>1);
|
||||
@ -997,7 +1049,9 @@ void Nibble_brush(void)
|
||||
}
|
||||
|
||||
free(old_brush);
|
||||
|
||||
// Copy without remap
|
||||
memcpy(Brush_original_pixels, Brush, (long)Brush_height*Brush_width);
|
||||
|
||||
// On recentre la prise sur la brosse
|
||||
Brush_offset_X=(Brush_width>>1);
|
||||
Brush_offset_Y=(Brush_height>>1);
|
||||
@ -1096,6 +1150,8 @@ void Capture_brush_with_lasso(int vertices, short * points,short clear)
|
||||
if (clear)
|
||||
Pixel_in_current_screen(x_pos,y_pos,Back_color,0);
|
||||
}
|
||||
// Copy without remap
|
||||
memcpy(Brush_original_pixels, Brush, (long)Brush_height*Brush_width);
|
||||
|
||||
// On centre la prise sur la brosse
|
||||
Brush_offset_X=(Brush_width>>1);
|
||||
|
||||
@ -4991,7 +4991,11 @@ void Button_Text(void)
|
||||
|
||||
Brush_offset_X=Brush_width>>1;
|
||||
Brush_offset_Y=Brush_height>>1;
|
||||
|
||||
|
||||
// TODO: Import original palette
|
||||
// Remap to current screen palette
|
||||
Remap_brush();
|
||||
|
||||
// Fermeture
|
||||
Close_window();
|
||||
Unselect_button(BUTTON_TEXT);
|
||||
@ -5283,8 +5287,9 @@ byte Restore_brush(int index)
|
||||
if (!Realloc_brush(Brush_container[index].Width,Brush_container[index].Height,NULL,NULL))
|
||||
{
|
||||
// Realloc sets Brush_width and Brush_height to new size.
|
||||
memcpy(Brush, Brush_container[index].Brush, Brush_height*Brush_width);
|
||||
|
||||
memcpy(Brush_original_pixels, Brush_container[index].Brush, (long)Brush_height*Brush_width);
|
||||
// Copy without remap
|
||||
memcpy(Brush, Brush_original_pixels, (long)Brush_height*Brush_width);
|
||||
Brush_offset_X=Brush_width>>1;
|
||||
Brush_offset_Y=Brush_height>>1;
|
||||
}
|
||||
|
||||
@ -1082,6 +1082,8 @@ void Button_Sieve_menu(void)
|
||||
for (x_pos=0; x_pos<Sieve_width; x_pos++)
|
||||
Pixel_in_brush(x_pos,y_pos,(Sieve[x_pos][y_pos])?Fore_color:Back_color);
|
||||
|
||||
// Copy without remap
|
||||
memcpy(Brush_original_pixels, Brush, (long)Brush_height*Brush_width);
|
||||
Brush_offset_X=(Brush_width>>1);
|
||||
Brush_offset_Y=(Brush_height>>1);
|
||||
|
||||
|
||||
@ -165,9 +165,9 @@ int L_SetBrushSize(lua_State* L)
|
||||
{
|
||||
return luaL_error(L, "setbrushsize: Resize failed");
|
||||
}
|
||||
|
||||
Brush_was_altered=1;
|
||||
// Fill with Back_color
|
||||
memset(Brush_original_pixels,Back_color,(long)Brush_width*Brush_height);
|
||||
memset(Brush,Back_color,(long)Brush_width*Brush_height);
|
||||
// Center the handle
|
||||
Brush_offset_X=(Brush_width>>1);
|
||||
|
||||
10
src/global.h
10
src/global.h
@ -430,8 +430,16 @@ GFX2_GLOBAL T_List_of_pages * Spare_backups;
|
||||
|
||||
// -- Brush data
|
||||
|
||||
/// Pixel data of the current brush.
|
||||
/// Pixel data of the current brush (remapped).
|
||||
GFX2_GLOBAL byte * Brush;
|
||||
/// Pixel data of the current brush (before remap).
|
||||
GFX2_GLOBAL byte * Brush_original_pixels;
|
||||
/// Palette of the brush, from when it was grabbed.
|
||||
GFX2_GLOBAL T_Palette Brush_original_palette;
|
||||
/// Back_color used when the brush was grabbed
|
||||
GFX2_GLOBAL byte Brush_original_back_color;
|
||||
/// Color mapping from ::Brush_original_pixels to ::Brush
|
||||
GFX2_GLOBAL byte Brush_colormap[256];
|
||||
/// X coordinate of the brush's "hot spot". It is < ::Brush_width
|
||||
GFX2_GLOBAL word Brush_offset_X;
|
||||
/// Y coordinate of the brush's "hot spot". It is < ::Brush_height
|
||||
|
||||
@ -681,7 +681,7 @@ void Remap_spare(void)
|
||||
// qui craint un peu, on peut faire l'échange dans la brosse de toutes les
|
||||
// teintes.
|
||||
for (layer=0; layer<Spare_backups->Pages->Nb_layers; layer++)
|
||||
Remap_general_lowlevel(used,Spare_backups->Pages->Image[layer],Spare_image_width,Spare_image_height,Spare_image_width);
|
||||
Remap_general_lowlevel(used,Spare_backups->Pages->Image[layer],Spare_backups->Pages->Image[layer],Spare_image_width,Spare_image_height,Spare_image_width);
|
||||
|
||||
// Change transparent color index
|
||||
Spare_backups->Pages->Transparent_color=used[Spare_backups->Pages->Transparent_color];
|
||||
|
||||
@ -780,6 +780,8 @@ void Load_image(T_IO_Context *context)
|
||||
File_error=3;
|
||||
free(context->Buffer_image);
|
||||
}
|
||||
memcpy(Brush_original_palette, context->Palette, sizeof(T_Palette));
|
||||
|
||||
context->Buffer_image = NULL;
|
||||
}
|
||||
else if (context->Type == CONTEXT_SURFACE)
|
||||
|
||||
@ -754,8 +754,11 @@ int Init_program(int argc,char * argv[])
|
||||
// On initialise la brosse initiale à 1 pixel blanc:
|
||||
Brush_width=1;
|
||||
Brush_height=1;
|
||||
for (temp=0;temp<256;temp++)
|
||||
Brush_colormap[temp]=temp;
|
||||
Capture_brush(0,0,0,0,0);
|
||||
*Brush=MC_White;
|
||||
*Brush_original_pixels=MC_White;
|
||||
|
||||
// Test de recuperation de fichiers sauvés
|
||||
switch (Check_recovery())
|
||||
|
||||
10
src/misc.c
10
src/misc.c
@ -340,7 +340,7 @@ void Rotate_270_deg_lowlevel(byte * source, byte * dest, short width, short heig
|
||||
|
||||
// Replace une couleur par une autre dans un buffer
|
||||
|
||||
void Remap_general_lowlevel(byte * conversion_table,byte * buffer,short width,short height,short buffer_width)
|
||||
void Remap_general_lowlevel(byte * conversion_table,byte * in_buffer, byte *out_buffer,short width,short height,short buffer_width)
|
||||
{
|
||||
int dx,cx;
|
||||
|
||||
@ -350,10 +350,12 @@ void Remap_general_lowlevel(byte * conversion_table,byte * buffer,short width,sh
|
||||
// Pour chaque pixel
|
||||
for(cx=width;cx>0;cx--)
|
||||
{
|
||||
*buffer = conversion_table[*buffer];
|
||||
buffer++;
|
||||
*out_buffer = conversion_table[*in_buffer];
|
||||
in_buffer++;
|
||||
out_buffer++;
|
||||
}
|
||||
buffer += buffer_width-width;
|
||||
in_buffer += buffer_width-width;
|
||||
out_buffer += buffer_width-width;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
#define SWAP_PBYTES(a,b) { byte * c=a; a=b; b=c;}
|
||||
|
||||
void Copy_image_to_brush(short start_x,short start_y,short Brush_width,short Brush_height,word image_width);
|
||||
void Remap_general_lowlevel(byte * conversion_table,byte * buffer,short width,short height,short buffer_width);
|
||||
void Remap_general_lowlevel(byte * conversion_table,byte * in_buffer, byte *out_buffer,short width,short height,short buffer_width);
|
||||
void Scroll_picture(byte * main_src, byte * main_dest, short x_offset,short y_offset);
|
||||
void Wait_end_of_click(void);
|
||||
void Set_color(byte color, byte red, byte green, byte blue);
|
||||
|
||||
@ -250,12 +250,12 @@ void Remap_image_highlevel(byte * conversion_table)
|
||||
int layer;
|
||||
|
||||
// Remap the flatenned image view
|
||||
Remap_general_lowlevel(conversion_table,Main_screen,
|
||||
Remap_general_lowlevel(conversion_table,Main_screen,Main_screen,
|
||||
Main_image_width,Main_image_height,Main_image_width);
|
||||
|
||||
// Remap all layers
|
||||
for (layer=0; layer<Main_backups->Pages->Nb_layers; layer++)
|
||||
Remap_general_lowlevel(conversion_table,Main_backups->Pages->Image[layer],Main_image_width,Main_image_height,Main_image_width);
|
||||
Remap_general_lowlevel(conversion_table,Main_backups->Pages->Image[layer],Main_backups->Pages->Image[layer],Main_image_width,Main_image_height,Main_image_width);
|
||||
|
||||
// Remap transparent color
|
||||
Main_backups->Pages->Transparent_color =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user