Fix on loading all formats 'misc': Marking some formats 'Backup_done=0' didn't work because this flag was specialized for importing and exporting palettes (a modification of the image), without updating the image on screen or remembering the file name.

git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1183 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
Yves Rizoud 2009-11-14 17:16:46 +00:00
parent 17d3e62398
commit 33ef5cfde2
4 changed files with 63 additions and 58 deletions

View File

@ -2619,7 +2619,7 @@ void Load_picture(byte image)
{
// Si c'est une image qu'on charge, on efface l'ancien commentaire
// C'est loin d'ętre indispensable, m'enfin bon...
if (Get_fileformat(Main_fileformat)->Backup_done)
if (! Get_fileformat(Main_fileformat)->Palette_only)
Main_comment[0]='\0';
Original_screen_X=0;
@ -2683,7 +2683,7 @@ void Load_picture(byte image)
Cursor_shape=old_cursor_shape;
}
if ( (File_error==1) || (!Get_fileformat(Main_fileformat)->Backup_done) )
if ( (File_error==1) || (Get_fileformat(Main_fileformat)->Palette_only) )
{
do_not_restore=0;
if (File_error!=1)
@ -2953,7 +2953,7 @@ void Save_picture(byte image)
Hide_cursor();
Cursor_shape=old_cursor_shape;
if ((File_error==1) || (!Get_fileformat(Main_fileformat)->Backup_done))
if ((File_error==1) || (Get_fileformat(Main_fileformat)->Palette_only))
do_not_restore=0;
Display_cursor();

View File

@ -132,29 +132,29 @@ void Save_PNG(void);
// (TGA, BMP, PNM, XPM, XCF, PCX, GIF, JPG, TIF, LBM, PNG, ICO)
void Load_SDL_Image(void);
// ENUM Name TestFunc LoadFunc SaveFunc Backup Comment Layers Ext Exts
// ENUM Name TestFunc LoadFunc SaveFunc PalOnly Comment Layers Ext Exts
T_Format File_formats[NB_KNOWN_FORMATS] = {
{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, 0, "", "*"},
{FORMAT_GIF, " gif", Test_GIF, Load_GIF, Save_GIF, 1, 1, 1, "gif", "gif"},
{FORMAT_GIF, " gif", Test_GIF, Load_GIF, Save_GIF, 0, 1, 1, "gif", "gif"},
#ifndef __no_pnglib__
{FORMAT_PNG, " png", Test_PNG, Load_PNG, Save_PNG, 1, 1, 0, "png", "png"},
{FORMAT_PNG, " png", Test_PNG, Load_PNG, Save_PNG, 0, 1, 0, "png", "png"},
#endif
{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, 0, "pcx", "pcx"},
{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, 0, "lbm", "lbm;iff"},
{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, 0, "sc?", "sci;scq;scf;scn;sco"},
{FORMAT_BMP, " bmp", Test_BMP, Load_BMP, Save_BMP, 0, 0, 0, "bmp", "bmp"},
{FORMAT_PCX, " pcx", Test_PCX, Load_PCX, Save_PCX, 0, 0, 0, "pcx", "pcx"},
{FORMAT_PKM, " pkm", Test_PKM, Load_PKM, Save_PKM, 0, 1, 0, "pkm", "pkm"},
{FORMAT_LBM, " lbm", Test_LBM, Load_LBM, Save_LBM, 0, 0, 0, "lbm", "lbm;iff"},
{FORMAT_IMG, " img", Test_IMG, Load_IMG, Save_IMG, 0, 0, 0, "img", "img"},
{FORMAT_SCx, " sc?", Test_SCx, Load_SCx, Save_SCx, 0, 0, 0, "sc?", "sci;scq;scf;scn;sco"},
{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, 0, "pc1", "pc1"},
{FORMAT_CEL, " cel", Test_CEL, Load_CEL, Save_CEL, 1, 0, 0, "cel", "cel"},
{FORMAT_CEL, " cel", Test_CEL, Load_CEL, Save_CEL, 0, 0, 0, "cel", "cel"},
{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, 0, "kcf", "kcf"},
{FORMAT_PAL, " pal", Test_PAL, Load_PAL, Save_PAL, 0, 0, 0, "pal", "pal"},
{FORMAT_KCF, " kcf", Test_KCF, Load_KCF, Save_KCF, 1, 0, 0, "kcf", "kcf"},
{FORMAT_PAL, " pal", Test_PAL, Load_PAL, Save_PAL, 1, 0, 0, "pal", "pal"},
{FORMAT_C64, " c64", Test_C64, Load_C64, Save_C64, 0, 1, 0, "c64", "c64;koa"},
{FORMAT_SCR, " cpc", NULL, NULL, Save_SCR, 0, 0, 0, "cpc", "cpc;scr"},
{FORMAT_MISC,"misc.",NULL, NULL, NULL, 1, 0, 0, "", "tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico"},
{FORMAT_MISC,"misc.",NULL, NULL, NULL, 0, 0, 0, "", "tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico"},
};
// Cette variable est alimentée après chargement réussi d'une image.
@ -703,7 +703,7 @@ void Load_image(byte image)
if (image)
{
if ( (File_error!=1) && (format->Backup_done) )
if ( (File_error!=1) && (!format->Palette_only) )
{
if (Pixel_load_function==Pixel_load_in_preview)
{
@ -783,7 +783,7 @@ void Save_image(byte image)
Error(0);
else
{
if ((image) && (Get_fileformat(Main_fileformat)->Backup_done))
if ((image) && !(Get_fileformat(Main_fileformat)->Palette_only))
Main_image_is_modified=0;
}
}

View File

@ -48,9 +48,9 @@ typedef struct {
Func_action Test; ///< Function which tests if the file is of this format
Func_action Load; ///< Function which loads 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 Palette_only; ///< Boolean, true if this format saves/loads only the palette.
byte Comment; ///< This file format allows a text comment
byte Supports_layers; ///< Boolean, true if this format preserves layers on saving
byte Supports_layers; ///< Boolean, true if this format preserves layers on saving
char *Default_extension; ///< Default file extension
char *Extensions; ///< List of semicolon-separated file extensions
} T_Format;

View File

@ -191,22 +191,20 @@ void Save_PAL(void)
//////////////////////////////////// PKM ////////////////////////////////////
#pragma pack(1)
typedef struct
{
char Ident[3]; // Chaîne "PKM" }
byte Method; // Compression method
// 0 = compression en ligne (c)KM
// autres = inconnues pour le moment
byte recog1; // Octet de reconnaissance sur 1 octet }
byte recog2; // Octet de reconnaissance sur 2 octets }
word Width; // width de l'image
word Height; // height de l'image
T_Palette Palette; // Palette RVB 256*3
word Jump; // Taille du saut entre le header et l'image:
// On va s'en servir pour rajouter un commentaire
char Ident[3]; // String "PKM" }
byte Method; // Compression method
// 0 = per-line compression (c)KM
// others = unknown at the moment
byte Recog1; // Recognition byte 1
byte Recog2; // Recognition byte 2
word Width; // Image width
word Height; // Image height
T_Palette Palette;// RGB Palette 256*3, on a 1-64 scale for each component
word Jump; // Size of the jump between header and image:
// Used to insert a comment
} T_PKM_Header;
#pragma pack()
// -- Tester si un fichier est au format PKM --------------------------------
void Test_PKM(void)
@ -224,7 +222,14 @@ void Test_PKM(void)
if ((file=fopen(filename, "rb")))
{
// Lecture du header du fichier
if (Read_bytes(file,&header,sizeof(T_PKM_Header)))
if (Read_bytes(file,&header.Ident,3) &&
Read_byte(file,&header.Method) &&
Read_byte(file,&header.Recog1) &&
Read_byte(file,&header.Recog2) &&
Read_word_le(file,&header.Width) &&
Read_word_le(file,&header.Height) &&
Read_bytes(file,&header.Palette,sizeof(T_Palette)) &&
Read_word_le(file,&header.Jump))
{
// On regarde s'il y a la signature PKM suivie de la méthode 0.
// La constante "PKM" étant un chaîne, elle se termine toujours par 0.
@ -261,15 +266,15 @@ void Load_PKM(void)
{
file_size=File_length_file(file);
if (Read_bytes(file,&header,sizeof(T_PKM_Header)))
if (Read_bytes(file,&header.Ident,3) &&
Read_byte(file,&header.Method) &&
Read_byte(file,&header.Recog1) &&
Read_byte(file,&header.Recog2) &&
Read_word_le(file,&header.Width) &&
Read_word_le(file,&header.Height) &&
Read_bytes(file,&header.Palette,sizeof(T_Palette)) &&
Read_word_le(file,&header.Jump))
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
header.Width = SDL_Swap16(header.Width);
header.Height = SDL_Swap16(header.Height);
header.Jump = SDL_Swap16(header.Jump);
#endif
Main_comment[0]='\0'; // On efface le commentaire
if (header.Jump)
{
@ -390,7 +395,7 @@ void Load_PKM(void)
}
// Si ce n'est pas un octet de reconnaissance, c'est un pixel brut
if ( (temp_byte!=header.recog1) && (temp_byte!=header.recog2) )
if ( (temp_byte!=header.Recog1) && (temp_byte!=header.Recog2) )
{
Pixel_load_function(Compteur_de_pixels % Main_image_width,
Compteur_de_pixels / Main_image_width,
@ -400,7 +405,7 @@ void Load_PKM(void)
}
else // Sinon, On regarde si on va décompacter un...
{ // ... nombre de pixels tenant sur un byte
if (temp_byte==header.recog1)
if (temp_byte==header.Recog1)
{
if(Read_byte(file, &color)!=1)
{
@ -507,7 +512,7 @@ void Save_PKM(void)
// Construction du header
memcpy(header.Ident,"PKM",3);
header.Method=0;
Find_recog(&header.recog1,&header.recog2);
Find_recog(&header.Recog1,&header.Recog2);
header.Width=Main_image_width;
header.Height=Main_image_height;
memcpy(header.Palette,Main_palette,sizeof(T_Palette));
@ -527,15 +532,15 @@ void Save_PKM(void)
// Ouverture du fichier
if ((file=fopen(filename,"wb")))
{
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
header.Width = SDL_Swap16(header.Width);
header.Height = SDL_Swap16(header.Height);
header.Jump = SDL_Swap16(header.Jump);
#endif
// Ecriture du header
if (Write_bytes(file,&header,sizeof(T_PKM_Header)))
if (Write_bytes(file,&header.Ident,3) &&
Write_byte(file,header.Method) &&
Write_byte(file,header.Recog1) &&
Write_byte(file,header.Recog2) &&
Write_word_le(file,header.Width) &&
Write_word_le(file,header.Height) &&
Write_bytes(file,&header.Palette,sizeof(T_Palette)) &&
Write_word_le(file,header.Jump))
{
Init_write_buffer();
@ -584,7 +589,7 @@ void Save_PKM(void)
pixel_value=Read_pixel_function(Compteur_de_pixels % Main_image_width,Compteur_de_pixels / Main_image_width);
}
if ( (last_color!=header.recog1) && (last_color!=header.recog2) )
if ( (last_color!=header.Recog1) && (last_color!=header.Recog2) )
{
if (repetitions==1)
Write_one_byte(file,last_color);
@ -597,14 +602,14 @@ void Save_PKM(void)
else
if ( (repetitions>2) && (repetitions<256) )
{ // RECON1/couleur/nombre
Write_one_byte(file,header.recog1);
Write_one_byte(file,header.Recog1);
Write_one_byte(file,last_color);
Write_one_byte(file,repetitions&0xFF);
}
else
if (repetitions>=256)
{ // RECON2/couleur/hi(nombre)/lo(nombre)
Write_one_byte(file,header.recog2);
Write_one_byte(file,header.Recog2);
Write_one_byte(file,last_color);
Write_one_byte(file,repetitions>>8);
Write_one_byte(file,repetitions&0xFF);
@ -614,13 +619,13 @@ void Save_PKM(void)
{
if (repetitions<256)
{
Write_one_byte(file,header.recog1);
Write_one_byte(file,header.Recog1);
Write_one_byte(file,last_color);
Write_one_byte(file,repetitions&0xFF);
}
else
{
Write_one_byte(file,header.recog2);
Write_one_byte(file,header.Recog2);
Write_one_byte(file,last_color);
Write_one_byte(file,repetitions>>8);
Write_one_byte(file,repetitions&0xFF);