/*************************************************************************************************************************************/
/*                                                                                                                                   */
/*        D O N N E E S   C O M M U N E S   D E                                                                                      */
/*        E T U D E   D E   L A   C O M P L E X I T E   S T R U C T U R E L L E  :                                                   */
/*                                                                                                                                   */
/*                                                                                                                                   */
/*        Author of '$xrC/images.01$vv$I' :                                                                                          */
/*                                                                                                                                   */
/*                    Jean-Francois Colonna (LACTAMME, 20130509211035).                                                              */
/*                                                                                                                                   */
/*************************************************************************************************************************************/

#include  <stdlib.h>
#include  <stdio.h>

int       DebutDuSourceSimplifie;
                                        /* ATTENTION : Cette ligne doit imperativement etre la premiere apres les includes systeme   */
                                        /* a cause de 'v $xrC/SimplificationSourceC.01$vv$Z MarqueurDeDebut'...                      */

#define   TypeImage                                                                                                                     \
                    unsigned  char                                                                                                      \
                                        /* Type introduit le 20130904082239...                                                       */

#ifndef   IMAGES_DYNAMIQUES
#         define    DEFINITION_IMAGE(image,dimensionY,dimensionX)                                                                       \
                              image[dimensionY][dimensionX]
#         define    gINDEXATION_IMAGE(image,coordonneeY,coordonneeX,dimensionX)                                                         \
                              image[coordonneeY][coordonneeX]
#         define    INDEXATION_IMAGE(image,coordonneeY,coordonneeX)                                                                     \
                              gINDEXATION_IMAGE(image,coordonneeY,coordonneeX,dimensionX)
                                        /* Definitions introduites le 20140506100446 pour permettre ulterieurement la definition     */
                                        /* d'images dynamiques...                                                                    */
#else
#         define    DEFINITION_IMAGE(image,dimensionY,dimensionX)                                                                       \
                              *image=PointeurNULL;
#         define    gINDEXATION_IMAGE(image,coordonneeY,coordonneeX,dimensionX)                                                         \
                              (*(COND((image==PointeurNULL),image=malloc(gMUL2(dimensionX,dimY)),image)                                 \
                                 + (((coordonneeY-Ymin)*dimensionX) + (coordonneeX-Xmin)))                                              \
                               )
#         define    INDEXATION_IMAGE(image,coordonneeY,coordonneeX)                                                                     \
                              gINDEXATION_IMAGE(image,coordonneeY,coordonneeX,dimXb)
#endif

#define   STDIN                                                                                                                         \
                    0
#define   STDOUT                                                                                                                        \
                    1
                                        /* Introduits le 20131001162651. Au passage, le principe des programmes '$c' de '$xrC'       */
                                        /* de compression/decompression est le suivant :                                             */
                                        /*                                                                                           */
                                        /*                  Lire le fichier Argument de nom donne en argument du '$X',               */
                                        /*                                                                                           */
                                        /*                  Ecrire le fichier Resultat sur 'STDOUT'                                  */
                                        /*                                                                                           */
                                        /* et ce afin d'etre compatibles avec 'bzip2' et 'gzip' tels qu'ils sont exploites ici...    */

#define   INDEX0                                                                                                                        \
                    0                                                                                                                   \
                                        /* Introduit le 20141216134545...                                                            */
#define   IndexVersNombre(index)                                                                                                        \
                    (((index)-INDEX0)+1)
#define   NombreVersIndex(nombre)                                                                                                       \
                    (INDEX0+((nombre)-1))
                                        /* Introduit le 20141216134753...                                                            */

#define   PointeurNULL                                                                                                                  \
                    0                                                                                                                   \
                                        /* Introduit le 20131003132812...                                                            */
#define   EndOfChain                                                                                                                    \
                    0                                                                                                                   \
                                        /* Introduit le 20131014094349...                                                            */

#define   OK                                                                                                                            \
                    0
#define   NOK                                                                                                                           \
                    (OK+1)
#define   EOF                                                                                                                           \
                    (-1)

#define   BIT                                                                                                                           \
                    1

#define   FAUX                                                                                                                          \
                    (0 == 1)
#define   VRAI                                                                                                                          \
                    (1 == 1)

#define   NOMBRE_DE_BITS_PAR_CHIFFRE_HEXADECIMAL                                                                                        \
                    (4)
#define   NBITOC                                                                                                                        \
                    (8)
#define   MASKO                                                                                                                         \
                    (255)
#define   NOCMO                                                                                                                         \
                    (4)
#define   NBITMO                                                                                                                        \
                    (NOCMO*NBITOC)
#define   NOMBRE_DE_BITS_PAR_MOT                                                                                                        \
                    (64)
#define   NOMBRE_D_OCTETS_PAR_MOT                                                                                                       \
                    gDIVI(NOMBRE_DE_BITS_PAR_MOT,NBITOC)

#define   NOIR                                                                                                                          \
                    0

#if       (NOIR != 0)
#         message   "Il est essentiel que 'NOIR' soit nul, la nullite etant assumer implicitement a de nombreux endroits."
                                        /* C'est le cas de 'v $xrC/images_1octet.01$vv$I QUANTIFIER_LES_NIVEAUX___METHODE_01' par    */
                                        /* exemple ou en toute logique il faudrait d'abord faire 'SOUS(...,NOIR)' puis enfin         */
                                        /* 'ADD2(...,NOIR)'. Mais etant donne qu'a de nombreux endroits on fait des "cast"s selon    */
                                        /* '(TypeImage)', cela ne serait donc que partiel...                                         */
#else
#endif

#define   GRIS                                                                                                                          \
                    gADD2(gDIVI(gSOUS(BLANC,NOIR),2),NOIR)                                                                              \
                                        /* Parametre introduit le 20130729111349 pour 'v $xrC/images_1bit.01$vv$I GRIS'...           */
#define   GRIS_0                                                                                                                        \
                    gDIVI(gMUL2(0,BLANC),8)
#define   GRIS_1                                                                                                                        \
                    gDIVI(gMUL2(1,BLANC),8)
#define   GRIS_2                                                                                                                        \
                    gDIVI(gMUL2(2,BLANC),8)
#define   GRIS_3                                                                                                                        \
                    gDIVI(gMUL2(3,BLANC),8)
#define   GRIS_4                                                                                                                        \
                    gDIVI(gMUL2(4,BLANC),8)
#define   GRIS_5                                                                                                                        \
                    gDIVI(gMUL2(5,BLANC),8)
#define   GRIS_6                                                                                                                        \
                    gDIVI(gMUL2(6,BLANC),8)
#define   GRIS_7                                                                                                                        \
                    gDIVI(gMUL2(7,BLANC),8)
#define   GRIS_8                                                                                                                        \
                    gDIVI(gMUL2(8,BLANC),8)
                                        /* Definitions introduites le 20130730112504...                                              */
#define   BLANC                                                                                                                         \
                    255
#define   COULEURS                                                                                                                      \
                    gADD2(gSOUS(BLANC,NOIR),1)

#define   IFEQ(x,a)                                                                                                                     \
                    ((x) == (a))
#define   IFNE(x,a)                                                                                                                     \
                    ((x) != (a))
                                        /* Definitions introduites le 20151119074457 ('v $xrC/OperateursComptage$vv$I')...           */
#define   IFLE(x,a)                                                                                                                     \
                    ((x) <= (a))
#define   IFLT(x,a)                                                                                                                     \
                    ((x) < (a))
#define   IFGE(x,a)                                                                                                                     \
                    ((x) >= (a))
#define   IFGT(x,a)                                                                                                                     \
                    ((x) > (a))
#define   COND(condition,valeur_si_vrai,valeur_si_faux)                                                                                 \
                    ((condition) ? (valeur_si_vrai) : (valeur_si_faux))

#define   NEUT(x)                                                                                                                       \
                    (x)
#define   NEGA(x)                                                                                                                       \
                    SOUS(0,x)
#define   ABSO(x)                                                                                                                       \
                    COND(((x) > 0),NEUT(x),NEGA(x))

#define   MIN2(a,b)                                                                                                                     \
                    COND(((a) <= (b)),(a),(b))
#define   MAX2(a,b)                                                                                                                     \
                    COND(((a) >= (b)),(a),(b))

#define   gOUIN(a,b)                                                                                                                    \
                    ((a)|(b))
#define   gOUEX(a,b)                                                                                                                    \
                    ((a)^(b))
#define   gETLO(a,b)                                                                                                                    \
                    ((a)&(b))

#define   gDECD(a,b)                                                                                                                    \
                    ((a) >> (b))
#define   gDECG(a,b)                                                                                                                    \
                    ((a) << (b))

#define   gADD2(a,b)                                                                                                                    \
                    ((a)+(b))
#define   gSOUS(a,b)                                                                                                                    \
                    ((a)-(b))

#define   gMUL2(a,b)                                                                                                                    \
                    ((a)*(b))
#define   gDIVI(a,b)                                                                                                                    \
                    ((a)/(b))
#define   gREST(a,b)                                                                                                                    \
                    ((a)%(b))

#ifndef   dimXY
#         define    dimXY                                                                                                               \
                              (1024)                                                                                                    \
                                        /* La valeur par defaut est passee de 9000 a 1024 (format 'Sdu') le 20130607111456...        */
#else
#endif

#ifndef   nodefine_dimX
#         ifndef   dimX
                                        /* Introduit le 20131122152536 pour 'v $xrC/CompressionDeCompression.01$vv$I dimX'.          */
#                  define     dimX                                                                                                      \
                                        dimXY
#         else
#         endif
#else
#endif

#define   dimXs2                                                                                                                        \
                    gDIVI(dimX,2)
#define   Xmin                                                                                                                          \
                    0
#define   Xmax                                                                                                                          \
                    gADD2(Xmin,gSOUS(dimX,1))
#define   Xcentre                                                                                                                       \
                    gADD2(Xmin,gDIVI(dimX,2))

#ifndef   nodefine_dimY
#         ifndef   dimY
                                        /* Introduit le 20131122152536 pour 'v $xrC/CompressionDeCompression.01$vv$I dimY'.          */
#                  define     dimY                                                                                                      \
                                        dimXY
#         else
#         endif
#else
#endif

#define   dimYs2                                                                                                                        \
                    gDIVI(dimY,2)
#define   Ymin                                                                                                                          \
                    0
#define   Ymax                                                                                                                          \
                    gADD2(Ymin,gSOUS(dimY,1))
#define   Ycentre                                                                                                                       \
                    gADD2(Ymin,gDIVI(dimY,2))

#define   GDimImages                                                                                                                    \
                    gMUL2(dimX,dimY)                                                                                                    \
                                        /* Dimension introduit le 20140124144354...                                                  */

#ifndef   DimImages
#    define    DimImages                                                                                                                \
                         GDimImages                                                                                                     \
                                        /* Dimension introduit le 20130925144336...                                                  */
#else
#endif

int                 x,y;

#define   INITIALISATION_IMAGE(niveau)                                                                                                  \
                    {                                                                                                                   \
                    for       (y=Ymin ; y <= Ymax ; y=gADD2(y,1))                                                                       \
                              {                                                                                                         \
                              for       (x=Xmin ; x <= Xmax ; x=gADD2(x,1))                                                             \
                                        {                                                                                               \
                                        STORE_IMAGE_PLAN(x,y,niveau);                                                                   \
                                        }                                                                                               \
                              }                                                                                                         \
                    }

#ifndef   METHODE_CONVOLUTION_IMAGE_VIDE
                                        /* Test introduit le 20131220120248...                                                       */
#         ifndef    METHODE_CONVOLUTION_IMAGE_FLOU
#                   ifndef    METHODE_CONVOLUTION_IMAGE_PAVE
                                        /* Dispositif introduit le 20131218103316, l'initialisation par defaut ("PAVE") ci-dessous   */
                                        /* garantissant la compatibilite anterieure...                                               */
#                             define    METHODE_CONVOLUTION_IMAGE_PAVE
#                   else
#                   endif
#         else
#         endif
#else
#endif

#define   CONVOLUTION_IMAGE_VIDE                                                                                                        \
                    {                                                                                                                   \
                    }

#ifdef    METHODE_CONVOLUTION_IMAGE_FLOU
#    define    CONVOLUTION_IMAGE_FLOU                                                                                                   \
                         {                                                                                                              \
                         for       (y=Ymin ; y <= Ymax ; y=gADD2(y,1))                                                                  \
                                   {                                                                                                    \
                                   for       (x=Xmin ; x <= Xmax ; x=gADD2(x,1))                                                        \
                                             {                                                                                          \
                                             int       xp;                                                                              \
                                             int       yp;                                                                              \
                                             int       cumul=0;                                                                         \
                                             int       nombre=0;                                                                        \
                                             for       (yp=y ; yp <= (y+pave_Y-1) ; yp=gADD2(yp,1))                                     \
                                                       {                                                                                \
                                                       for       (xp=x ; xp <= (x+pave_X-1) ; xp=gADD2(xp,1))                           \
                                                                 {                                                                      \
                                                                 if        ((xp <= Xmax) && (yp <= Ymax))                               \
                                                                           {                                                            \
                                                                           cumul=ADD2(cumul,LOAD_IMAGE_PLAN_BIT_OCTET(xp,yp));          \
                                                                           nombre=ADD2(nombre,1);                                       \
                                                                           }                                                            \
                                                                 else                                                                   \
                                                                           {                                                            \
                                                                           }                                                            \
                                                                 }                                                                      \
                                                       }                                                                                \
                                                                                                                                        \
                                             cumul=DIVI(cumul,nombre);                                                                  \
                                        /* Calcul du niveau moyen dans le pave courant {pave_X,pave_Y}.                              */ \
                                                                                                                                        \
                                             STORE_IMAGE_PLAN(x,y,cumul);                                                               \
                                        /* On notera le 20131221081521 que :                                                         */ \
                                        /*                                                                                           */ \
                                        /*                  LOAD_IMAGE_PLAN_BIT_OCTET(...)                                           */ \
                                        /*                                                                                           */ \
                                        /* et :                                                                                      */ \
                                        /*                                                                                           */ \
                                        /*                  STORE_IMAGE_PLAN(...)                                                    */ \
                                        /*                                                                                           */ \
                                        /* n'utilisent qu'une seule image (de nom 'image') comme "source" et comme "destination"     */ \
                                        /* mais que cela ne presente aucun danger car, en effet, le point courant {x,y} est le       */ \
                                        /* sommet inferieur gauche du pave de convolution. Ainsi aucun des autres points de ce pave  */ \
                                        /* n'ont pas encore ete le sommet inferieur gauche d'un pave de convolution, cela viendra    */ \
                                        /* ensuite etant donne les variations des coordonnees {x,y}...                               */ \
                                        /*                                                                                           */ \
                                        /* On notera qu'il en aurait ete autrement si le point courant {x,y} avait ete, par exemple, */ \
                                        /* au centre du pave de convolution...                                                       */ \
                                             }                                                                                          \
                                   }                                                                                                    \
                         }
#else
#    define    CONVOLUTION_IMAGE_FLOU                                                                                                   \
                         {                                                                                                              \
                         }
#endif

#ifdef    METHODE_CONVOLUTION_IMAGE_PAVE
#    define   CONVOLUTION_IMAGE_PAVE                                                                                                    \
                                        /* Le nom 'CONVOLUTION_IMAGE' a ete change en 'CONVOLUTION_IMAGE_PAVE' le 20131218100556.    */ \
                         {                                                                                                              \
                         for       (y=Ymin ; y <= Ymax ; y=gADD2(y,pave_Y))                                                             \
                                   {                                                                                                    \
                                   for       (x=Xmin ; x <= Xmax ; x=gADD2(x,pave_X))                                                   \
                                             {                                                                                          \
                                             int       xp;                                                                              \
                                             int       yp;                                                                              \
                                             int       cumul=0;                                                                         \
                                             int       nombre=0;                                                                        \
                                             for       (yp=y ; yp <= (y+pave_Y-1) ; yp=gADD2(yp,1))                                     \
                                                       {                                                                                \
                                                       for       (xp=x ; xp <= (x+pave_X-1) ; xp=gADD2(xp,1))                           \
                                                                 {                                                                      \
                                                                 if        ((xp <= Xmax) && (yp <= Ymax))                               \
                                                                           {                                                            \
                                                                           cumul=ADD2(cumul,LOAD_IMAGE_PLAN_BIT_OCTET(xp,yp));          \
                                                                           nombre=ADD2(nombre,1);                                       \
                                                                           }                                                            \
                                                                 else                                                                   \
                                                                           {                                                            \
                                                                           }                                                            \
                                                                 }                                                                      \
                                                       }                                                                                \
                                                                                                                                        \
                                             cumul=DIVI(cumul,nombre);                                                                  \
                                        /* Calcul du niveau moyen dans le pave courant {pave_X,pave_Y}.                              */ \
                                                                                                                                        \
                                             for       (yp=y ; yp <= (y+pave_Y-1) ; yp=gADD2(yp,1))                                     \
                                                       {                                                                                \
                                                       for       (xp=x ; xp <= (x+pave_X-1) ; xp=gADD2(xp,1))                           \
                                                                 {                                                                      \
                                                                 if        ((xp <= Xmax) && (yp <= Ymax))                               \
                                                                           {                                                            \
                                                                           STORE_IMAGE_PLAN(xp,yp,cumul);                               \
                                                                           }                                                            \
                                                                 else                                                                   \
                                                                           {                                                            \
                                                                           }                                                            \
                                                                 }                                                                      \
                                                       }                                                                                \
                                             }                                                                                          \
                                   }                                                                                                    \
                         }
#else
#    define    CONVOLUTION_IMAGE_PAVE                                                                                                   \
                         {                                                                                                              \
                         }
#endif

#ifdef    METHODE_CONVOLUTION_IMAGE_PLAN
#    define   CONVOLUTION_IMAGE_PLAN                                                                                                    \
                                        /* Introduit le 20140313085157...                                                            */ \
                    {                                                                                                                   \
                    TypeImage masque=DECG(BIT,plan);                                                                                    \
                                                                                                                                        \
                    for       (y=Ymin ; y <= Ymax ; y=gADD2(y,1))                                                                       \
                              {                                                                                                         \
                              for       (x=Xmin ; x <= Xmax ; x=gADD2(x,1))                                                             \
                                        {                                                                                               \
                                        STORE_IMAGE_PLAN(x                                                                              \
                                                        ,y                                                                              \
                                                        ,COND(IFGT(ETLO(LOAD_IMAGE_PLAN_BIT_OCTET(x,y),masque),0),BLANC,NOIR)           \
                                                         );                                                                             \
                                        }                                                                                               \
                              }                                                                                                         \
                    }
#else
#    define    CONVOLUTION_IMAGE_PLAN                                                                                                   \
                         {                                                                                                              \
                         }
#endif

#ifndef   CONVOLUER_LE_FICHIER_IMAGE
#         define    CONVOLUTION_IMAGE                                                                                                   \
                              {                                                                                                         \
                              CONVOLUTION_IMAGE_VIDE;                                                                                   \
                              }
#else
#         define    CONVOLUTION_IMAGE                                                                                                   \
                              {                                                                                                         \
                              CONVOLUTION_IMAGE_FLOU;                                                                                   \
                              CONVOLUTION_IMAGE_PAVE;                                                                                   \
                              CONVOLUTION_IMAGE_PLAN;                                                                                   \
                              }
#endif

#define   TRANSFORMATION_IMAGE_VIDE                                                                                                     \
                    {                                                                                                                   \
                    }

#define   gXmin_effectif                                                                                                                \
                    MAX2(Xmin,Ymin)
#define   gXmax_effectif                                                                                                                \
                    MIN2(Xmax,Ymax)
#define   gYmin_effectif                                                                                                                \
                    MAX2(Xmin,Ymin)
#define   gYmax_effectif                                                                                                                \
                    MIN2(Xmax,Ymax)

#ifdef    METHODE_TRANSFORMATION_IMAGE_SYMETRIE_OX
#    define    TRANSFORMATION_IMAGE_SYMETRIE_OX                                                                                         \
                         {                                                                                                              \
                         int       Xmin_effectif=gXmin_effectif;                                                                        \
                         int       Xmax_effectif=gXmax_effectif;                                                                        \
                         int       Ymin_effectif=gYmin_effectif;                                                                        \
                         int       Ymax_effectif=gYmax_effectif;                                                                        \
                                                                                                                                        \
                         for       (y=Ymin_effectif ; y <= ((Ymax_effectif-Ymin_effectif)/2)+Ymin_effectif ; y=gADD2(y,1))              \
                                        /* Ainsi, on balaye la moitie horizontale du bas de l'image...                               */ \
                                   {                                                                                                    \
                                   for       (x=Xmin_effectif ; x <= Xmax_effectif ; x=gADD2(x,1))                                      \
                                             {                                                                                          \
                                             TypeImage niveau1=LOAD_IMAGE_PLAN_BIT_OCTET(x,y);                                          \
                                             TypeImage niveau2=LOAD_IMAGE_PLAN_BIT_OCTET(x,(Ymax_effectif-y)+Ymin_effectif);            \
                                             STORE_IMAGE_PLAN(x,y,niveau2);                                                             \
                                             STORE_IMAGE_PLAN(x,(Ymax_effectif-y)+Ymin_effectif,niveau1);                               \
                                             }                                                                                          \
                                   }                                                                                                    \
                         }
#else
#    define    TRANSFORMATION_IMAGE_SYMETRIE_OX                                                                                         \
                         {                                                                                                              \
                         }
#endif

#ifdef    METHODE_TRANSFORMATION_IMAGE_SYMETRIE_OY
#    define    TRANSFORMATION_IMAGE_SYMETRIE_OY                                                                                         \
                         {                                                                                                              \
                         int       Xmin_effectif=gXmin_effectif;                                                                        \
                         int       Xmax_effectif=gXmax_effectif;                                                                        \
                         int       Ymin_effectif=gYmin_effectif;                                                                        \
                         int       Ymax_effectif=gYmax_effectif;                                                                        \
                                                                                                                                        \
                         for       (y=Ymin_effectif ; y <= Ymax_effectif ; y=gADD2(y,1))                                                \
                                   {                                                                                                    \
                                   for       (x=Xmin_effectif ; x <= ((Xmax_effectif-Xmin_effectif)/2)+Xmin_effectif ; x=gADD2(x,1))    \
                                        /* Ainsi, on balaye la moitie verticale de gauche de l'image...                              */ \
                                             {                                                                                          \
                                             TypeImage niveau1=LOAD_IMAGE_PLAN_BIT_OCTET(x,y);                                          \
                                             TypeImage niveau2=LOAD_IMAGE_PLAN_BIT_OCTET((Xmax_effectif-x)+Xmin_effectif,y);            \
                                             STORE_IMAGE_PLAN(x,y,niveau2);                                                             \
                                             STORE_IMAGE_PLAN((Xmax_effectif-x)+Xmin_effectif,y,niveau1);                               \
                                             }                                                                                          \
                                   }                                                                                                    \
                         }
#else
#    define    TRANSFORMATION_IMAGE_SYMETRIE_OY                                                                                         \
                         {                                                                                                              \
                         }
#endif

#define   DEPLACEMENT_DE_L_IMAGE_TEMPORAIRE_1                                                                                           \
                    {                                                                                                                   \
                    for       (y=Ymin_effectif ; y <= Ymax_effectif ; y=gADD2(y,1))                                                     \
                              {                                                                                                         \
                              for       (x=Xmin_effectif ; x <= Xmax_effectif ; x=gADD2(x,1))                                           \
                                        {                                                                                               \
                                        STORE_IMAGE_PLAN(x                                                                              \
                                                        ,y                                                                              \
                                                        ,gLOAD_IMAGE_PLAN_BIT_OCTET(imageT1,x,y)                                        \
                                                         );                                                                             \
                                        }                                                                                               \
                              }                                                                                                         \
                    }

#ifdef    METHODE_TRANSFORMATION_IMAGE_ROTATION_pPIs2
#    define    TRANSFORMATION_IMAGE_ROTATION_pPIs2                                                                                      \
                         {                                                                                                              \
                         IMAGE_TEMPORAIRE_1;                                                                                            \
                                                                                                                                        \
                         int       Xmin_effectif=gXmin_effectif;                                                                        \
                         int       Xmax_effectif=gXmax_effectif;                                                                        \
                         int       Ymin_effectif=gYmin_effectif;                                                                        \
                         int       Ymax_effectif=gYmax_effectif;                                                                        \
                                                                                                                                        \
                         for       (y=Ymin_effectif ; y <= Ymax_effectif ; y=gADD2(y,1))                                                \
                                   {                                                                                                    \
                                   for       (x=Xmin_effectif ; x <= Xmax_effectif ; x=gADD2(x,1))                                      \
                                             {                                                                                          \
                                             gSTORE_IMAGE_PLAN(imageT1                                                                  \
                                                              ,(Ymax_effectif-y)+Ymin_effectif                                          \
                                                              ,x                                                                        \
                                                              ,LOAD_IMAGE_PLAN_BIT_OCTET(x,y)                                           \
                                                               );                                                                       \
                                        /* Multiplication par le nombre complexe '0+i.1' soit une rotation de +pi/2 ("Plus").        */ \
                                             }                                                                                          \
                                   }                                                                                                    \
                                                                                                                                        \
                         DEPLACEMENT_DE_L_IMAGE_TEMPORAIRE_1;                                                                           \
                         }
#else
#    define    TRANSFORMATION_IMAGE_ROTATION_pPIs2                                                                                      \
                         {                                                                                                              \
                         }
#endif

#ifdef    METHODE_TRANSFORMATION_IMAGE_ROTATION_PI
#    define    TRANSFORMATION_IMAGE_ROTATION_PI                                                                                         \
                         {                                                                                                              \
                         IMAGE_TEMPORAIRE_1;                                                                                            \
                                                                                                                                        \
                         int       Xmin_effectif=gXmin_effectif;                                                                        \
                         int       Xmax_effectif=gXmax_effectif;                                                                        \
                         int       Ymin_effectif=gYmin_effectif;                                                                        \
                         int       Ymax_effectif=gYmax_effectif;                                                                        \
                                                                                                                                        \
                         for       (y=Ymin_effectif ; y <= Ymax_effectif ; y=gADD2(y,1))                                                \
                                   {                                                                                                    \
                                   for       (x=Xmin_effectif ; x <= Xmax_effectif ; x=gADD2(x,1))                                      \
                                             {                                                                                          \
                                             gSTORE_IMAGE_PLAN(imageT1                                                                  \
                                                              ,(Xmax_effectif-x)+Xmin_effectif                                          \
                                                              ,(Ymax_effectif-y)+Ymin_effectif                                          \
                                                              ,LOAD_IMAGE_PLAN_BIT_OCTET(x,y)                                           \
                                                               );                                                                       \
                                        /* Multiplication par le nombre complexe '-1+i.0' soit une rotation de pi.                   */ \
                                             }                                                                                          \
                                   }                                                                                                    \
                                                                                                                                        \
                         DEPLACEMENT_DE_L_IMAGE_TEMPORAIRE_1;                                                                           \
                         }
#else
#    define    TRANSFORMATION_IMAGE_ROTATION_PI                                                                                         \
                         {                                                                                                              \
                         }
#endif

#ifdef    METHODE_TRANSFORMATION_IMAGE_ROTATION_mPIs2
#    define    TRANSFORMATION_IMAGE_ROTATION_mPIs2                                                                                      \
                         {                                                                                                              \
                         IMAGE_TEMPORAIRE_1;                                                                                            \
                                                                                                                                        \
                         int       Xmin_effectif=gXmin_effectif;                                                                        \
                         int       Xmax_effectif=gXmax_effectif;                                                                        \
                         int       Ymin_effectif=gYmin_effectif;                                                                        \
                         int       Ymax_effectif=gYmax_effectif;                                                                        \
                                                                                                                                        \
                         for       (y=Ymin_effectif ; y <= Ymax_effectif ; y=gADD2(y,1))                                                \
                                   {                                                                                                    \
                                   for       (x=Xmin_effectif ; x <= Xmax_effectif ; x=gADD2(x,1))                                      \
                                             {                                                                                          \
                                             gSTORE_IMAGE_PLAN(imageT1                                                                  \
                                                              ,y                                                                        \
                                                              ,(Xmax_effectif-x)+Xmin_effectif                                          \
                                                              ,LOAD_IMAGE_PLAN_BIT_OCTET(x,y)                                           \
                                                               );                                                                       \
                                        /* Multiplication par le nombre complexe '0-i.1' soit une rotation de -pi/2 ("Moins").       */ \
                                             }                                                                                          \
                                   }                                                                                                    \
                                                                                                                                        \
                         DEPLACEMENT_DE_L_IMAGE_TEMPORAIRE_1;                                                                           \
                         }
#else
#    define    TRANSFORMATION_IMAGE_ROTATION_mPIs2                                                                                      \
                         {                                                                                                              \
                         }
#endif

#ifdef    METHODE_TRANSFORMATION_IMAGE_TRANSPOSITION
#    define    TRANSFORMATION_IMAGE_TRANSPOSITION                                                                                       \
                         {                                                                                                              \
                         int       Xmin_effectif=gXmin_effectif;                                                                        \
                         int       Xmax_effectif=gXmax_effectif;                                                                        \
                         int       Ymin_effectif=gYmin_effectif;                                                                        \
                         int       Ymax_effectif=gYmax_effectif;                                                                        \
                                                                                                                                        \
                         for       (y=Ymin_effectif ; y <= Ymax_effectif ; y=gADD2(y,1))                                                \
                                   {                                                                                                    \
                                   for       (x=Xmin_effectif ; x <= (y-Ymin_effectif)+Xmin_effectif ; x=gADD2(x,1))                    \
                                        /* Ainsi, on balaye le triangle inferieur (en partant de l'origine...).                      */ \
                                             {                                                                                          \
                                             TypeImage niveau1=LOAD_IMAGE_PLAN_BIT_OCTET(x,y);                                          \
                                             TypeImage niveau2=LOAD_IMAGE_PLAN_BIT_OCTET(y,x);                                          \
                                             STORE_IMAGE_PLAN(x,y,niveau2);                                                             \
                                             STORE_IMAGE_PLAN(y,x,niveau1);                                                             \
                                             }                                                                                          \
                                   }                                                                                                    \
                         }
#else
#    define    TRANSFORMATION_IMAGE_TRANSPOSITION                                                                                       \
                         {                                                                                                              \
                         }
#endif

#ifndef   TRANSFORMER_LE_FICHIER_IMAGE
#         define    TRANSFORMATION_IMAGE                                                                                                \
                              {                                                                                                         \
                              TRANSFORMATION_IMAGE_VIDE;                                                                                \
                              }
#else
#         define    TRANSFORMATION_IMAGE                                                                                                \
                              {                                                                                                         \
                              TRANSFORMATION_IMAGE_SYMETRIE_OX;                                                                         \
                              TRANSFORMATION_IMAGE_SYMETRIE_OY                                                                          \
                              TRANSFORMATION_IMAGE_ROTATION_pPIs2;                                                                      \
                              TRANSFORMATION_IMAGE_ROTATION_PI;                                                                         \
                              TRANSFORMATION_IMAGE_ROTATION_mPIs2;                                                                      \
                              TRANSFORMATION_IMAGE_TRANSPOSITION;                                                                       \
                              }
#endif

#ifndef   GENERER_DES_FONCTIONS
#         define    OUIN(a,b)                                                                                                           \
                              gOUIN(a,b)
#         define    OUEX(a,b)                                                                                                           \
                              gOUEX(a,b)
#         define    ETLO(a,b)                                                                                                           \
                              gETLO(a,b)

#         define    DECD(a,b)                                                                                                           \
                              gDECD(a,b)
#         define    DECG(a,b)                                                                                                           \
                              gDECG(a,b)

#         define    ADD2(a,b)                                                                                                           \
                              gADD2(a,b)
#         define    SOUS(a,b)                                                                                                           \
                              gSOUS(a,b)

#         define    MUL2(a,b)                                                                                                           \
                              gMUL2(a,b)
#         define    DIVI(a,b)                                                                                                           \
                              gDIVI(a,b)
#         define    REST(a,b)                                                                                                           \
                              gREST(a,b)

#         define    ADD2f(a,b)                                                                                                          \
                              gADD2(a,b)
#         define    SOUSf(a,b)                                                                                                          \
                              gSOUS(a,b)

#         define    MUL2f(a,b)                                                                                                          \
                              gMUL2(a,b)
#         define    DIVIf(a,b)                                                                                                          \
                              gDIVI(a,b)
#         define    RESTf(a,b)                                                                                                          \
                              gREST(a,b)

#         define    EDITER_LES_COMPTEURS_DES_FONCTIONS
#else
#         define    FONCTION(nom,type,operateur,compteur)                                                                               \
                              long      int       compteur=0;                                                                           \
                              type                nom(type x,type y)                                                                    \
                                                  {                                                                                     \
                                                  compteur++;                                                                           \
                                                  return(operateur(x,y));                                                               \
                                                  }

          FONCTION(OUIN,long int,gOUIN,compteur_OUIN)
          FONCTION(OUEX,long int,gOUEX,compteur_OUEX)
          FONCTION(ETLO,long int,gETLO,compteur_ETLO)

          FONCTION(DECD,long int,gDECD,compteur_DECD)
          FONCTION(DECG,long int,gDECG,compteur_DECG)

          FONCTION(ADD2,long int,gADD2,compteur_ADD2)
          FONCTION(SOUS,long int,gSOUS,compteur_SOUS)
          FONCTION(MUL2,long int,gMUL2,compteur_MUL2)
          FONCTION(DIVI,long int,gDIVI,compteur_DIVI)
          FONCTION(REST,long int,gREST,compteur_REST)

          FONCTION(ADD2f,double,gADD2,compteur_ADD2f)
          FONCTION(SOUSf,double,gSOUS,compteur_SOUSf)
          FONCTION(MUL2f,double,gMUL2,compteur_MUL2f)
          FONCTION(DIVIf,double,gDIVI,compteur_DIVIf)

#         ifndef    NE_PAS_SORTIR_LE_FICHIER_IMAGE
#                   define    EDITER_LES_COMPTEURS_DES_FONCTIONS
#         else
#                   define    EDITER_LES_COMPTEURS_DES_FONCTIONS                                                                        \
                                        {                                                                                               \
                                        printf("OUIN=%ld\n",compteur_OUIN);                                                             \
                                        printf("OUEX=%ld\n",compteur_OUEX);                                                             \
                                        printf("ETLO=%ld\n",compteur_ETLO);                                                             \
                                        printf("DECD=%ld\n",compteur_DECD);                                                             \
                                        printf("DECG=%ld\n",compteur_DECG);                                                             \
                                        printf("ADD2=%ld\n",compteur_ADD2+compteur_ADD2f);                                              \
                                        printf("SOUS=%ld\n",compteur_SOUS+compteur_SOUSf);                                              \
                                        printf("MUL2=%ld\n",compteur_MUL2+compteur_MUL2f);                                              \
                                        printf("DIVI=%ld\n",compteur_DIVI+compteur_DIVIf);                                              \
                                        printf("REST=%ld\n",compteur_REST);                                                             \
                                        printf("OperationsElementaires=%ld\n"                                                           \
                                              ,compteur_OUIN+compteur_OUEX+compteur_ETLO                                                \
                                              +compteur_DECD+compteur_DECG                                                              \
                                              +compteur_ADD2+compteur_SOUS+compteur_MUL2+compteur_DIVI+compteur_REST                    \
                                              +compteur_ADD2f+compteur_SOUSf+compteur_MUL2f+compteur_DIVIf                              \
                                               );                                                                                       \
                                        }
#         endif
#endif

#ifdef    NE_PAS_GENERER_SOUS_MAIN
                                        /* Introduit le 20130607094036 afin de permettre l'usage de '/usr/bin/valgrind'...           */
#         define    MAIN(sequence)                                                                                                      \
                              int       main()                                                                                          \
                                        {                                                                                               \
                                        sequence                                                                                        \
                                        }                                                                                               \
                                        /* Definition du 'main(...)' standard.                                                       */ \
                                        /*                                                                                           */ \
                                        /* TRES IMPORTANT : l'argument 'sequence' de la procedure 'MAIN(...)' ne doit evidemment     */ \
                                        /* pas contenir de virgules, sauf a l'interieur de couples de parentheses. C'est pourquoi    */ \
                                        /* les declarations (qui sont semble-t-il les seules structures a poser probleme) du type :  */ \
                                        /*                                                                                           */ \
                                        /*                  int       variable1,variable2;                                           */ \
                                        /*                                                                                           */ \
                                        /* devront etre remplacees par :                                                             */ \
                                        /*                                                                                           */ \
                                        /*                  int       variable1;                                                     */ \
                                        /*                  int       variable2;                                                     */ \
                                        /*                                                                                           */ \
                                        /* alors que :                                                                               */ \
                                        /*                                                                                           */ \
                                        /*                  fonction(argument1,arguments2);                                          */ \
                                        /*                                                                                           */ \
                                        /* sera autorise...                                                                          */
#else
#         define    MAIN(sequence)                                                                                                      \
                              void      FonctionPrivee_sous_main()                                                                      \
                                        {                                                                                               \
                                        sequence                                                                                        \
                                        }                                                                                               \
                              int       main()                                                                                          \
                                        {                                                                                               \
                                        FonctionPrivee_sous_main();                                                                     \
                                        return(OK);                                                                                     \
                                        }                                                                                               \
                                        /* Definition du 'main(...)' avec un UNIQUE appel a 'FonctionPrivee_sous_main(...)' qui      */ \
                                        /* contient le code "prive" et qui ne contiendra donc pas (en binaire) les appels aux        */ \
                                        /* fonctions systeme que l'on ne maitrise pas et qui eux sont dans 'main(...)'.              */
#endif




Copyright © Jean-François Colonna, 2013-2021.
Copyright © CMAP (Centre de Mathématiques APpliquées) UMR CNRS 7641 / Ecole Polytechnique, 2013-2021.