Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- Programme à compléter
- --
- with GAda.Text_IO, GAda.Graphics, GAda.Plus, JPG;
- with Caracteres; use Caracteres;
- procedure Mission35 is
- package Graph renames GAda.Graphics;
- package Plus renames GAda.Plus;
- package Tet renames GAda.Text_IO;
- ------------------------------------------ Version 1 de l'affichage
- type T_Qua is (Basse, Moyenne, Haute);
- type T_Res is record
- Long : Float;
- Haut : Float;
- end record;
- function Get_Char (Nuance : Integer ; Qualite : T_Qua) return Character is
- -- Cette fonction utilise une liste déja triée de caractères et
- -- va chercher le bon caractere avec un produit en croix
- -- (-1 et +1 pour éviter des problemes d'index
- Index_Ch : Integer := 1;
- Ch_Ret : Character;
- Encod_Bas : String := "# ";
- Encod_Moy : String := "@B%8#O([koi+-.' ";
- Encod_Hau : String := "@B%8&WM#*ZO0QLCJUYXhkbqwmzcunxr/\|()1{}[]?-_+~<>i!l;:,`'. ";
- begin
- case Qualite is
- when Basse => Ch_Ret := Encod_Bas(1 + Integer(Float(Nuance)*(Float(Encod_Bas'Length-1))/255.0));
- when Moyenne => Ch_Ret := Encod_Moy(1 + Integer(Float(Nuance)*(Float(Encod_Moy'Length-1))/255.0));
- when Haute => Ch_Ret := Encod_Hau(1 + Integer(Float(Nuance)*(Float(Encod_Hau'Length-1))/255.0));
- end case;
- -- Nuance de 0 a 255, indexChar de 1 a longeur de l'encodage
- return Ch_Ret;
- end Get_Char;
- procedure Affiche_Ascii(Path : String ; Qualite : T_Qua ; FlipV, FlipH, FlipNEB : Boolean) is
- Img : JPG.T_Image := JPG.Lire_Image(path);
- Haut : Integer := Img'Length(1);
- Larg : Integer := Img'Length(2);
- LigneCor, ColCor : Integer;
- CTemp : Graph.T_Couleur;
- Nua_Temp : Integer;
- begin
- for Ligne in Img'Range(1) loop
- if FlipV then
- LigneCor := Haut - Ligne + 1;
- else
- LigneCor := Ligne;
- end if;
- for Colonne in Img'Range(2) loop
- -- Récupère les valeurs RGB et prend en compte des flips
- -- horizontal : lignes inversees, vertical : l'autre
- if FlipH then
- ColCor := Larg - Colonne + 1;
- else
- ColCor := Colonne;
- end if;
- CTemp := Img(LigneCor, ColCor);
- Nua_Temp := (CTemp.Rouge + CTemp.Vert + CTemp.Bleu) / 3;
- if FlipNEB then
- Nua_Temp := 255 - Nua_Temp;
- end if;
- Tet.Put(Get_Char(Nua_Temp, Qualite));
- end loop;
- Tet.New_Line;
- end loop;
- end Affiche_Ascii;
- ------------------------------------------ Version 1.5 de l'affichage (redimmensionnement image)
- procedure Affiche_Ascii_Blocs(Path:String ; RecadL,RecadH:Integer ; Qualite:T_Qua ; FlipNEB:Boolean) is
- Img : JPG.T_Image := JPG.Lire_Image(path);
- ImgH : Integer := Img'Length(1);
- ImgL : Integer := Img'Length(2);
- Xmin, Ymin : Integer;
- BlocL : Integer := Integer(Float(ImgL)/Float(RecadL))-1;
- BlocH : Integer := Integer(Float(ImgH)/Float(RecadH))-1;
- CTemp : Graph.T_Couleur;
- Nua_Temp : Integer;
- Compt : Integer;
- begin
- -- Pour tous les blocs (nouveaux pixels)
- for Y in 1..RecadH loop
- Ymin := ((Y-1) * BlocL ) + 1;
- for X in 1..RecadL loop
- Xmin := ((X-1) * BlocH) + 1;
- -- Calcule la lum moyenne du bloc
- Nua_Temp := 0;
- Compt := 0;
- for Ylum in Ymin..Ymin+BlocH-1 loop
- for Xlum in Xmin..Xmin+blocL-1 loop
- CTemp := Img(Ylum, Xlum);
- Nua_Temp := Nua_Temp + (CTemp.Rouge + CTemp.Vert + CTemp.Bleu) / 3;
- Compt := Compt + 1;
- end loop;
- end loop;
- Nua_Temp := Nua_Temp / Compt;
- if FlipNEB then
- Nua_Temp := 255 - Nua_Temp;
- end if;
- -- Affiche le bon caractere
- Tet.Put(Get_Char(Nua_Temp, Qualite));
- end loop;
- Tet.New_Line;
- end loop;
- end Affiche_Ascii_Blocs;
- ------------------------------------------ Version 2 (version "normale")
- type T_Dico is record
- Car : Character;
- Lum : Integer;
- end record;
- type T_Infos is array(Integer range <>) of T_Dico;
- procedure remplisInfos(Inf : in out T_Infos) is
- lum_temp : Integer;
- lum_max : Integer := 0;
- lum_min : Integer := 255;
- begin
- for I in 1..Inf'length loop
- -- Moyenne
- lum_temp := 0;
- for Y in 1..Table(I).Trame'length(1) loop
- for X in 1..Table(I).Trame'length(2) loop
- case Table(I).Trame(Y,X) is
- when Allume => lum_temp := lum_temp + 1;
- when Eteint => null;
- end case;
- end loop;
- end loop;
- lum_temp := integer( Float(Lum_Temp)*255.0 / Float(Table(I).Trame'length(1)*Table(I).Trame'length(2)) );
- -- Min-max pour apres
- if lum_temp < lum_min then
- lum_min := lum_temp;
- Tet.Put_Line("min " & Lum_Min'Image);
- elsif lum_temp > lum_max then
- lum_max := lum_temp;
- Tet.Put_Line("max " & Lum_Max'Image);
- end if;
- -- On complete petit a petit Inf
- Inf(I).Car := Table(I).Car;
- Inf(I).Lum := lum_temp;
- end loop;
- Tet.Put_Line(Lum_Min'Image & " et " & Lum_Max'Image);
- -- On normalise / fait en sorte que tous vont de 0 a 255
- for I in 1..Inf'length loop
- Inf(I).Lum := Integer( float(Inf(I).Lum) * (255.0 / float(lum_max - lum_min)) );
- end loop;
- -- Pas besoin de trier dans tous les cas on ira chercher le meilleur sur toute la liste
- end RemplisInfos;
- function Get_Char2(lum_voulu : Integer ; Infos : T_Infos) return Character is
- DeltaMin : Integer := 9999;
- IndexMin : Integer := 35;
- begin
- for I in 1..Infos'Length loop
- -- Minimum du delta donc recherche du plus proche
- if abs(Infos(I).Lum - Lum_Voulu) < DeltaMin then
- DeltaMin := Infos(I).Lum;
- IndexMin := I;
- end if;
- Tet.Put_Line(Integer'image(Infos(I).Lum - Lum_Voulu));
- end loop;
- return Infos(IndexMin).Car;
- end Get_Char2;
- procedure Affiche2(Path:String ; FlipNEB:Boolean ; Infos:T_Infos) is
- Img : JPG.T_Image := JPG.Lire_Image(path);
- ImgH : Integer := Img'Length(1);
- ImgL : Integer := Img'Length(2);
- CTemp : Graph.T_Couleur;
- Nua_Temp : Integer;
- begin
- for Y in 1..Img'Length(1)-1 loop
- for X in 1..Img'Length(2)-1 loop
- CTemp := Img(Y,X);
- Nua_Temp := (CTemp.Rouge + CTemp.Vert + CTemp.Bleu) / 3;
- if FlipNEB then
- Nua_Temp := 255 - Nua_Temp;
- end if;
- Tet.Put(Get_Char2(Nua_Temp, Infos));
- end loop;
- Tet.New_Line;
- end loop;
- end Affiche2;
- -- trop chiant de devoir le mettre la paske monsieur veut pas alors qu'il le fait aussi
- Infos : T_Infos(1..Nombre_De_Caracteres);
- begin
- --Affiche_Ascii("/home/gadefait/1A-Algo-S2/algo2/logoBD.jpg", Haute, False, False, True);
- --Affiche_Ascii_blocs("/home/gadefait/1A-Algo-S2/algo2/logo.jpg", 30, 30, Haute, False);
- RemplisInfos(Infos);
- Tet.Put(Infos(34).Car & Get_Char2(Infos(34).Lum, Infos));
- --Affiche2("/home/gadefait/1A-Algo-S2/algo2/logoBD.jpg", True, Infos);
- end Mission35;
- -- @B%8&WM#*ZO0QLCJUYXhkbqwmzcunxr/\|()1{}[]?-_+~<>i!l;:,"`'. 59 char encoding
- -- @B%8#O([koi+-.' 16 char encoding
- -- # 2 char encoding
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement