diff --git a/Makefile b/Makefile index cf0e13f3..8beba9db 100644 --- a/Makefile +++ b/Makefile @@ -42,7 +42,7 @@ ifdef COMSPEC RMDIR = rmdir CP = cp BIN = grafx2.exe - COPT = -W -Wall -Wdeclaration-after-statement -O$(OPTIM) -g -ggdb `sdl-config --cflags` $(TTFCOPT) $(JOYCOPT) $(LUACOPT) + COPT = -W -Wall -Wdeclaration-after-statement -O$(OPTIM) -g -ggdb `sdl-config --cflags` $(TTFCOPT) $(JOYCOPT) $(LUACOPT) $(LAYERCOPT) LOPT = `sdl-config --libs` -lSDL_image $(TTFLOPT) -lpng $(LUALOPT) CC = gcc OBJDIR = obj/win32 @@ -274,6 +274,14 @@ else JOYCOPT = endif +#To speed up rendering, can disable the layered editing +# with NOLAYERS=1 +ifeq ($(NOLAYERS),1) + LAYERCOPT = -DNOLAYERS +else + LAYERCOPT = +endif + ### And now for the real build rules ### .PHONY : all debug release clean depend zip version force install uninstall diff --git a/buttons.c b/buttons.c index 3b3cde15..85c3ec2c 100644 --- a/buttons.c +++ b/buttons.c @@ -1013,6 +1013,7 @@ void Draw_one_skin_name(word x, word y, word index, byte highlighted) #define SWAP_BYTES(a,b) { byte c=a; a=b; b=c;} #define SWAP_WORDS(a,b) { word c=a; a=b; b=c;} +#define SWAP_DWORDS(a,b) { dword c=a; a=b; b=c;} #define SWAP_SHORTS(a,b) { short c=a; a=b; b=c;} #define SWAP_FLOATS(a,b) { float c=a; a=b; b=c;} @@ -1286,7 +1287,7 @@ void Button_Page(void) SWAP_WORDS (Main_fileselector_position,Spare_fileselector_position) SWAP_WORDS (Main_fileselector_offset,Spare_fileselector_offset) SWAP_SHORTS(Main_current_layer,Spare_current_layer) - SWAP_WORDS (Main_layers_visible,Spare_layers_visible) + SWAP_DWORDS (Main_layers_visible,Spare_layers_visible) // A la fin, on affiche l'écran for (factor_index=0; ZOOM_FACTOR[factor_index]!=Main_magnifier_factor; factor_index++); diff --git a/engine.c b/engine.c index 6b040a9b..b83e91a0 100644 --- a/engine.c +++ b/engine.c @@ -1055,6 +1055,7 @@ void Main_handler(void) Backup_layers(0); if (!Delete_layer(Main_backups,Main_current_layer)) { + Update_screen_targets(); Redraw_layered_image(); Hide_cursor(); Display_all_screen(); @@ -1070,7 +1071,8 @@ void Main_handler(void) Backup_layers(1<<(Main_current_layer-1)); Merge_layer(); - + + Update_screen_targets(); Redraw_layered_image(); Hide_cursor(); Display_all_screen(); @@ -1103,7 +1105,8 @@ void Main_handler(void) Main_layers_visible ^= (3 << Main_current_layer); } Main_current_layer++; - + + Update_screen_targets(); Redraw_layered_image(); Hide_cursor(); Display_all_screen(); @@ -1138,7 +1141,7 @@ void Main_handler(void) Main_layers_visible ^= (3 << (Main_current_layer-1)); } Main_current_layer--; - + Update_screen_targets(); Redraw_layered_image(); Hide_cursor(); Display_all_screen(); diff --git a/factory.c b/factory.c index 5034e97f..e14fd12a 100644 --- a/factory.c +++ b/factory.c @@ -85,7 +85,7 @@ int L_GetPictureSize(lua_State* L) int L_PutPicturePixel(lua_State* L) { Pixel_in_current_layer(lua_tonumber(L, 1), lua_tonumber(L, 2), - lua_tonumber(L, 3),1); + lua_tonumber(L, 3)); return 0; // no values returned for lua } diff --git a/global.h b/global.h index d45ad4db..32765b6b 100644 --- a/global.h +++ b/global.h @@ -415,14 +415,6 @@ GFX2_GLOBAL T_List_of_pages * Main_backups; GFX2_GLOBAL T_List_of_pages * Spare_backups; -// -- Layers data - -/// Array of two images, that contains the "flattened" version of the visible layers. -GFX2_GLOBAL T_Image Visible_image[2]; -GFX2_GLOBAL T_Image Visible_image_depth_buffer; -/// Index that is 0 or 1, it ways which of the two ::Visible_image[] contains the current image (the other contains the data from last backup) -GFX2_GLOBAL int Visible_image_index; - // -- Brush data /// Pixel data of the current brush. diff --git a/graph.c b/graph.c index e5411ae9..a7a6870a 100644 --- a/graph.c +++ b/graph.c @@ -2867,3 +2867,52 @@ void Redraw_grid(short x, short y, unsigned short w, unsigned short h) col+= Snap_width*Main_magnifier_factor; } } + +byte Read_pixel_from_current_screen (word x,word y) +{ + #ifndef NOLAYERS + byte depth; + byte color; + color = *(Main_screen+y*Main_image_width+x); + if (color != Main_backups->Pages->Transparent_color) // transparent color + return color; + + depth = *(Visible_image_depth_buffer.Image+x+y*Main_image_width); + return *(Main_backups->Pages->Image[depth] + x+y*Main_image_width); + #else + return *((y)*Main_image_width+(x)+Main_backups->Pages->Image[Main_current_layer]); + #endif +} + +void Pixel_in_current_screen (word x,word y,byte color,int with_preview) +{ + #ifndef NOLAYERS + byte depth = *(Visible_image_depth_buffer.Image+x+y*Main_image_width); + *(Main_backups->Pages->Image[Main_current_layer] + x+y*Main_image_width)=color; + if ( depth <= Main_current_layer) + { + if (color == Main_backups->Pages->Transparent_color) // transparent color + // fetch pixel color from the topmost visible layer + color=*(Main_backups->Pages->Image[depth] + x+y*Main_image_width); + + *(x+y*Main_image_width+Main_screen)=color; + + if (with_preview) + Pixel_preview(x,y,color); + } + #else + *((y)*Main_image_width+(x)+Main_backups->Pages->Image[Main_current_layer])=color; + if (with_preview) + Pixel_preview(x,y,color); + #endif +} + +void Pixel_in_current_layer(word x,word y, byte color) +{ + *((y)*Main_image_width+(x)+Main_backups->Pages->Image[Main_current_layer])=color; +} + +byte Read_pixel_from_current_layer(word x,word y) +{ + return *((y)*Main_image_width+(x)+Main_backups->Pages->Image[Main_current_layer]); +} diff --git a/graph.h b/graph.h index 08154832..96f12f99 100644 --- a/graph.h +++ b/graph.h @@ -111,3 +111,8 @@ extern Func_pixel Pixel_figure; void Update_part_of_screen(short x, short y, short width, short height); void Redraw_grid(short x, short y, unsigned short w, unsigned short h); + +void Pixel_in_current_screen (word x,word y,byte color,int with_preview); +void Pixel_in_current_layer(word x,word y, byte color); +byte Read_pixel_from_current_screen (word x,word y); +byte Read_pixel_from_current_layer(word x,word y); diff --git a/loadsave.c b/loadsave.c index 5395efcd..517f6a6b 100644 --- a/loadsave.c +++ b/loadsave.c @@ -37,6 +37,7 @@ #include "io.h" #include "loadsave.h" #include "misc.h" +#include "graph.h" #include "op_c.h" #include "pages.h" #include "palette.h" diff --git a/main.c b/main.c index 6ec7e6b4..9b6bad14 100644 --- a/main.c +++ b/main.c @@ -639,6 +639,7 @@ int Init_program(int argc,char * argv[]) Spare_image_width=Screen_width/Pixel_width; Spare_image_height=Screen_height/Pixel_height; + #ifndef NOLAYERS Visible_image[0].Width = 0; Visible_image[0].Height = 0; Visible_image[0].Image = NULL; @@ -648,6 +649,7 @@ int Init_program(int argc,char * argv[]) Visible_image_depth_buffer.Width = 0; Visible_image_depth_buffer.Height = 0; Visible_image_depth_buffer.Image = NULL; + #endif // Allocation de mémoire pour les différents écrans virtuels (et brosse) if (Init_all_backup_lists(Screen_width,Screen_height)==0) diff --git a/misc.c b/misc.c index 162d35b8..a5937a58 100644 --- a/misc.c +++ b/misc.c @@ -34,6 +34,7 @@ #include "windows.h" #include "palette.h" #include "input.h" +#include "graph.h" ///Count used palette indexes in the whole picture ///Return the total number of different colors @@ -216,47 +217,6 @@ byte Read_pixel_from_brush (word x, word y) return *(Brush + y * Brush_width + x); } - -byte Read_pixel_from_current_screen (word x,word y) -{ - byte depth; - byte color; - color = *(Main_screen+y*Main_image_width+x); - if (color != Main_backups->Pages->Transparent_color) // transparent color - return color; - - depth = *(Visible_image_depth_buffer.Image+x+y*Main_image_width); - return *(Main_backups->Pages->Image[depth] + x+y*Main_image_width); - // return *(Main_screen+y*Main_image_width+x); -} - -void Pixel_in_current_screen (word x,word y,byte color,int with_preview) -{ - byte depth = *(Visible_image_depth_buffer.Image+x+y*Main_image_width); - *(Main_backups->Pages->Image[Main_current_layer] + x+y*Main_image_width)=color; - if ( depth <= Main_current_layer) - { - if (color == Main_backups->Pages->Transparent_color) // transparent color - // fetch pixel color from the topmost visible layer - color=*(Main_backups->Pages->Image[depth] + x+y*Main_image_width); - - *(x+y*Main_image_width+Main_screen)=color; - - if (with_preview) - Pixel_preview(x,y,color); - } -} - -void Pixel_in_current_layer(word x,word y, byte color) -{ - *((y)*Main_image_width+(x)+Main_backups->Pages->Image[Main_current_layer])=color; -} - -byte Read_pixel_from_current_layer(word x,word y) -{ - return *((y)*Main_image_width+(x)+Main_backups->Pages->Image[Main_current_layer]); -} - void Replace_a_color(byte old_color, byte new_color) { word x; diff --git a/misc.h b/misc.h index 8dd97925..d91f0f74 100644 --- a/misc.h +++ b/misc.h @@ -36,15 +36,11 @@ dword Round_div(dword numerator,dword divisor); word Count_used_colors(dword * usage); word Count_used_colors_area(dword* usage, word start_x, word start_y, word width, word height); word Count_used_colors_screen_area(dword* usage, word start_x, word start_y, word width, word height); -void Pixel_in_current_screen (word x,word y,byte color,int with_preview); void Pixel_in_brush (word x,word y,byte color); -byte Read_pixel_from_current_screen (word x,word y); byte Read_pixel_from_spare_screen(word x,word y); byte Read_pixel_from_backup_screen (word x,word y); byte Read_pixel_from_feedback_screen (word x,word y); byte Read_pixel_from_brush (word x,word y); -byte Read_pixel_from_current_layer(word x,word y); -void Pixel_in_current_layer(word x,word y, byte color); void Ellipse_compute_limites(short horizontal_radius,short vertical_radius); // Calcule les valeurs suivantes en fonction des deux paramètres: diff --git a/pages.c b/pages.c index 80c139b9..cbfa0d36 100644 --- a/pages.c +++ b/pages.c @@ -31,6 +31,15 @@ #include "misc.h" #include "windows.h" +// -- Layers data + +/// Array of two images, that contains the "flattened" version of the visible layers. +#ifndef NOLAYERS +T_Image Visible_image[2]; +T_Image Visible_image_depth_buffer; +#endif + + /// /// GESTION DES PAGES /// @@ -162,6 +171,7 @@ void Download_infos_page_main(T_Page * page) void Redraw_layered_image(void) { + #ifndef NOLAYERS // Re-construct the image with the visible layers int layer; // First layer @@ -202,11 +212,15 @@ void Redraw_layered_image(void) } } } + #else + Update_screen_targets(); + #endif Download_infos_backup(Main_backups); } void Update_depth_buffer(void) { + #ifndef NOLAYERS // Re-construct the depth buffer with the visible layers. // This function doesn't touch the visible buffer, it assumes // that it was already up-to-date. (Ex. user only changed active layer) @@ -247,11 +261,13 @@ void Update_depth_buffer(void) } } } + #endif Download_infos_backup(Main_backups); } void Redraw_current_layer(void) { +#ifndef NOLAYERS int i; for (i=0; iPages->Image[Main_current_layer]; - // Visible_image[0].Image; else FX_feedback_screen=list->Pages->Next->Image[Main_current_layer]; - // Visible_image[1].Image; } void Clear_page(T_Page * page) @@ -567,26 +582,35 @@ int Update_buffer(T_Image * image, int width, int height) return 1; } +void Update_screen_targets(void) +{ + #ifndef NOLAYERS + Main_screen=Visible_image[0].Image; + Screen_backup=Visible_image[1].Image; + #else + Main_screen=Main_backups->Pages->Image[Main_current_layer]; + Screen_backup=Main_backups->Pages->Next->Image[Main_current_layer]; + #endif +} + /// Update all the special image buffers, if necessary. int Update_buffers(int width, int height) { +#ifndef NOLAYERS if (! Update_buffer(&Visible_image_depth_buffer, width, height)) return 0; - if (! Update_buffer(&Visible_image[0], width, height)) return 0; - Main_screen=Visible_image[0].Image; - if (! Update_buffer(&Visible_image[1], width, height)) - return 0; - Screen_backup=Visible_image[1].Image; - + return 0; +#endif + Update_screen_targets(); return 1; } - /// - /// GESTION DES BACKUPS - /// +/// +/// GESTION DES BACKUPS +/// int Init_all_backup_lists(int width,int height) { @@ -611,7 +635,7 @@ int Init_all_backup_lists(int width,int height) return 0; memset(Main_backups->Pages->Image[i], 0, width*height); } - +#ifndef NOLAYERS Visible_image[0].Width = 0; Visible_image[0].Height = 0; Visible_image[0].Image = NULL; @@ -623,14 +647,15 @@ int Init_all_backup_lists(int width,int height) Visible_image_depth_buffer.Width = 0; Visible_image_depth_buffer.Height = 0; Visible_image_depth_buffer.Image = NULL; - +#endif if (!Update_buffers(width, height)) return 0; +#ifndef NOLAYERS // For speed, instead of Redraw_layered_image() we'll directly set the buffers. memset(Visible_image[0].Image, 0, width*height); memset(Visible_image[1].Image, 0, width*height); memset(Visible_image_depth_buffer.Image, 0, width*height); - +#endif Download_infos_page_main(Main_backups->Pages); Download_infos_backup(Main_backups); @@ -930,10 +955,11 @@ void End_of_modification(void) //Update_buffers(Main_image_width, Main_image_height); - +#ifndef NOLAYERS memcpy(Visible_image[1].Image, Visible_image[0].Image, Main_image_width*Main_image_height); +#endif Download_infos_backup(Main_backups); /* diff --git a/pages.h b/pages.h index c36d98dc..2e434c50 100644 --- a/pages.h +++ b/pages.h @@ -30,6 +30,8 @@ /////////////////////////// BACKUP /////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// +extern T_Image Visible_image[2]; +extern T_Image Visible_image_depth_buffer; /// /// INDIVIDUAL PAGES @@ -92,6 +94,8 @@ void Update_depth_buffer(void); void Redraw_layered_image(void); void Redraw_current_layer(void); +void Update_screen_targets(void); + /// /// STATISTICS /// diff --git a/special.c b/special.c index 5b29f155..0b0c1ce1 100644 --- a/special.c +++ b/special.c @@ -476,6 +476,9 @@ void Layer_activate(short layer, short side) // Keep a copy of which layers were visible old_layers = Main_layers_visible; + + #ifndef NOLAYERS + if (side == RIGHT_SIDE) { // Right-click on current layer @@ -504,6 +507,16 @@ void Layer_activate(short layer, short side) Main_current_layer = layer; Main_layers_visible |= 1<