diff --git a/src/filesel.c b/src/filesel.c index 459af1b4..53352035 100644 --- a/src/filesel.c +++ b/src/filesel.c @@ -1226,6 +1226,7 @@ byte Button_Load_or_Save(byte load, T_IO_Context *context) T_Dropdown_button * formats_dropdown; T_Dropdown_button * bookmark_dropdown[4]; short temp; + unsigned int format; int dummy=0; // Sert à appeler SDL_GetKeyState byte save_or_load_image=0; byte has_clicked_ok=0;// Indique si on a clické sur Load ou Save ou sur @@ -1304,11 +1305,11 @@ byte Button_Load_or_Save(byte load, T_IO_Context *context) Get_fileformat(Main_format)->Label, 1,0,1,RIGHT_SIDE|LEFT_SIDE,0); // 6 - for (temp=0; temp < NB_KNOWN_FORMATS; temp++) + for (format=0; format < Nb_known_formats(); format++) { - if ((load && (File_formats[temp].Identifier <= FORMAT_ALL_FILES || File_formats[temp].Load)) || - (!load && File_formats[temp].Save)) - Window_dropdown_add_item(formats_dropdown,File_formats[temp].Identifier,File_formats[temp].Label); + if ((load && (File_formats[format].Identifier <= FORMAT_ALL_FILES || File_formats[format].Load)) || + (!load && File_formats[format].Save)) + Window_dropdown_add_item(formats_dropdown,File_formats[format].Identifier,File_formats[format].Label); } Print_in_window(70,18,"Format",MC_Dark,MC_Light); diff --git a/src/loadsave.c b/src/loadsave.c index 2c53f7c2..264dca00 100644 --- a/src/loadsave.c +++ b/src/loadsave.c @@ -139,7 +139,7 @@ void Save_PNG(T_IO_Context *); void Load_SDL_Image(T_IO_Context *); // ENUM Name TestFunc LoadFunc SaveFunc PalOnly Comment Layers Ext Exts -T_Format File_formats[NB_KNOWN_FORMATS] = { +T_Format File_formats[] = { {FORMAT_ALL_IMAGES, "(all)", NULL, NULL, NULL, 0, 0, 0, "", "gif;png;bmp;pcx;pkm;lbm;ilbm;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, 0, 1, 1, "gif", "gif"}, @@ -164,6 +164,12 @@ T_Format File_formats[NB_KNOWN_FORMATS] = { {FORMAT_MISC,"misc.",NULL, NULL, NULL, 0, 0, 0, "", "tga;pnm;xpm;xcf;jpg;jpeg;tif;tiff;ico"}, }; +/// Total number of known file formats +unsigned int Nb_known_formats(void) +{ + return sizeof(File_formats)/sizeof(File_formats[0]); +} + /// Set the color of a pixel (on load) void Set_pixel(T_IO_Context *context, short x_pos, short y_pos, byte color) { @@ -567,7 +573,7 @@ void Load_image(T_IO_Context *context) { // Sinon, on va devoir scanner les différents formats qu'on connait pour // savoir à quel format est le fichier: - for (index=0; index < NB_KNOWN_FORMATS; index++) + for (index=0; index < Nb_known_formats(); index++) { format = Get_fileformat(index); // Loadable format @@ -1089,7 +1095,7 @@ T_Format * Get_fileformat(byte format) unsigned int i; T_Format * safe_default = File_formats; - for (i=0; i < NB_KNOWN_FORMATS; i++) + for (i=0; i < Nb_known_formats(); i++) { if (File_formats[i].Identifier == format) return &(File_formats[i]); diff --git a/src/loadsave.h b/src/loadsave.h index 70fe2758..0266e16c 100644 --- a/src/loadsave.h +++ b/src/loadsave.h @@ -194,12 +194,8 @@ T_Format * Get_fileformat(byte format); // -- File formats -#ifndef __no_pnglib__ -#define NB_KNOWN_FORMATS 19 ///< Total number of known file formats. -#else -// Without pnglib -#define NB_KNOWN_FORMATS 18 ///< Total number of known file formats. -#endif +/// Total number of known file formats +unsigned int Nb_known_formats(void); // Internal use