diff --git a/gfx2.cfg b/gfx2.cfg index f250eb60..0b52ae55 100644 Binary files a/gfx2.cfg and b/gfx2.cfg differ diff --git a/graph.c b/graph.c index abe2fbb8..bbb347af 100644 --- a/graph.c +++ b/graph.c @@ -598,7 +598,7 @@ void Resize_image(word chosen_width,word chosen_height) Main_image_is_modified=1; // On copie donc maintenant la partie C dans la nouvelle image. - for (i=0; iPages->Nb_layers; i++) { Copy_part_of_image_to_another( Main_backups->Pages->Next->Image[i],0,0,Min(old_width,Main_image_width), diff --git a/main.c b/main.c index 8e8bebfb..9866aa98 100644 --- a/main.c +++ b/main.c @@ -635,18 +635,6 @@ int Init_program(int argc,char * argv[]) // Allocation de mémoire pour les différents écrans virtuels (et brosse) if (Init_all_backup_lists(Screen_width,Screen_height)==0) 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) memset(Main_screen,0,Main_image_width*Main_image_height); diff --git a/operatio.c b/operatio.c index 35308969..e21d0ae6 100644 --- a/operatio.c +++ b/operatio.c @@ -4026,7 +4026,7 @@ void Scroll_0_5(void) // Do the actual scroll operation on all layers. - for (i=0; iPages->Nb_layers; i++) Scroll_picture(Main_backups->Pages->Next->Image[i], Main_backups->Pages->Image[i], x_offset, y_offset); } else diff --git a/pages.c b/pages.c index 780b5f3f..0792371d 100644 --- a/pages.c +++ b/pages.c @@ -39,15 +39,15 @@ static word Last_backed_up_layers=0; /// Allocate and initialize a new page. -T_Page * New_page(void) +T_Page * New_page(byte nb_layers) { T_Page * page; - page = (T_Page *)malloc(sizeof(T_Page)); + page = (T_Page *)malloc(sizeof(T_Page)+NB_LAYERS*sizeof(byte *)); if (page!=NULL) { int i; - for (i=0; iImage[i]=NULL; page->Width=0; page->Height=0; @@ -56,12 +56,26 @@ T_Page * New_page(void) page->File_directory[0]='\0'; page->Filename[0]='\0'; page->File_format=DEFAULT_FILEFORMAT; - + page->Nb_layers=nb_layers; page->Next = page->Prev = NULL; } 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) // Affiche la page à l'écran { @@ -102,7 +116,7 @@ void Redraw_layered_image(void) // Re-construct the image with the visible layers int layer; // First layer - for (layer=0; layerPages->Nb_layers; layer++) { if ((1<Pages->Nb_layers; layer++) { if ((1<Image[Spare_current_layer]; + //Spare_screen=page->Image[Spare_current_layer]; Spare_image_width=page->Width; Spare_image_height=page->Height; memcpy(Spare_palette,page->Palette,sizeof(T_Palette)); @@ -177,7 +191,7 @@ void Upload_infos_page_spare(T_Page * page) { if (page!=NULL) { - page->Image[Spare_current_layer]=Spare_screen; + //page->Image[Spare_current_layer]=Spare_screen; page->Width=Spare_image_width; page->Height=Spare_image_height; 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. int i; - for (i=0; iNb_layers; i++) { - free(page->Image[i]); + Free_layer(page->Image[i]); page->Image[i]=NULL; } page->Width=0; @@ -240,7 +254,7 @@ int Allocate_list_of_pages(T_List_of_pages * list) T_Page * page; // On initialise chacune des nouvelles pages - page=New_page(); + page=New_page(NB_LAYERS); if (!page) return 0; @@ -372,8 +386,8 @@ int Create_new_page(T_Page * new_page,T_List_of_pages * list) } { int i; - for (i=0; iImage[i]=(byte *)malloc(new_page->Height*new_page->Width); + for (i=0; iNb_layers; i++) + 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. int i; - if (Allocate_list_of_pages(Main_backups) && - Allocate_list_of_pages(Spare_backups)) + if (! Allocate_list_of_pages(Main_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; iPages->Nb_layers; i++) { - // 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; iPages->Image[i]=(byte *)malloc(width*height); - } - - if (!Update_visible_page_buffer(0, width, height)) + Main_backups->Pages->Image[i]=New_layer(width*height); + if (! Main_backups->Pages->Image[i]) 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; iPages->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) @@ -530,6 +559,7 @@ int Backup_with_new_dimensions(int upload,int width,int height) // 0 sinon. T_Page * new_page; + byte nb_layers; int return_code=0; int i; @@ -538,8 +568,9 @@ int Backup_with_new_dimensions(int upload,int width,int height) // retrouver plus tard) Upload_infos_page_main(Main_backups->Pages); + nb_layers=Main_backups->Pages->Nb_layers; // On crée un descripteur pour la nouvelle page courante - new_page=New_page(); + new_page=New_page(nb_layers); if (!new_page) { Error(0); @@ -551,7 +582,7 @@ int Backup_with_new_dimensions(int upload,int width,int height) new_page->Height=height; if (Create_new_page(new_page,Main_backups)) { - for (i=0; iPages->Image[i]=(byte *)malloc(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); // 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) { Error(0); @@ -632,7 +663,7 @@ void Backup(void) Upload_infos_page_main(Main_backups->Pages); // 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) { Error(0); @@ -647,7 +678,7 @@ void Backup(void) Download_infos_backup(Main_backups); // On copie l'image du backup vers la page courante: - for (i=0; iPages->Nb_layers;i++) memcpy(Main_backups->Pages->Image[i], Main_backups->Pages->Next->Image[i], 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 // et backup. - /* 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; + Update_depth_buffer(Main_backups->Pages->Width, Main_backups->Pages->Height); + + Update_visible_page_buffer(0, Main_backups->Pages->Width, Main_backups->Pages->Height); + Main_screen=Visible_image[0].Image; + + Update_visible_page_buffer(1, Main_backups->Pages->Width, Main_backups->Pages->Height); + Screen_backup=Visible_image[1].Image; + + + /* 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_backup(Main_backups); diff --git a/pages.h b/pages.h index e715d2e9..18fdaba0 100644 --- a/pages.h +++ b/pages.h @@ -39,7 +39,7 @@ void Download_infos_page_main(T_Page * page); void Upload_infos_page_main(T_Page * page); // private -T_Page * New_page(void); +T_Page * New_page(byte nb_layers); void Download_infos_page_spare(T_Page * page); void Upload_infos_page_spare(T_Page * page); void Download_infos_backup(T_List_of_pages * list); diff --git a/struct.h b/struct.h index 4b62483f..2b245943 100644 --- a/struct.h +++ b/struct.h @@ -330,9 +330,10 @@ typedef struct T_Page char File_directory[MAX_PATH_CHARACTERS];///< Directory that contains the file. char Filename[MAX_PATH_CHARACTERS]; ///< Filename without directory. byte File_format; ///< File format, in enum ::FILE_FORMATS - struct T_Page *Next; - struct T_Page *Prev; - byte * Image[NB_LAYERS];///< Pixel data for the image. + struct T_Page *Next; ///< Pointer to the next backup + struct T_Page *Prev; ///< Pointer to the previous backup + byte Nb_layers; ///< Number of layers + byte * Image[0]; ///< Pixel data for the image. } T_Page; /// Collection of undo/redo steps. diff --git a/transform.c b/transform.c index ccf2ffe3..dd714391 100644 --- a/transform.c +++ b/transform.c @@ -380,40 +380,40 @@ void Button_Transform_menu(void) int i; case 2 : // Flip X - for (i=0; iPages->Nb_layers; i++) { 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); } break; case 3 : // Flip Y - for (i=0; iPages->Nb_layers; i++) { 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); } break; case 4 : // -90° Rotation - for (i=0; iPages->Nb_layers; i++) { Rotate_270_deg_lowlevel(Main_backups->Pages->Next->Image[i], Main_backups->Pages->Image[i], old_width, old_height); } break; case 5 : // +90° Rotation - for (i=0; iPages->Nb_layers; i++) { Rotate_90_deg_lowlevel(Main_backups->Pages->Next->Image[i], Main_backups->Pages->Image[i], old_width, old_height); } break; case 6 : // 180° Rotation - for (i=0; iPages->Nb_layers; i++) { 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); } break; case 7 : // Resize - for (i=0; iPages->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); }