From e87f9140c785745a11091c69956cf98e13ece196 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Tue, 16 Oct 2012 00:07:42 +0000 Subject: [PATCH] Fix issue 516: Some changes can't be undone on animations > 32 frames git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@2033 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- src/buttons.c | 10 +++++----- src/factory.c | 2 +- src/graph.c | 2 +- src/layers.c | 16 ++++++++-------- src/loadsave.c | 2 +- src/oldies.c | 2 +- src/operatio.c | 2 +- src/pages.c | 51 ++++++++++++++++++++++++++++---------------------- src/pages.h | 9 ++++++--- src/palette.c | 12 ++++++------ 10 files changed, 59 insertions(+), 49 deletions(-) diff --git a/src/buttons.c b/src/buttons.c index 61f62091..78780a4b 100644 --- a/src/buttons.c +++ b/src/buttons.c @@ -1705,7 +1705,7 @@ void Copy_some_colors(void) if (confirmation) { // Make a backup with the same pixel data as previous history steps - Backup_the_spare(0); + Backup_the_spare(LAYER_NONE); for (index=0; index<256; index++) { if (mask_color_to_copy[index]) @@ -1749,7 +1749,7 @@ void Button_Copy_page(void) switch (clicked_button) { case 1: // Pixels+palette - Backup_the_spare(-1); + // backup is done by the following function Copy_image_only(); // copie de la palette memcpy(Spare_palette,Main_palette,sizeof(T_Palette)); @@ -1762,7 +1762,7 @@ void Button_Copy_page(void) break; case 2: // Pixels only - Backup_the_spare(-1); + // backup is done by the following function Copy_image_only(); // Equivalent of 'end_of_modifications' for spare. Update_spare_buffers(Spare_image_width,Spare_image_height); @@ -1773,7 +1773,7 @@ void Button_Copy_page(void) break; case 3: // Palette only - Backup_the_spare(0); + Backup_the_spare(LAYER_NONE); // Copy palette memcpy(Spare_palette,Main_palette,sizeof(T_Palette)); // Equivalent of 'end_of_modifications' for spare. @@ -1788,7 +1788,7 @@ void Button_Copy_page(void) break; case 5: // Palette and remap - Backup_the_spare(-1); + Backup_the_spare(LAYER_ALL); Remap_spare(); // Copy palette memcpy(Spare_palette,Main_palette,sizeof(T_Palette)); diff --git a/src/factory.c b/src/factory.c index 8c7664ab..53380878 100644 --- a/src/factory.c +++ b/src/factory.c @@ -1808,7 +1808,7 @@ void Run_script(const char *script_subdirectory, const char *script_filename) // The backup also allows the script to read from it to make something // like a feedback off effect (convolution matrix comes to mind). Backup(); - Backup_the_spare(-1); + Backup_the_spare(LAYER_ALL); Palette_has_changed=0; Brush_was_altered=0; diff --git a/src/graph.c b/src/graph.c index 7bab467e..fcec800d 100644 --- a/src/graph.c +++ b/src/graph.c @@ -719,7 +719,7 @@ void Get_colors_from_brush(void) //if (Confirmation_box("Modify current palette ?")) // Backup with unchanged layers, only palette is modified - Backup_layers(0); + Backup_layers(LAYER_NONE); // Init array of new colors for (color=0;color<=255;color++) diff --git a/src/layers.c b/src/layers.c index 09ea4288..eb77a34d 100644 --- a/src/layers.c +++ b/src/layers.c @@ -107,7 +107,7 @@ void Button_Layer_add(void) if (Main_backups->Pages->Nb_layers < max[Main_backups->Pages->Image_mode]) { // Backup with unchanged layers - Backup_layers(0); + Backup_layers(LAYER_NONE); if (!Add_layer(Main_backups,Main_current_layer+1)) { if (Main_backups->Pages->Image_mode == IMAGE_MODE_ANIMATION) @@ -142,7 +142,7 @@ void Button_Layer_remove(void) if (Main_backups->Pages->Nb_layers > 1) { // Backup with unchanged layers - Backup_layers(0); + Backup_layers(LAYER_NONE); if (!Delete_layer(Main_backups,Main_current_layer)) { Update_screen_targets(); @@ -278,7 +278,7 @@ void Button_Layer_menu(void) if (Main_backups->Pages->Transparent_color != transparent_color || Main_backups->Pages->Background_transparent != transparent_background) { - Backup_layers(-1); + Backup_layers(LAYER_NONE); Main_backups->Pages->Transparent_color = transparent_color; Main_backups->Pages->Background_transparent = transparent_background; Redraw_layered_image(); @@ -297,7 +297,7 @@ void Button_Layer_set_transparent(void) if (Main_backups->Pages->Transparent_color != Back_color) { - Backup_layers(-1); + Backup_layers(LAYER_ALL); Main_backups->Pages->Transparent_color = Back_color; Redraw_layered_image(); @@ -329,7 +329,7 @@ void Button_Layer_merge(void) if (Main_current_layer>0) { // Backup layer below the current - Backup_layers(1<<(Main_current_layer-1)); + Backup_layers(Main_current_layer-1); Merge_layer(); @@ -354,7 +354,7 @@ void Button_Layer_up(void) dword layer_flags; // Backup with unchanged layers - Backup_layers(0); + Backup_layers(LAYER_NONE); // swap tmp = Main_backups->Pages->Image[Main_current_layer]; @@ -394,7 +394,7 @@ void Button_Layer_down(void) dword layer_flags; // Backup with unchanged layers - Backup_layers(0); + Backup_layers(LAYER_NONE); // swap tmp = Main_backups->Pages->Image[Main_current_layer]; @@ -513,7 +513,7 @@ void Button_Anim_time(void) if (clicked_button==5) { // Accept changes - Backup_layers(0); + Backup_layers(LAYER_NONE); switch(mode) { case 0: diff --git a/src/loadsave.c b/src/loadsave.c index 8039cd4e..eb4e77ab 100644 --- a/src/loadsave.c +++ b/src/loadsave.c @@ -758,7 +758,7 @@ void Load_image(T_IO_Context *context) if (format->Palette_only) { // Make a backup step - Backup_layers(0); + Backup_layers(LAYER_NONE); } // Copy the loaded palette memcpy(Main_palette, context->Palette, sizeof(T_Palette)); diff --git a/src/oldies.c b/src/oldies.c index 4bbccd44..10942555 100644 --- a/src/oldies.c +++ b/src/oldies.c @@ -363,7 +363,7 @@ byte C64_FLI_enforcer(void) if (Main_backups->Pages->Nb_layers != 4) return 2; - Backup_layers(1<<3); + Backup_layers(3); memset(bitmap,0,8000); memset(background,0,200); diff --git a/src/operatio.c b/src/operatio.c index 232b74b0..9d9a987a 100644 --- a/src/operatio.c +++ b/src/operatio.c @@ -2784,7 +2784,7 @@ void Scroll_12_0(void) Backup(); else { - Backup_layers(-1); // Main_layers_visible + Backup_layers(LAYER_ALL); // Main_layers_visible if (Main_backups->Pages->Image_mode != IMAGE_MODE_ANIMATION) { // Ensure the backup visible image is up-to-date diff --git a/src/pages.c b/src/pages.c index 8e40ffaa..9762e524 100644 --- a/src/pages.c +++ b/src/pages.c @@ -609,8 +609,9 @@ void Free_last_page_of_list(T_List_of_pages * list) } } -// layer_mask tells which layers have to be fresh copies instead of references -int Create_new_page(T_Page * new_page, T_List_of_pages * list, dword layer_mask) +// layer tells which layers have to be fresh copies instead of references : +// it's a layer number (>=0) or LAYER_NONE or LAYER_ALL +int Create_new_page(T_Page * new_page, T_List_of_pages * list, int layer) { // This function fills the "Image" field of a new Page, @@ -632,15 +633,15 @@ int Create_new_page(T_Page * new_page, T_List_of_pages * list, dword layer_mask) int i; for (i=0; iNb_layers; i++) { - if ((1<Image[i].Pixels=New_layer(new_page->Height*new_page->Width); else new_page->Image[i].Pixels=Dup_layer(list->Pages->Image[i].Pixels); new_page->Image[i].Duration=list->Pages->Image[i].Duration; } } - + // Insert as first new_page->Next = list->Pages; new_page->Prev = list->Pages->Prev; @@ -879,7 +880,7 @@ int Backup_new_image(int layers,int width,int height) new_page->Height=height; new_page->Transparent_color=0; new_page->Gradients=Dup_gradient(NULL); - if (!Create_new_page(new_page,Main_backups,0xFFFFFFFF)) + if (!Create_new_page(new_page,Main_backups,LAYER_ALL)) { Error(0); return 0; @@ -912,7 +913,7 @@ int Backup_with_new_dimensions(int width,int height) new_page->Width=width; new_page->Height=height; new_page->Transparent_color=0; - if (!Create_new_page(new_page,Main_backups,0xFFFFFFFF)) + if (!Create_new_page(new_page,Main_backups,LAYER_ALL)) { Error(0); return 0; @@ -1062,7 +1063,7 @@ int Backup_and_resize_the_spare(int width,int height) new_page->Width=width; new_page->Height=height; - if (Create_new_page(new_page,Spare_backups,0xFFFFFFFF)) + if (Create_new_page(new_page,Spare_backups,LAYER_ALL)) { byte i; @@ -1087,10 +1088,10 @@ void Backup(void) // Sauve la page courante comme première page de backup et crée une nouvelle page // pur continuer à dessiner. Utilisé par exemple pour le fill { - Backup_layers(1<Pages); new_page->Gradients=Dup_gradient(Main_backups->Pages); - Create_new_page(new_page,Main_backups,layer_mask); + Create_new_page(new_page,Main_backups,layer); Download_infos_page_main(new_page); Update_FX_feedback(Config.FX_Feedback); // Copy the actual pixels from the backup to the latest page - for (i=0; iPages->Nb_layers;i++) + if (layer != LAYER_NONE) { - if ((1<Pages->Image[i].Pixels, - Main_backups->Pages->Next->Image[i].Pixels, - Main_image_width*Main_image_height); + for (i=0; iPages->Nb_layers;i++) + { + if (layer == LAYER_ALL || i == layer) + memcpy(Main_backups->Pages->Image[i].Pixels, + Main_backups->Pages->Next->Image[i].Pixels, + Main_image_width*Main_image_height); + } } // Light up the 'has unsaved changes' indicator Main_image_is_modified=1; @@ -1136,7 +1140,7 @@ void Backup_layers(dword layer_mask) */ } -void Backup_the_spare(dword layer_mask) +void Backup_the_spare(int layer) { int i; T_Page *new_page; @@ -1152,15 +1156,18 @@ void Backup_the_spare(dword layer_mask) // Fill it with a copy of the latest history Copy_S_page(new_page,Spare_backups->Pages); new_page->Gradients=Dup_gradient(Spare_backups->Pages); - Create_new_page(new_page,Spare_backups,layer_mask); + Create_new_page(new_page,Spare_backups,layer); // Copy the actual pixels from the backup to the latest page - for (i=0; iPages->Nb_layers;i++) + if (layer != LAYER_NONE) { - if ((1<Pages->Image[i].Pixels, - Spare_backups->Pages->Next->Image[i].Pixels, - Spare_image_width*Spare_image_height); + for (i=0; iPages->Nb_layers;i++) + { + if (layer == LAYER_ALL || i == layer) + memcpy(Spare_backups->Pages->Image[i].Pixels, + Spare_backups->Pages->Next->Image[i].Pixels, + Spare_image_width*Spare_image_height); + } } // Light up the 'has unsaved changes' indicator Spare_image_is_modified=1; diff --git a/src/pages.h b/src/pages.h index f01ea54a..cad7ebec 100644 --- a/src/pages.h +++ b/src/pages.h @@ -81,7 +81,7 @@ int Allocate_list_of_pages(T_List_of_pages * list); void Backward_in_list_of_pages(T_List_of_pages * list); void Advance_in_list_of_pages(T_List_of_pages * list); void Free_last_page_of_list(T_List_of_pages * list); -int Create_new_page(T_Page * new_page,T_List_of_pages * current_list, dword layer_mask); +int Create_new_page(T_Page * new_page,T_List_of_pages * current_list, int layer); void Change_page_number_of_list(T_List_of_pages * list,int number); void Free_page_of_a_list(T_List_of_pages * list); @@ -91,6 +91,9 @@ void Free_page_of_a_list(T_List_of_pages * list); /// BACKUP HIGH-LEVEL FUNCTIONS /// +static const int LAYER_NONE = -1; +static const int LAYER_ALL = -2; + int Init_all_backup_lists(enum IMAGE_MODES image_mode,int width,int height); void Set_number_of_backups(int nb_backups); int Backup_new_image(int layers,int width,int height); @@ -101,12 +104,12 @@ int Backup_with_new_dimensions(int width,int height); /// pixels. This function is meant to be used from within Lua scripts. int Backup_in_place(int width,int height); /// Backup the spare image, the one you don't see. -void Backup_the_spare(dword layer_mask); +void Backup_the_spare(int layer); int Backup_and_resize_the_spare(int width,int height); /// Backup with a new copy for the working layer, and references for all others. void Backup(void); /// Backup with a new copy of some layers (the others are references). -void Backup_layers(dword layer_mask); +void Backup_layers(int layer); void Undo(void); void Redo(void); void Free_current_page(void); // 'Kill' button diff --git a/src/palette.c b/src/palette.c index 21287922..d8ecf597 100644 --- a/src/palette.c +++ b/src/palette.c @@ -1768,7 +1768,7 @@ void Button_Palette(void) // est en mode X-SWAP. if (!image_is_backed_up) { - Backup_layers(-1); + Backup_layers(LAYER_ALL); image_is_backed_up=1; } @@ -1916,7 +1916,7 @@ void Button_Palette(void) { if (!image_is_backed_up) { - Backup_layers(-1); + Backup_layers(LAYER_ALL); image_is_backed_up = 1; } @@ -2290,7 +2290,7 @@ void Button_Palette(void) { if (!image_is_backed_up) { - Backup_layers(-1); + Backup_layers(LAYER_ALL); image_is_backed_up=1; } Hide_cursor(); @@ -2371,7 +2371,7 @@ void Button_Palette(void) // Make a backup because remapping is an undoable modification if (!image_is_backed_up) { - Backup_layers(-1); + Backup_layers(LAYER_ALL); image_is_backed_up=1; } @@ -2614,7 +2614,7 @@ void Button_Palette(void) { if (!image_is_backed_up) { - Backup_layers(-1); + Backup_layers(LAYER_ALL); image_is_backed_up=1; } if (used_colors==-1) @@ -2743,7 +2743,7 @@ void Button_Palette(void) { if ( (!image_is_backed_up) && memcmp(Main_palette,working_palette,sizeof(T_Palette)) ) - Backup_layers(-1); + Backup_layers(LAYER_NONE); memcpy(Main_palette,working_palette,sizeof(T_Palette)); End_of_modification(); // Not really needed, the change was in palette entries