DEL remove useless code
[powerfractal.git] / Src / power_IO.adb
1 ------------------------------------------------------------------------------------------------
2 -- Nom : Power_IO / fait partie du programme Power Fractal --
3 -- --
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 ------------------------------------------------------------------------------------------------
9
10 with Ada.Sequential_IO; --Pour ecrire en binaire dans un fichier
11 with Power_Types; use Power_Types;
12 with Ada.Text_IO;
13 with Power_Calculator;
14 with Power_Bmp;
15 with Power_Colors;
16 with Power_List;
17
18 package body Power_IO is
19
20 --Instentie pour faire ecrire le type Cara_Fractal dans un fichier
21 package Fractal_IO is new Ada.Sequential_IO (Cara_Fractal);
22
23 ------------------------------------------------------------------------------------------------
24 -- Nom : Enregistrer_Fractal --
25 -- But : Enregistrer les caracteristiques d'un fractal dans un fichier --
26 -- --
27 -- Parametres ----------------------------------------------------------------------------------
28 -- In : * Le nom du fichier : Nom_Fichier --
29 -- * Les caracteristiques de la fractal : Fractal --
30 -- --
31 ------------------------------------------------------------------------------------------------
32 procedure Enregistrer_Fractal (Nom_Fichier : String; Fractal : Cara_Fractal) is
33
34 Fichier_Fractal : Fractal_IO.File_Type; --Le fichier
35
36 begin --Enregistrer_Fractal
37
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
41
42 exception --Traite les exceptions concernant les fichiers
43 when Fractal_IO.Name_Error | Fractal_IO.Device_Error =>
44 raise Erreur_Fichier;
45
46 end Enregistrer_Fractal;
47
48 ------------------------------------------------------------------------------------------------
49 -- Nom : Charger_Fractal --
50 -- But : Charger les caracteristiques d'un fractal depuis un fichier --
51 -- --
52 -- Parametres ----------------------------------------------------------------------------------
53 -- In : * Le nom du fichier --
54 -- --
55 -- return : * Les caracteristiques de la fractal --
56 -- --
57 ------------------------------------------------------------------------------------------------
58 function Charger_Fractal (Nom_Fichier : String) return Cara_Fractal is
59
60 Fichier_Fractal : Fractal_IO.File_Type; --Le fichier
61 Fractal : Cara_Fractal;
62 begin --Enregistrer_Fractal
63
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
67 return Fractal;
68 exception --Traite les exceptions concernant les fichiers
69 when Fractal_IO.Name_Error | Fractal_IO.Device_Error =>
70 raise Erreur_Fichier;
71
72 end Charger_Fractal;
73
74 ------------------------------------------------------------------------------------------------
75 -- Nom : Enregistrer_Liste --
76 -- But : Enregistrer une liste contenant des fractals --
77 -- --
78 -- Parametres ----------------------------------------------------------------------------------
79 -- In : * Le nom du fichier : Nom_Fichier --
80 -- * La liste de fractals : Liste --
81 -- --
82 ------------------------------------------------------------------------------------------------
83 procedure Enregistrer_Liste (Nom_Fichier : String; Liste : Power_Types.T_Liste_Fractals) is
84
85 use Power_List;
86 Fichier_Liste : Fractal_IO.File_Type; --Le fichier
87
88 begin --Enregistrer_Liste
89 Fractal_IO.Create (Fichier_Liste, Fractal_IO.Out_File, Nom_Fichier); --Cree le fichier
90
91 for I in 1..Nb_Fractals(Liste) loop
92 Fractal_IO.Write (Fichier_Liste, Fractal_Num(Liste, I).Fractal); --Ecrit une fractal
93 end loop;
94
95 Fractal_IO.Close (Fichier_Liste); --Ferme le fichier
96
97 exception --Traite les exceptions concernant les fichiers
98 when Fractal_IO.Name_Error | Fractal_IO.Device_Error =>
99 raise Erreur_Fichier;
100
101 end Enregistrer_Liste;
102
103 ------------------------------------------------------------------------------------------------
104 -- Nom : Charger_List --
105 -- But : Charger toutes les fractals contenues dans un fichier --
106 -- --
107 -- Parametres ----------------------------------------------------------------------------------
108 -- In : * Le nom du fichier --
109 -- --
110 -- In out : * La liste de fractals --
111 -- --
112 ------------------------------------------------------------------------------------------------
113 procedure Charger_Liste (Nom_Fichier : String; Liste : in out Power_Types.T_Liste_Fractals) is
114
115 use Power_List;
116 Fichier_Liste : Fractal_IO.File_Type; --Le fichier
117 Fractal_Tmp : Cara_Fractal;
118
119 begin --Charger_Liste
120
121 Fractal_IO.Open (Fichier_Liste, Fractal_IO.In_File, Nom_Fichier); --Ouvre le fichier
122
123 Vider_Liste(Liste);
124
125 while not Fractal_IO.End_Of_File(Fichier_Liste) loop
126
127 Fractal_IO.Read (Fichier_Liste, Fractal_Tmp); --Lit les informations
128 Ajouter(Liste, Fractal_Tmp);
129
130 end loop;
131
132 Fractal_IO.Close (Fichier_Liste); --ferme le fichier
133
134
135 exception --Traite les exceptions concernant les fichiers
136 when Fractal_IO.Name_Error | Fractal_IO.Device_Error =>
137 raise Erreur_Fichier;
138
139 end Charger_Liste;
140
141 ------------------------------------------------------------------------------------------------
142 -- Nom : Rendre_Bmp --
143 -- But : Rendre un fichier image au format bmp (a l'aide de la library BMPLib) --
144 -- --
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 --
149 -- --
150 ------------------------------------------------------------------------------------------------
151 procedure Rendre_Bmp (Fractal : Power_Types.Cara_Fractal; Nom_Fichier : String;
152 Largeur_Zone : Natural := 1024; Hauteur_Zone : Natural := 768) is
153
154 use Power_Calculator;
155 use Ada.Text_IO;
156 use Power_Bmp;
157 use Power_Colors;
158
159 Degrade : T_Tab_Couleur(1 .. Fractal.Nb_Iteration_Max); --Le degrade de couleur
160
161 --2 si la matrice doit etre calcule quatre fois plus grande sinon 1
162 Quadruple : Natural := Boolean'Pos(Fractal.Antialiasing) + 1;
163
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);
167
168 Hauteur_Zone_Anti : Natural := (Hauteur_Zone - 1) * Quadruple
169 + Boolean'Pos(Fractal.Antialiasing);
170 --
171
172 --La matrice d'iteration
173 Matrice_Iteration : T_Matrice_Iteration (0..Largeur_Zone_Anti, 0..Hauteur_Zone_Anti);
174
175 --La matrice de sortie
176 Matrice_Tampon : T_Matrice_Tampon (0 .. Largeur_Zone - 1, 0 .. Hauteur_Zone - 1);
177
178 begin -- Rendre_Bmp
179
180 New_Line;
181 Put(" Matrix... ");
182
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);
187 else --sinon (Julia)
188 --Calcul la fractal sur l'ensemble de julia
189 Matrice_Iteration := Julia_Gen (Largeur_Zone_Anti, Hauteur_Zone_Anti, Fractal);
190 end if;
191
192 Put_Line("OK");
193
194 -- Put(" Colors... ");
195 -- --Calcul le degrade de couleur
196 -- Creer_Degrade(Fractal, Degrade, Fractal.Nb_Iteration_Max);
197 -- Put_Line("OK");
198 Put(" Conversion... ");
199
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));
204 else
205
206 Matrice_Tampon := Conversion_Couleur(Matrice_Iteration, fractal);
207 end if;
208
209 Put_Line("OK");
210
211 Put(" Saving... ");
212 Ecrire_Bmp (Matrice_Tampon, Nom_Fichier); --Enregistre le bmp
213 Put_Line("OK");
214
215 end Rendre_Bmp;
216
217 end Power_IO;