1 ------------------------------------------------------------------------------------------------
2 -- Nom : Power_IO / fait partie du programme Power Fractal --
4 -- Auteurs : Gregory Burri & Adrien Crivelli --
5 ------------------------------------------------------------------------------------------------
6 -- But : Outils Pour Rendre une fractal au format .bmp ou --
7 -- Enregistrer et charger au format .pof --
8 ------------------------------------------------------------------------------------------------
10 with Ada
.Sequential_IO
; --Pour ecrire en binaire dans un fichier
11 with Power_Types
; use Power_Types
;
13 with Power_Calculator
;
18 package body Power_IO
is
20 --Instentie pour faire ecrire le type Cara_Fractal dans un fichier
21 package Fractal_IO
is new Ada
.Sequential_IO (Cara_Fractal
);
23 ------------------------------------------------------------------------------------------------
24 -- Nom : Enregistrer_Fractal --
25 -- But : Enregistrer les caracteristiques d'un fractal dans un fichier --
27 -- Parametres ----------------------------------------------------------------------------------
28 -- In : * Le nom du fichier : Nom_Fichier --
29 -- * Les caracteristiques de la fractal : Fractal --
31 ------------------------------------------------------------------------------------------------
32 procedure Enregistrer_Fractal (Nom_Fichier
: String; Fractal
: Cara_Fractal
) is
34 Fichier_Fractal
: Fractal_IO
.File_Type
; --Le fichier
36 begin --Enregistrer_Fractal
38 Fractal_IO
.Create (Fichier_Fractal
, Fractal_IO
.Out_File
, Nom_Fichier
); --Cree le fichier
39 Fractal_IO
.Write (Fichier_Fractal
, Fractal
); --Ecrit les informations
40 Fractal_IO
.Close (Fichier_Fractal
); --Ferme le fichier
42 exception --Traite les exceptions concernant les fichiers
43 when Fractal_IO
.Name_Error | Fractal_IO
.Device_Error
=>
46 end Enregistrer_Fractal
;
48 ------------------------------------------------------------------------------------------------
49 -- Nom : Charger_Fractal --
50 -- But : Charger les caracteristiques d'un fractal depuis un fichier --
52 -- Parametres ----------------------------------------------------------------------------------
53 -- In : * Le nom du fichier --
55 -- return : * Les caracteristiques de la fractal --
57 ------------------------------------------------------------------------------------------------
58 function Charger_Fractal (Nom_Fichier
: String) return Cara_Fractal
is
60 Fichier_Fractal
: Fractal_IO
.File_Type
; --Le fichier
61 Fractal
: Cara_Fractal
;
62 begin --Enregistrer_Fractal
64 Fractal_IO
.Open (Fichier_Fractal
, Fractal_IO
.In_File
, Nom_Fichier
); --Ouvre le fichier
65 Fractal_IO
.Read (Fichier_Fractal
, Fractal
); --Lit les informations
66 Fractal_IO
.Close (Fichier_Fractal
); --ferme le fichier
68 exception --Traite les exceptions concernant les fichiers
69 when Fractal_IO
.Name_Error | Fractal_IO
.Device_Error
=>
74 ------------------------------------------------------------------------------------------------
75 -- Nom : Enregistrer_Liste --
76 -- But : Enregistrer une liste contenant des fractals --
78 -- Parametres ----------------------------------------------------------------------------------
79 -- In : * Le nom du fichier : Nom_Fichier --
80 -- * La liste de fractals : Liste --
82 ------------------------------------------------------------------------------------------------
83 procedure Enregistrer_Liste (Nom_Fichier
: String; Liste
: Power_Types
.T_Liste_Fractals
) is
86 Fichier_Liste
: Fractal_IO
.File_Type
; --Le fichier
88 begin --Enregistrer_Liste
89 Fractal_IO
.Create (Fichier_Liste
, Fractal_IO
.Out_File
, Nom_Fichier
); --Cree le fichier
91 for I
in 1..Nb_Fractals(Liste
) loop
92 Fractal_IO
.Write (Fichier_Liste
, Fractal_Num(Liste
, I
).Fractal
); --Ecrit une fractal
95 Fractal_IO
.Close (Fichier_Liste
); --Ferme le fichier
97 exception --Traite les exceptions concernant les fichiers
98 when Fractal_IO
.Name_Error | Fractal_IO
.Device_Error
=>
101 end Enregistrer_Liste
;
103 ------------------------------------------------------------------------------------------------
104 -- Nom : Charger_List --
105 -- But : Charger toutes les fractals contenues dans un fichier --
107 -- Parametres ----------------------------------------------------------------------------------
108 -- In : * Le nom du fichier --
110 -- In out : * La liste de fractals --
112 ------------------------------------------------------------------------------------------------
113 procedure Charger_Liste (Nom_Fichier
: String; Liste
: in out Power_Types
.T_Liste_Fractals
) is
116 Fichier_Liste
: Fractal_IO
.File_Type
; --Le fichier
117 Fractal_Tmp
: Cara_Fractal
;
119 begin --Charger_Liste
121 Fractal_IO
.Open (Fichier_Liste
, Fractal_IO
.In_File
, Nom_Fichier
); --Ouvre le fichier
125 while not Fractal_IO
.End_Of_File(Fichier_Liste
) loop
127 Fractal_IO
.Read (Fichier_Liste
, Fractal_Tmp
); --Lit les informations
128 Ajouter(Liste
, Fractal_Tmp
);
132 Fractal_IO
.Close (Fichier_Liste
); --ferme le fichier
135 exception --Traite les exceptions concernant les fichiers
136 when Fractal_IO
.Name_Error | Fractal_IO
.Device_Error
=>
137 raise Erreur_Fichier
;
141 ------------------------------------------------------------------------------------------------
142 -- Nom : Rendre_Bmp --
143 -- But : Rendre un fichier image au format bmp (a l'aide de la library BMPLib) --
145 -- Parametres ----------------------------------------------------------------------------------
146 -- In : * Les dimensions du bmp : Largeur_Zone et Hauteur_Zone --
147 -- * La fractal a rendre : Cara_Fractal --
148 -- * Le nom du fichier bmp : Nom_Fichier --
150 ------------------------------------------------------------------------------------------------
151 procedure Rendre_Bmp (Fractal
: Power_Types
.Cara_Fractal
; Nom_Fichier
: String;
152 Largeur_Zone
: Natural := 1024; Hauteur_Zone
: Natural := 768) is
154 use Power_Calculator
;
159 Degrade
: T_Tab_Couleur(1 .. Fractal
.Nb_Iteration_Max
); --Le degrade de couleur
161 --2 si la matrice doit etre calcule quatre fois plus grande sinon 1
162 Quadruple
: Natural := Boolean'Pos(Fractal
.Antialiasing
) + 1;
164 --les dimensions de la zone de calcul, elles sont double si l'antialiasing est active
165 Largeur_Zone_Anti
: Natural := (Largeur_Zone
- 1) * Quadruple
166 + Boolean'Pos(Fractal
.Antialiasing
);
168 Hauteur_Zone_Anti
: Natural := (Hauteur_Zone
- 1) * Quadruple
169 + Boolean'Pos(Fractal
.Antialiasing
);
172 --La matrice d'iteration
173 Matrice_Iteration
: T_Matrice_Iteration (0..Largeur_Zone_Anti
, 0..Hauteur_Zone_Anti
);
175 --La matrice de sortie
176 Matrice_Tampon
: T_Matrice_Tampon (0 .. Largeur_Zone
- 1, 0 .. Hauteur_Zone
- 1);
183 --Si la fractal est de type mandelbrot alors
184 if Fractal
.Ensemble
= Mandelbrot
then
185 --Calcul la fractal sur l'ensemble de mandelbrot
186 Matrice_Iteration
:= Mandel_Gen (Largeur_Zone_Anti
, Hauteur_Zone_Anti
, Fractal
);
188 --Calcul la fractal sur l'ensemble de julia
189 Matrice_Iteration
:= Julia_Gen (Largeur_Zone_Anti
, Hauteur_Zone_Anti
, Fractal
);
194 -- Put(" Colors... ");
195 -- --Calcul le degrade de couleur
196 -- Creer_Degrade(Fractal, Degrade, Fractal.Nb_Iteration_Max);
198 Put(" Conversion... ");
200 --Si l'antialiasing est active alors
201 if Fractal
.Antialiasing
then
202 --Calcul la matrice de sortie avec antialiasing
203 Matrice_Tampon
:= Calcul_Antialiasing(Conversion_Couleur(Matrice_Iteration
, fractal
));
206 Matrice_Tampon
:= Conversion_Couleur(Matrice_Iteration
, fractal
);
212 Ecrire_Bmp (Matrice_Tampon
, Nom_Fichier
); --Enregistre le bmp