[layers] working swap between main/spare, and loading files in command-line. Start of work on variable layers number and layer sharing.

git-svn-id: svn://pulkomandy.tk/GrafX2/branches/layers@1044 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2009-09-28 18:48:05 +00:00
parent b534cfd7d4
commit 057d5e76e4
8 changed files with 139 additions and 110 deletions

BIN
gfx2.cfg

Binary file not shown.

View File

@ -598,7 +598,7 @@ void Resize_image(word chosen_width,word chosen_height)
Main_image_is_modified=1;
// On copie donc maintenant la partie C dans la nouvelle image.
for (i=0; i<NB_LAYERS; i++)
for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{
Copy_part_of_image_to_another(
Main_backups->Pages->Next->Image[i],0,0,Min(old_width,Main_image_width),

12
main.c
View File

@ -635,18 +635,6 @@ int Init_program(int argc,char * argv[])
// Allocation de mémoire pour les différents écrans virtuels (et brosse)
if (Init_all_backup_lists(Screen_width,Screen_height)==0)
Error(ERROR_MEMORY);
// 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.
// Note: le fait que l'on ne modifie que les variables globales
// Brouillon_* et pas les infos contenues dans la page de brouillon
// elle-même ne m'inspire pas confiance mais ça a l'air de marcher sans
// poser de problèmes, alors...
if (File_in_command_line)
{
strcpy(Spare_file_directory,Spare_current_directory);
strcpy(Spare_filename,"NO_NAME.GIF");
Spare_fileformat=DEFAULT_FILEFORMAT;
}
// Nettoyage de l'écran virtuel (les autres recevront celui-ci par copie)
memset(Main_screen,0,Main_image_width*Main_image_height);

View File

@ -4026,7 +4026,7 @@ void Scroll_0_5(void)
// Do the actual scroll operation on all layers.
for (i=0; i<NB_LAYERS; i++)
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);
}
else

118
pages.c
View File

@ -39,15 +39,15 @@
static word Last_backed_up_layers=0;
/// Allocate and initialize a new page.
T_Page * New_page(void)
T_Page * New_page(byte nb_layers)
{
T_Page * page;
page = (T_Page *)malloc(sizeof(T_Page));
page = (T_Page *)malloc(sizeof(T_Page)+NB_LAYERS*sizeof(byte *));
if (page!=NULL)
{
int i;
for (i=0; i<NB_LAYERS; i++)
for (i=0; i<nb_layers; i++)
page->Image[i]=NULL;
page->Width=0;
page->Height=0;
@ -56,12 +56,26 @@ T_Page * New_page(void)
page->File_directory[0]='\0';
page->Filename[0]='\0';
page->File_format=DEFAULT_FILEFORMAT;
page->Nb_layers=nb_layers;
page->Next = page->Prev = NULL;
}
return page;
}
byte * New_layer(long pixel_size)
{
return (byte *)(malloc(pixel_size));
}
void Free_layer(byte * layer)
{
free(layer);
}
byte * Dup_layer(byte * layer)
{
return layer;
}
void Download_infos_page_main(T_Page * page)
// Affiche la page à l'écran
{
@ -102,7 +116,7 @@ void Redraw_layered_image(void)
// Re-construct the image with the visible layers
int layer;
// First layer
for (layer=0; layer<NB_LAYERS; layer++)
for (layer=0; layer<Main_backups->Pages->Nb_layers; layer++)
{
if ((1<<layer) & Main_layers_visible)
{
@ -122,7 +136,7 @@ void Redraw_layered_image(void)
}
}
// subsequent layer(s)
for (; layer<NB_LAYERS; layer++)
for (; layer<Main_backups->Pages->Nb_layers; layer++)
{
if ((1<<layer) & Main_layers_visible)
{
@ -162,7 +176,7 @@ void Download_infos_page_spare(T_Page * page)
{
if (page!=NULL)
{
Spare_screen=page->Image[Spare_current_layer];
//Spare_screen=page->Image[Spare_current_layer];
Spare_image_width=page->Width;
Spare_image_height=page->Height;
memcpy(Spare_palette,page->Palette,sizeof(T_Palette));
@ -177,7 +191,7 @@ void Upload_infos_page_spare(T_Page * page)
{
if (page!=NULL)
{
page->Image[Spare_current_layer]=Spare_screen;
//page->Image[Spare_current_layer]=Spare_screen;
page->Width=Spare_image_width;
page->Height=Spare_image_height;
memcpy(page->Palette,Spare_palette,sizeof(T_Palette));
@ -204,9 +218,9 @@ void Clear_page(T_Page * page)
{
// On peut appeler cette fonction sur une page non allouée.
int i;
for (i=0; i<NB_LAYERS; i++)
for (i=0; i<page->Nb_layers; i++)
{
free(page->Image[i]);
Free_layer(page->Image[i]);
page->Image[i]=NULL;
}
page->Width=0;
@ -240,7 +254,7 @@ int Allocate_list_of_pages(T_List_of_pages * list)
T_Page * page;
// On initialise chacune des nouvelles pages
page=New_page();
page=New_page(NB_LAYERS);
if (!page)
return 0;
@ -372,8 +386,8 @@ int Create_new_page(T_Page * new_page,T_List_of_pages * list)
}
{
int i;
for (i=0; i<NB_LAYERS; i++)
new_page->Image[i]=(byte *)malloc(new_page->Height*new_page->Width);
for (i=0; i<new_page->Nb_layers; i++)
new_page->Image[i]=New_layer(new_page->Height*new_page->Width);
}
@ -449,9 +463,9 @@ int Init_all_backup_lists(int width,int height)
// width et height correspondent à la dimension des images de départ.
int i;
if (Allocate_list_of_pages(Main_backups) &&
Allocate_list_of_pages(Spare_backups))
{
if (! Allocate_list_of_pages(Main_backups) ||
! Allocate_list_of_pages(Spare_backups))
return 0;
// On a réussi à allouer deux listes de pages dont la taille correspond à
// celle demandée par l'utilisateur.
@ -460,9 +474,11 @@ int Init_all_backup_lists(int width,int height)
// On y met les infos sur la dimension de démarrage
Main_backups->Pages->Width=width;
Main_backups->Pages->Height=height;
for (i=0; i<NB_LAYERS; i++)
for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{
Main_backups->Pages->Image[i]=(byte *)malloc(width*height);
Main_backups->Pages->Image[i]=New_layer(width*height);
if (! Main_backups->Pages->Image[i])
return 0;
}
if (!Update_visible_page_buffer(0, width, height))
@ -476,13 +492,28 @@ int Init_all_backup_lists(int width,int height)
Download_infos_page_main(Main_backups->Pages);
Download_infos_backup(Main_backups);
// Maintenant, on regarde si on a le droit de créer la même page dans
// la page de brouillon.
// Default values for spare page
Spare_backups->Pages->Width = width;
Spare_backups->Pages->Height = height;
memcpy(Spare_backups->Pages->Palette,Main_palette,sizeof(T_Palette));
strcpy(Spare_backups->Pages->Comment,"");
strcpy(Spare_backups->Pages->File_directory,Spare_current_directory);
strcpy(Spare_backups->Pages->Filename,"NO_NAME.GIF");
Spare_backups->Pages->File_format=DEFAULT_FILEFORMAT;
// Copy this informations in the global Spare_ variables
Download_infos_page_spare(Spare_backups->Pages);
// Et on efface les 2 images en les remplacant de "0"
memset(Main_screen,0,Main_image_width*Main_image_height);
memset(Spare_screen,0,Spare_image_width*Spare_image_height);
// Clear the initial Visible buffer
//memset(Main_screen,0,Main_image_width*Main_image_height);
// Spare
for (i=0; i<NB_LAYERS; i++)
{
Spare_backups->Pages->Image[i]=New_layer(width*height);
if (! Spare_backups->Pages->Image[i])
return 0;
}
//memset(Spare_screen,0,Spare_image_width*Spare_image_height);
Visible_image[0].Width = width;
Visible_image[0].Height = height;
@ -497,22 +528,20 @@ int Init_all_backup_lists(int width,int height)
Visible_image_depth_buffer.Image = NULL;
Visible_image[0].Image = (byte *)malloc(Visible_image[0].Width * Visible_image[0].Height);
if (Visible_image[0].Image)
{
if (! Visible_image[0].Image)
return 0;
Visible_image[1].Image = (byte *)malloc(Visible_image[1].Width * Visible_image[1].Height);
if (Visible_image[1].Image)
{
if (! Visible_image[1].Image)
return 0;
Visible_image_depth_buffer.Image = (byte *)malloc(Visible_image_depth_buffer.Width * Visible_image_depth_buffer.Height);
if (Visible_image_depth_buffer.Image)
{
if (! Visible_image_depth_buffer.Image)
return 0;
End_of_modification();
return 1;
}
}
}
}
return 0;
}
void Set_number_of_backups(int nb_backups)
{
@ -530,6 +559,7 @@ int Backup_with_new_dimensions(int upload,int width,int height)
// 0 sinon.
T_Page * new_page;
byte nb_layers;
int return_code=0;
int i;
@ -538,8 +568,9 @@ int Backup_with_new_dimensions(int upload,int width,int height)
// retrouver plus tard)
Upload_infos_page_main(Main_backups->Pages);
nb_layers=Main_backups->Pages->Nb_layers;
// On crée un descripteur pour la nouvelle page courante
new_page=New_page();
new_page=New_page(nb_layers);
if (!new_page)
{
Error(0);
@ -551,7 +582,7 @@ int Backup_with_new_dimensions(int upload,int width,int height)
new_page->Height=height;
if (Create_new_page(new_page,Main_backups))
{
for (i=0; i<NB_LAYERS;i++)
for (i=0; i<nb_layers;i++)
{
//Main_backups->Pages->Image[i]=(byte *)malloc(width*height);
memset(Main_backups->Pages->Image[i], 0, width*height);
@ -592,7 +623,7 @@ int Backup_and_resize_the_spare(int width,int height)
Upload_infos_page_spare(Spare_backups->Pages);
// On crée un descripteur pour la nouvelle page de brouillon
new_page=New_page();
new_page=New_page(Spare_backups->Pages->Nb_layers);
if (!new_page)
{
Error(0);
@ -632,7 +663,7 @@ void Backup(void)
Upload_infos_page_main(Main_backups->Pages);
// On crée un descripteur pour la nouvelle page courante
new_page=New_page();
new_page=New_page(Main_backups->Pages->Nb_layers);
if (!new_page)
{
Error(0);
@ -647,7 +678,7 @@ void Backup(void)
Download_infos_backup(Main_backups);
// On copie l'image du backup vers la page courante:
for (i=0; i<NB_LAYERS;i++)
for (i=0; i<Main_backups->Pages->Nb_layers;i++)
memcpy(Main_backups->Pages->Image[i],
Main_backups->Pages->Next->Image[i],
Main_image_width*Main_image_height);
@ -743,6 +774,15 @@ void Exchange_main_and_spare(void)
// On extrait ensuite les infos sur les nouvelles pages courante, brouillon
// et backup.
Update_depth_buffer(Main_backups->Pages->Width, Main_backups->Pages->Height);
Update_visible_page_buffer(0, Main_backups->Pages->Width, Main_backups->Pages->Height);
Main_screen=Visible_image[0].Image;
Update_visible_page_buffer(1, Main_backups->Pages->Width, Main_backups->Pages->Height);
Screen_backup=Visible_image[1].Image;
/* SECTION GROS CACA PROUT PROUT */
// Auparavant on ruse en mettant déjà à jour les dimensions de la
// nouvelle page courante. Si on ne le fait pas, le "Download" va détecter

View File

@ -39,7 +39,7 @@ void Download_infos_page_main(T_Page * page);
void Upload_infos_page_main(T_Page * page);
// private
T_Page * New_page(void);
T_Page * New_page(byte nb_layers);
void Download_infos_page_spare(T_Page * page);
void Upload_infos_page_spare(T_Page * page);
void Download_infos_backup(T_List_of_pages * list);

View File

@ -330,9 +330,10 @@ typedef struct T_Page
char File_directory[MAX_PATH_CHARACTERS];///< Directory that contains the file.
char Filename[MAX_PATH_CHARACTERS]; ///< Filename without directory.
byte File_format; ///< File format, in enum ::FILE_FORMATS
struct T_Page *Next;
struct T_Page *Prev;
byte * Image[NB_LAYERS];///< Pixel data for the image.
struct T_Page *Next; ///< Pointer to the next backup
struct T_Page *Prev; ///< Pointer to the previous backup
byte Nb_layers; ///< Number of layers
byte * Image[0]; ///< Pixel data for the image.
} T_Page;
/// Collection of undo/redo steps.

View File

@ -380,40 +380,40 @@ void Button_Transform_menu(void)
int i;
case 2 : // Flip X
for (i=0; i<NB_LAYERS; i++)
for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{
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;
case 3 : // Flip Y
for (i=0; i<NB_LAYERS; i++)
for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{
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;
case 4 : // -90° Rotation
for (i=0; i<NB_LAYERS; i++)
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;
case 5 : // +90° Rotation
for (i=0; i<NB_LAYERS; i++)
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;
case 6 : // 180° Rotation
for (i=0; i<NB_LAYERS; i++)
for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{
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;
case 7 : // Resize
for (i=0; i<NB_LAYERS; i++)
for (i=0; i<Main_backups->Pages->Nb_layers; i++)
{
Rescale(Main_backups->Pages->Next->Image[i], old_width, old_height, Main_backups->Pages->Image[i], Main_image_width, Main_image_height, 0, 0);
}