
unsigned char * reversesprite( const unsigned char * spritein,int br_x , int br_y)
{

if(spritein == NULL)return NULL;

    int taille, lx , decalage;

    unsigned char transit;
    unsigned char out;

    unsigned char * spriteout;

        decalage = size_x % 8;

    if(decalage == 0)lx = size_x/8;//Calcul la taille en octets de l'image.
    else lx = (size_x/8) + 1;

    taille = lx * size_y;

    this->spriteout = (unsigned char*) malloc(sizeof(unsigned char) * taille);//Alloue l'espace mmoire, ne pas oublier de librer  la fin du programme.

        for(int i = 0 ; i < size_y ; i++)
          for(int a = 0; a < lx; a++)
            spriteout[i * lx + a] = spritein[ (i +1)*lx - (a+1)]; //Copie l'image en inversant l'ordre des octets de chaques lignes.

        for(int i = 0; i < taille ; i++) //Applique l'effet miroir aux octets.
         {
             transit = spriteout[i];
             out = 0x0;
             if((transit & 0x80) != 0x0)  out = out | 0x01;
             if((transit & 0x40) != 0x0)  out = out | 0x02;
             if((transit & 0x20) != 0x0)  out = out | 0x04;
             if((transit & 0x10) != 0x0)  out = out | 0x08;
             if((transit & 0x08) != 0x0)   out = out | 0x10;
             if((transit & 0x04) != 0x0)   out = out | 0x20;
             if((transit & 0x02) != 0x0)   out = out | 0x40;
             if((transit & 0x01) != 0x0)   out = out | 0x80;

             spriteout[i] = out;

         }

    if(decalage != 0) //Replace l'image correctement et enlve le surplus de pixel noir qui se trouve  la fin.
    {
         for(int i = 0 ; i < size_y ; i++)
            for(int a = 0; a < lx; a++)
            {
                transit = ((unsigned char)spriteout[i * lx + a] >> ( decalage));

                spriteout[i * lx + a] = ((unsigned char)spriteout[i * lx + a] << ( 8 - decalage));

                if(a != 0)spriteout[i * lx + a - 1] = spriteout[i * lx + a - 1] | transit;
            }

    }

return spriteout; //Retourne le pointeur.

}

