[layers] working swap between main/spare, and loading files in command-line. Start of work on variable layers number and layer sharing.

git-svn-id: svn://pulkomandy.tk/GrafX2/branches/layers@1044 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2009-09-28 18:48:05 +00:00
parent b534cfd7d4
commit 057d5e76e4
8 changed files with 139 additions and 110 deletions

BIN
gfx2.cfg

Binary file not shown.

View File

@ -598,7 +598,7 @@ void Resize_image(word chosen_width,word chosen_height)
Main_image_is_modified=1; Main_image_is_modified=1;
// On copie donc maintenant la partie C dans la nouvelle image. // On copie donc maintenant la partie C dans la nouvelle image.
for (i=0; i<NB_LAYERS; i++) for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{ {
Copy_part_of_image_to_another( Copy_part_of_image_to_another(
Main_backups->Pages->Next->Image[i],0,0,Min(old_width,Main_image_width), Main_backups->Pages->Next->Image[i],0,0,Min(old_width,Main_image_width),

12
main.c
View File

@ -635,18 +635,6 @@ int Init_program(int argc,char * argv[])
// Allocation de mémoire pour les différents écrans virtuels (et brosse) // Allocation de mémoire pour les différents écrans virtuels (et brosse)
if (Init_all_backup_lists(Screen_width,Screen_height)==0) if (Init_all_backup_lists(Screen_width,Screen_height)==0)
Error(ERROR_MEMORY); Error(ERROR_MEMORY);
// On remet le nom par défaut pour la page de brouillon car il été modifié
// par le passage d'un fichier en paramètre lors du traitement précédent.
// Note: le fait que l'on ne modifie que les variables globales
// Brouillon_* et pas les infos contenues dans la page de brouillon
// elle-même ne m'inspire pas confiance mais ça a l'air de marcher sans
// poser de problèmes, alors...
if (File_in_command_line)
{
strcpy(Spare_file_directory,Spare_current_directory);
strcpy(Spare_filename,"NO_NAME.GIF");
Spare_fileformat=DEFAULT_FILEFORMAT;
}
// Nettoyage de l'écran virtuel (les autres recevront celui-ci par copie) // Nettoyage de l'écran virtuel (les autres recevront celui-ci par copie)
memset(Main_screen,0,Main_image_width*Main_image_height); memset(Main_screen,0,Main_image_width*Main_image_height);

View File

@ -4026,7 +4026,7 @@ void Scroll_0_5(void)
// Do the actual scroll operation on all layers. // Do the actual scroll operation on all layers.
for (i=0; i<NB_LAYERS; i++) for (i=0; i<Main_backups->Pages->Nb_layers; i++)
Scroll_picture(Main_backups->Pages->Next->Image[i], Main_backups->Pages->Image[i], x_offset, y_offset); Scroll_picture(Main_backups->Pages->Next->Image[i], Main_backups->Pages->Image[i], x_offset, y_offset);
} }
else else

212
pages.c
View File

@ -39,15 +39,15 @@
static word Last_backed_up_layers=0; static word Last_backed_up_layers=0;
/// Allocate and initialize a new page. /// Allocate and initialize a new page.
T_Page * New_page(void) T_Page * New_page(byte nb_layers)
{ {
T_Page * page; T_Page * page;
page = (T_Page *)malloc(sizeof(T_Page)); page = (T_Page *)malloc(sizeof(T_Page)+NB_LAYERS*sizeof(byte *));
if (page!=NULL) if (page!=NULL)
{ {
int i; int i;
for (i=0; i<NB_LAYERS; i++) for (i=0; i<nb_layers; i++)
page->Image[i]=NULL; page->Image[i]=NULL;
page->Width=0; page->Width=0;
page->Height=0; page->Height=0;
@ -56,12 +56,26 @@ T_Page * New_page(void)
page->File_directory[0]='\0'; page->File_directory[0]='\0';
page->Filename[0]='\0'; page->Filename[0]='\0';
page->File_format=DEFAULT_FILEFORMAT; page->File_format=DEFAULT_FILEFORMAT;
page->Nb_layers=nb_layers;
page->Next = page->Prev = NULL; page->Next = page->Prev = NULL;
} }
return page; return page;
} }
byte * New_layer(long pixel_size)
{
return (byte *)(malloc(pixel_size));
}
void Free_layer(byte * layer)
{
free(layer);
}
byte * Dup_layer(byte * layer)
{
return layer;
}
void Download_infos_page_main(T_Page * page) void Download_infos_page_main(T_Page * page)
// Affiche la page à l'écran // Affiche la page à l'écran
{ {
@ -102,7 +116,7 @@ void Redraw_layered_image(void)
// Re-construct the image with the visible layers // Re-construct the image with the visible layers
int layer; int layer;
// First layer // First layer
for (layer=0; layer<NB_LAYERS; layer++) for (layer=0; layer<Main_backups->Pages->Nb_layers; layer++)
{ {
if ((1<<layer) & Main_layers_visible) if ((1<<layer) & Main_layers_visible)
{ {
@ -122,7 +136,7 @@ void Redraw_layered_image(void)
} }
} }
// subsequent layer(s) // subsequent layer(s)
for (; layer<NB_LAYERS; layer++) for (; layer<Main_backups->Pages->Nb_layers; layer++)
{ {
if ((1<<layer) & Main_layers_visible) if ((1<<layer) & Main_layers_visible)
{ {
@ -162,7 +176,7 @@ void Download_infos_page_spare(T_Page * page)
{ {
if (page!=NULL) if (page!=NULL)
{ {
Spare_screen=page->Image[Spare_current_layer]; //Spare_screen=page->Image[Spare_current_layer];
Spare_image_width=page->Width; Spare_image_width=page->Width;
Spare_image_height=page->Height; Spare_image_height=page->Height;
memcpy(Spare_palette,page->Palette,sizeof(T_Palette)); memcpy(Spare_palette,page->Palette,sizeof(T_Palette));
@ -177,7 +191,7 @@ void Upload_infos_page_spare(T_Page * page)
{ {
if (page!=NULL) if (page!=NULL)
{ {
page->Image[Spare_current_layer]=Spare_screen; //page->Image[Spare_current_layer]=Spare_screen;
page->Width=Spare_image_width; page->Width=Spare_image_width;
page->Height=Spare_image_height; page->Height=Spare_image_height;
memcpy(page->Palette,Spare_palette,sizeof(T_Palette)); memcpy(page->Palette,Spare_palette,sizeof(T_Palette));
@ -204,9 +218,9 @@ void Clear_page(T_Page * page)
{ {
// On peut appeler cette fonction sur une page non allouée. // On peut appeler cette fonction sur une page non allouée.
int i; int i;
for (i=0; i<NB_LAYERS; i++) for (i=0; i<page->Nb_layers; i++)
{ {
free(page->Image[i]); Free_layer(page->Image[i]);
page->Image[i]=NULL; page->Image[i]=NULL;
} }
page->Width=0; page->Width=0;
@ -240,7 +254,7 @@ int Allocate_list_of_pages(T_List_of_pages * list)
T_Page * page; T_Page * page;
// On initialise chacune des nouvelles pages // On initialise chacune des nouvelles pages
page=New_page(); page=New_page(NB_LAYERS);
if (!page) if (!page)
return 0; return 0;
@ -372,8 +386,8 @@ int Create_new_page(T_Page * new_page,T_List_of_pages * list)
} }
{ {
int i; int i;
for (i=0; i<NB_LAYERS; i++) for (i=0; i<new_page->Nb_layers; i++)
new_page->Image[i]=(byte *)malloc(new_page->Height*new_page->Width); new_page->Image[i]=New_layer(new_page->Height*new_page->Width);
} }
@ -449,69 +463,84 @@ int Init_all_backup_lists(int width,int height)
// width et height correspondent à la dimension des images de départ. // width et height correspondent à la dimension des images de départ.
int i; int i;
if (Allocate_list_of_pages(Main_backups) && if (! Allocate_list_of_pages(Main_backups) ||
Allocate_list_of_pages(Spare_backups)) ! Allocate_list_of_pages(Spare_backups))
return 0;
// On a réussi à allouer deux listes de pages dont la taille correspond à
// celle demandée par l'utilisateur.
// On crée un descripteur de page correspondant à la page principale
Upload_infos_page_main(Main_backups->Pages);
// On y met les infos sur la dimension de démarrage
Main_backups->Pages->Width=width;
Main_backups->Pages->Height=height;
for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{ {
// On a réussi à allouer deux listes de pages dont la taille correspond à Main_backups->Pages->Image[i]=New_layer(width*height);
// celle demandée par l'utilisateur. if (! Main_backups->Pages->Image[i])
// On crée un descripteur de page correspondant à la page principale
Upload_infos_page_main(Main_backups->Pages);
// On y met les infos sur la dimension de démarrage
Main_backups->Pages->Width=width;
Main_backups->Pages->Height=height;
for (i=0; i<NB_LAYERS; i++)
{
Main_backups->Pages->Image[i]=(byte *)malloc(width*height);
}
if (!Update_visible_page_buffer(0, width, height))
return 0; return 0;
Main_screen=Visible_image[0].Image;
if (!Update_visible_page_buffer(1, width, height))
return 0;
Screen_backup=Visible_image[1].Image;
Download_infos_page_main(Main_backups->Pages);
Download_infos_backup(Main_backups);
// Maintenant, on regarde si on a le droit de créer la même page dans
// la page de brouillon.
Download_infos_page_spare(Spare_backups->Pages);
// Et on efface les 2 images en les remplacant de "0"
memset(Main_screen,0,Main_image_width*Main_image_height);
memset(Spare_screen,0,Spare_image_width*Spare_image_height);
Visible_image[0].Width = width;
Visible_image[0].Height = height;
Visible_image[0].Image = NULL;
Visible_image[1].Width = width;
Visible_image[1].Height = height;
Visible_image[1].Image = NULL;
Visible_image_depth_buffer.Width = width;
Visible_image_depth_buffer.Height = height;
Visible_image_depth_buffer.Image = NULL;
Visible_image[0].Image = (byte *)malloc(Visible_image[0].Width * Visible_image[0].Height);
if (Visible_image[0].Image)
{
Visible_image[1].Image = (byte *)malloc(Visible_image[1].Width * Visible_image[1].Height);
if (Visible_image[1].Image)
{
Visible_image_depth_buffer.Image = (byte *)malloc(Visible_image_depth_buffer.Width * Visible_image_depth_buffer.Height);
if (Visible_image_depth_buffer.Image)
{
End_of_modification();
return 1;
}
}
}
} }
return 0;
if (!Update_visible_page_buffer(0, width, height))
return 0;
Main_screen=Visible_image[0].Image;
if (!Update_visible_page_buffer(1, width, height))
return 0;
Screen_backup=Visible_image[1].Image;
Download_infos_page_main(Main_backups->Pages);
Download_infos_backup(Main_backups);
// Default values for spare page
Spare_backups->Pages->Width = width;
Spare_backups->Pages->Height = height;
memcpy(Spare_backups->Pages->Palette,Main_palette,sizeof(T_Palette));
strcpy(Spare_backups->Pages->Comment,"");
strcpy(Spare_backups->Pages->File_directory,Spare_current_directory);
strcpy(Spare_backups->Pages->Filename,"NO_NAME.GIF");
Spare_backups->Pages->File_format=DEFAULT_FILEFORMAT;
// Copy this informations in the global Spare_ variables
Download_infos_page_spare(Spare_backups->Pages);
// Clear the initial Visible buffer
//memset(Main_screen,0,Main_image_width*Main_image_height);
// Spare
for (i=0; i<NB_LAYERS; i++)
{
Spare_backups->Pages->Image[i]=New_layer(width*height);
if (! Spare_backups->Pages->Image[i])
return 0;
}
//memset(Spare_screen,0,Spare_image_width*Spare_image_height);
Visible_image[0].Width = width;
Visible_image[0].Height = height;
Visible_image[0].Image = NULL;
Visible_image[1].Width = width;
Visible_image[1].Height = height;
Visible_image[1].Image = NULL;
Visible_image_depth_buffer.Width = width;
Visible_image_depth_buffer.Height = height;
Visible_image_depth_buffer.Image = NULL;
Visible_image[0].Image = (byte *)malloc(Visible_image[0].Width * Visible_image[0].Height);
if (! Visible_image[0].Image)
return 0;
Visible_image[1].Image = (byte *)malloc(Visible_image[1].Width * Visible_image[1].Height);
if (! Visible_image[1].Image)
return 0;
Visible_image_depth_buffer.Image = (byte *)malloc(Visible_image_depth_buffer.Width * Visible_image_depth_buffer.Height);
if (! Visible_image_depth_buffer.Image)
return 0;
End_of_modification();
return 1;
} }
void Set_number_of_backups(int nb_backups) void Set_number_of_backups(int nb_backups)
@ -530,6 +559,7 @@ int Backup_with_new_dimensions(int upload,int width,int height)
// 0 sinon. // 0 sinon.
T_Page * new_page; T_Page * new_page;
byte nb_layers;
int return_code=0; int return_code=0;
int i; int i;
@ -538,8 +568,9 @@ int Backup_with_new_dimensions(int upload,int width,int height)
// retrouver plus tard) // retrouver plus tard)
Upload_infos_page_main(Main_backups->Pages); Upload_infos_page_main(Main_backups->Pages);
nb_layers=Main_backups->Pages->Nb_layers;
// On crée un descripteur pour la nouvelle page courante // On crée un descripteur pour la nouvelle page courante
new_page=New_page(); new_page=New_page(nb_layers);
if (!new_page) if (!new_page)
{ {
Error(0); Error(0);
@ -551,7 +582,7 @@ int Backup_with_new_dimensions(int upload,int width,int height)
new_page->Height=height; new_page->Height=height;
if (Create_new_page(new_page,Main_backups)) if (Create_new_page(new_page,Main_backups))
{ {
for (i=0; i<NB_LAYERS;i++) for (i=0; i<nb_layers;i++)
{ {
//Main_backups->Pages->Image[i]=(byte *)malloc(width*height); //Main_backups->Pages->Image[i]=(byte *)malloc(width*height);
memset(Main_backups->Pages->Image[i], 0, width*height); memset(Main_backups->Pages->Image[i], 0, width*height);
@ -592,7 +623,7 @@ int Backup_and_resize_the_spare(int width,int height)
Upload_infos_page_spare(Spare_backups->Pages); Upload_infos_page_spare(Spare_backups->Pages);
// On crée un descripteur pour la nouvelle page de brouillon // On crée un descripteur pour la nouvelle page de brouillon
new_page=New_page(); new_page=New_page(Spare_backups->Pages->Nb_layers);
if (!new_page) if (!new_page)
{ {
Error(0); Error(0);
@ -632,7 +663,7 @@ void Backup(void)
Upload_infos_page_main(Main_backups->Pages); Upload_infos_page_main(Main_backups->Pages);
// On crée un descripteur pour la nouvelle page courante // On crée un descripteur pour la nouvelle page courante
new_page=New_page(); new_page=New_page(Main_backups->Pages->Nb_layers);
if (!new_page) if (!new_page)
{ {
Error(0); Error(0);
@ -647,7 +678,7 @@ void Backup(void)
Download_infos_backup(Main_backups); Download_infos_backup(Main_backups);
// On copie l'image du backup vers la page courante: // On copie l'image du backup vers la page courante:
for (i=0; i<NB_LAYERS;i++) for (i=0; i<Main_backups->Pages->Nb_layers;i++)
memcpy(Main_backups->Pages->Image[i], memcpy(Main_backups->Pages->Image[i],
Main_backups->Pages->Next->Image[i], Main_backups->Pages->Next->Image[i],
Main_image_width*Main_image_height); Main_image_width*Main_image_height);
@ -743,14 +774,23 @@ void Exchange_main_and_spare(void)
// On extrait ensuite les infos sur les nouvelles pages courante, brouillon // On extrait ensuite les infos sur les nouvelles pages courante, brouillon
// et backup. // et backup.
/* SECTION GROS CACA PROUT PROUT */ Update_depth_buffer(Main_backups->Pages->Width, Main_backups->Pages->Height);
// Auparavant on ruse en mettant déjà à jour les dimensions de la
// nouvelle page courante. Si on ne le fait pas, le "Download" va détecter Update_visible_page_buffer(0, Main_backups->Pages->Width, Main_backups->Pages->Height);
// un changement de dimensions et va bêtement sortir du mode loupe, alors Main_screen=Visible_image[0].Image;
// que lors d'un changement de page, on veut bien conserver l'état du mode
// loupe du brouillon. Update_visible_page_buffer(1, Main_backups->Pages->Width, Main_backups->Pages->Height);
Main_image_width=Main_backups->Pages->Width; Screen_backup=Visible_image[1].Image;
Main_image_height=Main_backups->Pages->Height;
/* SECTION GROS CACA PROUT PROUT */
// Auparavant on ruse en mettant déjà à jour les dimensions de la
// nouvelle page courante. Si on ne le fait pas, le "Download" va détecter
// un changement de dimensions et va bêtement sortir du mode loupe, alors
// que lors d'un changement de page, on veut bien conserver l'état du mode
// loupe du brouillon.
Main_image_width=Main_backups->Pages->Width;
Main_image_height=Main_backups->Pages->Height;
Download_infos_page_main(Main_backups->Pages); Download_infos_page_main(Main_backups->Pages);
Download_infos_backup(Main_backups); Download_infos_backup(Main_backups);

View File

@ -39,7 +39,7 @@ void Download_infos_page_main(T_Page * page);
void Upload_infos_page_main(T_Page * page); void Upload_infos_page_main(T_Page * page);
// private // private
T_Page * New_page(void); T_Page * New_page(byte nb_layers);
void Download_infos_page_spare(T_Page * page); void Download_infos_page_spare(T_Page * page);
void Upload_infos_page_spare(T_Page * page); void Upload_infos_page_spare(T_Page * page);
void Download_infos_backup(T_List_of_pages * list); void Download_infos_backup(T_List_of_pages * list);

View File

@ -330,9 +330,10 @@ typedef struct T_Page
char File_directory[MAX_PATH_CHARACTERS];///< Directory that contains the file. char File_directory[MAX_PATH_CHARACTERS];///< Directory that contains the file.
char Filename[MAX_PATH_CHARACTERS]; ///< Filename without directory. char Filename[MAX_PATH_CHARACTERS]; ///< Filename without directory.
byte File_format; ///< File format, in enum ::FILE_FORMATS byte File_format; ///< File format, in enum ::FILE_FORMATS
struct T_Page *Next; struct T_Page *Next; ///< Pointer to the next backup
struct T_Page *Prev; struct T_Page *Prev; ///< Pointer to the previous backup
byte * Image[NB_LAYERS];///< Pixel data for the image. byte Nb_layers; ///< Number of layers
byte * Image[0]; ///< Pixel data for the image.
} T_Page; } T_Page;
/// Collection of undo/redo steps. /// Collection of undo/redo steps.

View File

@ -380,40 +380,40 @@ void Button_Transform_menu(void)
int i; int i;
case 2 : // Flip X case 2 : // Flip X
for (i=0; i<NB_LAYERS; i++) for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{ {
memcpy(Main_backups->Pages->Image[i],Main_backups->Pages->Next->Image[i],Main_image_width*Main_image_height); memcpy(Main_backups->Pages->Image[i],Main_backups->Pages->Next->Image[i],Main_image_width*Main_image_height);
Flip_X_lowlevel(Main_backups->Pages->Image[i], Main_image_width, Main_image_height); Flip_X_lowlevel(Main_backups->Pages->Image[i], Main_image_width, Main_image_height);
} }
break; break;
case 3 : // Flip Y case 3 : // Flip Y
for (i=0; i<NB_LAYERS; i++) for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{ {
memcpy(Main_backups->Pages->Image[i],Main_backups->Pages->Next->Image[i],Main_image_width*Main_image_height); memcpy(Main_backups->Pages->Image[i],Main_backups->Pages->Next->Image[i],Main_image_width*Main_image_height);
Flip_Y_lowlevel(Main_backups->Pages->Image[i], Main_image_width, Main_image_height); Flip_Y_lowlevel(Main_backups->Pages->Image[i], Main_image_width, Main_image_height);
} }
break; break;
case 4 : // -90° Rotation case 4 : // -90° Rotation
for (i=0; i<NB_LAYERS; i++) for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{ {
Rotate_270_deg_lowlevel(Main_backups->Pages->Next->Image[i], Main_backups->Pages->Image[i], old_width, old_height); Rotate_270_deg_lowlevel(Main_backups->Pages->Next->Image[i], Main_backups->Pages->Image[i], old_width, old_height);
} }
break; break;
case 5 : // +90° Rotation case 5 : // +90° Rotation
for (i=0; i<NB_LAYERS; i++) for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{ {
Rotate_90_deg_lowlevel(Main_backups->Pages->Next->Image[i], Main_backups->Pages->Image[i], old_width, old_height); Rotate_90_deg_lowlevel(Main_backups->Pages->Next->Image[i], Main_backups->Pages->Image[i], old_width, old_height);
} }
break; break;
case 6 : // 180° Rotation case 6 : // 180° Rotation
for (i=0; i<NB_LAYERS; i++) for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{ {
memcpy(Main_backups->Pages->Image[i],Main_backups->Pages->Next->Image[i],Main_image_width*Main_image_height); memcpy(Main_backups->Pages->Image[i],Main_backups->Pages->Next->Image[i],Main_image_width*Main_image_height);
Rotate_180_deg_lowlevel(Main_backups->Pages->Image[i], Main_image_width, Main_image_height); Rotate_180_deg_lowlevel(Main_backups->Pages->Image[i], Main_image_width, Main_image_height);
} }
break; break;
case 7 : // Resize case 7 : // Resize
for (i=0; i<NB_LAYERS; i++) for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{ {
Rescale(Main_backups->Pages->Next->Image[i], old_width, old_height, Main_backups->Pages->Image[i], Main_image_width, Main_image_height, 0, 0); Rescale(Main_backups->Pages->Next->Image[i], old_width, old_height, Main_backups->Pages->Image[i], Main_image_width, Main_image_height, 0, 0);
} }