Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void Shuffle(unsigned char R[WIDTH][HEIGHT], unsigned char G[WIDTH][HEIGHT], unsigned char B[WIDTH][HEIGHT])
  2. {
  3.   srand (time(NULL));
  4.   int x, y;
  5.   int r_temp, g_temp, b_temp;
  6.   int x_block, y_block;
  7.   int x_temp, y_temp;
  8.  
  9.   for (y = 0; y < (HEIGHT/SHUFF_HEIGHT_DIV - 1); y++)
  10.   {
  11.     for (x = 0; x < (WIDTH/SHUFF_WIDTH_DIV - 1); x++)
  12.     {
  13.       if ((x == 0) && (y == 0))
  14.       {
  15.         x_block = (rand () % 4) + 1;
  16.         y_block = (rand () % 4) + 1;
  17.       } /*end randomizing if block*/
  18.  
  19.       for (y_temp = y_block*(HEIGHT/SHUFF_HEIGHT_DIV); y_temp < ((y_block + 1)*(HEIGHT/SHUFF_HEIGHT_DIV)) - 1; y_temp++)
  20.       {
  21.         for (x_temp = x_block*(WIDTH/SHUFF_WIDTH_DIV); x_temp < ((x_block + 1)*(WIDTH/SHUFF_WIDTH_DIV)) - 1; x_temp++)
  22.         {
  23.           r_temp = R[x][y];
  24.           g_temp = G[x][y];
  25.           b_temp = B[x][y];
  26.  
  27.           R[x][y] = R[x_temp][y_temp];
  28.           G[x][y] = G[x_temp][y_temp];
  29.           B[x][y] = B[x_temp][y_temp];
  30.  
  31.           R[x_temp][y_temp] = r_temp;
  32.           G[x_temp][y_temp] = g_temp;
  33.           B[x_temp][y_temp] = b_temp;
  34.         }/*end x_temp counting block*/
  35.       }/*end y_temp block*/
  36.     } /*end x counting block*/
  37.   } /*end y counting block*/
  38.  
  39.   for (y = HEIGHT/SHUFF_HEIGHT_DIV; y < 2*(HEIGHT/SHUFF_HEIGHT_DIV) - 1; y++)
  40.   {
  41.     for (x = WIDTH/SHUFF_WIDTH_DIV; x < 2*(WIDTH/SHUFF_WIDTH_DIV) - 1; x++)
  42.     {
  43.       if ((x == WIDTH/SHUFF_WIDTH_DIV) && (y == HEIGHT/SHUFF_HEIGHT_DIV))
  44.       {
  45.         x_block = (rand () % 4) + 1;
  46.         y_block = (rand () % 4) + 1;
  47.       } /*end randomizing if block*/
  48.  
  49.       for (y_temp = y_block*(HEIGHT/SHUFF_HEIGHT_DIV); y_temp < ((y_block + 1)*(HEIGHT/SHUFF_HEIGHT_DIV)) - 1; y_temp++)
  50.       {
  51.         for (x_temp = x_block*(WIDTH/SHUFF_WIDTH_DIV); x_temp < ((x_block + 1)*(WIDTH/SHUFF_WIDTH_DIV)) - 1; x_temp++)
  52.         {
  53.           r_temp = R[x][y];
  54.           g_temp = G[x][y];
  55.           b_temp = B[x][y];
  56.  
  57.           R[x][y] = R[x_temp][y_temp];
  58.           G[x][y] = G[x_temp][y_temp];
  59.           B[x][y] = B[x_temp][y_temp];
  60.  
  61.           R[x_temp][y_temp] = r_temp;
  62.           G[x_temp][y_temp] = g_temp;
  63.           B[x_temp][y_temp] = b_temp;
  64.         }/*end x_temp counting block*/
  65.       }/*end y_temp block*/
  66.     } /*end x counting block*/
  67.   } /*end y counting block*/
  68.  
  69.   for (y = 2*(HEIGHT/SHUFF_HEIGHT_DIV); y < 3*(HEIGHT/SHUFF_HEIGHT_DIV) - 1; y++)
  70.   {
  71.     for (x = 2*(WIDTH/SHUFF_WIDTH_DIV); x < 3*(WIDTH/SHUFF_WIDTH_DIV) - 1; x++)
  72.     {
  73.       if ((x == 2*(WIDTH/SHUFF_WIDTH_DIV)) && (y == 2*(HEIGHT/SHUFF_HEIGHT_DIV)))
  74.       {
  75.         x_block = (rand () % 4) + 1;
  76.         y_block = (rand () % 4) + 1;
  77.       } /*end randomizing if block*/
  78.  
  79.       for (y_temp = y_block*(HEIGHT/SHUFF_HEIGHT_DIV); y_temp < ((y_block + 1)*(HEIGHT/SHUFF_HEIGHT_DIV)) - 1; y_temp++)
  80.       {
  81.         for (x_temp = x_block*(WIDTH/SHUFF_WIDTH_DIV); x_temp < ((x_block + 1)*(WIDTH/SHUFF_WIDTH_DIV)) - 1; x_temp++)
  82.         {
  83.           r_temp = R[x][y];
  84.           g_temp = G[x][y];
  85.           b_temp = B[x][y];
  86.  
  87.           R[x][y] = R[x_temp][y_temp];
  88.           G[x][y] = G[x_temp][y_temp];
  89.           B[x][y] = B[x_temp][y_temp];
  90.  
  91.           R[x_temp][y_temp] = r_temp;
  92.           G[x_temp][y_temp] = g_temp;
  93.           B[x_temp][y_temp] = b_temp;
  94.         }/*end x_temp counting block*/
  95.       }/*end y_temp block*/
  96.     } /*end x counting block*/
  97.   } /*end y counting block*/
  98.  
  99.   for (y = 3*(HEIGHT/SHUFF_HEIGHT_DIV); y < HEIGHT; y++)
  100.   {
  101.     for (x = 3*(WIDTH/SHUFF_WIDTH_DIV); x < WIDTH; x++)
  102.     {
  103.       if ((x == 3*(WIDTH/SHUFF_WIDTH_DIV)) && (y == 3*(HEIGHT/SHUFF_HEIGHT_DIV)))
  104.       {
  105.         x_block = (rand () % 4) + 1;
  106.         y_block = (rand () % 4) + 1;
  107.       } /*end randomizing if block*/
  108.  
  109.       for (y_temp = y_block*(HEIGHT/SHUFF_HEIGHT_DIV); y_temp < ((y_block + 1)*(HEIGHT/SHUFF_HEIGHT_DIV)) - 1; y_temp++)
  110.       {
  111.         for (x_temp = x_block*(WIDTH/SHUFF_WIDTH_DIV); x_temp < ((x_block + 1)*(WIDTH/SHUFF_WIDTH_DIV)) - 1; x_temp++)
  112.         {
  113.           r_temp = R[x][y];
  114.           g_temp = G[x][y];
  115.           b_temp = B[x][y];
  116.  
  117.           R[x][y] = R[x_temp][y_temp];
  118.           G[x][y] = G[x_temp][y_temp];
  119.           B[x][y] = B[x_temp][y_temp];
  120.  
  121.           R[x_temp][y_temp] = r_temp;
  122.           G[x_temp][y_temp] = g_temp;
  123.          B[x_temp][y_temp] = b_temp;
  124.         }/*end x_temp counting block*/
  125.       }/*end y_temp block*/
  126.     } /*end x counting block*/
  127.   } /*end y counting block*/
  128.   printf("Shuffle is done!\n");
  129. }/*end of Shuffle operation*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement