------------------------------------------------------------------------------------------------ -- Nom : Power_IO / fait partie du programme Power Fractal -- -- -- -- Auteurs : Gregory Burri & Adrien Crivelli -- ------------------------------------------------------------------------------------------------ -- But : Outils Pour Rendre une fractal au format .bmp ou -- -- Enregistrer et charger au format .pof -- ------------------------------------------------------------------------------------------------ with Ada.Sequential_IO; --Pour ecrire en binaire dans un fichier with Power_Types; use Power_Types; with Ada.Text_IO; with Power_Calculator; with Power_Bmp; with Power_Colors; with Power_List; package body Power_IO is --Instentie pour faire ecrire le type Cara_Fractal dans un fichier package Fractal_IO is new Ada.Sequential_IO (Cara_Fractal); ------------------------------------------------------------------------------------------------ -- Nom : Enregistrer_Fractal -- -- But : Enregistrer les caracteristiques d'un fractal dans un fichier -- -- -- -- Parametres ---------------------------------------------------------------------------------- -- In : * Le nom du fichier : Nom_Fichier -- -- * Les caracteristiques de la fractal : Fractal -- -- -- ------------------------------------------------------------------------------------------------ procedure Enregistrer_Fractal (Nom_Fichier : String; Fractal : Cara_Fractal) is Fichier_Fractal : Fractal_IO.File_Type; --Le fichier begin --Enregistrer_Fractal Fractal_IO.Create (Fichier_Fractal, Fractal_IO.Out_File, Nom_Fichier); --Cree le fichier Fractal_IO.Write (Fichier_Fractal, Fractal); --Ecrit les informations Fractal_IO.Close (Fichier_Fractal); --Ferme le fichier exception --Traite les exceptions concernant les fichiers when Fractal_IO.Name_Error | Fractal_IO.Device_Error => raise Erreur_Fichier; end Enregistrer_Fractal; ------------------------------------------------------------------------------------------------ -- Nom : Charger_Fractal -- -- But : Charger les caracteristiques d'un fractal depuis un fichier -- -- -- -- Parametres ---------------------------------------------------------------------------------- -- In : * Le nom du fichier -- -- -- -- return : * Les caracteristiques de la fractal -- -- -- ------------------------------------------------------------------------------------------------ function Charger_Fractal (Nom_Fichier : String) return Cara_Fractal is Fichier_Fractal : Fractal_IO.File_Type; --Le fichier Fractal : Cara_Fractal; begin --Enregistrer_Fractal Fractal_IO.Open (Fichier_Fractal, Fractal_IO.In_File, Nom_Fichier); --Ouvre le fichier Fractal_IO.Read (Fichier_Fractal, Fractal); --Lit les informations Fractal_IO.Close (Fichier_Fractal); --ferme le fichier return Fractal; exception --Traite les exceptions concernant les fichiers when Fractal_IO.Name_Error | Fractal_IO.Device_Error => raise Erreur_Fichier; end Charger_Fractal; ------------------------------------------------------------------------------------------------ -- Nom : Enregistrer_Liste -- -- But : Enregistrer une liste contenant des fractals -- -- -- -- Parametres ---------------------------------------------------------------------------------- -- In : * Le nom du fichier : Nom_Fichier -- -- * La liste de fractals : Liste -- -- -- ------------------------------------------------------------------------------------------------ procedure Enregistrer_Liste (Nom_Fichier : String; Liste : Power_Types.T_Liste_Fractals) is use Power_List; Fichier_Liste : Fractal_IO.File_Type; --Le fichier begin --Enregistrer_Liste Fractal_IO.Create (Fichier_Liste, Fractal_IO.Out_File, Nom_Fichier); --Cree le fichier for I in 1..Nb_Fractals(Liste) loop Fractal_IO.Write (Fichier_Liste, Fractal_Num(Liste, I).Fractal); --Ecrit une fractal end loop; Fractal_IO.Close (Fichier_Liste); --Ferme le fichier exception --Traite les exceptions concernant les fichiers when Fractal_IO.Name_Error | Fractal_IO.Device_Error => raise Erreur_Fichier; end Enregistrer_Liste; ------------------------------------------------------------------------------------------------ -- Nom : Charger_List -- -- But : Charger toutes les fractals contenues dans un fichier -- -- -- -- Parametres ---------------------------------------------------------------------------------- -- In : * Le nom du fichier -- -- -- -- In out : * La liste de fractals -- -- -- ------------------------------------------------------------------------------------------------ procedure Charger_Liste (Nom_Fichier : String; Liste : in out Power_Types.T_Liste_Fractals) is use Power_List; Fichier_Liste : Fractal_IO.File_Type; --Le fichier Fractal_Tmp : Cara_Fractal; begin --Charger_Liste Fractal_IO.Open (Fichier_Liste, Fractal_IO.In_File, Nom_Fichier); --Ouvre le fichier Vider_Liste(Liste); while not Fractal_IO.End_Of_File(Fichier_Liste) loop Fractal_IO.Read (Fichier_Liste, Fractal_Tmp); --Lit les informations Ajouter(Liste, Fractal_Tmp); end loop; Fractal_IO.Close (Fichier_Liste); --ferme le fichier exception --Traite les exceptions concernant les fichiers when Fractal_IO.Name_Error | Fractal_IO.Device_Error => raise Erreur_Fichier; end Charger_Liste; ------------------------------------------------------------------------------------------------ -- Nom : Rendre_Bmp -- -- But : Rendre un fichier image au format bmp (a l'aide de la library BMPLib) -- -- -- -- Parametres ---------------------------------------------------------------------------------- -- In : * Les dimensions du bmp : Largeur_Zone et Hauteur_Zone -- -- * La fractal a rendre : Cara_Fractal -- -- * Le nom du fichier bmp : Nom_Fichier -- -- -- ------------------------------------------------------------------------------------------------ procedure Rendre_Bmp (Fractal : Power_Types.Cara_Fractal; Nom_Fichier : String; Largeur_Zone : Natural := 1024; Hauteur_Zone : Natural := 768) is use Power_Calculator; use Ada.Text_IO; use Power_Bmp; use Power_Colors; Degrade : T_Tab_Couleur(1 .. Fractal.Nb_Iteration_Max); --Le degrade de couleur --2 si la matrice doit etre calcule quatre fois plus grande sinon 1 Quadruple : Natural := Boolean'Pos(Fractal.Antialiasing) + 1; --les dimensions de la zone de calcul, elles sont double si l'antialiasing est active Largeur_Zone_Anti : Natural := (Largeur_Zone - 1) * Quadruple + Boolean'Pos(Fractal.Antialiasing); Hauteur_Zone_Anti : Natural := (Hauteur_Zone - 1) * Quadruple + Boolean'Pos(Fractal.Antialiasing); -- --La matrice d'iteration Matrice_Iteration : T_Matrice_Iteration (0..Largeur_Zone_Anti, 0..Hauteur_Zone_Anti); --La matrice de sortie Matrice_Tampon : T_Matrice_Tampon (0 .. Largeur_Zone - 1, 0 .. Hauteur_Zone - 1); begin -- Rendre_Bmp New_Line; Put(" Matrix... "); --Si la fractal est de type mandelbrot alors if Fractal.Ensemble = Mandelbrot then --Calcul la fractal sur l'ensemble de mandelbrot Matrice_Iteration := Mandel_Gen (Largeur_Zone_Anti, Hauteur_Zone_Anti, Fractal); else --sinon (Julia) --Calcul la fractal sur l'ensemble de julia Matrice_Iteration := Julia_Gen (Largeur_Zone_Anti, Hauteur_Zone_Anti, Fractal); end if; Put_Line("OK"); -- Put(" Colors... "); -- --Calcul le degrade de couleur -- Creer_Degrade(Fractal, Degrade, Fractal.Nb_Iteration_Max); -- Put_Line("OK"); Put(" Conversion... "); --Si l'antialiasing est active alors if Fractal.Antialiasing then --Calcul la matrice de sortie avec antialiasing Matrice_Tampon := Calcul_Antialiasing(Conversion_Couleur(Matrice_Iteration, fractal)); else Matrice_Tampon := Conversion_Couleur(Matrice_Iteration, fractal); end if; Put_Line("OK"); Put(" Saving... "); Ecrire_Bmp (Matrice_Tampon, Nom_Fichier); --Enregistre le bmp Put_Line("OK"); end Rendre_Bmp; end Power_IO;