[layers] NOLAYERS option at compile time. Unfinished.

git-svn-id: svn://pulkomandy.tk/GrafX2/branches/layers@1140 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2009-11-01 23:22:43 +00:00
parent 119e679e32
commit 3ede1f3a56
14 changed files with 134 additions and 74 deletions

View File

@ -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

View File

@ -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++);

View File

@ -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();

View File

@ -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
}

View File

@ -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.

49
graph.c
View File

@ -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]);
}

View File

@ -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);

View File

@ -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"

2
main.c
View File

@ -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)

42
misc.c
View File

@ -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;

4
misc.h
View File

@ -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:

56
pages.c
View File

@ -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; i<Main_image_width*Main_image_height; i++)
{
@ -269,6 +285,7 @@ void Redraw_current_layer(void)
}
}
}
#endif
}
void Upload_infos_page_main(T_Page * page)
@ -323,10 +340,8 @@ void Download_infos_backup(T_List_of_pages * list)
if (Config.FX_Feedback)
FX_feedback_screen=list->Pages->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);
/*

View File

@ -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
///

View File

@ -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<<layer;
}
#else
// Handler for limited layers support: only allow one visible at a time
if (side == LEFT_SIDE)
{
Main_current_layer = layer;
Main_layers_visible = 1<<layer;
Update_screen_targets();
}
#endif
Hide_cursor();
if (Main_layers_visible != old_layers)