verbatim -> lstlisting
This commit is contained in:
		
							parent
							
								
									faf008265c
								
							
						
					
					
						commit
						a75e018133
					
				@ -138,18 +138,18 @@ un format complètement inconnu, puisque je viens de l'inventer
 | 
			
		||||
Tout d'abord, nous devons déclarer et garnir quelques variables
 | 
			
		||||
pour gérer la machinerie interne.
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
int             width = 640, height = 480;
 | 
			
		||||
char            *fname = "exemple.fimg";
 | 
			
		||||
FloatImg        fimg;
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
\end{lstlisting}
 | 
			
		||||
 | 
			
		||||
Ensuite, nous enchainerons trois étapes : création de l'image
 | 
			
		||||
en mémoire centrale, initialisation des valeurs de chaque pixel à 0.0,
 | 
			
		||||
et pour conclure, enregistrement dans un fichier\footnote{Au format
 | 
			
		||||
ésotérique, mais très véloce.} binaire.
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
foo = fimg_create(&fimg, width, height, FIMG_TYPE_RGB);
 | 
			
		||||
if (foo) {
 | 
			
		||||
        fprintf(stderr, "create floatimg -> %d\n", foo);
 | 
			
		||||
@ -161,7 +161,7 @@ if (foo) {
 | 
			
		||||
        fprintf(stderr, "dump fimg -> %d\n", foo);
 | 
			
		||||
        exit(1);
 | 
			
		||||
        }
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
\end{lstlisting}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Une fois ce code enrobé dans un \texttt{main()}, compilé et exécuté,
 | 
			
		||||
@ -261,7 +261,7 @@ sont décrits par un ensemble
 | 
			
		||||
de données (certains appelent ça des \textsl{metadatas}) regroupées
 | 
			
		||||
dans une jolie structure que nous allons examiner dès maintenant.
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
/*      in memory descriptor */
 | 
			
		||||
typedef struct {
 | 
			
		||||
        int             width;
 | 
			
		||||
@ -272,7 +272,7 @@ typedef struct {
 | 
			
		||||
        float           *R, *G, *B, *A;
 | 
			
		||||
        int             reserved;
 | 
			
		||||
        } FloatImg;
 | 
			
		||||
\end{verbatim}\index{FloatImg}
 | 
			
		||||
\end{lstlisting}\index{FloatImg}
 | 
			
		||||
 | 
			
		||||
Les deux premiers champs sont \textsl{obvious}.
 | 
			
		||||
Le troisième est le type d'image : pour le moment, il y en a trois
 | 
			
		||||
@ -280,12 +280,12 @@ qui sont définis\footnote{et plus ou moins bien gérés\dots} :
 | 
			
		||||
gris, rgb et rgba\index{rgba}.
 | 
			
		||||
Les constantes adéquates sont dans \texttt{floatimg.h}
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
#define FIMG_TYPE_GRAY              1
 | 
			
		||||
#define FIMG_TYPE_RGB               3
 | 
			
		||||
#define FIMG_TYPE_RGBA              4
 | 
			
		||||
#define FIMG_TYPE_RGBZ              99
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
\end{lstlisting}
 | 
			
		||||
 | 
			
		||||
Un peu plus loin, nous avons les pointeurs vers les
 | 
			
		||||
différents \textsl{pixmaps} de l'image. En principe l'organisation
 | 
			
		||||
@ -324,10 +324,10 @@ dynamique de la mémoire qui sera occupée par tous ces pixels flottants,
 | 
			
		||||
ce qui est un sujet parfois délicat\footnote{GC or not GC ?}.
 | 
			
		||||
Elle est donc faite, à la base, par ces deux fonctions~:
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
int fimg_create(FloatImg *fimg, int w, int h, int type);
 | 
			
		||||
int fimg_destroy(FloatImg *fimg);
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
\end{lstlisting}
 | 
			
		||||
 | 
			
		||||
L'appelant doit lui-même gérer le descripteur d'image (une structure
 | 
			
		||||
C décrite plus haut) en le considérant comme un type semi-opaque dont
 | 
			
		||||
@ -341,10 +341,10 @@ pouvoir aussi exister à long terme en étant stocké dans la matrice
 | 
			
		||||
est tout aussi pertinent. Il y a deux opérations qui supportent le
 | 
			
		||||
reste des transits ram/ps.
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
int fimg_dump_to_file(FloatImg *fimg, char *fname, int notused);
 | 
			
		||||
int fimg_load_from_dump(char *fname, FloatImg *where);
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
\end{lstlisting}
 | 
			
		||||
 | 
			
		||||
Recharger une image depuis un fichier nécessite que celle-ci et
 | 
			
		||||
l'image de destination en mémoire 
 | 
			
		||||
@ -365,11 +365,11 @@ simple, une fonction qui enchaine ces deux actions
 | 
			
		||||
(allocation, puis lecture), et s'utilise
 | 
			
		||||
comme ça :
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
FloatImg       head;
 | 
			
		||||
memset(&head, 0, sizeof(FloatImg));
 | 
			
		||||
foo = fimg_create_from_dump("lena.fimg", &head);
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
\end{lstlisting}
 | 
			
		||||
 | 
			
		||||
Si la valeur retournée est différente de 0, c'est que quelque
 | 
			
		||||
chose s'est mal passé.
 | 
			
		||||
@ -383,9 +383,9 @@ Bon, vous avez une image latente, et vous souhaitez dessiner dessus
 | 
			
		||||
(ou dedans ?) avec vos encres flottantes ?
 | 
			
		||||
Il y a des fonctions pour ça, par exemple~:
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
int fimg_plot_rgb(FloatImg *head, int x, int y, float r, float g, float b);
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
\end{lstlisting}
 | 
			
		||||
 | 
			
		||||
Les paramètres sont explicites, mais leur validité doit être
 | 
			
		||||
sévèrement controlée par l'appelant. Il y a une fonction 
 | 
			
		||||
@ -420,13 +420,13 @@ est un nombre en double précision donnant la valeur
 | 
			
		||||
maximale \textsl{supposée} de l'image source,
 | 
			
		||||
valeur qui peut être déterminée de plusieurs manières.
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
/* source in lib/contrast.c */
 | 
			
		||||
int fimg_square_root(FloatImg *s, FloatImg *d, double maxval);
 | 
			
		||||
int fimg_power_2(FloatImg *s, FloatImg *d, double maxval);
 | 
			
		||||
int fimg_cos_01(FloatImg *s, FloatImg *d, double maxval);
 | 
			
		||||
int fimg_cos_010(FloatImg *s, FloatImg *d, double maxval);
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
\end{lstlisting}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Si vous souhaitez rajouter votre propre méthode de modification
 | 
			
		||||
@ -475,10 +475,10 @@ de pixel flottant.
 | 
			
		||||
 | 
			
		||||
Très prochainement, le retour du blitter\index{blitter}.
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
/*	module funcs/geometry.c		*/
 | 
			
		||||
int fimg_halfsize_0(FloatImg *src, FloatImg *dst, int notused);
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
\end{lstlisting}
 | 
			
		||||
 | 
			
		||||
Attention lors de l'appel, le descripteur \texttt{dst} ne doit pas
 | 
			
		||||
contenir d'image, et doit être effacé avec un bon
 | 
			
		||||
@ -510,9 +510,9 @@ l'utilisation du codage \textsc{ascii}\index{ascii}
 | 
			
		||||
(alors qu'on pourrait mettre du binaire, plus compact) y est
 | 
			
		||||
pour quelque chose.
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
int fimg_save_as_pnm(FloatImg *head, char *fname, int flags);
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
\end{lstlisting}
 | 
			
		||||
 | 
			
		||||
Le bit \texttt{0} du paramètre \texttt{flags} mis à \texttt{1} demande
 | 
			
		||||
à la fonction de faire la mise à l'échelle avec le couple
 | 
			
		||||
@ -533,9 +533,9 @@ mais on a quand même une bonne compression, ça compense.
 | 
			
		||||
J'utilise \textsl{libpnglite} avec qui j'ai un peu de mal à suivre.
 | 
			
		||||
Mais je me soigne. Le mode 16 bits va bientôt arriver.
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
int fimg_save_as_png(FloatImg *src, char *outname, int flags);
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
\end{lstlisting}
 | 
			
		||||
 | 
			
		||||
Tous les flags doivent être à zéro.
 | 
			
		||||
 | 
			
		||||
@ -561,10 +561,10 @@ dans des domaines annexes,
 | 
			
		||||
tels que l'interprétation d'arguments dans la ligne de commande ou un
 | 
			
		||||
fichier de configuration.
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
int parse_WxH(char *str, int *pw, int *ph)
 | 
			
		||||
int parse_double(char *str, double *dptr)
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
\end{lstlisting}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
La fonction \texttt{int format\_from\_extension(char *fname)} examine un
 | 
			
		||||
@ -580,10 +580,10 @@ To be continued\index{XXX}
 | 
			
		||||
 | 
			
		||||
Quelques routines qui servent futilement à \textsl{brotcher} les images.
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
int fimg_killcolors_a(FloatImg *fimg, float fval);
 | 
			
		||||
int fimg_killcolors_b(FloatImg *fimg, float fval);
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
\end{lstlisting}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
%		----------------------------------
 | 
			
		||||
@ -614,7 +614,7 @@ Pour simplifier les choses, nous n'allons traiter que les
 | 
			
		||||
images de type \textsc{FIMG\_TYPE\_RGB}, de loin le plus
 | 
			
		||||
répandu par les temps qui courent.
 | 
			
		||||
 | 
			
		||||
\begin{verbatim}
 | 
			
		||||
\begin{lstlisting}
 | 
			
		||||
int fimg_example(FloatImg *s, FloatImg *d, float value)
 | 
			
		||||
{
 | 
			
		||||
int     size, index;
 | 
			
		||||
@ -633,7 +633,7 @@ for (idx=0; idx<size; idx++) {
 | 
			
		||||
 | 
			
		||||
return 0;
 | 
			
		||||
}
 | 
			
		||||
\end{verbatim}
 | 
			
		||||
\end{lstlisting}
 | 
			
		||||
 | 
			
		||||
Je vous laisse imaginer les dégats que peut faire cette 
 | 
			
		||||
fontion en utilisation réelle. Mieux, je vous propose
 | 
			
		||||
@ -648,7 +648,7 @@ de fonctions prévues à cet effet..
 | 
			
		||||
% -------------------------------------------------------------------
 | 
			
		||||
\section{Les outils}\label{outils}
 | 
			
		||||
 | 
			
		||||
\textsl{3615mavie} : sur des projets comme celui-ci, qui travaillent
 | 
			
		||||
\textsf{3615mavie} : sur des projets comme celui-ci, qui travaillent
 | 
			
		||||
in-fine sur des objets que l'on peut considérer comme « physiques »,
 | 
			
		||||
il est important de passer à une utilisation
 | 
			
		||||
normale\footnote{Il y a une vie en dehors de git.} et construire
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user