Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.67 KB | None | 0 0
  1. void charToPixel(int tab[], int w, Char c, int pTab[])
  2. {
  3.   int m = c.w;
  4.   if(m < c.h)
  5.   {
  6.     m = c.h;
  7.   }
  8.  
  9.   int cTab[m*m];
  10.  
  11.   squareBorder(tab, w, cTab, c, m);
  12.   properSquare(cTab, m, pTab);
  13.  
  14. }
  15.  
  16. void squareBorder(int tab[], int w, int cTab[], Char c, int m)
  17. {
  18.   if(m == c.h)
  19.   {
  20.     int nbWhCol = (m - c.w) /2;
  21.  
  22.     for(int x = 0; x < m; x++)
  23.     {
  24.       for(int y = 0; y < m; y++)
  25.       {
  26.         if(x < nbWhCol || x > (nbWhCol + c.w))
  27.         {
  28.           cTab[(y*m)+x] = 0;
  29.         }
  30.         else
  31.         {
  32.           cTab[(y*m)+x] = tab[((y+c.y)*w)+(x+c.x)];
  33.         }
  34.       }
  35.     }
  36.   }
  37.   else
  38.   {
  39.     int nbWhRow = (m - c.h) /2;
  40.  
  41.     for(int y = 0; y < m; y++)
  42.     {
  43.       for(int x = 0; x < m; x++)
  44.       {
  45.         if(y < nbWhRow || y > (nbWhRow + c.h))
  46.         {
  47.           cTab[(y*m)+x] = 0;
  48.         }
  49.         else
  50.         {
  51.           cTab[(y*m)+x] = tab[((y+c.y)*w)+(x+c.x)];
  52.         }
  53.       }
  54.     }
  55.   }
  56. }
  57.  
  58. void properSquare(int cTab[], int m, int pTab[])
  59. {
  60.   int s = 16; //Taille pTab
  61.   int t = s*m; //Taille tempTab
  62.   int tempTab[t*t];
  63.  
  64.   for(int x = 0; x < t; x++)
  65.   {
  66.     for(int y = 0; y < t; y++)
  67.     {
  68.       tempTab[x*t + y] = cTab[(x/s)*m + (y/s)];
  69.     }
  70.   }
  71.  
  72.   for(int x = 0; x < s; x++)
  73.   {
  74.     for(int y = 0; y < s; y++)
  75.     {
  76.       int nbB = 0;
  77.       int nbW = 0;
  78.  
  79.       for(int i = 0; i < m; i++)
  80.       {
  81.         for(int j = 0; j < m; j++)
  82.         {
  83.           if(tempTab[(x*m + i)*m + (y*m + j)])
  84.             nbB++;
  85.           else
  86.             nbW++;
  87.         }
  88.       }
  89.  
  90.       if(nbW > nbB)
  91.       {
  92.         pTab[x*s+y] = 0;
  93.       }
  94.       else
  95.       {
  96.         pTab[x*s+y] = 1;
  97.       }
  98.     }
  99.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement