diff --git a/boutons.c b/boutons.c index 8e4de8ef..c6f7a19a 100644 --- a/boutons.c +++ b/boutons.c @@ -2291,7 +2291,7 @@ void Print_Format(void) if (Principal_Format==0) Print_dans_fenetre(83,65,"*.*",CM_Noir,CM_Clair); else - Print_dans_fenetre(83,65,Format_Extension[Principal_Format-1],CM_Noir,CM_Clair); + Print_dans_fenetre(83,65,FormatFichier[Principal_Format-1].Extension,CM_Noir,CM_Clair); } @@ -2486,7 +2486,7 @@ byte Bouton_Load_ou_Save(byte Load, byte Image) Principal_File_list_Decalage=0; } // Affichage du commentaire - if (Format_Commentaire[Principal_Format-1]) + if (FormatFichier[Principal_Format-1].Commentaire) Print_dans_fenetre(46,175+FILENAMESPACE,Principal_Commentaire,CM_Noir,CM_Clair); } @@ -2752,7 +2752,7 @@ byte Bouton_Load_ou_Save(byte Load, byte Image) Nouvelle_preview=1; break; case 7 : // Saisie d'un commentaire pour la sauvegarde - if ( (!Load) && (Format_Commentaire[Principal_Format-1]) ) + if ( (!Load) && (FormatFichier[Principal_Format-1].Commentaire) ) { Effacer_curseur(); Readline(46,175+FILENAMESPACE,Principal_Commentaire,32,0); @@ -2779,7 +2779,7 @@ byte Bouton_Load_ou_Save(byte Load, byte Image) if(!Repertoire_existe(Principal_Nom_fichier)) { strcat(Principal_Nom_fichier,"."); - strcat(Principal_Nom_fichier,Format_Extension[Principal_Format-1]); + strcat(Principal_Nom_fichier,FormatFichier[Principal_Format-1].Extension); } } else @@ -3005,7 +3005,7 @@ byte Bouton_Load_ou_Save(byte Load, byte Image) Block(Fenetre_Pos_X+226*Menu_Facteur_X,Fenetre_Pos_Y+ 72*Menu_Facteur_Y, Menu_Facteur_X*72,Menu_Facteur_Y<<3,CM_Clair); // Affichage du commentaire - if ( (!Load) && (Format_Commentaire[Principal_Format-1]) ) + if ( (!Load) && (FormatFichier[Principal_Format-1].Commentaire) ) { Print_dans_fenetre(46,175+FILENAMESPACE,Principal_Commentaire,CM_Noir,CM_Clair); } @@ -3247,7 +3247,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 (Format_Backup_done[Principal_Format_fichier-1]) + if (FormatFichier[Principal_Format_fichier-1].Backup_done) Principal_Commentaire[0]='\0'; Ecran_original_X=0; @@ -3311,7 +3311,7 @@ void Load_picture(byte Image) Forme_curseur=Ancienne_forme_curseur; } - if ( (Erreur_fichier==1) || (!Format_Backup_done[Principal_Format_fichier-1]) ) + if ( (Erreur_fichier==1) || (!FormatFichier[Principal_Format_fichier-1].Backup_done) ) { Ne_pas_restaurer=0; if (Erreur_fichier!=1) @@ -3550,7 +3550,7 @@ void Save_picture(byte Image) Effacer_curseur(); Forme_curseur=Ancienne_forme_curseur; - if ((Erreur_fichier==1) || (!Format_Backup_done[Principal_Format_fichier-1])) + if ((Erreur_fichier==1) || (!FormatFichier[Principal_Format_fichier-1].Backup_done)) Ne_pas_restaurer=0; Afficher_curseur(); diff --git a/divers.c b/divers.c index 91c725e5..ddff1e20 100644 --- a/divers.c +++ b/divers.c @@ -382,28 +382,6 @@ byte Lit_pixel_dans_ecran_backup (word X,word Y) return *(Ecran_backup + X + Principal_Largeur_image * Y); } -// Les images ILBM sont stockés en bitplanes donc on doit trifouiller les bits pour -// en faire du chunky - -byte Couleur_ILBM_line(word Pos_X, word Vraie_taille_ligne, byte HBPm1) -{ - // CL sera le rang auquel on extrait les bits de la couleur - byte cl = 7 - (Pos_X & 7); - int ax,bh,dx; - byte bl=0; - - for(dx=HBPm1;dx>=0;dx--) - { - //CIL_Loop - ax = (Vraie_taille_ligne * dx + Pos_X) >> 3; - bh = (LBM_Buffer[ax] >> cl) & 1; - - bl = (bl << 1) + bh; - } - - return bl; -} - void Palette_256_to_64(T_Palette Palette) { int i; diff --git a/divers.h b/divers.h index c64a3100..9b93b11a 100644 --- a/divers.h +++ b/divers.h @@ -74,9 +74,6 @@ byte Pixel_dans_cercle(void); byte Bit(byte Octet, byte Rang); // Extrait un bit d'un certain rang à partir d'un octet. -byte Couleur_ILBM_line(word Pos_X, word Vraie_taille_ligne, byte HBPm1); -// Renvoie la couleur du pixel (ILBM) en Pos_X. - // Gestion du chrono dans les fileselects void Initialiser_chrono(dword Delai); void Tester_chrono(void); diff --git a/files.c b/files.c index b3c13311..1cd7b344 100644 --- a/files.c +++ b/files.c @@ -53,6 +53,7 @@ #include "erreurs.h" #include "io.h" #include "windows.h" +#include "loadsave.h" #define COULEUR_FICHIER_NORMAL CM_Clair // Couleur du texte pour une ligne de fichier non sélectionné #define COULEUR_REPERTOIRE_NORMAL CM_Fonce // Couleur du texte pour une ligne de répertoire non sélectionné @@ -217,7 +218,7 @@ void Lire_liste_des_fichiers(byte Format_demande) // Tout d'abord, on déduit du format demandé un filtre à utiliser: if (Format_demande) // Format (extension) spécifique - Filtre = Format_Extension[Format_demande-1]; + Filtre = FormatFichier[Format_demande-1].Extension; // Ensuite, on vide la liste actuelle: Detruire_liste_du_fileselect(); diff --git a/global.h b/global.h index a221c498..f1aea41a 100644 --- a/global.h +++ b/global.h @@ -657,126 +657,8 @@ GFX2_GLOBAL struct Element_de_liste_de_fileselect * Liste_du_fileselect; // ------------------- Inititialisation des formats connus ------------------- -#include "loadsave.h" void Rien_du_tout(void); -#ifdef VARIABLES_GLOBALES - // Extension du format - char Format_Extension[NB_FORMATS_CONNUS][4]= - { - "pkm", // PKM - "lbm", // LBM - "gif", // GIF - "bmp", // BMP - "pcx", // PCX - "img", // IMG - "sc?", // SCx - "pi1", // PI1 - "pc1", // PC1 - "cel", // CEL - "kcf", // KCF - "pal", // PAL - "png", // PNG - }; - - // Fonction à appeler pour vérifier la signature du fichier - fonction_action Format_Test[NB_FORMATS_LOAD]= - { - Test_PKM, // PKM - Test_LBM, // LBM - Test_GIF, // GIF - Test_BMP, // BMP - Test_PCX, // PCX - Test_IMG, // IMG - Test_SCx, // SCx - Test_PI1, // PI1 - Test_PC1, // PC1 - Test_CEL, // CEL - Test_KCF, // KCF - Test_PAL, // PAL - Test_PNG // PNG - }; - - // Fonction à appeler pour charger l'image - fonction_action Format_Load[NB_FORMATS_LOAD]= - { - Load_PKM, // PKM - Load_LBM, // LBM - Load_GIF, // GIF - Load_BMP, // BMP - Load_PCX, // PCX - Load_IMG, // IMG - Load_SCx, // SCx - Load_PI1, // PI1 - Load_PC1, // PC1 - Load_CEL, // CEL - Load_KCF, // KCF - Load_PAL, // PAL - Load_PNG // PNG - }; - - // Fonction à appeler pour sauvegarder l'image - fonction_action Format_Save[NB_FORMATS_SAVE]= - { - Save_PKM, // PKM - Save_LBM, // LBM - Save_GIF, // GIF - Save_BMP, // BMP - Save_PCX, // PCX - Save_IMG, // IMG - Save_SCx, // SCx - Save_PI1, // PI1 - Save_PC1, // PC1 - Save_CEL, // CEL - Save_KCF, // KCF - Save_PAL, // PAL - Save_PNG // PNG - }; - - // indique si l'on doit considérer que l'image n'est plus modifiée - byte Format_Backup_done[NB_FORMATS_CONNUS]= - { - 1, // PKM - 1, // LBM - 1, // GIF - 1, // BMP - 1, // PCX - 1, // IMG - 1, // SCx - 1, // PI1 - 1, // PC1 - 1, // CEL - 0, // KCF - 0, // PAL - 1 // PNG - }; - - // Le format de fichier autorise un commentaire - byte Format_Commentaire[NB_FORMATS_CONNUS]= - { - 1, // PKM - 0, // LBM - 0, // GIF - 0, // BMP - 0, // PCX - 0, // IMG - 0, // SCx - 0, // PI1 - 0, // PC1 - 0, // CEL - 0, // KCF - 0, // PAL - 0 // PNG - }; -#else - extern char Format_Extension[NB_FORMATS_CONNUS][4]; - extern fonction_action Format_Load[NB_FORMATS_LOAD]; - extern fonction_action Format_Save[NB_FORMATS_SAVE]; - extern fonction_action Format_Test[NB_FORMATS_LOAD]; - extern byte Format_Backup_done[NB_FORMATS_CONNUS]; - extern byte Format_Commentaire[NB_FORMATS_CONNUS]; -#endif - GFX2_GLOBAL signed char Erreur_fichier; // 0: opération I/O OK // 1: Erreur dès le début de l'opération // 2: Erreur durant l'opération => données modifiées diff --git a/loadsave.c b/loadsave.c index a3ee7c44..7aa762b6 100644 --- a/loadsave.c +++ b/loadsave.c @@ -43,9 +43,91 @@ #include "io.h" #include "sdlscreen.h" #include "windows.h" +#include "loadsave.h" #define FILENAMESPACE 13 +// -- PKM ------------------------------------------------------------------- +void Test_PKM(void); +void Load_PKM(void); +void Save_PKM(void); + +// -- LBM ------------------------------------------------------------------- +void Test_LBM(void); +void Load_LBM(void); +void Save_LBM(void); + +// -- GIF ------------------------------------------------------------------- +void Test_GIF(void); +void Load_GIF(void); +void Save_GIF(void); + +// -- PCX ------------------------------------------------------------------- +void Test_PCX(void); +void Load_PCX(void); +void Save_PCX(void); + +// -- BMP ------------------------------------------------------------------- +void Test_BMP(void); +void Load_BMP(void); +void Save_BMP(void); + +// -- IMG ------------------------------------------------------------------- +void Test_IMG(void); +void Load_IMG(void); +void Save_IMG(void); + +// -- SCx ------------------------------------------------------------------- +void Test_SCx(void); +void Load_SCx(void); +void Save_SCx(void); + +// -- CEL ------------------------------------------------------------------- +void Test_CEL(void); +void Load_CEL(void); +void Save_CEL(void); + +// -- KCF ------------------------------------------------------------------- +void Test_KCF(void); +void Load_KCF(void); +void Save_KCF(void); + +// -- PAL ------------------------------------------------------------------- +void Test_PAL(void); +void Load_PAL(void); +void Save_PAL(void); + +// -- PI1 ------------------------------------------------------------------- +void Test_PI1(void); +void Load_PI1(void); +void Save_PI1(void); + +// -- PC1 ------------------------------------------------------------------- +void Test_PC1(void); +void Load_PC1(void); +void Save_PC1(void); + +// -- PNG ------------------------------------------------------------------- +void Test_PNG(void); +void Load_PNG(void); +void Save_PNG(void); + +T_Format FormatFichier[NB_FORMATS_CONNUS] = { + {"pkm", Test_PKM, Load_PKM, Save_PKM, 1, 1}, + {"lbm", Test_LBM, Load_LBM, Save_LBM, 1, 0}, + {"gif", Test_GIF, Load_GIF, Save_GIF, 1, 0}, + {"bmp", Test_BMP, Load_BMP, Save_BMP, 1, 0}, + {"pcx", Test_PCX, Load_PCX, Save_PCX, 1, 0}, + {"img", Test_IMG, Load_IMG, Save_IMG, 1, 0}, + {"sc?", Test_SCx, Load_SCx, Save_SCx, 1, 0}, + {"pi1", Test_PI1, Load_PI1, Save_PI1, 1, 0}, + {"pc1", Test_PC1, Load_PC1, Save_PC1, 1, 0}, + {"cel", Test_CEL, Load_CEL, Save_CEL, 1, 0}, + {"kcf", Test_KCF, Load_KCF, Save_KCF, 0, 0}, + {"pal", Test_PAL, Load_PAL, Save_PAL, 0, 0}, + {"png", Test_PNG, Load_PNG, Save_PNG, 1, 0} +}; + // Taille de fichier, en octets int FileLength(FILE * Fichier) { @@ -254,14 +336,14 @@ void Initialiser_preview(short Largeur,short Hauteur,long Taille,int Format) // Affichage du vrai format if (Format!=Principal_Format) { - Print_dans_fenetre( 274,72,Format_Extension[Format-1],CM_Noir,CM_Clair); + Print_dans_fenetre( 274,72,FormatFichier[Format-1].Extension,CM_Noir,CM_Clair); } // On efface le commentaire précédent Block(Fenetre_Pos_X+46*Menu_Facteur_X,Fenetre_Pos_Y+(175+FILENAMESPACE)*Menu_Facteur_Y, Menu_Facteur_X<<8,Menu_Facteur_Y<<3,CM_Clair); // Affichage du commentaire - if (Format_Commentaire[Format-1]) + if (FormatFichier[Format-1].Commentaire) Print_dans_fenetre(46,175+FILENAMESPACE,Principal_Commentaire,CM_Noir,CM_Clair); // Calculs des données nécessaires à l'affichage de la preview: @@ -462,7 +544,7 @@ void Charger_image(byte Image) if (Principal_Format!=0) { - Format_Test[Principal_Format-1](); + FormatFichier[Principal_Format-1].Test(); if (!Erreur_fichier) // Si dans le sélecteur il y a un format valide on le prend tout de suite Format=Principal_Format-1; @@ -475,7 +557,7 @@ void Charger_image(byte Image) for (Indice=0;Indice0) { @@ -528,7 +610,7 @@ void Charger_image(byte Image) if (Image) { - if ( (Erreur_fichier!=1) && (Format_Backup_done[Format]) ) + if ( (Erreur_fichier!=1) && (FormatFichier[Format].Backup_done) ) { // On considère que l'image chargée n'est plus modifiée Principal_Image_modifiee=0; @@ -574,13 +656,13 @@ void Sauver_image(byte Image) Lit_pixel_de_sauvegarde=(Image)?Lit_pixel_dans_ecran_courant:Lit_pixel_dans_brosse; - Format_Save[Principal_Format_fichier-1](); + FormatFichier[Principal_Format_fichier-1].Save(); if (Erreur_fichier) Erreur(0); else { - if ((Image) && (Format_Backup_done[Principal_Format_fichier-1])) + if ((Image) && (FormatFichier[Principal_Format_fichier-1].Backup_done)) Principal_Image_modifiee=0; } } @@ -1338,9 +1420,10 @@ typedef struct word Yscreen; } __attribute__((__packed__)) T_Header_LBM; -// -- Tester si un fichier est au format LBM -------------------------------- +byte * LBM_Buffer; +FILE *LBM_Fichier; - FILE *LBM_Fichier; +// -- Tester si un fichier est au format LBM -------------------------------- void Test_LBM(void) { @@ -1512,6 +1595,29 @@ void Test_LBM(void) return 1; } +// Les images ILBM sont stockés en bitplanes donc on doit trifouiller les bits pour +// en faire du chunky + +byte Couleur_ILBM_line(word Pos_X, word Vraie_taille_ligne, byte HBPm1) +{ + // Renvoie la couleur du pixel (ILBM) en Pos_X. + // CL sera le rang auquel on extrait les bits de la couleur + byte cl = 7 - (Pos_X & 7); + int ax,bh,dx; + byte bl=0; + + for(dx=HBPm1;dx>=0;dx--) + { + //CIL_Loop + ax = (Vraie_taille_ligne * dx + Pos_X) >> 3; + bh = (LBM_Buffer[ax] >> cl) & 1; + + bl = (bl << 1) + bh; + } + + return bl; +} + // ----------------------- Afficher une ligne ILBM ------------------------ void Draw_ILBM_line(short Pos_Y, short Vraie_taille_ligne) { @@ -5462,7 +5568,7 @@ void Load_PNG(void) Principal_Palette[x].V=palette[x].green; Principal_Palette[x].B=palette[x].blue; } - //free(palette); + free(palette); } Set_palette(Principal_Palette); Remapper_fileselect(); diff --git a/loadsave.h b/loadsave.h index 8792eabe..853b0dea 100644 --- a/loadsave.h +++ b/loadsave.h @@ -28,70 +28,15 @@ void Nom_fichier_complet(char * Nom_du_fichier, byte Sauve_Colorix); void Charger_image(byte Image); void Sauver_image(byte Image); -// -- PKM ------------------------------------------------------------------- -void Test_PKM(void); -void Load_PKM(void); -void Save_PKM(void); +typedef struct { + char *Extension; + fonction_action Test; + fonction_action Load; + fonction_action Save; + byte Backup_done; // Le format enregistre toute l'image, on la considère à jour. + byte Commentaire; // Le format de fichier autorise un commentaire. +} T_Format; -// -- LBM ------------------------------------------------------------------- -void Test_LBM(void); -void Load_LBM(void); -void Save_LBM(void); +// Tableau des formats connus +extern T_Format FormatFichier[NB_FORMATS_CONNUS]; - byte * LBM_Buffer; - - -// -- GIF ------------------------------------------------------------------- -void Test_GIF(void); -void Load_GIF(void); -void Save_GIF(void); - -// -- PCX ------------------------------------------------------------------- -void Test_PCX(void); -void Load_PCX(void); -void Save_PCX(void); - -// -- BMP ------------------------------------------------------------------- -void Test_BMP(void); -void Load_BMP(void); -void Save_BMP(void); - -// -- IMG ------------------------------------------------------------------- -void Test_IMG(void); -void Load_IMG(void); -void Save_IMG(void); - -// -- SCx ------------------------------------------------------------------- -void Test_SCx(void); -void Load_SCx(void); -void Save_SCx(void); - -// -- CEL ------------------------------------------------------------------- -void Test_CEL(void); -void Load_CEL(void); -void Save_CEL(void); - -// -- KCF ------------------------------------------------------------------- -void Test_KCF(void); -void Load_KCF(void); -void Save_KCF(void); - -// -- PAL ------------------------------------------------------------------- -void Test_PAL(void); -void Load_PAL(void); -void Save_PAL(void); - -// -- PI1 ------------------------------------------------------------------- -void Test_PI1(void); -void Load_PI1(void); -void Save_PI1(void); - -// -- PC1 ------------------------------------------------------------------- -void Test_PC1(void); -void Load_PC1(void); -void Save_PC1(void); - -// -- PNG ------------------------------------------------------------------- -void Test_PNG(void); -void Load_PNG(void); -void Save_PNG(void);