diff --git a/src/fileformats.c b/src/fileformats.c index 21d281e2..bef58bcc 100644 --- a/src/fileformats.c +++ b/src/fileformats.c @@ -2085,7 +2085,7 @@ void Load_GIF(T_IO_Context * context) // This a second layer/frame, or more. // Attempt to add a layer to current image current_layer++; - Set_layer(context, current_layer); + Set_loading_layer(context, current_layer); } number_LID++; @@ -2444,7 +2444,7 @@ void Save_GIF(T_IO_Context * context) GCE_block[3] |= 1; // Transparent color flag GCE_block[6] = context->Transparent_color; - Set_layer(context, current_layer); + Set_saving_layer(context, current_layer); if (current_layer == context->Nb_layers -1) { diff --git a/src/loadsave.c b/src/loadsave.c index 281879e5..e9e73edb 100644 --- a/src/loadsave.c +++ b/src/loadsave.c @@ -436,7 +436,7 @@ void Pre_load(T_IO_Context *context, short width, short height, long file_size, context->Nb_layers=1; Main_current_layer=0; Main_layers_visible=1<<0; - Set_layer(context,0); + Set_loading_layer(context,0); // Remove previous comment, unless we load just a palette if (! Get_fileformat(context->Format)->Palette_only) @@ -1261,7 +1261,18 @@ void Init_context_surface(T_IO_Context * context, char *file_name, char *file_di } /// Function to call when need to switch layers. -void Set_layer(T_IO_Context *context, byte layer) +void Set_saving_layer(T_IO_Context *context, byte layer) +{ + context->Current_layer = layer; + + if (context->Type == CONTEXT_MAIN_IMAGE) + { + context->Target_address=Main_backups->Pages->Image[layer]; + } +} + +/// Function to call when need to switch layers. +void Set_loading_layer(T_IO_Context *context, byte layer) { context->Current_layer = layer; @@ -1280,9 +1291,8 @@ void Set_layer(T_IO_Context *context, byte layer) context->Nb_layers = Main_backups->Pages->Nb_layers; Main_layers_visible = (2<Target_address=Main_backups->Pages->Image[layer]; - Main_current_layer = layer; + context->Target_address=Main_backups->Pages->Image[layer]; } } diff --git a/src/loadsave.h b/src/loadsave.h index 8fcd6376..ca05b6ef 100644 --- a/src/loadsave.h +++ b/src/loadsave.h @@ -215,7 +215,9 @@ void Set_pixel(T_IO_Context *context, short x, short y, byte c); /// Set the color of a 24bit pixel (on load) void Set_pixel_24b(T_IO_Context *context, short x, short y, byte r, byte g, byte b); /// Function to call when need to switch layers. -void Set_layer(T_IO_Context *context, byte layer); +void Set_loading_layer(T_IO_Context *context, byte layer); +/// Function to call when need to switch layers. +void Set_saving_layer(T_IO_Context *context, byte layer); // ================================================================= diff --git a/src/miscfileformats.c b/src/miscfileformats.c index c0629c3c..9747799a 100644 --- a/src/miscfileformats.c +++ b/src/miscfileformats.c @@ -2206,7 +2206,7 @@ void Load_C64_fli(T_IO_Context *context, byte *bitmap, byte *screen_ram, byte *c } } - Set_layer(context, 1); + Set_loading_layer(context, 1); for(cy=0; cy<25; cy++) { for(cx=0; cx<40; cx++) @@ -2222,7 +2222,7 @@ void Load_C64_fli(T_IO_Context *context, byte *bitmap, byte *screen_ram, byte *c } } - Set_layer(context, 2); + Set_loading_layer(context, 2); for(cy=0; cy<25; cy++) { for(cx=0; cx<40; cx++) @@ -2244,7 +2244,7 @@ void Load_C64_fli(T_IO_Context *context, byte *bitmap, byte *screen_ram, byte *c } } } - Set_layer(context, 3); + Set_loading_layer(context, 3); for(y=0; y<200; y++) { for(x=0; x<160; x++) @@ -3015,7 +3015,7 @@ void Load_CM5(T_IO_Context* context) if (Read_byte(file, &value)!=1) File_error = 2; - Set_layer(context, 0); + Set_loading_layer(context, 0); for(ty=0; tyHeight; ty++) for(tx=0; txWidth; tx++) { @@ -3029,19 +3029,19 @@ void Load_CM5(T_IO_Context* context) { case 0: // This is color for layer 1 - Set_layer(context, 1); + Set_loading_layer(context, 1); for(tx=0; txWidth; tx++) Set_pixel(context, tx, line, value); break; case 1: // This is color for layer 2 - Set_layer(context, 2); + Set_loading_layer(context, 2); for(tx=0; txWidth; tx++) Set_pixel(context, tx, line, value); break; default: // This is color for a block in layer 4 - Set_layer(context, 3); + Set_loading_layer(context, 3); for(tx=(mod-2)*48; tx<(mod-1)*48; tx++) Set_pixel(context, tx, line, value); break; @@ -3065,7 +3065,7 @@ void Load_CM5(T_IO_Context* context) return; } - Set_layer(context, 4); + Set_loading_layer(context, 4); for (ty = 0; ty < 256; ty++) { @@ -3106,15 +3106,15 @@ void Save_CM5(T_IO_Context* context) } // Write layer 0 - Set_layer(context, 0); + Set_saving_layer(context, 0); Write_byte(file, Get_pixel(context, 0, 0)); for(ty = 0; ty < 256; ty++) { - Set_layer(context, 1); + Set_saving_layer(context, 1); Write_byte(file, Get_pixel(context, 0, ty)); - Set_layer(context, 2); + Set_saving_layer(context, 2); Write_byte(file, Get_pixel(context, 0, ty)); - Set_layer(context, 3); + Set_saving_layer(context, 3); for(tx = 0; tx < 6; tx++) { Write_byte(file, Get_pixel(context, tx*48, ty)); @@ -3132,7 +3132,7 @@ void Save_CM5(T_IO_Context* context) return; } - Set_layer(context, 4); + Set_saving_layer(context, 4); for (ty = 0; ty < 256; ty++) {