[layers] Fix a bug with scroll. Implemented basic save/load of layers in GIF as non-looping animation.
git-svn-id: svn://pulkomandy.tk/GrafX2/branches/layers@1058 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
416ad0cd78
commit
874ccd4430
106
loadsave.c
106
loadsave.c
@ -465,6 +465,9 @@ void Init_preview(short width,short height,long size,int format, enum PIXEL_RATI
|
||||
// La nouvelle page a pu être allouée, elle est pour l'instant pleine
|
||||
// de 0s. Elle fait Main_image_width de large.
|
||||
// Normalement tout va bien, tout est sous contrôle...
|
||||
|
||||
// Load into layer 0, by default.
|
||||
Main_current_layer=0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -3024,11 +3027,6 @@ void Load_GIF(void)
|
||||
/////////////////////////////////////////////////// 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;
|
||||
|
||||
Get_full_filename(filename,0);
|
||||
@ -3063,11 +3061,6 @@ void Load_GIF(void)
|
||||
// Nombre de bits/pixel = (LSDB.Resol and $07)+1
|
||||
// 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));
|
||||
initial_nb_bits=(LSDB.Resol & 0x07)+2;
|
||||
|
||||
@ -3150,8 +3143,7 @@ void Load_GIF(void)
|
||||
// Si on a deja lu une image, c'est une GIF animée ou bizarroide, on sort.
|
||||
if (number_LID!=0)
|
||||
{
|
||||
File_error=2;
|
||||
break;
|
||||
Main_current_layer++;
|
||||
}
|
||||
number_LID++;
|
||||
|
||||
@ -3167,6 +3159,7 @@ void Load_GIF(void)
|
||||
Main_image_width=IDB.Image_width;
|
||||
Main_image_height=IDB.Image_height;
|
||||
|
||||
if (number_LID==1)
|
||||
Init_preview(IDB.Image_width,IDB.Image_height,file_size,FORMAT_GIF,PIXEL_SIMPLE);
|
||||
|
||||
// Palette locale dispo = (IDB.Indicator and $80)
|
||||
@ -3219,6 +3212,13 @@ void Load_GIF(void)
|
||||
|
||||
//////////////////////////////////////////// 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) )
|
||||
{
|
||||
if (GIF_current_code<=alphabet_free)
|
||||
@ -3404,15 +3404,14 @@ void Save_GIF(void)
|
||||
byte current_char; // Caractère à coder
|
||||
word index; // index de recherche de chaîne
|
||||
|
||||
byte old_current_layer=Main_current_layer;
|
||||
|
||||
/////////////////////////////////////////////////// FIN DES DECLARATIONS //
|
||||
|
||||
if (Read_pixel_function==Read_pixel_from_current_screen)
|
||||
Read_pixel_function=Read_pixel_from_current_layer;
|
||||
|
||||
GIF_pos_X=0;
|
||||
GIF_pos_Y=0;
|
||||
GIF_last_byte=0;
|
||||
GIF_remainder_bits=0;
|
||||
GIF_remainder_byte=0;
|
||||
File_error=0;
|
||||
|
||||
Get_full_filename(filename,0);
|
||||
|
||||
@ -3446,12 +3445,11 @@ void Save_GIF(void)
|
||||
|
||||
// On sauve le LSDB dans le fichier
|
||||
|
||||
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
||||
LSDB.Width = SDL_Swap16(LSDB.Width);
|
||||
LSDB.Height = SDL_Swap16(LSDB.Height);
|
||||
#endif
|
||||
|
||||
if (Write_bytes(GIF_file,&LSDB,sizeof(T_GIF_LSDB)))
|
||||
if (Write_word_le(GIF_file,LSDB.Width) &&
|
||||
Write_word_le(GIF_file,LSDB.Height) &&
|
||||
Write_byte(GIF_file,LSDB.Resol) &&
|
||||
Write_byte(GIF_file,LSDB.Backcol) &&
|
||||
Write_byte(GIF_file,LSDB.Aspect) )
|
||||
{
|
||||
// Le LSDB a été correctement écrit.
|
||||
|
||||
@ -3466,6 +3464,11 @@ void Save_GIF(void)
|
||||
// Ecriture de la transparence
|
||||
//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
|
||||
if (Main_comment[0])
|
||||
{
|
||||
@ -3474,10 +3477,25 @@ void Save_GIF(void)
|
||||
Write_bytes(GIF_file,Main_comment,strlen(Main_comment)+1);
|
||||
}
|
||||
|
||||
|
||||
// Loop on all layers
|
||||
for (Main_current_layer=0;
|
||||
Main_current_layer < Main_backups->Pages->Nb_layers && !File_error;
|
||||
Main_current_layer++)
|
||||
{
|
||||
// Write a Graphic Control Extension
|
||||
char * GCE_block = "\x21\xF9\x04\x05\x05\x00\x00\x00";
|
||||
//if (Main_current_layer > 0)
|
||||
// GCE_block[3] = '\x05';
|
||||
if (Main_current_layer == Main_backups->Pages->Nb_layers -1)
|
||||
{
|
||||
// "Infinite" delay for last frame
|
||||
GCE_block[4] = 255;
|
||||
GCE_block[5] = 255;
|
||||
}
|
||||
if (Write_bytes(GIF_file,GCE_block,8))
|
||||
{
|
||||
|
||||
// On va écrire un block indicateur d'IDB et l'IDB du fichier
|
||||
|
||||
block_indentifier=0x2C;
|
||||
IDB.Pos_X=0;
|
||||
IDB.Pos_Y=0;
|
||||
@ -3486,18 +3504,23 @@ void Save_GIF(void)
|
||||
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)) )
|
||||
if ( Write_byte(GIF_file,block_indentifier) &&
|
||||
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))
|
||||
{
|
||||
// Le block indicateur d'IDB et l'IDB ont étés correctements
|
||||
// écrits.
|
||||
|
||||
Init_write_buffer();
|
||||
GIF_pos_X=0;
|
||||
GIF_pos_Y=0;
|
||||
GIF_last_byte=0;
|
||||
GIF_remainder_bits=0;
|
||||
GIF_remainder_byte=0;
|
||||
|
||||
index=4096;
|
||||
File_error=0;
|
||||
@ -3637,16 +3660,24 @@ void Save_GIF(void)
|
||||
// On écrit un \0
|
||||
if (! Write_byte(GIF_file,'\x00'))
|
||||
File_error=1;
|
||||
// On écrit un GIF TERMINATOR, exigé par SVGA et SEA.
|
||||
if (! Write_byte(GIF_file,'\x3B'))
|
||||
File_error=1;
|
||||
|
||||
|
||||
}
|
||||
|
||||
} // On a pu écrire l'IDB
|
||||
else
|
||||
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
|
||||
else
|
||||
@ -3673,6 +3704,9 @@ void Save_GIF(void)
|
||||
} // On a pu ouvrir le fichier en écriture
|
||||
else
|
||||
File_error=1;
|
||||
|
||||
// Restore original layer
|
||||
Main_current_layer = old_current_layer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -4032,6 +4032,10 @@ void Scroll_0_5(void)
|
||||
// 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
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user