Merged back the layers branch into trunk. Common version now!

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1163 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2009-11-11 00:03:07 +00:00
commit c3e087fa7e
29 changed files with 1849 additions and 1093 deletions

View File

@ -42,7 +42,7 @@ ifdef COMSPEC
RMDIR = rmdir RMDIR = rmdir
CP = cp CP = cp
BIN = grafx2.exe 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) LOPT = `sdl-config --libs` -lSDL_image $(TTFLOPT) -lpng $(LUALOPT)
CC = gcc CC = gcc
OBJDIR = obj/win32 OBJDIR = obj/win32
@ -274,6 +274,14 @@ else
JOYCOPT = JOYCOPT =
endif 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 ### ### And now for the real build rules ###
.PHONY : all debug release clean depend zip version force install uninstall .PHONY : all debug release clean depend zip version force install uninstall

View File

@ -7,7 +7,11 @@ $(OBJDIR)/buttons.o: buttons.c const.h struct.h global.h misc.h graph.h engine.h
sdlscreen.h windows.h brush.h input.h special.h sdlscreen.h windows.h brush.h input.h special.h
$(OBJDIR)/engine.o: engine.c const.h struct.h global.h graph.h misc.h special.h \ $(OBJDIR)/engine.o: engine.c const.h struct.h global.h graph.h misc.h special.h \
buttons.h operatio.h shade.h errors.h sdlscreen.h windows.h brush.h \ buttons.h operatio.h shade.h errors.h sdlscreen.h windows.h brush.h \
input.h engine.h input.h engine.h pages.h
$(OBJDIR)/factory.o: factory.c brush.h struct.h const.h buttons.h engine.h errors.h \
filesel.h global.h graph.h io.h misc.h readline.h sdlscreen.h windows.h
$(OBJDIR)/fileformats.o: fileformats.c errors.h global.h struct.h const.h \
loadsave.h misc.h
$(OBJDIR)/filesel.o: filesel.c const.h struct.h global.h misc.h errors.h io.h \ $(OBJDIR)/filesel.o: filesel.c const.h struct.h global.h misc.h errors.h io.h \
windows.h sdlscreen.h loadsave.h mountlist.h engine.h readline.h \ windows.h sdlscreen.h loadsave.h mountlist.h engine.h readline.h \
input.h help.h filesel.h input.h help.h filesel.h
@ -16,23 +20,27 @@ $(OBJDIR)/graph.o: graph.c global.h struct.h const.h engine.h buttons.h pages.h
pxdouble.h pxtriple.h pxwide2.h pxtall2.h pxquad.h windows.h input.h pxdouble.h pxtriple.h pxwide2.h pxtall2.h pxquad.h windows.h input.h
$(OBJDIR)/help.o: help.c const.h struct.h global.h misc.h engine.h helpfile.h \ $(OBJDIR)/help.o: help.c const.h struct.h global.h misc.h engine.h helpfile.h \
help.h sdlscreen.h text.h keyboard.h windows.h input.h hotkeys.h \ help.h sdlscreen.h text.h keyboard.h windows.h input.h hotkeys.h \
errors.h errors.h pages.h
$(OBJDIR)/hotkeys.o: hotkeys.c struct.h const.h global.h hotkeys.h $(OBJDIR)/hotkeys.o: hotkeys.c struct.h const.h global.h hotkeys.h
$(OBJDIR)/init.o: init.c const.h struct.h global.h graph.h buttons.h palette.h \ $(OBJDIR)/init.o: init.c buttons.h struct.h const.h errors.h global.h graph.h \
help.h operatio.h misc.h errors.h keyboard.h io.h hotkeys.h setup.h \ init.h io.h factory.h help.h hotkeys.h keyboard.h loadsave.h misc.h \
windows.h sdlscreen.h mountlist.h loadsave.h init.h transform.h mountlist.h operatio.h palette.h sdlscreen.h setup.h transform.h \
windows.h
$(OBJDIR)/input.o: input.c global.h struct.h const.h keyboard.h sdlscreen.h \ $(OBJDIR)/input.o: input.c global.h struct.h const.h keyboard.h sdlscreen.h \
windows.h errors.h misc.h input.h windows.h errors.h misc.h input.h
$(OBJDIR)/io.o: io.c struct.h const.h io.h realpath.h $(OBJDIR)/io.o: io.c struct.h const.h io.h realpath.h
$(OBJDIR)/keyboard.o: keyboard.c global.h struct.h const.h keyboard.h $(OBJDIR)/keyboard.o: keyboard.c global.h struct.h const.h keyboard.h
$(OBJDIR)/libraw2crtc.o: libraw2crtc.c global.h struct.h const.h
$(OBJDIR)/loadsave.o: loadsave.c buttons.h struct.h const.h errors.h global.h io.h \ $(OBJDIR)/loadsave.o: loadsave.c buttons.h struct.h const.h errors.h global.h io.h \
loadsave.h misc.h op_c.h pages.h palette.h sdlscreen.h windows.h \ loadsave.h misc.h graph.h op_c.h pages.h palette.h sdlscreen.h \
engine.h windows.h engine.h
$(OBJDIR)/main.o: main.c const.h struct.h global.h graph.h misc.h init.h buttons.h \ $(OBJDIR)/main.o: main.c const.h struct.h global.h graph.h misc.h init.h buttons.h \
engine.h pages.h loadsave.h sdlscreen.h errors.h readini.h saveini.h \ engine.h pages.h loadsave.h sdlscreen.h errors.h readini.h saveini.h \
io.h text.h setup.h windows.h brush.h palette.h realpath.h io.h text.h setup.h windows.h brush.h palette.h realpath.h
$(OBJDIR)/misc.o: misc.c struct.h const.h sdlscreen.h global.h errors.h buttons.h \ $(OBJDIR)/misc.o: misc.c struct.h const.h sdlscreen.h global.h errors.h buttons.h \
engine.h misc.h keyboard.h windows.h palette.h input.h engine.h misc.h keyboard.h windows.h palette.h input.h graph.h
$(OBJDIR)/miscfileformats.o: miscfileformats.c engine.h struct.h const.h errors.h \
global.h io.h libraw2crtc.h loadsave.h misc.h sdlscreen.h windows.h
$(OBJDIR)/mountlist.o: mountlist.c $(OBJDIR)/mountlist.o: mountlist.c
$(OBJDIR)/op_c.o: op_c.c op_c.h struct.h const.h errors.h $(OBJDIR)/op_c.o: op_c.c op_c.h struct.h const.h errors.h
$(OBJDIR)/operatio.o: operatio.c const.h struct.h global.h misc.h engine.h graph.h \ $(OBJDIR)/operatio.o: operatio.c const.h struct.h global.h misc.h engine.h graph.h \
@ -68,15 +76,15 @@ $(OBJDIR)/saveini.o: saveini.c const.h global.h struct.h readini.h io.h errors.h
$(OBJDIR)/sdlscreen.o: sdlscreen.c global.h struct.h const.h sdlscreen.h errors.h \ $(OBJDIR)/sdlscreen.o: sdlscreen.c global.h struct.h const.h sdlscreen.h errors.h \
misc.h misc.h
$(OBJDIR)/setup.o: setup.c struct.h const.h io.h setup.h $(OBJDIR)/setup.o: setup.c struct.h const.h io.h setup.h
$(OBJDIR)/shade.o: shade.c global.h struct.h const.h graph.h engine.h misc.h \ $(OBJDIR)/shade.o: shade.c global.h struct.h const.h graph.h engine.h errors.h \
readline.h help.h sdlscreen.h windows.h input.h shade.h misc.h readline.h help.h sdlscreen.h windows.h input.h shade.h
$(OBJDIR)/special.o: special.c const.h struct.h global.h graph.h engine.h windows.h \ $(OBJDIR)/special.o: special.c const.h struct.h global.h graph.h engine.h windows.h \
special.h special.h pages.h misc.h buttons.h
$(OBJDIR)/text.o: text.c SFont.h struct.h const.h global.h sdlscreen.h io.h \ $(OBJDIR)/text.o: text.c SFont.h struct.h const.h global.h sdlscreen.h io.h \
errors.h errors.h
$(OBJDIR)/transform.o: transform.c global.h struct.h const.h transform.h engine.h \ $(OBJDIR)/transform.o: transform.c global.h struct.h const.h transform.h engine.h \
sdlscreen.h windows.h input.h help.h misc.h readline.h buttons.h \ sdlscreen.h windows.h input.h help.h misc.h readline.h buttons.h \
pages.h pages.h
$(OBJDIR)/version.o: version.c $(OBJDIR)/version.o: version.c
$(OBJDIR)/windows.o: windows.c windows.h struct.h const.h global.h graph.h engine.h \ $(OBJDIR)/windows.o: windows.c windows.h struct.h const.h engine.h errors.h \
misc.h sdlscreen.h errors.h input.h global.h graph.h input.h misc.h readline.h sdlscreen.h

View File

@ -730,8 +730,7 @@ void Capture_brush(short start_x,short start_y,short end_x,short end_y,short cle
for (y_pos=start_y;y_pos<start_y+Brush_height;y_pos++) for (y_pos=start_y;y_pos<start_y+Brush_height;y_pos++)
for (x_pos=start_x;x_pos<start_x+Brush_width;x_pos++) for (x_pos=start_x;x_pos<start_x+Brush_width;x_pos++)
{ {
Pixel_in_current_screen(x_pos,y_pos,Back_color); Pixel_in_current_screen(x_pos,y_pos,Back_color,1);
Pixel_preview (x_pos,y_pos,Back_color);
} }
Update_part_of_screen(start_x,start_y,Brush_width,Brush_height); Update_part_of_screen(start_x,start_y,Brush_width,Brush_height);
} }
@ -1156,10 +1155,10 @@ void Capture_brush_with_lasso(int vertices, short * points,short clear)
for (x_pos=start_x;x_pos<=end_x;x_pos++) for (x_pos=start_x;x_pos<=end_x;x_pos++)
if (Read_pixel_from_brush(x_pos-start_x,y_pos-start_y)!=Back_color) if (Read_pixel_from_brush(x_pos-start_x,y_pos-start_y)!=Back_color)
{ {
Pixel_in_brush(x_pos-start_x,y_pos-start_y,Read_pixel_from_current_screen(x_pos,y_pos)); Pixel_in_brush(x_pos-start_x,y_pos-start_y,Read_pixel_from_current_layer(x_pos,y_pos));
// On regarde s'il faut effacer quelque chose: // On regarde s'il faut effacer quelque chose:
if (clear) if (clear)
Pixel_in_current_screen(x_pos,y_pos,Back_color); Pixel_in_current_screen(x_pos,y_pos,Back_color,0);
} }
// On centre la prise sur la brosse // On centre la prise sur la brosse

135
buttons.c
View File

@ -513,6 +513,7 @@ void Button_Clear(void)
Hide_current_image_with_stencil(0,Stencil); Hide_current_image_with_stencil(0,Stencil);
else else
Hide_current_image(0); Hide_current_image(0);
Redraw_layered_image();
Display_all_screen(); Display_all_screen();
End_of_modification(); End_of_modification();
Unselect_button(BUTTON_CLEAR); Unselect_button(BUTTON_CLEAR);
@ -527,6 +528,7 @@ void Button_Clear_with_backcolor(void)
Hide_current_image_with_stencil(Back_color,Stencil); Hide_current_image_with_stencil(Back_color,Stencil);
else else
Hide_current_image(Back_color); Hide_current_image(Back_color);
Redraw_layered_image();
Display_all_screen(); Display_all_screen();
End_of_modification(); End_of_modification();
Unselect_button(BUTTON_CLEAR); Unselect_button(BUTTON_CLEAR);
@ -1013,6 +1015,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_BYTES(a,b) { byte c=a; a=b; b=c;}
#define SWAP_WORDS(a,b) { word 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_SHORTS(a,b) { short c=a; a=b; b=c;}
#define SWAP_FLOATS(a,b) { float c=a; a=b; b=c;} #define SWAP_FLOATS(a,b) { float c=a; a=b; b=c;}
@ -1251,7 +1254,7 @@ void Button_Page(void)
{ {
byte factor_index; byte factor_index;
char Temp_buffer[256]; char Temp_buffer[256];
Hide_cursor(); Hide_cursor();
// On dégrossit le travail avec les infos des listes de pages // On dégrossit le travail avec les infos des listes de pages
@ -1278,14 +1281,19 @@ void Button_Page(void)
SWAP_BYTES (Main_image_is_modified,Spare_image_is_modified) SWAP_BYTES (Main_image_is_modified,Spare_image_is_modified)
// Swap des infos sur les fileselects // Swap des infos sur les fileselects
strcpy(Temp_buffer ,Spare_current_directory); strcpy(Temp_buffer ,Spare_current_directory);
strcpy(Spare_current_directory,Main_current_directory); strcpy(Spare_current_directory,Main_current_directory);
strcpy(Main_current_directory,Temp_buffer ); strcpy(Main_current_directory,Temp_buffer );
SWAP_BYTES (Main_format,Spare_format) SWAP_BYTES (Main_format,Spare_format)
SWAP_WORDS (Main_fileselector_position,Spare_fileselector_position) SWAP_WORDS (Main_fileselector_position,Spare_fileselector_position)
SWAP_WORDS (Main_fileselector_offset,Spare_fileselector_offset) SWAP_WORDS (Main_fileselector_offset,Spare_fileselector_offset)
SWAP_SHORTS(Main_current_layer,Spare_current_layer)
SWAP_DWORDS (Main_layers_visible,Spare_layers_visible)
Update_screen_targets();
// A la fin, on affiche l'écran // A la fin, on affiche l'écran
for (factor_index=0; ZOOM_FACTOR[factor_index]!=Main_magnifier_factor; factor_index++); for (factor_index=0; ZOOM_FACTOR[factor_index]!=Main_magnifier_factor; factor_index++);
Change_magnifier_factor(factor_index); Change_magnifier_factor(factor_index);
@ -1305,18 +1313,38 @@ void Button_Page(void)
void Copy_image_only(void) void Copy_image_only(void)
{ {
word old_width=Spare_image_width;
word old_height=Spare_image_height;
if (Backup_and_resize_the_spare(Main_image_width,Main_image_height)) if (Backup_and_resize_the_spare(Main_image_width,Main_image_height))
{ {
// copie de l'image byte i;
memcpy(Spare_screen,Main_screen,Main_image_width*Main_image_height); for (i=0; i<Spare_backups->Pages->Nb_layers; i++)
{
if (i == Spare_current_layer)
{
// Copy the current layer
memcpy(Spare_backups->Pages->Image[i],Main_backups->Pages->Image[Main_current_layer],Main_image_width*Main_image_height);
}
else
{
// Resize the original layer
Copy_part_of_image_to_another(
Spare_backups->Pages->Next->Image[i],0,0,Min(old_width,Spare_image_width),
Min(old_height,Spare_image_height),old_width,
Spare_backups->Pages->Image[i],0,0,Spare_image_width);
}
}
// Copie des dimensions de l'image // Copie des dimensions de l'image
/* /*
C'est inutile, le "Backuper et redimensionner brouillon" a déjà modifié C'est inutile, le "Backuper et redimensionner brouillon" a déjà modifié
ces valeurs pour qu'elles soient correctes. ces valeurs pour qu'elles soient correctes.
*/ */
/*
Spare_image_width=Main_image_width; Spare_image_width=Main_image_width;
Spare_image_height=Main_image_height; Spare_image_height=Main_image_height;
*/
// Copie des décalages de la fenêtre principale (non zoomée) de l'image // Copie des décalages de la fenêtre principale (non zoomée) de l'image
Spare_offset_X=Main_offset_X; Spare_offset_X=Main_offset_X;
@ -1430,10 +1458,10 @@ void Button_Copy_page(void)
// -- Suppression d'une page ------------------------------------------------- // -- Suppression d'une page -------------------------------------------------
void Button_Kill(void) void Button_Kill(void)
{ {
if ( (Main_backups->Nb_pages_allocated==1) if ( (Main_backups->List_size==1)
|| (!Confirmation_box("Delete the current page?")) ) || (!Confirmation_box("Delete the current page?")) )
{ {
if (Main_backups->Nb_pages_allocated==1) if (Main_backups->List_size==1)
Warning_message("You can't delete the last page."); Warning_message("You can't delete the last page.");
Hide_cursor(); Hide_cursor();
Unselect_button(BUTTON_KILL); Unselect_button(BUTTON_KILL);
@ -2467,33 +2495,33 @@ void Button_Paintbrush_menu(void)
Hide_cursor(); Hide_cursor();
Display_stored_brush_in_window(x_pos+2, y_pos+2, index); Display_stored_brush_in_window(x_pos+2, y_pos+2, index);
Display_cursor(); Display_cursor();
} }
else else
{ {
// Restore and exit // Restore and exit
if (Restore_brush(index)) if (Restore_brush(index))
{ {
Close_window(); Close_window();
break; break;
} }
} }
} }
else if (clicked_button>1 && Window_attribute1==LEFT_SIDE) else if (clicked_button>1 && Window_attribute1==LEFT_SIDE)
// Standard paintbrushes // Standard paintbrushes
{ {
Close_window(); Close_window();
index=clicked_button-2; index=clicked_button-2;
Paintbrush_shape=Gfx->Paintbrush_type[index]; Paintbrush_shape=Gfx->Paintbrush_type[index];
Paintbrush_width=Gfx->Preset_paintbrush_width[index]; Paintbrush_width=Gfx->Preset_paintbrush_width[index];
Paintbrush_height=Gfx->Preset_paintbrush_height[index]; Paintbrush_height=Gfx->Preset_paintbrush_height[index];
Paintbrush_offset_X=Gfx->Preset_paintbrush_offset_X[index]; Paintbrush_offset_X=Gfx->Preset_paintbrush_offset_X[index];
Paintbrush_offset_Y=Gfx->Preset_paintbrush_offset_Y[index]; Paintbrush_offset_Y=Gfx->Preset_paintbrush_offset_Y[index];
for (y_pos=0; y_pos<Paintbrush_height; y_pos++) for (y_pos=0; y_pos<Paintbrush_height; y_pos++)
for (x_pos=0; x_pos<Paintbrush_width; x_pos++) for (x_pos=0; x_pos<Paintbrush_width; x_pos++)
Paintbrush_sprite[(y_pos*MAX_PAINTBRUSH_SIZE)+x_pos]=Gfx->Paintbrush_sprite[index][y_pos][x_pos]; Paintbrush_sprite[(y_pos*MAX_PAINTBRUSH_SIZE)+x_pos]=Gfx->Paintbrush_sprite[index][y_pos][x_pos];
Change_paintbrush_shape(Gfx->Paintbrush_type[index]); Change_paintbrush_shape(Gfx->Paintbrush_type[index]);
break; break;
} }
@ -2802,6 +2830,7 @@ void Load_picture(byte image)
} }
Compute_optimal_menu_colors(Main_palette); Compute_optimal_menu_colors(Main_palette);
Redraw_layered_image();
Display_all_screen(); Display_all_screen();
if (image) if (image)
@ -2903,7 +2932,7 @@ void Button_Reload(void)
Compute_limits(); Compute_limits();
Compute_paintbrush_coordinates(); Compute_paintbrush_coordinates();
} }
Redraw_layered_image();
Display_all_screen(); Display_all_screen();
Main_image_is_modified=0; Main_image_is_modified=0;
@ -4158,56 +4187,6 @@ void Effects_off(void)
Snap_mode=0; Snap_mode=0;
} }
void Transparency_set(byte amount)
{
const int doubleclick_delay = Config.Double_key_speed;
static long time_click = 0;
long time_previous;
if (!Colorize_mode)
{
// Activate mode
switch(Colorize_current_mode)
{
case 0 :
Effect_function=Effect_interpolated_colorize;
break;
case 1 :
Effect_function=Effect_additive_colorize;
break;
case 2 :
Effect_function=Effect_substractive_colorize;
}
Shade_mode=0;
Quick_shade_mode=0;
Smooth_mode=0;
Tiling_mode=0;
Colorize_mode=1;
}
time_previous = time_click;
time_click = SDL_GetTicks();
// Check if it's a quick re-press
if (time_click - time_previous < doubleclick_delay)
{
// Use the typed amount as units, keep the tens.
Colorize_opacity = ((Colorize_opacity%100) /10 *10) + amount;
if (Colorize_opacity == 0)
Colorize_opacity = 100;
}
else
{
// Use 10% units: "1"=10%, ... "0"=100%
if (amount == 0)
Colorize_opacity = 100;
else
Colorize_opacity = amount*10;
}
Compute_colorize_table();
}
//---------------------------- Courbes de Bézier ---------------------------- //---------------------------- Courbes de Bézier ----------------------------
void Button_Curves(void) void Button_Curves(void)
@ -5396,9 +5375,11 @@ void Button_Effects(void)
break; break;
case 13 : // Feedback (pour Colorize et Shade) case 13 : // Feedback (pour Colorize et Shade)
if ((Config.FX_Feedback=!Config.FX_Feedback)) //!!! if ((Config.FX_Feedback=!Config.FX_Feedback)) //!!!
FX_feedback_screen=Main_screen; FX_feedback_screen=Main_backups->Pages->Image[Main_current_layer];
// Main_screen
else else
FX_feedback_screen=Screen_backup; FX_feedback_screen=Main_backups->Pages->Next->Image[Main_current_layer];
// Screen_backup
Hide_cursor(); Hide_cursor();
Display_feedback_state(); Display_feedback_state();
Display_cursor(); Display_cursor();
@ -5706,10 +5687,10 @@ void Display_stored_brush_in_window(word x_pos,word y_pos,int index)
offset_y = (BRUSH_CONTAINER_PREVIEW_HEIGHT-Brush_container[index].Height)/2; offset_y = (BRUSH_CONTAINER_PREVIEW_HEIGHT-Brush_container[index].Height)/2;
// Determine corner pixel of paintbrush to draw (if bigger than preview area) // Determine corner pixel of paintbrush to draw (if bigger than preview area)
// //
// Clear // Clear
Window_rectangle(x_pos,y_pos,BRUSH_CONTAINER_PREVIEW_WIDTH,BRUSH_CONTAINER_PREVIEW_HEIGHT,MC_Light); Window_rectangle(x_pos,y_pos,BRUSH_CONTAINER_PREVIEW_WIDTH,BRUSH_CONTAINER_PREVIEW_HEIGHT,MC_Light);
// Draw up to 16x16 // Draw up to 16x16
for (y=0; y<Brush_container[index].Height && y<BRUSH_CONTAINER_PREVIEW_HEIGHT; y++) for (y=0; y<Brush_container[index].Height && y<BRUSH_CONTAINER_PREVIEW_HEIGHT; y++)
{ {

View File

@ -440,11 +440,6 @@ void Button_Tiling_menu(void);
*/ */
void Effects_off(void); void Effects_off(void);
/*!
Command that sets the transparency level.
*/
void Transparency_set(byte amount);
// Menu des effets // Menu des effets
/*! /*!

View File

@ -66,7 +66,7 @@
#define LEFT_TRIANGLE_CHARACTER 17 #define LEFT_TRIANGLE_CHARACTER 17
/// Character to display in menus for an ellipsis. /// Character to display in menus for an ellipsis.
#define ELLIPSIS_CHARACTER '…' #define ELLIPSIS_CHARACTER '…'
#define NB_LAYERS 1 ///< Initial number of layers for a new image
#define BRUSH_CONTAINER_PREVIEW_WIDTH 16 ///< Size for preview of a brush in Brush container #define BRUSH_CONTAINER_PREVIEW_WIDTH 16 ///< Size for preview of a brush in Brush container
#define BRUSH_CONTAINER_PREVIEW_HEIGHT 16 ///< Size for preview of a brush in Brush container #define BRUSH_CONTAINER_PREVIEW_HEIGHT 16 ///< Size for preview of a brush in Brush container
#define BRUSH_CONTAINER_COLUMNS 4 ///< Number of columns in the Brush container #define BRUSH_CONTAINER_COLUMNS 4 ///< Number of columns in the Brush container

136
engine.c
View File

@ -38,6 +38,7 @@
#include "brush.h" #include "brush.h"
#include "input.h" #include "input.h"
#include "engine.h" #include "engine.h"
#include "pages.h"
// we need this as global // we need this as global
@ -1016,6 +1017,141 @@ void Main_handler(void)
Zoom_set(11); Zoom_set(11);
action++; action++;
break; break;
case SPECIAL_LAYER1_SELECT:
case SPECIAL_LAYER2_SELECT:
case SPECIAL_LAYER3_SELECT:
case SPECIAL_LAYER4_SELECT:
case SPECIAL_LAYER5_SELECT:
case SPECIAL_LAYER6_SELECT:
case SPECIAL_LAYER7_SELECT:
case SPECIAL_LAYER8_SELECT:
Layer_activate((key_index-SPECIAL_LAYER1_SELECT)/2, LEFT_SIDE);
action++;
break;
case SPECIAL_LAYER1_TOGGLE:
case SPECIAL_LAYER2_TOGGLE:
case SPECIAL_LAYER3_TOGGLE:
case SPECIAL_LAYER4_TOGGLE:
case SPECIAL_LAYER5_TOGGLE:
case SPECIAL_LAYER6_TOGGLE:
case SPECIAL_LAYER7_TOGGLE:
case SPECIAL_LAYER8_TOGGLE:
Layer_activate((key_index-SPECIAL_LAYER1_TOGGLE)/2, RIGHT_SIDE);
action++;
break;
case SPECIAL_LAYER_ADD:
// Backup with unchanged layers
Backup_layers(0);
if (!Add_layer(Main_backups,Main_current_layer+1))
{
Update_depth_buffer();
Hide_cursor();
Display_all_screen();
Display_cursor();
End_of_modification();
}
action++;
break;
case SPECIAL_LAYER_DELETE:
// Backup with unchanged layers
Backup_layers(0);
if (!Delete_layer(Main_backups,Main_current_layer))
{
Update_screen_targets();
Redraw_layered_image();
Hide_cursor();
Display_all_screen();
Display_cursor();
End_of_modification();
}
action++;
break;
case SPECIAL_LAYER_MERGE:
if (Main_current_layer>0)
{
// Backup layer below the current
Backup_layers(1<<(Main_current_layer-1));
Merge_layer();
Update_screen_targets();
Redraw_layered_image();
Hide_cursor();
Display_all_screen();
Display_cursor();
End_of_modification();
}
action++;
break;
case SPECIAL_LAYER_SWAP_UP:
if (Main_current_layer < (Main_backups->Pages->Nb_layers-1))
{
byte * tmp;
dword layer_flags;
// Backup with unchanged layers
Backup_layers(0);
// swap
tmp = Main_backups->Pages->Image[Main_current_layer];
Main_backups->Pages->Image[Main_current_layer] = Main_backups->Pages->Image[Main_current_layer+1];
Main_backups->Pages->Image[Main_current_layer+1] = tmp;
// Swap visibility indicators
layer_flags = (Main_layers_visible >> Main_current_layer) & 3;
// Only needed if they are different.
if (layer_flags == 1 || layer_flags == 2)
{
// One is on, the other is off. Negating them will
// perform the swap.
Main_layers_visible ^= (3 << Main_current_layer);
}
Main_current_layer++;
Update_screen_targets();
Redraw_layered_image();
Hide_cursor();
Display_all_screen();
Display_cursor();
End_of_modification();
}
action++;
break;
case SPECIAL_LAYER_SWAP_DOWN:
if (Main_current_layer > 0)
{
byte * tmp;
dword layer_flags;
// Backup with unchanged layers
Backup_layers(0);
// swap
tmp = Main_backups->Pages->Image[Main_current_layer];
Main_backups->Pages->Image[Main_current_layer] = Main_backups->Pages->Image[Main_current_layer-1];
Main_backups->Pages->Image[Main_current_layer-1] = tmp;
// Swap visibility indicators
layer_flags = (Main_layers_visible >> (Main_current_layer-1)) & 3;
// Only needed if they are different.
if (layer_flags == 1 || layer_flags == 2)
{
// Only needed if they are different.
// One is on, the other is off. Negating them will
// perform the swap.
Main_layers_visible ^= (3 << (Main_current_layer-1));
}
Main_current_layer--;
Update_screen_targets();
Redraw_layered_image();
Hide_cursor();
Display_all_screen();
Display_cursor();
End_of_modification();
}
action++;
break;
} }
} }
} // End of special keys } // End of special keys

View File

@ -86,14 +86,14 @@ int L_GetPictureSize(lua_State* L)
int L_PutPicturePixel(lua_State* L) int L_PutPicturePixel(lua_State* L)
{ {
Pixel_in_current_screen(lua_tonumber(L, 1), lua_tonumber(L, 2), Pixel_in_current_layer(lua_tonumber(L, 1), lua_tonumber(L, 2),
lua_tonumber(L, 3)); lua_tonumber(L, 3));
return 0; // no values returned for lua return 0; // no values returned for lua
} }
int L_GetPicturePixel(lua_State* L) int L_GetPicturePixel(lua_State* L)
{ {
uint8_t c = Read_pixel_from_current_screen(lua_tonumber(L, 1), uint8_t c = Read_pixel_from_current_layer(lua_tonumber(L, 1),
lua_tonumber(L, 2)); lua_tonumber(L, 2));
lua_pushinteger(L, c); lua_pushinteger(L, c);
return 1; return 1;

View File

@ -1544,24 +1544,38 @@ void Save_BMP(void)
#pragma pack(1) #pragma pack(1)
typedef struct typedef struct
{ {
word Width; // width de l'écran virtuel word Width; // Width of the complete image area
word Height; // height de l'écran virtuel word Height; // Height of the complete image area
byte Resol; // Informations sur la résolution (et autres) byte Resol; // Informations about the resolution (and other)
byte Backcol; // color de fond byte Backcol; // Proposed background color
byte Aspect; // Informations sur l'aspect ratio (et autres) byte Aspect; // Informations about aspect ratio (and other)
} T_GIF_LSDB; // Logical Screen Descriptor Block } T_GIF_LSDB; // Logical Screen Descriptor Block
typedef struct typedef struct
{ {
word Pos_X; // Abscisse où devrait être affichée l'image word Pos_X; // X offset where the image should be pasted
word Pos_Y; // Ordonnée où devrait être affichée l'image word Pos_Y; // Y offset where the image should be pasted
word Image_width; // width de l'image word Image_width; // Width of image
word Image_height; // height de l'image word Image_height; // Height of image
byte Indicator; // Informations diverses sur l'image byte Indicator; // Misc image information
byte Nb_bits_pixel; // Nb de bits par pixel byte Nb_bits_pixel; // Nb de bits par pixel
} T_GIF_IDB; // Image Descriptor Block } T_GIF_IDB; // Image Descriptor Block
#pragma pack() #pragma pack()
typedef struct
{
// byte Block_identifier : 0x21
// byte Function : 0xF9
// byte Block_size // 4
byte Packed_fields; // 11100000 : Reserved
// 00011100 : Disposal method
// 00000010 : User input flag
// 00000001 : Transparent flag
word Delay_time; // Time for this frame to stay displayed
byte Transparent_color; // Which color index acts as transparent
//word Bloc_terminator; // 0x00
} T_GIF_GCE; // Graphic Control Extension
// -- Tester si un fichier est au format GIF -------------------------------- // -- Tester si un fichier est au format GIF --------------------------------
void Test_GIF(void) void Test_GIF(void)
@ -1587,104 +1601,106 @@ void Test_GIF(void)
} }
// -- Lire un fichier au format GIF -----------------------------------------
// -- Lire un fichier au format GIF ----------------------------------------- // -- Lire un fichier au format GIF -----------------------------------------
// Définition de quelques variables globales au chargement du GIF87a // Définition de quelques variables globales au chargement du GIF87a
word GIF_nb_bits; // Nb de bits composants un code complet word GIF_nb_bits; // Nb de bits composants un code complet
word GIF_remainder_bits; // Nb de bits encore dispos dans GIF_last_byte word GIF_remainder_bits; // Nb de bits encore dispos dans GIF_last_byte
byte GIF_remainder_byte; // Nb d'octets avant le prochain bloc de Raster Data byte GIF_remainder_byte; // Nb d'octets avant le prochain bloc de Raster Data
word GIF_current_code; // Code traité (qui vient d'être lu en général) word GIF_current_code; // Code traité (qui vient d'être lu en général)
byte GIF_last_byte; // Octet de lecture des bits byte GIF_last_byte; // Octet de lecture des bits
word GIF_pos_X; // Coordonnées d'affichage de l'image word GIF_pos_X; // Coordonnées d'affichage de l'image
word GIF_pos_Y; word GIF_pos_Y;
word GIF_interlaced; // L'image est entrelacée word GIF_interlaced; // L'image est entrelacée
word GIF_finished_interlaced_image; // L'image entrelacée est finie de charger word GIF_finished_interlaced_image; // L'image entrelacée est finie de charger
word GIF_pass; // index de passe de l'image entrelacée word GIF_pass; // index de passe de l'image entrelacée
FILE *GIF_file; // L'handle du fichier FILE *GIF_file; // L'handle du fichier
// -- Lit le code à GIF_nb_bits suivant -- // -- Lit le code à GIF_nb_bits suivant --
word GIF_get_next_code(void) word GIF_get_next_code(void)
{
word nb_bits_to_process=GIF_nb_bits;
word nb_bits_processed =0;
word current_nb_bits;
GIF_current_code=0;
while (nb_bits_to_process)
{ {
word nb_bits_to_process=GIF_nb_bits; if (GIF_remainder_bits==0) // Il ne reste plus de bits...
word nb_bits_processed =0;
word current_nb_bits;
GIF_current_code=0;
while (nb_bits_to_process)
{ {
if (GIF_remainder_bits==0) // Il ne reste plus de bits... // Lire l'octet suivant:
{
// Lire l'octet suivant:
// Si on a atteint la fin du bloc de Raster Data // Si on a atteint la fin du bloc de Raster Data
if (GIF_remainder_byte==0) if (GIF_remainder_byte==0)
// Lire l'octet nous donnant la taille du bloc de Raster Data suivant // Lire l'octet nous donnant la taille du bloc de Raster Data suivant
if(Read_byte(GIF_file, &GIF_remainder_byte)!=1) if(Read_byte(GIF_file, &GIF_remainder_byte)!=1)
File_error=2; File_error=2;
if(Read_byte(GIF_file,&GIF_last_byte)!=1) if(Read_byte(GIF_file,&GIF_last_byte)!=1)
File_error = 2; File_error = 2;
GIF_remainder_byte--; GIF_remainder_byte--;
GIF_remainder_bits=8; GIF_remainder_bits=8;
}
current_nb_bits=(nb_bits_to_process<=GIF_remainder_bits)?nb_bits_to_process:GIF_remainder_bits;
GIF_current_code|=(GIF_last_byte & ((1<<current_nb_bits)-1))<<nb_bits_processed;
GIF_last_byte>>=current_nb_bits;
nb_bits_processed +=current_nb_bits;
nb_bits_to_process-=current_nb_bits;
GIF_remainder_bits -=current_nb_bits;
} }
return GIF_current_code; current_nb_bits=(nb_bits_to_process<=GIF_remainder_bits)?nb_bits_to_process:GIF_remainder_bits;
GIF_current_code|=(GIF_last_byte & ((1<<current_nb_bits)-1))<<nb_bits_processed;
GIF_last_byte>>=current_nb_bits;
nb_bits_processed +=current_nb_bits;
nb_bits_to_process-=current_nb_bits;
GIF_remainder_bits -=current_nb_bits;
} }
// -- Affiche un nouveau pixel -- return GIF_current_code;
}
void GIF_new_pixel(byte color) // -- Affiche un nouveau pixel --
void GIF_new_pixel(T_GIF_IDB *idb, byte color)
{
if (color != Main_backups->Pages->Transparent_color) // transparent color
Pixel_load_function(idb->Pos_X+GIF_pos_X, idb->Pos_Y+GIF_pos_Y,color);
GIF_pos_X++;
if (GIF_pos_X>=idb->Image_width)
{ {
Pixel_load_function(GIF_pos_X,GIF_pos_Y,color); GIF_pos_X=0;
GIF_pos_X++; if (!GIF_interlaced)
GIF_pos_Y++;
if (GIF_pos_X>=Main_image_width) else
{ {
GIF_pos_X=0; switch (GIF_pass)
if (!GIF_interlaced)
GIF_pos_Y++;
else
{ {
switch (GIF_pass) case 0 : GIF_pos_Y+=8;
{ break;
case 0 : GIF_pos_Y+=8; case 1 : GIF_pos_Y+=8;
break; break;
case 1 : GIF_pos_Y+=8; case 2 : GIF_pos_Y+=4;
break; break;
case 2 : GIF_pos_Y+=4; default: GIF_pos_Y+=2;
break; }
default: GIF_pos_Y+=2;
}
if (GIF_pos_Y>=Main_image_height) if (GIF_pos_Y>=idb->Image_height)
{
switch(++GIF_pass)
{ {
switch(++GIF_pass) case 1 : GIF_pos_Y=4;
{ break;
case 1 : GIF_pos_Y=4; case 2 : GIF_pos_Y=2;
break; break;
case 2 : GIF_pos_Y=2; case 3 : GIF_pos_Y=1;
break; break;
case 3 : GIF_pos_Y=1; case 4 : GIF_finished_interlaced_image=1;
break;
case 4 : GIF_finished_interlaced_image=1;
}
} }
} }
} }
} }
}
void Load_GIF(void) void Load_GIF(void)
@ -1701,11 +1717,12 @@ void Load_GIF(void)
T_GIF_LSDB LSDB; T_GIF_LSDB LSDB;
T_GIF_IDB IDB; T_GIF_IDB IDB;
T_GIF_GCE GCE;
word nb_colors; // Nombre de couleurs dans l'image word nb_colors; // Nombre de couleurs dans l'image
word color_index; // index de traitement d'une couleur word color_index; // index de traitement d'une couleur
byte size_to_read; // Nombre de données à lire (divers) byte size_to_read; // Nombre de données à lire (divers)
byte block_indentifier; // Code indicateur du type de bloc en cours byte block_identifier; // Code indicateur du type de bloc en cours
word initial_nb_bits; // Nb de bits au début du traitement LZW word initial_nb_bits; // Nb de bits au début du traitement LZW
word special_case=0; // Mémoire pour le cas spécial word special_case=0; // Mémoire pour le cas spécial
word old_code=0; // Code précédent word old_code=0; // Code précédent
@ -1718,11 +1735,6 @@ void Load_GIF(void)
/////////////////////////////////////////////////// FIN DES DECLARATIONS // /////////////////////////////////////////////////// FIN DES DECLARATIONS //
GIF_pos_X=0;
GIF_pos_Y=0;
GIF_last_byte=0;
GIF_remainder_bits=0;
GIF_remainder_byte=0;
number_LID=0; number_LID=0;
Get_full_filename(filename,0); Get_full_filename(filename,0);
@ -1752,16 +1764,15 @@ void Load_GIF(void)
Original_screen_X=LSDB.Width; Original_screen_X=LSDB.Width;
Original_screen_Y=LSDB.Height; Original_screen_Y=LSDB.Height;
Init_preview(LSDB.Width,LSDB.Height,file_size,FORMAT_GIF,PIXEL_SIMPLE);
Main_image_width=LSDB.Width;
Main_image_height=LSDB.Height;
// Palette globale dispo = (LSDB.Resol and $80) // Palette globale dispo = (LSDB.Resol and $80)
// Profondeur de couleur =((LSDB.Resol and $70) shr 4)+1 // Profondeur de couleur =((LSDB.Resol and $70) shr 4)+1
// Nombre de bits/pixel = (LSDB.Resol and $07)+1 // Nombre de bits/pixel = (LSDB.Resol and $07)+1
// Ordre de Classement = (LSDB.Aspect and $80) // Ordre de Classement = (LSDB.Aspect and $80)
alphabet_stack_pos=0;
GIF_last_byte =0;
GIF_remainder_bits =0;
GIF_remainder_byte =0;
nb_colors=(1 << ((LSDB.Resol & 0x07)+1)); nb_colors=(1 << ((LSDB.Resol & 0x07)+1));
initial_nb_bits=(LSDB.Resol & 0x07)+2; initial_nb_bits=(LSDB.Resol & 0x07)+2;
@ -1795,10 +1806,10 @@ void Load_GIF(void)
} }
// On lit un indicateur de block // On lit un indicateur de block
Read_byte(GIF_file,&block_indentifier); Read_byte(GIF_file,&block_identifier);
while (block_indentifier!=0x3B && !File_error) while (block_identifier!=0x3B && !File_error)
{ {
switch (block_indentifier) switch (block_identifier)
{ {
case 0x21: // Bloc d'extension case 0x21: // Bloc d'extension
{ {
@ -1828,7 +1839,20 @@ void Load_GIF(void)
break; break;
case 0xF9: // Graphics Control Extension case 0xF9: // Graphics Control Extension
// Prévu pour la transparence // Prévu pour la transparence
if ( Read_byte(GIF_file,&(GCE.Packed_fields))
&& Read_word_le(GIF_file,&(GCE.Delay_time))
&& Read_byte(GIF_file,&(GCE.Transparent_color)))
{
if (GCE.Packed_fields & 1)
Main_backups->Pages->Transparent_color= GCE.Transparent_color;
else
Main_backups->Pages->Transparent_color = -1;
}
else
File_error=2;
break;
default: default:
// On saute le bloc: // On saute le bloc:
fseek(GIF_file,size_to_read,SEEK_CUR); fseek(GIF_file,size_to_read,SEEK_CUR);
@ -1842,10 +1866,11 @@ void Load_GIF(void)
case 0x2C: // Local Image Descriptor case 0x2C: // Local Image Descriptor
{ {
// Si on a deja lu une image, c'est une GIF animée ou bizarroide, on sort. // Si on a deja lu une image, c'est une GIF animée ou bizarroide, on sort.
if (number_LID!=0) if (number_LID!=0 && Pixel_load_function==Pixel_load_in_current_screen)
{ {
File_error=2; // This a second layer/frame, or more.
break; // Attempt to add a layer to current image
Add_layer(Main_backups, Main_current_layer+1);
} }
number_LID++; number_LID++;
@ -1858,10 +1883,6 @@ void Load_GIF(void)
&& Read_byte(GIF_file,&(IDB.Nb_bits_pixel)) && Read_byte(GIF_file,&(IDB.Nb_bits_pixel))
&& IDB.Image_width && IDB.Image_height) && IDB.Image_width && IDB.Image_height)
{ {
Main_image_width=IDB.Image_width;
Main_image_height=IDB.Image_height;
Init_preview(IDB.Image_width,IDB.Image_height,file_size,FORMAT_GIF,PIXEL_SIMPLE);
// Palette locale dispo = (IDB.Indicator and $80) // Palette locale dispo = (IDB.Indicator and $80)
// Image entrelacée = (IDB.Indicator and $40) // Image entrelacée = (IDB.Indicator and $40)
@ -1913,6 +1934,13 @@ void Load_GIF(void)
//////////////////////////////////////////// DECOMPRESSION LZW // //////////////////////////////////////////// DECOMPRESSION LZW //
GIF_pos_X=0;
GIF_pos_Y=0;
alphabet_stack_pos=0;
GIF_last_byte =0;
GIF_remainder_bits =0;
GIF_remainder_byte =0;
while ( (GIF_get_next_code()!=value_eof) && (!File_error) ) while ( (GIF_get_next_code()!=value_eof) && (!File_error) )
{ {
if (GIF_current_code<=alphabet_free) if (GIF_current_code<=alphabet_free)
@ -1934,7 +1962,7 @@ void Load_GIF(void)
special_case=alphabet_stack[alphabet_stack_pos++]=GIF_current_code; special_case=alphabet_stack[alphabet_stack_pos++]=GIF_current_code;
do do
GIF_new_pixel(alphabet_stack[--alphabet_stack_pos]); GIF_new_pixel(&IDB, alphabet_stack[--alphabet_stack_pos]);
while (alphabet_stack_pos!=0); while (alphabet_stack_pos!=0);
alphabet_prefix[alphabet_free ]=old_code; alphabet_prefix[alphabet_free ]=old_code;
@ -1954,7 +1982,7 @@ void Load_GIF(void)
alphabet_free =nb_colors+2; alphabet_free =nb_colors+2;
special_case =GIF_get_next_code(); special_case =GIF_get_next_code();
old_code =GIF_current_code; old_code =GIF_current_code;
GIF_new_pixel(GIF_current_code); GIF_new_pixel(&IDB, GIF_current_code);
} }
} }
else else
@ -1965,7 +1993,7 @@ void Load_GIF(void)
if (File_error>=0) if (File_error>=0)
if ( /* (GIF_pos_X!=0) || */ if ( /* (GIF_pos_X!=0) || */
( ( (!GIF_interlaced) && (GIF_pos_Y!=Main_image_height) ) || ( ( (!GIF_interlaced) && (GIF_pos_Y!=IDB.Image_height) ) ||
( (GIF_interlaced) && (!GIF_finished_interlaced_image) ) ( (GIF_interlaced) && (!GIF_finished_interlaced_image) )
) ) ) )
File_error=2; File_error=2;
@ -1977,7 +2005,7 @@ void Load_GIF(void)
break; break;
} }
// Lecture du code de fonction suivant: // Lecture du code de fonction suivant:
Read_byte(GIF_file,&block_indentifier); Read_byte(GIF_file,&block_identifier);
} }
} // Le fichier contenait un LSDB } // Le fichier contenait un LSDB
else else
@ -2058,16 +2086,16 @@ void Load_GIF(void)
// -- Lire le pixel suivant -- // -- Lire le pixel suivant --
byte GIF_next_pixel(void) byte GIF_next_pixel(T_GIF_IDB *idb)
{ {
byte temp; byte temp;
temp=Read_pixel_function(GIF_pos_X,GIF_pos_Y); temp=Read_pixel_function(GIF_pos_X,GIF_pos_Y);
if (++GIF_pos_X>=Main_image_width) if (++GIF_pos_X>=idb->Image_width)
{ {
GIF_pos_X=0; GIF_pos_X=0;
if (++GIF_pos_Y>=Main_image_height) if (++GIF_pos_Y>=idb->Image_height)
GIF_stop=1; GIF_stop=1;
} }
@ -2093,21 +2121,17 @@ void Save_GIF(void)
T_GIF_IDB IDB; T_GIF_IDB IDB;
byte block_indentifier; // Code indicateur du type de bloc en cours byte block_identifier; // Code indicateur du type de bloc en cours
word current_string; // Code de la chaîne en cours de traitement word current_string; // Code de la chaîne en cours de traitement
byte current_char; // Caractère à coder byte current_char; // Caractère à coder
word index; // index de recherche de chaîne word index; // index de recherche de chaîne
byte old_current_layer=Main_current_layer;
/////////////////////////////////////////////////// FIN DES DECLARATIONS // /////////////////////////////////////////////////// FIN DES DECLARATIONS //
File_error=0;
GIF_pos_X=0;
GIF_pos_Y=0;
GIF_last_byte=0;
GIF_remainder_bits=0;
GIF_remainder_byte=0;
Get_full_filename(filename,0); Get_full_filename(filename,0);
if ((GIF_file=fopen(filename,"wb"))) if ((GIF_file=fopen(filename,"wb")))
@ -2140,12 +2164,11 @@ void Save_GIF(void)
// On sauve le LSDB dans le fichier // On sauve le LSDB dans le fichier
#if SDL_BYTEORDER == SDL_BIG_ENDIAN if (Write_word_le(GIF_file,LSDB.Width) &&
LSDB.Width = SDL_Swap16(LSDB.Width); Write_word_le(GIF_file,LSDB.Height) &&
LSDB.Height = SDL_Swap16(LSDB.Height); Write_byte(GIF_file,LSDB.Resol) &&
#endif Write_byte(GIF_file,LSDB.Backcol) &&
Write_byte(GIF_file,LSDB.Aspect) )
if (Write_bytes(GIF_file,&LSDB,sizeof(T_GIF_LSDB)))
{ {
// Le LSDB a été correctement écrit. // Le LSDB a été correctement écrit.
@ -2160,6 +2183,11 @@ void Save_GIF(void)
// Ecriture de la transparence // Ecriture de la transparence
//Write_bytes(GIF_file,"\x21\xF9\x04\x01\x00\x00\xNN\x00",8); //Write_bytes(GIF_file,"\x21\xF9\x04\x01\x00\x00\xNN\x00",8);
// "Netscape" animation extension
// Write_bytes(GIF_file,"\x21\xFF\x0BNETSCAPE2.0\x03\xLL\xSS\xSS\x00",19);
// LL : 01 to loop
// SSSS : number of loops
// Ecriture du commentaire // Ecriture du commentaire
if (Main_comment[0]) if (Main_comment[0])
{ {
@ -2167,180 +2195,208 @@ void Save_GIF(void)
Write_byte(GIF_file,strlen(Main_comment)); Write_byte(GIF_file,strlen(Main_comment));
Write_bytes(GIF_file,Main_comment,strlen(Main_comment)+1); Write_bytes(GIF_file,Main_comment,strlen(Main_comment)+1);
} }
// On va écrire un block indicateur d'IDB et l'IDB du fichier // Loop on all layers
for (Main_current_layer=0;
block_indentifier=0x2C; Main_current_layer < Main_backups->Pages->Nb_layers && !File_error;
IDB.Pos_X=0; Main_current_layer++)
IDB.Pos_Y=0;
IDB.Image_width=Main_image_width;
IDB.Image_height=Main_image_height;
IDB.Indicator=0x07; // Image non entrelacée, pas de palette locale.
IDB.Nb_bits_pixel=8; // Image 256 couleurs;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
IDB.Image_width = SDL_Swap16(IDB.Image_width);
IDB.Image_height = SDL_Swap16(IDB.Image_height);
#endif
if ( Write_bytes(GIF_file,&block_indentifier,1) &&
Write_bytes(GIF_file,&IDB,sizeof(T_GIF_IDB)) )
{ {
// Le block indicateur d'IDB et l'IDB ont étés correctements // Write a Graphic Control Extension
// écrits. char * GCE_block = "\x21\xF9\x04\x05\x05\x00\x00\x00";
//if (Main_current_layer > 0)
Init_write_buffer(); // GCE_block[3] = '\x05';
if (Main_current_layer == Main_backups->Pages->Nb_layers -1)
index=4096;
File_error=0;
GIF_stop=0;
// Réintialisation de la table:
alphabet_free=258;
GIF_nb_bits =9;
alphabet_max =511;
GIF_set_code(256);
for (start=0;start<4096;start++)
{ {
alphabet_daughter[start]=4096; // "Infinite" delay for last frame
alphabet_sister[start]=4096; GCE_block[4] = 255;
GCE_block[5] = 255;
} }
if (Write_bytes(GIF_file,GCE_block,8))
////////////////////////////////////////////// COMPRESSION LZW //
start=current_string=GIF_next_pixel();
descend=1;
do
{ {
current_char=GIF_next_pixel();
// On va écrire un block indicateur d'IDB et l'IDB du fichier
// On regarde si dans la table on aurait pas une chaîne block_identifier=0x2C;
// équivalente à current_string+Caractere IDB.Pos_X=0;
IDB.Pos_Y=0;
while ( (index<alphabet_free) && IDB.Image_width=Main_image_width;
( (current_string!=alphabet_prefix[index]) || IDB.Image_height=Main_image_height;
(current_char !=alphabet_suffix[index]) ) ) IDB.Indicator=0x07; // Image non entrelacée, pas de palette locale.
IDB.Nb_bits_pixel=8; // Image 256 couleurs;
if ( Write_byte(GIF_file,block_identifier) &&
Write_word_le(GIF_file,IDB.Pos_X) &&
Write_word_le(GIF_file,IDB.Pos_Y) &&
Write_word_le(GIF_file,IDB.Image_width) &&
Write_word_le(GIF_file,IDB.Image_height) &&
Write_byte(GIF_file,IDB.Indicator) &&
Write_byte(GIF_file,IDB.Nb_bits_pixel))
{ {
descend=0; // Le block indicateur d'IDB et l'IDB ont étés correctements
start=index; // écrits.
index=alphabet_sister[index];
} Init_write_buffer();
GIF_pos_X=0;
if (index<alphabet_free) GIF_pos_Y=0;
{ GIF_last_byte=0;
// On sait ici que la current_string+Caractere se trouve GIF_remainder_bits=0;
// en position index dans les tables. GIF_remainder_byte=0;
descend=1; index=4096;
start=current_string=index; File_error=0;
index=alphabet_daughter[index]; GIF_stop=0;
}
else // Réintialisation de la table:
{ alphabet_free=258;
// On fait la jonction entre la current_string et l'actuelle GIF_nb_bits =9;
if (descend) alphabet_max =511;
alphabet_daughter[start]=alphabet_free; GIF_set_code(256);
else for (start=0;start<4096;start++)
alphabet_sister[start]=alphabet_free;
// On rajoute la chaîne current_string+Caractere à la table
alphabet_prefix[alphabet_free ]=current_string;
alphabet_suffix[alphabet_free++]=current_char;
// On écrit le code dans le fichier
GIF_set_code(current_string);
if (alphabet_free>0xFFF)
{ {
// Réintialisation de la table: alphabet_daughter[start]=4096;
GIF_set_code(256); alphabet_sister[start]=4096;
alphabet_free=258; }
GIF_nb_bits =9;
alphabet_max =511; ////////////////////////////////////////////// COMPRESSION LZW //
for (start=0;start<4096;start++)
start=current_string=GIF_next_pixel(&IDB);
descend=1;
do
{
current_char=GIF_next_pixel(&IDB);
// On regarde si dans la table on aurait pas une chaîne
// équivalente à current_string+Caractere
while ( (index<alphabet_free) &&
( (current_string!=alphabet_prefix[index]) ||
(current_char !=alphabet_suffix[index]) ) )
{ {
alphabet_daughter[start]=4096; descend=0;
alphabet_sister[start]=4096; start=index;
index=alphabet_sister[index];
}
if (index<alphabet_free)
{
// On sait ici que la current_string+Caractere se trouve
// en position index dans les tables.
descend=1;
start=current_string=index;
index=alphabet_daughter[index];
}
else
{
// On fait la jonction entre la current_string et l'actuelle
if (descend)
alphabet_daughter[start]=alphabet_free;
else
alphabet_sister[start]=alphabet_free;
// On rajoute la chaîne current_string+Caractere à la table
alphabet_prefix[alphabet_free ]=current_string;
alphabet_suffix[alphabet_free++]=current_char;
// On écrit le code dans le fichier
GIF_set_code(current_string);
if (alphabet_free>0xFFF)
{
// Réintialisation de la table:
GIF_set_code(256);
alphabet_free=258;
GIF_nb_bits =9;
alphabet_max =511;
for (start=0;start<4096;start++)
{
alphabet_daughter[start]=4096;
alphabet_sister[start]=4096;
}
}
else if (alphabet_free>alphabet_max+1)
{
// On augmente le nb de bits
GIF_nb_bits++;
alphabet_max=(1<<GIF_nb_bits)-1;
}
// On initialise la current_string et le reste pour la suite
index=alphabet_daughter[current_char];
start=current_string=current_char;
descend=1;
} }
} }
else if (alphabet_free>alphabet_max+1) while ((!GIF_stop) && (!File_error));
if (!File_error)
{ {
// On augmente le nb de bits // On écrit le code dans le fichier
GIF_set_code(current_string); // Dernière portion d'image
GIF_nb_bits++;
alphabet_max=(1<<GIF_nb_bits)-1; // Cette dernière portion ne devrait pas poser de problèmes
} // du côté GIF_nb_bits puisque pour que GIF_nb_bits change de
// valeur, il faudrait que la table de chaîne soit remplie or
// On initialise la current_string et le reste pour la suite // c'est impossible puisqu'on traite une chaîne qui se trouve
index=alphabet_daughter[current_char]; // déjà dans la table, et qu'elle n'a rien d'inédit. Donc on
start=current_string=current_char; // ne devrait pas avoir à changer de taille, mais je laisse
descend=1; // quand même en remarque tout ça, au cas où il subsisterait
} // des problèmes dans certains cas exceptionnels.
} //
while ((!GIF_stop) && (!File_error)); // Note: de toutes façons, ces lignes en commentaires ont étés
// écrites par copier/coller du temps où la sauvegarde du
if (!File_error) // GIF déconnait. Il y a donc fort à parier qu'elles ne
{ // sont pas correctes.
// On écrit le code dans le fichier
GIF_set_code(current_string); // Dernière portion d'image /*
if (current_string==alphabet_max)
// Cette dernière portion ne devrait pas poser de problèmes {
// du côté GIF_nb_bits puisque pour que GIF_nb_bits change de if (alphabet_max==0xFFF)
// valeur, il faudrait que la table de chaîne soit remplie or {
// c'est impossible puisqu'on traite une chaîne qui se trouve // On balargue un Clear Code
// déjà dans la table, et qu'elle n'a rien d'inédit. Donc on GIF_set_code(256);
// ne devrait pas avoir à changer de taille, mais je laisse
// quand même en remarque tout ça, au cas où il subsisterait // On réinitialise les données LZW
// des problèmes dans certains cas exceptionnels. alphabet_free=258;
// GIF_nb_bits =9;
// Note: de toutes façons, ces lignes en commentaires ont étés alphabet_max =511;
// écrites par copier/coller du temps où la sauvegarde du }
// GIF déconnait. Il y a donc fort à parier qu'elles ne else
// sont pas correctes. {
GIF_nb_bits++;
/* alphabet_max=(1<<GIF_nb_bits)-1;
if (current_string==alphabet_max) }
{ }
if (alphabet_max==0xFFF) */
{
// On balargue un Clear Code GIF_set_code(257); // Code de End d'image
GIF_set_code(256); if (GIF_remainder_bits!=0)
GIF_set_code(0); // Code bidon permettant de s'assurer que tous les bits du dernier code aient bien étés inscris dans le buffer GIF
// On réinitialise les données LZW GIF_empty_buffer(); // On envoie les dernières données du buffer GIF dans le buffer KM
alphabet_free=258; End_write(GIF_file); // On envoie les dernières données du buffer KM dans le fichier
GIF_nb_bits =9;
alphabet_max =511; // On écrit un \0
} if (! Write_byte(GIF_file,'\x00'))
else File_error=1;
{
GIF_nb_bits++; }
alphabet_max=(1<<GIF_nb_bits)-1;
} } // On a pu écrire l'IDB
} else
*/
GIF_set_code(257); // Code de End d'image
if (GIF_remainder_bits!=0)
GIF_set_code(0); // Code bidon permettant de s'assurer que tous les bits du dernier code aient bien étés inscris dans le buffer GIF
GIF_empty_buffer(); // On envoie les dernières données du buffer GIF dans le buffer KM
End_write(GIF_file); // On envoie les dernières données du buffer KM dans le fichier
// On écrit un \0
if (! Write_byte(GIF_file,'\x00'))
File_error=1; File_error=1;
// On écrit un GIF TERMINATOR, exigé par SVGA et SEA.
if (! Write_byte(GIF_file,'\x3B'))
File_error=1;
} }
else
} // On a pu écrire l'IDB File_error=1;
else }
File_error=1;
// After writing all layers
if (!File_error)
{
// On écrit un GIF TERMINATOR, exigé par SVGA et SEA.
if (! Write_byte(GIF_file,'\x3B'))
File_error=1;
}
} // On a pu écrire la palette } // On a pu écrire la palette
else else
@ -2367,9 +2423,14 @@ void Save_GIF(void)
} // On a pu ouvrir le fichier en écriture } // On a pu ouvrir le fichier en écriture
else else
File_error=1; File_error=1;
// Restore original index of current layer
Main_current_layer = old_current_layer;
} }
//////////////////////////////////// PCX //////////////////////////////////// //////////////////////////////////// PCX ////////////////////////////////////
#pragma pack(1) #pragma pack(1)
typedef struct typedef struct
@ -3117,7 +3178,7 @@ void Test_PNG(void)
fclose(file); fclose(file);
} }
} }
png_bytep * Row_pointers; png_bytep * Row_pointers;
// -- Lire un fichier au format PNG ----------------------------------------- // -- Lire un fichier au format PNG -----------------------------------------
void Load_PNG(void) void Load_PNG(void)
@ -3449,7 +3510,7 @@ void Save_PNG(void)
/* ecriture des pixels de l'image */ /* ecriture des pixels de l'image */
Row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * Main_image_height); Row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * Main_image_height);
pixel_ptr = (Read_pixel_function==Read_pixel_from_current_screen)?Main_screen:Brush; pixel_ptr = (Read_pixel_function==Read_pixel_from_brush)?Brush:Main_screen;
for (y=0; y<Main_image_height; y++) for (y=0; y<Main_image_height; y++)
Row_pointers[y] = (png_byte*)(pixel_ptr+y*Main_image_width); Row_pointers[y] = (png_byte*)(pixel_ptr+y*Main_image_width);

View File

@ -339,6 +339,10 @@ GFX2_GLOBAL word Main_magnifier_width;
GFX2_GLOBAL short Main_magnifier_offset_X; GFX2_GLOBAL short Main_magnifier_offset_X;
/// Y position (in image space) of the pixel to display in the top left corner of the magnified view. /// Y position (in image space) of the pixel to display in the top left corner of the magnified view.
GFX2_GLOBAL short Main_magnifier_offset_Y; GFX2_GLOBAL short Main_magnifier_offset_Y;
/// Index of layer currently being edited
GFX2_GLOBAL int Main_current_layer;
/// Bitfield that records which layers are visible. 2^0 for 0, 2^1 for 1, 2^2 for 2, etc.
GFX2_GLOBAL dword Main_layers_visible;
// -- Spare page data // -- Spare page data
@ -399,7 +403,10 @@ GFX2_GLOBAL word Spare_magnifier_width;
GFX2_GLOBAL short Spare_magnifier_offset_X; GFX2_GLOBAL short Spare_magnifier_offset_X;
/// Y position (in image space) of the pixel to display in the top left corner of the magnified view. /// Y position (in image space) of the pixel to display in the top left corner of the magnified view.
GFX2_GLOBAL short Spare_magnifier_offset_Y; GFX2_GLOBAL short Spare_magnifier_offset_Y;
/// Index of layer currently being edited
GFX2_GLOBAL short Spare_current_layer;
/// Bitfield that records which layers are visible. 2^0 for 0, 2^1 for 1, 2^2 for 2, etc.
GFX2_GLOBAL dword Spare_layers_visible;
// -- Image backups // -- Image backups
/// Backup of the current screen, used during drawing when FX feedback is OFF. /// Backup of the current screen, used during drawing when FX feedback is OFF.
@ -409,6 +416,7 @@ GFX2_GLOBAL T_List_of_pages * Main_backups;
/// List of backup pages for the spare page. /// List of backup pages for the spare page.
GFX2_GLOBAL T_List_of_pages * Spare_backups; GFX2_GLOBAL T_List_of_pages * Spare_backups;
// -- Brush data // -- Brush data
/// Pixel data of the current brush. /// Pixel data of the current brush.

132
graph.c
View File

@ -116,7 +116,8 @@ void Update_part_of_screen(short x, short y, short width, short height)
effective_h = Menu_Y - effective_Y; effective_h = Menu_Y - effective_Y;
/* /*
SDL_Rect r; r.x=effective_X; SDL_Rect r;
r.x=effective_X;
r.y=effective_Y; r.y=effective_Y;
r.h=effective_h; r.h=effective_h;
r.w=effective_w; r.w=effective_w;
@ -588,6 +589,7 @@ void Resize_image(word chosen_width,word chosen_height)
{ {
word old_width=Main_image_width; word old_width=Main_image_width;
word old_height=Main_image_height; word old_height=Main_image_height;
int i;
// +-+-+ // +-+-+
// |C| | A+B+C = Ancienne image // |C| | A+B+C = Ancienne image
@ -595,7 +597,7 @@ void Resize_image(word chosen_width,word chosen_height)
// |B| | C = Nouvelle image // |B| | C = Nouvelle image
// +-+-+ // +-+-+
if (Backup_with_new_dimensions(1,chosen_width,chosen_height)) if (Backup_with_new_dimensions(1,Main_backups->Pages->Nb_layers,chosen_width,chosen_height))
{ {
// La nouvelle page a pu être allouée, elle est pour l'instant pleine de // La nouvelle page a pu être allouée, elle est pour l'instant pleine de
// 0s. Elle fait Main_image_width de large. // 0s. Elle fait Main_image_width de large.
@ -603,10 +605,14 @@ void Resize_image(word chosen_width,word chosen_height)
Main_image_is_modified=1; Main_image_is_modified=1;
// On copie donc maintenant la partie C dans la nouvelle image. // On copie donc maintenant la partie C dans la nouvelle image.
Copy_part_of_image_to_another( for (i=0; i<Main_backups->Pages->Nb_layers; i++)
Screen_backup,0,0,Min(old_width,Main_image_width), {
Min(old_height,Main_image_height),old_width, Copy_part_of_image_to_another(
Main_screen,0,0,Main_image_width); Main_backups->Pages->Next->Image[i],0,0,Min(old_width,Main_image_width),
Min(old_height,Main_image_height),old_width,
Main_backups->Pages->Image[i],0,0,Main_image_width);
}
Redraw_layered_image();
} }
else else
{ {
@ -663,7 +669,8 @@ void Get_colors_from_brush(void)
if (Confirmation_box("Modify current palette ?")) if (Confirmation_box("Modify current palette ?"))
{ {
Backup(); // Backup with unchanged layers, only palette is modified
Backup_layers(0);
// On commence par initialiser le tableau de booléen à faux // On commence par initialiser le tableau de booléen à faux
for (color=0;color<=255;color++) for (color=0;color<=255;color++)
@ -731,7 +738,7 @@ void Fill(short * top_reached , short * bottom_reached,
current_limit_bottom =Min(Paintbrush_Y+1,Limit_bottom); current_limit_bottom =Min(Paintbrush_Y+1,Limit_bottom);
*left_reached=Paintbrush_X; *left_reached=Paintbrush_X;
*right_reached=Paintbrush_X+1; *right_reached=Paintbrush_X+1;
Pixel_in_current_screen(Paintbrush_X,Paintbrush_Y,2); Pixel_in_current_layer(Paintbrush_X,Paintbrush_Y,2);
while (changes_made) while (changes_made)
{ {
@ -750,7 +757,7 @@ void Fill(short * top_reached , short * bottom_reached,
{ {
// On cherche son début // On cherche son début
while((start_x<=Limit_right) && while((start_x<=Limit_right) &&
(Read_pixel_from_current_screen(start_x,line)!=1)) (Read_pixel_from_current_layer(start_x,line)!=1))
start_x++; start_x++;
if (start_x<=Limit_right) if (start_x<=Limit_right)
@ -758,7 +765,7 @@ void Fill(short * top_reached , short * bottom_reached,
// Un segment de couleur 1 existe et commence à la position start_x. // Un segment de couleur 1 existe et commence à la position start_x.
// On va donc en chercher la fin. // On va donc en chercher la fin.
for (end_x=start_x+1;(end_x<=Limit_right) && for (end_x=start_x+1;(end_x<=Limit_right) &&
(Read_pixel_from_current_screen(end_x,line)==1);end_x++); (Read_pixel_from_current_layer(end_x,line)==1);end_x++);
// On sait qu'il existe un segment de couleur 1 qui commence en // On sait qu'il existe un segment de couleur 1 qui commence en
// start_x et qui se termine en end_x-1. // start_x et qui se termine en end_x-1.
@ -769,16 +776,16 @@ void Fill(short * top_reached , short * bottom_reached,
can_propagate=( can_propagate=(
// Test de la présence d'un point à gauche du segment // Test de la présence d'un point à gauche du segment
((start_x>Limit_left) && ((start_x>Limit_left) &&
(Read_pixel_from_current_screen(start_x-1,line)==2)) || (Read_pixel_from_current_layer(start_x-1,line)==2)) ||
// Test de la présence d'un point à droite du segment // Test de la présence d'un point à droite du segment
((end_x-1<Limit_right) && ((end_x-1<Limit_right) &&
(Read_pixel_from_current_screen(end_x ,line)==2)) (Read_pixel_from_current_layer(end_x ,line)==2))
); );
// Test de la présence d'un point en haut du segment // Test de la présence d'un point en haut du segment
if (!can_propagate && (line>Limit_top)) if (!can_propagate && (line>Limit_top))
for (x_pos=start_x;x_pos<end_x;x_pos++) for (x_pos=start_x;x_pos<end_x;x_pos++)
if (Read_pixel_from_current_screen(x_pos,line-1)==2) if (Read_pixel_from_current_layer(x_pos,line-1)==2)
{ {
can_propagate=1; can_propagate=1;
break; break;
@ -792,7 +799,7 @@ void Fill(short * top_reached , short * bottom_reached,
*right_reached=end_x; *right_reached=end_x;
// On remplit le segment de start_x à end_x-1. // On remplit le segment de start_x à end_x-1.
for (x_pos=start_x;x_pos<end_x;x_pos++) for (x_pos=start_x;x_pos<end_x;x_pos++)
Pixel_in_current_screen(x_pos,line,2); Pixel_in_current_layer(x_pos,line,2);
// On vient d'effectuer des modifications. // On vient d'effectuer des modifications.
changes_made=1; changes_made=1;
line_is_modified=1; line_is_modified=1;
@ -830,14 +837,14 @@ void Fill(short * top_reached , short * bottom_reached,
{ {
// On cherche son début // On cherche son début
for (;(start_x<=Limit_right) && for (;(start_x<=Limit_right) &&
(Read_pixel_from_current_screen(start_x,line)!=1);start_x++); (Read_pixel_from_current_layer(start_x,line)!=1);start_x++);
if (start_x<=Limit_right) if (start_x<=Limit_right)
{ {
// Un segment de couleur 1 existe et commence à la position start_x. // Un segment de couleur 1 existe et commence à la position start_x.
// On va donc en chercher la fin. // On va donc en chercher la fin.
for (end_x=start_x+1;(end_x<=Limit_right) && for (end_x=start_x+1;(end_x<=Limit_right) &&
(Read_pixel_from_current_screen(end_x,line)==1);end_x++); (Read_pixel_from_current_layer(end_x,line)==1);end_x++);
// On sait qu'il existe un segment de couleur 1 qui commence en // On sait qu'il existe un segment de couleur 1 qui commence en
// start_x et qui se termine en end_x-1. // start_x et qui se termine en end_x-1.
@ -848,16 +855,16 @@ void Fill(short * top_reached , short * bottom_reached,
can_propagate=( can_propagate=(
// Test de la présence d'un point à gauche du segment // Test de la présence d'un point à gauche du segment
((start_x>Limit_left) && ((start_x>Limit_left) &&
(Read_pixel_from_current_screen(start_x-1,line)==2)) || (Read_pixel_from_current_layer(start_x-1,line)==2)) ||
// Test de la présence d'un point à droite du segment // Test de la présence d'un point à droite du segment
((end_x-1<Limit_right) && ((end_x-1<Limit_right) &&
(Read_pixel_from_current_screen(end_x ,line)==2)) (Read_pixel_from_current_layer(end_x ,line)==2))
); );
// Test de la présence d'un point en bas du segment // Test de la présence d'un point en bas du segment
if (!can_propagate && (line<Limit_bottom)) if (!can_propagate && (line<Limit_bottom))
for (x_pos=start_x;x_pos<end_x;x_pos++) for (x_pos=start_x;x_pos<end_x;x_pos++)
if (Read_pixel_from_current_screen(x_pos,line+1)==2) if (Read_pixel_from_current_layer(x_pos,line+1)==2)
{ {
can_propagate=1; can_propagate=1;
break; break;
@ -871,7 +878,7 @@ void Fill(short * top_reached , short * bottom_reached,
*right_reached=end_x; *right_reached=end_x;
// On remplit le segment de start_x à end_x-1. // On remplit le segment de start_x à end_x-1.
for (x_pos=start_x;x_pos<end_x;x_pos++) for (x_pos=start_x;x_pos<end_x;x_pos++)
Pixel_in_current_screen(x_pos,line,2); Pixel_in_current_layer(x_pos,line,2);
// On vient d'effectuer des modifications. // On vient d'effectuer des modifications.
changes_made=1; changes_made=1;
line_is_modified=1; line_is_modified=1;
@ -894,6 +901,10 @@ void Fill(short * top_reached , short * bottom_reached,
(*right_reached)--; (*right_reached)--;
} // end de la routine de remplissage "Fill" } // end de la routine de remplissage "Fill"
byte Read_pixel_from_backup_layer(word x,word y)
{
return *((y)*Main_image_width+(x)+Main_backups->Pages->Next->Image[Main_current_layer]);
}
void Fill_general(byte fill_color) void Fill_general(byte fill_color)
// //
@ -935,11 +946,11 @@ void Fill_general(byte fill_color)
// On va maintenant "épurer" la zone visible de l'image: // On va maintenant "épurer" la zone visible de l'image:
memset(replace_table,0,256); memset(replace_table,0,256);
replace_table[Read_pixel_from_current_screen(Paintbrush_X,Paintbrush_Y)]=1; replace_table[Read_pixel_from_backup_layer(Paintbrush_X,Paintbrush_Y)]=1;
Replace_colors_within_limits(replace_table); Replace_colors_within_limits(replace_table);
// On fait maintenant un remplissage classique de la couleur 1 avec la 2 // On fait maintenant un remplissage classique de la couleur 1 avec la 2
Fill(&top_reached ,&bottom_reached, Fill(&top_reached ,&bottom_reached,
&left_reached,&right_reached); &left_reached,&right_reached);
// On s'apprête à faire des opérations qui nécessitent un affichage. Il // On s'apprête à faire des opérations qui nécessitent un affichage. Il
@ -950,39 +961,39 @@ void Fill_general(byte fill_color)
// Il va maintenant falloir qu'on "turn" ce gros caca "into" un truc qui // Il va maintenant falloir qu'on "turn" ce gros caca "into" un truc qui
// ressemble un peu plus à ce à quoi l'utilisateur peut s'attendre. // ressemble un peu plus à ce à quoi l'utilisateur peut s'attendre.
if (top_reached>Limit_top) if (top_reached>Limit_top)
Copy_part_of_image_to_another(Screen_backup, // source Copy_part_of_image_to_another(Main_backups->Pages->Next->Image[Main_current_layer], // source
Limit_left,Limit_top, // Pos X et Y dans source Limit_left,Limit_top, // Pos X et Y dans source
(Limit_right-Limit_left)+1, // width copie (Limit_right-Limit_left)+1, // width copie
top_reached-Limit_top,// height copie top_reached-Limit_top,// height copie
Main_image_width, // width de la source Main_image_width, // width de la source
Main_screen, // Destination Main_backups->Pages->Image[Main_current_layer], // Destination
Limit_left,Limit_top, // Pos X et Y destination Limit_left,Limit_top, // Pos X et Y destination
Main_image_width); // width destination Main_image_width); // width destination
if (bottom_reached<Limit_bottom) if (bottom_reached<Limit_bottom)
Copy_part_of_image_to_another(Screen_backup, Copy_part_of_image_to_another(Main_backups->Pages->Next->Image[Main_current_layer],
Limit_left,bottom_reached+1, Limit_left,bottom_reached+1,
(Limit_right-Limit_left)+1, (Limit_right-Limit_left)+1,
Limit_bottom-bottom_reached, Limit_bottom-bottom_reached,
Main_image_width,Main_screen, Main_image_width,Main_backups->Pages->Image[Main_current_layer],
Limit_left,bottom_reached+1,Main_image_width); Limit_left,bottom_reached+1,Main_image_width);
if (left_reached>Limit_left) if (left_reached>Limit_left)
Copy_part_of_image_to_another(Screen_backup, Copy_part_of_image_to_another(Main_backups->Pages->Next->Image[Main_current_layer],
Limit_left,top_reached, Limit_left,top_reached,
left_reached-Limit_left, left_reached-Limit_left,
(bottom_reached-top_reached)+1, (bottom_reached-top_reached)+1,
Main_image_width,Main_screen, Main_image_width,Main_backups->Pages->Image[Main_current_layer],
Limit_left,top_reached,Main_image_width); Limit_left,top_reached,Main_image_width);
if (right_reached<Limit_right) if (right_reached<Limit_right)
Copy_part_of_image_to_another(Screen_backup, Copy_part_of_image_to_another(Main_backups->Pages->Next->Image[Main_current_layer],
right_reached+1,top_reached, right_reached+1,top_reached,
Limit_right-right_reached, Limit_right-right_reached,
(bottom_reached-top_reached)+1, (bottom_reached-top_reached)+1,
Main_image_width,Main_screen, Main_image_width,Main_backups->Pages->Image[Main_current_layer],
right_reached+1,top_reached,Main_image_width); right_reached+1,top_reached,Main_image_width);
for (y_pos=top_reached;y_pos<=bottom_reached;y_pos++) for (y_pos=top_reached;y_pos<=bottom_reached;y_pos++)
for (x_pos=left_reached;x_pos<=right_reached;x_pos++) for (x_pos=left_reached;x_pos<=right_reached;x_pos++)
if (Read_pixel_from_current_screen(x_pos,y_pos)==2) if (Read_pixel_from_current_layer(x_pos,y_pos)==2)
{ {
// Si le pixel en cours de traitement a été touché par le Fill() // Si le pixel en cours de traitement a été touché par le Fill()
// on se doit d'afficher le pixel modifié par la couleur de // on se doit d'afficher le pixel modifié par la couleur de
@ -991,14 +1002,14 @@ void Fill_general(byte fill_color)
// Ceci se fait en commençant par restaurer la couleur qu'il y avait // Ceci se fait en commençant par restaurer la couleur qu'il y avait
// précédemment (c'est important pour que les effets ne s'emmèlent // précédemment (c'est important pour que les effets ne s'emmèlent
// pas le pinceaux) // pas le pinceaux)
Pixel_in_current_screen(x_pos,y_pos,Read_pixel_from_backup_screen(x_pos,y_pos)); Pixel_in_current_screen(x_pos,y_pos,Read_pixel_from_backup_layer(x_pos,y_pos),0);
// Enfin, on peut afficher le pixel, en le soumettant aux effets en // Enfin, on peut afficher le pixel, en le soumettant aux effets en
// cours: // cours:
Display_pixel(x_pos,y_pos,fill_color); Display_pixel(x_pos,y_pos,fill_color);
} }
else else
Pixel_in_current_screen(x_pos,y_pos,Read_pixel_from_backup_screen(x_pos,y_pos)); Pixel_in_current_screen(x_pos,y_pos,Read_pixel_from_backup_layer(x_pos,y_pos),0);
FX_feedback_screen=old_fx_feedback_screen; FX_feedback_screen=old_fx_feedback_screen;
@ -1007,7 +1018,6 @@ void Fill_general(byte fill_color)
// puisque les seuls points qui ont changé dans l'image ont été raffichés // puisque les seuls points qui ont changé dans l'image ont été raffichés
// par l'utilisation de "Display_pixel()", et que les autres... eh bein // par l'utilisation de "Display_pixel()", et que les autres... eh bein
// on n'y a jamais touché à l'écran les autres: ils sont donc corrects. // on n'y a jamais touché à l'écran les autres: ils sont donc corrects.
if(Main_magnifier_mode) if(Main_magnifier_mode)
{ {
short w,h; short w,h;
@ -2551,7 +2561,7 @@ void Replace(byte New_color)
if ((Paintbrush_X<Main_image_width) if ((Paintbrush_X<Main_image_width)
&& (Paintbrush_Y<Main_image_height)) && (Paintbrush_Y<Main_image_height))
{ {
old_color=Read_pixel_from_current_screen(Paintbrush_X,Paintbrush_Y); old_color=Read_pixel_from_current_layer(Paintbrush_X,Paintbrush_Y);
if ( (old_color!=New_color) if ( (old_color!=New_color)
&& ((!Stencil_mode) || (!Stencil[old_color])) ) && ((!Stencil_mode) || (!Stencil[old_color])) )
{ {
@ -2648,8 +2658,7 @@ void Display_pixel(word x,word y,byte color)
&& (!((Mask_mode) && (Mask_table[Read_pixel_from_spare_screen(x,y)]))) ) && (!((Mask_mode) && (Mask_table[Read_pixel_from_spare_screen(x,y)]))) )
{ {
color=Effect_function(x,y,color); color=Effect_function(x,y,color);
Pixel_in_current_screen(x,y,color); Pixel_in_current_screen(x,y,color,1);
Pixel_preview(x,y,color);
} }
} }
@ -2860,3 +2869,52 @@ void Redraw_grid(short x, short y, unsigned short w, unsigned short h)
col+= Snap_width*Main_magnifier_factor; 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

@ -113,3 +113,8 @@ extern Func_pixel Pixel_figure;
void Update_part_of_screen(short x, short y, short width, short height); 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 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);

11
help.c
View File

@ -47,6 +47,7 @@
#include "input.h" #include "input.h"
#include "hotkeys.h" #include "hotkeys.h"
#include "errors.h" #include "errors.h"
#include "pages.h"
extern char Program_version[]; // generated in pversion.c extern char Program_version[]; // generated in pversion.c
extern char SVN_revision[]; // generated in pversion.c extern char SVN_revision[]; // generated in pversion.c
@ -642,6 +643,16 @@ void Button_Stats(void)
sprintf(buffer,"%u bytes",(unsigned int)freeRam); sprintf(buffer,"%u bytes",(unsigned int)freeRam);
Print_in_window(114,51,buffer,STATS_DATA_COLOR,MC_Black); Print_in_window(114,51,buffer,STATS_DATA_COLOR,MC_Black);
// Used memory
Print_in_window(10,59,"Used memory pages: ",STATS_TITLE_COLOR,MC_Black);
if(Stats_pages_memory > (100LL*1024*1024*1024))
sprintf(buffer,"%u (%u Gb)",Stats_pages_number, (unsigned int)(Stats_pages_memory/(1024*1024*1024)));
else if(Stats_pages_memory > (100*1024*1024))
sprintf(buffer,"%u (%u Mb)",Stats_pages_number, (unsigned int)(Stats_pages_memory/(1024*1024)));
else
sprintf(buffer,"%u (%u Kb)",Stats_pages_number, (unsigned int)(Stats_pages_memory/1024));
Print_in_window(162,59,buffer,STATS_DATA_COLOR,MC_Black);
// Affichage de l'espace disque libre // Affichage de l'espace disque libre
sprintf(buffer,"Free space on %c:",Main_current_directory[0]); sprintf(buffer,"Free space on %c:",Main_current_directory[0]);
Print_in_window(10,67,buffer,STATS_TITLE_COLOR,MC_Black); Print_in_window(10,67,buffer,STATS_TITLE_COLOR,MC_Black);

12
init.c
View File

@ -1593,12 +1593,12 @@ void Init_operations(void)
Scroll_12_0,HIDE_CURSOR,FAST_MOUSE); Scroll_12_0,HIDE_CURSOR,FAST_MOUSE);
Init_operation(OPERATION_SCROLL,2,0, Init_operation(OPERATION_SCROLL,2,0,
Scroll_12_0,HIDE_CURSOR,FAST_MOUSE); Scroll_12_0,HIDE_CURSOR,FAST_MOUSE);
Init_operation(OPERATION_SCROLL,1,4, Init_operation(OPERATION_SCROLL,1,5,
Scroll_12_4,0,FAST_MOUSE); Scroll_12_5,0,FAST_MOUSE);
Init_operation(OPERATION_SCROLL,2,4, Init_operation(OPERATION_SCROLL,2,5,
Scroll_12_4,0,FAST_MOUSE); Scroll_12_5,0,FAST_MOUSE);
Init_operation(OPERATION_SCROLL,0,4, Init_operation(OPERATION_SCROLL,0,5,
Scroll_0_4,HIDE_CURSOR,FAST_MOUSE); Scroll_0_5,HIDE_CURSOR,FAST_MOUSE);
Init_operation(OPERATION_GRAD_CIRCLE,1,0,Grad_circle_12_0,HIDE_CURSOR,FAST_MOUSE); Init_operation(OPERATION_GRAD_CIRCLE,1,0,Grad_circle_12_0,HIDE_CURSOR,FAST_MOUSE);
Init_operation(OPERATION_GRAD_CIRCLE,2,0,Grad_circle_12_0,HIDE_CURSOR,FAST_MOUSE); Init_operation(OPERATION_GRAD_CIRCLE,2,0,Grad_circle_12_0,HIDE_CURSOR,FAST_MOUSE);

View File

@ -39,6 +39,7 @@
#include "io.h" #include "io.h"
#include "loadsave.h" #include "loadsave.h"
#include "misc.h" #include "misc.h"
#include "graph.h"
#include "op_c.h" #include "op_c.h"
#include "pages.h" #include "pages.h"
#include "palette.h" #include "palette.h"
@ -134,29 +135,29 @@ void Load_SDL_Image(void);
void Init_preview(short width,short height,long size,int format,enum PIXEL_RATIO ratio); void Init_preview(short width,short height,long size,int format,enum PIXEL_RATIO ratio);
// ENUM Name TestFunc LoadFunc SaveFunc Backup Comment Ext Exts // ENUM Name TestFunc LoadFunc SaveFunc Backup Comment Layers Ext Exts
T_Format File_formats[NB_KNOWN_FORMATS] = { T_Format File_formats[NB_KNOWN_FORMATS] = {
{FORMAT_ALL_IMAGES,"(all)",NULL, NULL, NULL, 0, 0, "", "gif;png;bmp;pcx;pkm;lbm;iff;img;sci;scq;scf;scn;sco;pi1;pc1;cel;neo;kcf;pal;c64;koa;tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico"}, {FORMAT_ALL_IMAGES, "(all)", NULL, NULL, NULL, 0, 0, 0, "", "gif;png;bmp;pcx;pkm;lbm;iff;img;sci;scq;scf;scn;sco;pi1;pc1;cel;neo;kcf;pal;c64;koa;tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico"},
{FORMAT_ALL_FILES,"(*.*)",NULL, NULL, NULL, 0, 0, "", "*"}, {FORMAT_ALL_FILES, "(*.*)", NULL, NULL, NULL, 0, 0, 0, "", "*"},
{FORMAT_GIF, " gif", Test_GIF, Load_GIF, Save_GIF, 1, 1, "gif", "gif"}, {FORMAT_GIF, " gif", Test_GIF, Load_GIF, Save_GIF, 1, 1, 1, "gif", "gif"},
#ifndef __no_pnglib__ #ifndef __no_pnglib__
{FORMAT_PNG, " png", Test_PNG, Load_PNG, Save_PNG, 1, 1, "png", "png"}, {FORMAT_PNG, " png", Test_PNG, Load_PNG, Save_PNG, 1, 1, 0, "png", "png"},
#endif #endif
{FORMAT_BMP, " bmp", Test_BMP, Load_BMP, Save_BMP, 1, 0, "bmp", "bmp"}, {FORMAT_BMP, " bmp", Test_BMP, Load_BMP, Save_BMP, 1, 0, 0, "bmp", "bmp"},
{FORMAT_PCX, " pcx", Test_PCX, Load_PCX, Save_PCX, 1, 0, "pcx", "pcx"}, {FORMAT_PCX, " pcx", Test_PCX, Load_PCX, Save_PCX, 1, 0, 0, "pcx", "pcx"},
{FORMAT_PKM, " pkm", Test_PKM, Load_PKM, Save_PKM, 0, 1, "pkm", "pkm"}, // Not a backup since it does not save the full palette {FORMAT_PKM, " pkm", Test_PKM, Load_PKM, Save_PKM, 0, 1, 0, "pkm", "pkm"}, // Not a backup since it does not save the full palette
{FORMAT_LBM, " lbm", Test_LBM, Load_LBM, Save_LBM, 1, 0, "lbm", "lbm;iff"}, {FORMAT_LBM, " lbm", Test_LBM, Load_LBM, Save_LBM, 1, 0, 0, "lbm", "lbm;iff"},
{FORMAT_IMG, " img", Test_IMG, Load_IMG, Save_IMG, 1, 0, "img", "img"}, {FORMAT_IMG, " img", Test_IMG, Load_IMG, Save_IMG, 1, 0, 0, "img", "img"},
{FORMAT_SCx, " sc?", Test_SCx, Load_SCx, Save_SCx, 1, 0, "sc?", "sci;scq;scf;scn;sco"}, {FORMAT_SCx, " sc?", Test_SCx, Load_SCx, Save_SCx, 1, 0, 0, "sc?", "sci;scq;scf;scn;sco"},
{FORMAT_PI1, " pi1", Test_PI1, Load_PI1, Save_PI1, 0, 0, "pi1", "pi1"}, {FORMAT_PI1, " pi1", Test_PI1, Load_PI1, Save_PI1, 0, 0, 0, "pi1", "pi1"},
{FORMAT_PC1, " pc1", Test_PC1, Load_PC1, Save_PC1, 0, 0, "pc1", "pc1"}, {FORMAT_PC1, " pc1", Test_PC1, Load_PC1, Save_PC1, 0, 0, 0, "pc1", "pc1"},
{FORMAT_CEL, " cel", Test_CEL, Load_CEL, Save_CEL, 1, 0, "cel", "cel"}, {FORMAT_CEL, " cel", Test_CEL, Load_CEL, Save_CEL, 1, 0, 0, "cel", "cel"},
{FORMAT_NEO, " neo", Test_NEO, Load_NEO, Save_NEO, 0, 0, "neo", "neo"}, {FORMAT_NEO, " neo", Test_NEO, Load_NEO, Save_NEO, 0, 0, 0, "neo", "neo"},
{FORMAT_KCF, " kcf", Test_KCF, Load_KCF, Save_KCF, 0, 0, "kcf", "kcf"}, {FORMAT_KCF, " kcf", Test_KCF, Load_KCF, Save_KCF, 0, 0, 0, "kcf", "kcf"},
{FORMAT_PAL, " pal", Test_PAL, Load_PAL, Save_PAL, 0, 0, "pal", "pal"}, {FORMAT_PAL, " pal", Test_PAL, Load_PAL, Save_PAL, 0, 0, 0, "pal", "pal"},
{FORMAT_C64, " c64", Test_C64, Load_C64, Save_C64, 0, 1, "c64", "c64;koa"}, {FORMAT_C64, " c64", Test_C64, Load_C64, Save_C64, 0, 1, 0, "c64", "c64;koa"},
{FORMAT_SCR, " cpc", NULL, NULL, Save_SCR, 0, 0, "cpc", "cpc;scr"}, {FORMAT_SCR, " cpc", NULL, NULL, Save_SCR, 0, 0, 0, "cpc", "cpc;scr"},
{FORMAT_MISC,"misc.", NULL, NULL, NULL, 1, 0, "", "tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico"}, {FORMAT_MISC,"misc.",NULL, NULL, NULL, 1, 0, 0, "", "tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico"},
}; };
// Cette variable est alimentée après chargement réussi d'une image. // Cette variable est alimentée après chargement réussi d'une image.
@ -168,7 +169,7 @@ void Pixel_load_in_current_screen(word x_pos,word y_pos,byte color)
{ {
//if ((x_pos>=0) && (y_pos>=0)) //Toujours vrai ? //if ((x_pos>=0) && (y_pos>=0)) //Toujours vrai ?
if ((x_pos<Main_image_width) && (y_pos<Main_image_height)) if ((x_pos<Main_image_width) && (y_pos<Main_image_height))
Pixel_in_current_screen(x_pos,y_pos,color); Pixel_in_current_screen(x_pos,y_pos,color,0);
} }
@ -350,7 +351,7 @@ void Init_preview_24b(short width,short height,long size,int format)
// Allocate 24bit buffer // Allocate 24bit buffer
Buffer_image_24b= Buffer_image_24b=
(T_Components *)Borrow_memory_from_page(width*height*sizeof(T_Components)); (T_Components *)malloc(width*height*sizeof(T_Components));
if (!Buffer_image_24b) if (!Buffer_image_24b)
{ {
// Print an error message // Print an error message
@ -467,11 +468,14 @@ void Init_preview(short width,short height,long size,int format, enum PIXEL_RATI
{ {
if (Pixel_load_function==Pixel_load_in_current_screen) if (Pixel_load_function==Pixel_load_in_current_screen)
{ {
if (Backup_with_new_dimensions(0,width,height)) if (Backup_with_new_dimensions(0,1,width,height))
{ {
// La nouvelle page a pu être allouée, elle est pour l'instant pleine // La nouvelle page a pu être allouée, elle est pour l'instant pleine
// de 0s. Elle fait Main_image_width de large. // de 0s. Elle fait Main_image_width de large.
// Normalement tout va bien, tout est sous contrôle... // Normalement tout va bien, tout est sous contrôle...
// Load into layer 0, by default.
Main_current_layer=0;
} }
else else
{ {
@ -751,7 +755,28 @@ void Save_image(byte image)
// sauver le format du fichier: (Est-ce vraiment utile??? Je ne crois pas!) // sauver le format du fichier: (Est-ce vraiment utile??? Je ne crois pas!)
File_error=1; File_error=1;
Read_pixel_function=(image)?Read_pixel_from_current_screen:Read_pixel_from_brush; if (image)
{
if (!File_formats[Main_fileformat-1].Supports_layers
&& Main_backups->Pages->Nb_layers > 1)
{
if (! Confirmation_box("This format will save a flattened copy."))
{
// File_error is already set to 1.
return;
}
Read_pixel_function=Read_pixel_from_current_screen;
}
else
{
Read_pixel_function=Read_pixel_from_current_layer;
}
}
else
{
Read_pixel_function=Read_pixel_from_brush;
}
format = Get_fileformat(Main_fileformat); format = Get_fileformat(Main_fileformat);
if (format->Save) if (format->Save)

View File

@ -50,6 +50,7 @@ typedef struct {
Func_action Save; ///< Function which saves an image of this format Func_action Save; ///< Function which saves an image of this format
byte Backup_done; ///< Boolean, true if this format saves all the image, and considers it backed up. Set false for formats which only save the palette. byte Backup_done; ///< Boolean, true if this format saves all the image, and considers it backed up. Set false for formats which only save the palette.
byte Comment; ///< This file format allows a text comment byte Comment; ///< This file format allows a text comment
byte Supports_layers; ///< Boolean, true if this format preserves layers on saving
char *Default_extension; ///< Default file extension char *Default_extension; ///< Default file extension
char *Extensions; ///< List of semicolon-separated file extensions char *Extensions; ///< List of semicolon-separated file extensions
} T_Format; } T_Format;

20
main.c
View File

@ -376,6 +376,11 @@ int Init_program(int argc,char * argv[])
Main_fileselector_position=0; // Au début, le fileselect est en haut de la liste des fichiers Main_fileselector_position=0; // Au début, le fileselect est en haut de la liste des fichiers
Main_fileselector_offset=0; // Au début, le fileselect est en haut de la liste des fichiers Main_fileselector_offset=0; // Au début, le fileselect est en haut de la liste des fichiers
Main_format=FORMAT_ALL_IMAGES; Main_format=FORMAT_ALL_IMAGES;
Main_current_layer=0;
Main_layers_visible=0xFFFFFFFF;
Spare_current_layer=0;
Spare_layers_visible=0xFFFFFFFF;
Spare_fileselector_position=0; Spare_fileselector_position=0;
Spare_fileselector_offset=0; Spare_fileselector_offset=0;
Spare_format=FORMAT_ALL_IMAGES; Spare_format=FORMAT_ALL_IMAGES;
@ -635,8 +640,21 @@ int Init_program(int argc,char * argv[])
Main_image_height=Screen_height/Pixel_height; Main_image_height=Screen_height/Pixel_height;
Spare_image_width=Screen_width/Pixel_width; Spare_image_width=Screen_width/Pixel_width;
Spare_image_height=Screen_height/Pixel_height; Spare_image_height=Screen_height/Pixel_height;
#ifndef NOLAYERS
Visible_image[0].Width = 0;
Visible_image[0].Height = 0;
Visible_image[0].Image = NULL;
Visible_image[1].Width = 0;
Visible_image[1].Height = 0;
Visible_image[1].Image = NULL;
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) // Allocation de mémoire pour les différents écrans virtuels (et brosse)
if (Init_all_backup_lists(Config.Max_undo_pages+1,Screen_width,Screen_height)==0) if (Init_all_backup_lists(Screen_width,Screen_height)==0)
Error(ERROR_MEMORY); Error(ERROR_MEMORY);
// On remet le nom par défaut pour la page de brouillon car il été modifié // 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. // par le passage d'un fichier en paramètre lors du traitement précédent.

94
misc.c
View File

@ -36,6 +36,7 @@
#include "windows.h" #include "windows.h"
#include "palette.h" #include "palette.h"
#include "input.h" #include "input.h"
#include "graph.h"
///Count used palette indexes in the whole picture ///Count used palette indexes in the whole picture
///Return the total number of different colors ///Return the total number of different colors
@ -177,16 +178,16 @@ void Hide_current_image_with_stencil(byte color, byte * stencil)
int nb_pixels=0; //ECX int nb_pixels=0; //ECX
//al=color //al=color
//edi=Screen_pixels //edi=Screen_pixels
byte* Pixel_Courant=Screen_pixels; //dl byte* pixel=Main_backups->Pages->Image[Main_current_layer];
int i; int i;
nb_pixels=Main_image_height*Main_image_width; nb_pixels=Main_image_height*Main_image_width;
for(i=0;i<nb_pixels;i++) for(i=0;i<nb_pixels;i++)
{ {
if (stencil[*Pixel_Courant]==0) if (stencil[*pixel]==0)
*Pixel_Courant=color; *pixel=color;
Pixel_Courant++; pixel++;
} }
} }
@ -194,7 +195,7 @@ void Hide_current_image(byte color)
// Effacer l'image courante avec une certaine couleur // Effacer l'image courante avec une certaine couleur
{ {
memset( memset(
Main_screen , Main_backups->Pages->Image[Main_current_layer],
color , color ,
Main_image_width * Main_image_height Main_image_width * Main_image_height
); );
@ -218,26 +219,16 @@ byte Read_pixel_from_brush (word x, word y)
return *(Brush + y * Brush_width + x); return *(Brush + y * Brush_width + x);
} }
void Replace_a_color(byte old_color, byte new_color)
byte Read_pixel_from_current_screen (word x,word y)
{ {
return *(Main_screen+y*Main_image_width+x); word x;
} word y;
void Pixel_in_current_screen (word x,word y,byte color) // Update all pixels
{ for (y=0; y<Main_image_height; y++)
byte* dest=(x+y*Main_image_width+Main_screen); for (x=0; x<Main_image_width; x++)
*dest=color; if (Read_pixel_from_current_layer(x,y) == old_color)
} Pixel_in_current_screen(x,y,new_color,0);
void Replace_a_color(byte old_color, byte New_color)
{
byte* edi;
// pour chaque pixel :
for(edi = Main_screen;edi < Main_screen + Main_image_height * Main_image_width;edi++)
if (*edi == old_color)
*edi = New_color;
Update_rect(0,0,0,0); // On peut TOUT a jour Update_rect(0,0,0,0); // On peut TOUT a jour
// C'est pas un problème car il n'y a pas de preview // C'est pas un problème car il n'y a pas de preview
} }
@ -348,9 +339,9 @@ void Remap_general_lowlevel(byte * conversion_table,byte * buffer,short width,sh
void Copy_image_to_brush(short start_x,short start_y,short Brush_width,short Brush_height,word image_width) void Copy_image_to_brush(short start_x,short start_y,short Brush_width,short Brush_height,word image_width)
{ {
byte* src=start_y*image_width+start_x+Main_screen; //Adr départ image (ESI) byte* src=start_y*image_width+start_x+Main_backups->Pages->Image[Main_current_layer]; //Adr départ image (ESI)
byte* dest=Brush; //Adr dest brosse (EDI) byte* dest=Brush; //Adr dest brosse (EDI)
int dx; int dx;
for (dx=Brush_height;dx!=0;dx--) for (dx=Brush_height;dx!=0;dx--)
//Pour chaque ligne //Pour chaque ligne
@ -383,21 +374,18 @@ byte Effect_sieve(word x,word y)
void Replace_colors_within_limits(byte * replace_table) void Replace_colors_within_limits(byte * replace_table)
{ {
int line; int y;
int counter; int x;
byte* Adresse; byte* pixel;
byte old;
// Pour chaque ligne : // Pour chaque ligne :
for(line = Limit_top;line <= Limit_bottom; line++) for(y = Limit_top;y <= Limit_bottom; y++)
{ {
// Pour chaque pixel sur la ligne : // Pour chaque pixel sur la ligne :
for (counter = Limit_left;counter <= Limit_right;counter ++) for (x = Limit_left;x <= Limit_right;x ++)
{ {
Adresse = Main_screen+line*Main_image_width+counter; pixel = Main_backups->Pages->Image[Main_current_layer]+y*Main_image_width+x;
old=*Adresse; *pixel = replace_table[*pixel];
*Adresse = replace_table[old];
} }
} }
} }
@ -663,33 +651,33 @@ void Slider_timer(byte speed)
} while (Mouse_K == original_mouse_k && SDL_GetTicks()<end); } while (Mouse_K == original_mouse_k && SDL_GetTicks()<end);
} }
void Scroll_picture(short x_offset,short y_offset) void Scroll_picture(byte * main_src, byte * main_dest, short x_offset,short y_offset)
{ {
byte* esi = Screen_backup; //source de la copie byte* src = main_src; //source de la copie
byte* edi = Main_screen + y_offset * Main_image_width + x_offset; byte* dest = main_dest + y_offset * Main_image_width + x_offset;
const word ax = Main_image_width - x_offset; // Nombre de pixels à copier à droite const word length = Main_image_width - x_offset; // Nombre de pixels à copier à droite
word dx; word y;
for(dx = Main_image_height - y_offset;dx>0;dx--) for(y = Main_image_height - y_offset;y>0;y--)
{ {
// Pour chaque ligne // Pour chaque ligne
memcpy(edi,esi,ax); memcpy(dest,src,length);
memcpy(edi - x_offset,esi+ax,x_offset); memcpy(dest - x_offset,src+length,x_offset);
// On passe à la ligne suivante // On passe à la ligne suivante
edi += Main_image_width; dest += Main_image_width;
esi += Main_image_width; src += Main_image_width;
} }
// On vient de faire le traitement pour otutes les lignes au-dessous de y_offset // On vient de faire le traitement pour otutes les lignes au-dessous de y_offset
// Maintenant on traite celles au dessus // Maintenant on traite celles au dessus
edi = x_offset + Main_screen; dest = x_offset + main_dest;
for(dx = y_offset;dx>0;dx--) for(y = y_offset;y>0;y--)
{ {
memcpy(edi,esi,ax); memcpy(dest,src,length);
memcpy(edi - x_offset,esi+ax,x_offset); memcpy(dest - x_offset,src+length,x_offset);
edi += Main_image_width; dest += Main_image_width;
esi += Main_image_width; src += Main_image_width;
} }
Update_rect(0,0,0,0); Update_rect(0,0,0,0);

4
misc.h
View File

@ -25,7 +25,7 @@
void Copy_image_to_brush(short start_x,short start_y,short Brush_width,short Brush_height,word image_width); void Copy_image_to_brush(short start_x,short start_y,short Brush_width,short Brush_height,word image_width);
void Remap_general_lowlevel(byte * conversion_table,byte * buffer,short width,short height,short buffer_width); void Remap_general_lowlevel(byte * conversion_table,byte * buffer,short width,short height,short buffer_width);
void Scroll_picture(short x_offset,short y_offset); void Scroll_picture(byte * main_src, byte * main_dest, short x_offset,short y_offset);
void Wait_end_of_click(void); void Wait_end_of_click(void);
void Set_color(byte color, byte red, byte green, byte blue); void Set_color(byte color, byte red, byte green, byte blue);
void Set_palette(T_Palette palette); void Set_palette(T_Palette palette);
@ -38,9 +38,7 @@ dword Round_div(dword numerator,dword divisor);
word Count_used_colors(dword * usage); 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_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); 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);
void Pixel_in_brush (word x,word y,byte color); 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_spare_screen(word x,word y);
byte Read_pixel_from_backup_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_feedback_screen (word x,word y);

View File

@ -3007,7 +3007,8 @@ void Brush_0_5(void)
Brush_offset_X=(Brush_offset_X/Snap_width)*Snap_width; Brush_offset_X=(Brush_offset_X/Snap_width)*Snap_width;
Brush_offset_Y=(Brush_offset_Y/Snap_height)*Snap_height; Brush_offset_Y=(Brush_offset_Y/Snap_height)*Snap_height;
} }
End_of_modification();
End_of_modification(); End_of_modification();
Return_to_draw_mode(); Return_to_draw_mode();
} }
@ -3911,11 +3912,16 @@ void Scroll_12_0(void)
// //
{ {
Init_start_operation(); Init_start_operation();
Backup();
Operation_push(Paintbrush_X); Operation_push(Paintbrush_X);
Operation_push(Paintbrush_Y); Operation_push(Paintbrush_Y);
Operation_push(Paintbrush_X); Operation_push(Paintbrush_X);
Operation_push(Paintbrush_Y); Operation_push(Paintbrush_Y);
Operation_push(Mouse_K); // LEFT_SIDE or RIGHT_SIDE
if (Mouse_K == LEFT_SIDE)
Backup();
else
Backup_layers(Main_layers_visible);
Cursor_hidden_before_scroll=Cursor_hidden; Cursor_hidden_before_scroll=Cursor_hidden;
Cursor_hidden=1; Cursor_hidden=1;
if ((Config.Coords_rel) && (Menu_is_visible)) if ((Config.Coords_rel) && (Menu_is_visible))
@ -3923,11 +3929,11 @@ void Scroll_12_0(void)
} }
void Scroll_12_4(void) void Scroll_12_5(void)
// //
// Opération : OPERATION_SCROLL // Opération : OPERATION_SCROLL
// Click Souris: 1 ou 2 // Click Souris: 1 ou 2
// Taille_Pile : 4 // Taille_Pile : 5
// //
// Souris effacée: Non // Souris effacée: Non
// //
@ -3938,8 +3944,10 @@ void Scroll_12_4(void)
short y_pos; short y_pos;
short x_offset; short x_offset;
short y_offset; short y_offset;
short side;
//char str[5]; //char str[5];
Operation_pop(&side);
Operation_pop(&y_pos); Operation_pop(&y_pos);
Operation_pop(&x_pos); Operation_pop(&x_pos);
Operation_pop(&center_y); Operation_pop(&center_y);
@ -3961,7 +3969,18 @@ void Scroll_12_4(void)
Display_coords_rel_or_abs(center_x,center_y); Display_coords_rel_or_abs(center_x,center_y);
Scroll_picture(x_offset,y_offset); if (side == RIGHT_SIDE)
{
// All layers at once
Scroll_picture(Screen_backup, Main_screen, x_offset,y_offset);
}
else
{
// One layer at once
Scroll_picture(Main_backups->Pages->Next->Image[Main_current_layer], Main_backups->Pages->Image[Main_current_layer], x_offset, y_offset);
//Redraw_layered_image();
Redraw_current_layer();
}
Display_all_screen(); Display_all_screen();
} }
@ -3970,19 +3989,64 @@ void Scroll_12_4(void)
Operation_push(center_y); Operation_push(center_y);
Operation_push(Paintbrush_X); Operation_push(Paintbrush_X);
Operation_push(Paintbrush_Y); Operation_push(Paintbrush_Y);
Operation_push(side);
} }
void Scroll_0_4(void) void Scroll_0_5(void)
// //
// Opération : OPERATION_SCROLL // Opération : OPERATION_SCROLL
// Click Souris: 0 // Click Souris: 0
// Taille_Pile : 4 // Taille_Pile : 5
// //
// Souris effacée: Oui // Souris effacée: Oui
// //
{ {
Operation_stack_size-=4; // All layers at once
short center_x;
short center_y;
short x_pos;
short y_pos;
short x_offset;
short y_offset;
short side;
int i;
Operation_pop(&side);
Operation_pop(&y_pos);
Operation_pop(&x_pos);
Operation_pop(&center_y);
Operation_pop(&center_x);
if (side == RIGHT_SIDE)
{
// All layers at once
if (x_pos>=center_x)
x_offset=(x_pos-center_x)%Main_image_width;
else
x_offset=Main_image_width-((center_x-x_pos)%Main_image_width);
if (y_pos>=center_y)
y_offset=(y_pos-center_y)%Main_image_height;
else
y_offset=Main_image_height-((center_y-y_pos)%Main_image_height);
// Do the actual scroll operation on all layers.
for (i=0; i<Main_backups->Pages->Nb_layers; i++)
Scroll_picture(Main_backups->Pages->Next->Image[i], Main_backups->Pages->Image[i], x_offset, y_offset);
// Update the depth buffer too ...
// It would be faster to scroll it, but we don't have method
// for in-place scrolling.
Update_depth_buffer();
}
else
{
// One layer : everything was done while dragging the mouse
}
Cursor_hidden=Cursor_hidden_before_scroll; Cursor_hidden=Cursor_hidden_before_scroll;
End_of_modification(); End_of_modification();
if ((Config.Coords_rel) && (Menu_is_visible)) if ((Config.Coords_rel) && (Menu_is_visible))
{ {

View File

@ -183,8 +183,8 @@ void Filled_contour_0_8(void);
//////////////////////////////////////////////////////////// OPERATION_SCROLL //////////////////////////////////////////////////////////// OPERATION_SCROLL
void Scroll_12_0(void); void Scroll_12_0(void);
void Scroll_12_4(void); void Scroll_12_5(void);
void Scroll_0_4(void); void Scroll_0_5(void);
//////////////////////////////////////////////////// OPERATION_GRAD_CIRCLE //////////////////////////////////////////////////// OPERATION_GRAD_CIRCLE

1241
pages.c

File diff suppressed because it is too large Load Diff

42
pages.h
View File

@ -32,6 +32,8 @@
/////////////////////////// BACKUP /////////////////////////////////////// /////////////////////////// BACKUP ///////////////////////////////////////
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
extern T_Image Visible_image[2];
extern T_Image Visible_image_depth_buffer;
/// ///
/// INDIVIDUAL PAGES /// INDIVIDUAL PAGES
@ -39,15 +41,20 @@
void Download_infos_page_main(T_Page * page); void Download_infos_page_main(T_Page * page);
void Upload_infos_page_main(T_Page * page); void Upload_infos_page_main(T_Page * page);
/// Add a new layer to latest page of a list. Returns 0 on success.
byte Add_layer(T_List_of_pages *list, byte layer);
/// Delete a layer from the latest page of a list. Returns 0 on success.
byte Delete_layer(T_List_of_pages *list, byte layer);
/// Merges the current layer onto the one below it.
byte Merge_layer();
// private // private
void Init_page(T_Page * page); T_Page * New_page(byte nb_layers);
void Download_infos_page_spare(T_Page * page); void Download_infos_page_spare(T_Page * page);
void Upload_infos_page_spare(T_Page * page); void Upload_infos_page_spare(T_Page * page);
void Download_infos_backup(T_List_of_pages * list); void Download_infos_backup(T_List_of_pages * list);
void Free_a_page(T_Page * page); void Clear_page(T_Page * page);
void Copy_S_page(T_Page * dest,T_Page * source); void Copy_S_page(T_Page * dest,T_Page * source);
int Size_of_a_page(T_Page * page);
@ -57,14 +64,11 @@ int Size_of_a_page(T_Page * page);
void Init_list_of_pages(T_List_of_pages * list); void Init_list_of_pages(T_List_of_pages * list);
// private // private
int Allocate_list_of_pages(T_List_of_pages * list,int size); int Allocate_list_of_pages(T_List_of_pages * list);
void Free_a_list_of_pages(T_List_of_pages * list);
int Size_of_a_list_of_pages(T_List_of_pages * list);
void Backward_in_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 Advance_in_list_of_pages(T_List_of_pages * list);
int New_page_is_possible(T_Page * new_page,T_List_of_pages * current_list,T_List_of_pages * secondary_list);
void Free_last_page_of_list(T_List_of_pages * list); void Free_last_page_of_list(T_List_of_pages * list);
void Create_new_page(T_Page * new_page,T_List_of_pages * current_list,T_List_of_pages * secondary_list); int Create_new_page(T_Page * new_page,T_List_of_pages * current_list, dword layer_mask);
void Change_page_number_of_list(T_List_of_pages * list,int number); void Change_page_number_of_list(T_List_of_pages * list,int number);
void Free_page_of_a_list(T_List_of_pages * list); void Free_page_of_a_list(T_List_of_pages * list);
@ -74,25 +78,33 @@ void Free_page_of_a_list(T_List_of_pages * list);
/// BACKUP HIGH-LEVEL FUNCTIONS /// BACKUP HIGH-LEVEL FUNCTIONS
/// ///
int Init_all_backup_lists(int size,int width,int height); int Init_all_backup_lists(int width,int height);
void Set_number_of_backups(int nb_backups); void Set_number_of_backups(int nb_backups);
int Backup_with_new_dimensions(int upload,int width,int height); int Backup_with_new_dimensions(int upload,byte layers,int width,int height);
int Backup_and_resize_the_spare(int width,int height); 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); void Backup(void);
/// Backup with a new copy of some layers (the others are references).
void Backup_layers(dword layer_mask);
void Undo(void); void Undo(void);
void Redo(void); void Redo(void);
void Free_current_page(void); // 'Kill' button void Free_current_page(void); // 'Kill' button
void Exchange_main_and_spare(void); void Exchange_main_and_spare(void);
void End_of_modification(void); void End_of_modification(void);
void Update_depth_buffer(void);
void Redraw_layered_image(void);
void Redraw_current_layer(void);
void Update_screen_targets(void);
/// ///
/// BORROWING MEMORY FROM PAGE /// STATISTICS
/// ///
void * Borrow_memory_from_page(int size); /// Total number of unique bitmaps (layers, animation frames, backups)
// private extern long Stats_pages_number;
int Can_borrow_memory_from_page(int size); /// Total memory used by bitmaps (layers, animation frames, backups)
extern long long Stats_pages_memory;
#endif #endif

View File

@ -1316,7 +1316,7 @@ void Button_Palette(void)
// est en mode X-SWAP. // est en mode X-SWAP.
if (!image_is_backed_up) if (!image_is_backed_up)
{ {
Backup(); Backup_layers(-1);
image_is_backed_up=1; image_is_backed_up=1;
} }
@ -1472,12 +1472,11 @@ void Button_Palette(void)
reduce_colors_number = -1; reduce_colors_number = -1;
break; break;
} }
if (reduce_colors_number > 0) if (reduce_colors_number > 0)
{ {
if (!image_is_backed_up) if (!image_is_backed_up)
{ {
Backup(); Backup_layers(-1);
image_is_backed_up = 1; image_is_backed_up = 1;
} }
@ -1846,7 +1845,7 @@ void Button_Palette(void)
{ {
if (!image_is_backed_up) if (!image_is_backed_up)
{ {
Backup(); Backup_layers(-1);
image_is_backed_up=1; image_is_backed_up=1;
} }
Hide_cursor(); Hide_cursor();
@ -1923,7 +1922,7 @@ void Button_Palette(void)
// Make a backup because remapping is an undoable modification // Make a backup because remapping is an undoable modification
if (!image_is_backed_up) if (!image_is_backed_up)
{ {
Backup(); Backup_layers(-1);
image_is_backed_up=1; image_is_backed_up=1;
} }
@ -2067,7 +2066,7 @@ void Button_Palette(void)
// de ne pas trop modifier l'image. // de ne pas trop modifier l'image.
if (!image_is_backed_up) if (!image_is_backed_up)
{ {
Backup(); Backup_layers(-1);
image_is_backed_up=1; image_is_backed_up=1;
} }
if (used_colors==-1) if (used_colors==-1)
@ -2169,9 +2168,9 @@ void Button_Palette(void)
{ {
if ( (!image_is_backed_up) if ( (!image_is_backed_up)
&& memcmp(Main_palette,working_palette,sizeof(T_Palette)) ) && memcmp(Main_palette,working_palette,sizeof(T_Palette)) )
Backup(); Backup_layers(-1);
memcpy(Main_palette,working_palette,sizeof(T_Palette)); memcpy(Main_palette,working_palette,sizeof(T_Palette));
// End_of_modification(); End_of_modification();
// Not really needed, the change was in palette entries // Not really needed, the change was in palette entries
} }

View File

@ -1,3 +1,4 @@
/* vim:expandtab:ts=2 sw=2: /* vim:expandtab:ts=2 sw=2:
*/ */
char Program_version[]="2.2wip"; char Program_version[]="2.2wip";

128
special.c
View File

@ -27,6 +27,11 @@
#include "engine.h" #include "engine.h"
#include "windows.h" #include "windows.h"
#include "special.h" #include "special.h"
#include "pages.h"
#include "misc.h"
#include "buttons.h"
@ -413,3 +418,126 @@ void Zoom_set(int index)
} }
Display_cursor(); Display_cursor();
} }
void Transparency_set(byte amount)
{
const int doubleclick_delay = Config.Double_key_speed;
static long time_click = 0;
long time_previous;
if (!Colorize_mode)
{
// Activate mode
switch(Colorize_current_mode)
{
case 0 :
Effect_function=Effect_interpolated_colorize;
break;
case 1 :
Effect_function=Effect_additive_colorize;
break;
case 2 :
Effect_function=Effect_substractive_colorize;
}
Shade_mode=0;
Quick_shade_mode=0;
Smooth_mode=0;
Tiling_mode=0;
Colorize_mode=1;
}
time_previous = time_click;
time_click = SDL_GetTicks();
// Check if it's a quick re-press
if (time_click - time_previous < doubleclick_delay)
{
// Use the typed amount as units, keep the tens.
Colorize_opacity = ((Colorize_opacity%100) /10 *10) + amount;
if (Colorize_opacity == 0)
Colorize_opacity = 100;
}
else
{
// Use 10% units: "1"=10%, ... "0"=100%
if (amount == 0)
Colorize_opacity = 100;
else
Colorize_opacity = amount*10;
}
Compute_colorize_table();
}
void Layer_activate(short layer, short side)
{
word old_layers;
if (layer >= Main_backups->Pages->Nb_layers)
return;
// Keep a copy of which layers were visible
old_layers = Main_layers_visible;
#ifndef NOLAYERS
if (side == RIGHT_SIDE)
{
// Right-click on current layer
if (Main_current_layer == layer)
{
if (Main_layers_visible == (dword)(1<<layer))
{
// Set all layers visible
Main_layers_visible = 0xFFFFFFFF;
}
else
{
// Set only this one visible
Main_layers_visible = 1<<layer;
}
}
else
{
// Right-click on an other layer : toggle its visibility
Main_layers_visible ^= 1<<layer;
}
}
else
{
// Left-click on any layer
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)
Redraw_layered_image();
else
Update_depth_buffer(); // Only need the depth buffer
//Download_infos_page_main(Main_backups->Pages);
//Download_infos_backup(Main_backups);
Display_all_screen();
Display_cursor();
}
void Special_add_layer()
{
}
void Special_delete_layer()
{
}

View File

@ -50,3 +50,15 @@ void Zoom_set(int index);
void Display_stored_brush_in_window(word x,word y,int number); void Display_stored_brush_in_window(word x,word y,int number);
void Store_brush(int index); void Store_brush(int index);
byte Restore_brush(int index); byte Restore_brush(int index);
/*!
Command that sets the transparency level.
*/
void Transparency_set(byte amount);
void Layer_activate(short layer, short side);
void Special_add_layer(void);
void Special_delete_layer(void);

View File

@ -327,9 +327,8 @@ typedef struct
// backup dans "graph.c". // backup dans "graph.c".
/// This is the data for one step of Undo/Redo, for one image. /// This is the data for one step of Undo/Redo, for one image.
typedef struct typedef struct T_Page
{ {
byte * Image; ///< Pixel data for the image.
int Width; ///< Image width in pixels. int Width; ///< Image width in pixels.
int Height; ///< Image height in pixels. int Height; ///< Image height in pixels.
T_Palette Palette; ///< Image palette. T_Palette Palette; ///< Image palette.
@ -339,17 +338,29 @@ typedef struct
char File_directory[MAX_PATH_CHARACTERS];///< Directory that contains the file. char File_directory[MAX_PATH_CHARACTERS];///< Directory that contains the file.
char Filename[MAX_PATH_CHARACTERS]; ///< Filename without directory. char Filename[MAX_PATH_CHARACTERS]; ///< Filename without directory.
byte File_format; ///< File format, in enum ::FILE_FORMATS byte File_format; ///< File format, in enum ::FILE_FORMATS
struct T_Page *Next; ///< Pointer to the next backup
struct T_Page *Prev; ///< Pointer to the previous backup
word Transparent_color; ///< Index of transparent color. -1 or 0 to 255.
byte Nb_layers; ///< Number of layers
byte * Image[0]; ///< Pixel data for the (first layer of) image.
// No field after Image[] ! Dynamic layer allocation for Image[1], [2] etc.
} T_Page; } T_Page;
/// Collection of undo/redo steps. /// Collection of undo/redo steps.
typedef struct typedef struct
{ {
int List_size; ///< Number of ::T_Page in the vector "Pages". int List_size; ///< Number of ::T_Page in the vector "Pages".
int Nb_pages_allocated;///< Number of ::T_Page used so far in the vector "Pages". T_Page * Pages; ///< Head of a linked list of pages, each one being a undo/redo step.
T_Page * Pages; ///< Vector of Pages, each one being a undo/redo step.
} T_List_of_pages; } T_List_of_pages;
/// A single image bitmap
typedef struct
{
int Width; ///< Image width in pixels.
int Height; ///< Image height in pixels.
byte * Image; ///< Pixel data for the image.
} T_Image;
/// A single memorized brush from the Brush Container /// A single memorized brush from the Brush Container
typedef struct typedef struct
{ {
@ -363,7 +374,6 @@ typedef struct
byte Transp_color; byte Transp_color;
} T_Brush_template; } T_Brush_template;
/// GUI skin data /// GUI skin data
typedef struct typedef struct
{ {

View File

@ -370,7 +370,7 @@ void Button_Transform_menu(void)
old_height=Main_image_height; old_height=Main_image_height;
// Allocate a new page // Allocate a new page
if (Backup_with_new_dimensions(1,new_width,new_height)) if (Backup_with_new_dimensions(1,Main_backups->Pages->Nb_layers,new_width,new_height))
{ {
// The new image is allocated, the new dimensions are already updated. // The new image is allocated, the new dimensions are already updated.
@ -379,29 +379,60 @@ void Button_Transform_menu(void)
// Process the transformation: // Process the transformation:
switch(clicked_button) switch(clicked_button)
{ {
int i;
case 2 : // Flip X case 2 : // Flip X
memcpy(Main_screen,Screen_backup,Main_image_width*Main_image_height); for (i=0; i<Main_backups->Pages->Nb_layers; i++)
Flip_X_lowlevel(Main_screen, Main_image_width, Main_image_height); {
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; break;
case 3 : // Flip Y case 3 : // Flip Y
memcpy(Main_screen,Screen_backup,Main_image_width*Main_image_height); for (i=0; i<Main_backups->Pages->Nb_layers; i++)
Flip_Y_lowlevel(Main_screen, Main_image_width, Main_image_height); {
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; break;
case 4 : // -90° Rotation case 4 : // -90° Rotation
Rotate_270_deg_lowlevel(Screen_backup, Main_screen, old_width, old_height); for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{
Rotate_270_deg_lowlevel(Main_backups->Pages->Next->Image[i], Main_backups->Pages->Image[i], old_width, old_height);
}
break; break;
case 5 : // +90° Rotation case 5 : // +90° Rotation
Rotate_90_deg_lowlevel(Screen_backup, Main_screen, old_width, old_height); for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{
Rotate_90_deg_lowlevel(Main_backups->Pages->Next->Image[i], Main_backups->Pages->Image[i], old_width, old_height);
}
break; break;
case 6 : // 180° Rotation case 6 : // 180° Rotation
memcpy(Main_screen,Screen_backup,Main_image_width*Main_image_height); for (i=0; i<Main_backups->Pages->Nb_layers; i++)
Rotate_180_deg_lowlevel(Main_screen, Main_image_width, Main_image_height); {
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; break;
case 7 : // Resize case 7 : // Resize
Rescale(Screen_backup, old_width, old_height, Main_screen, Main_image_width, Main_image_height, 0, 0); for (i=0; i<Main_backups->Pages->Nb_layers; i++)
break; {
Rescale(Main_backups->Pages->Next->Image[i], old_width, old_height, Main_backups->Pages->Image[i], Main_image_width, Main_image_height, 0, 0);
}
break;
} }
Display_all_screen(); /*
for (i=0; i<NB_LAYERS; i++)
{
Copy_part_of_image_to_another(
Main_backups->Pages->Next->Image[i],0,0,Min(old_width,Main_image_width),
Min(old_height,Main_image_height),old_width,
Main_backups->Pages->Image[i],0,0,Main_image_width);
}
*/
Redraw_layered_image();
Display_all_screen();
End_of_modification();
} }
else else
{ {