Advertisement
xerpi

RGBA to 4x4RGBA

Jan 28th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.37 KB | None | 0 0
  1. /*by xerpi*/
  2.  
  3. void pngx_RGBAto4X4RGBA(uint8_t *srcBuff, uint8_t *dstBuff, uint32_t buffWidth, uint32_t buffHeight)
  4. {
  5.     //RGBA format: 0xRRGGBBAA
  6.    
  7.     /*
  8.     AARRAARR AARRAARR AARRAARR AARRAARR
  9.     AARRAARR AARRAARR AARRAARR AARRAARR
  10.     GGBBGGBB GGBBGGBB GGBBGGBB GGBBGGBB
  11.     GGBBGGBB GGBBGGBB GGBBGGBB GGBBGGBB
  12.     */
  13.     uint8_t *src = srcBuff;
  14.     uint8_t *dst = dstBuff;
  15.     uint32_t y, x, i, j;
  16.     uint8_t *block;
  17.    
  18.     for(y = 0;  y < buffHeight; y+=4)
  19.     {
  20.         for(x = 0; x < buffWidth; x+=4)
  21.         {
  22.             for(i = 0; i < 4; i++)
  23.             {  
  24.                 for(j = 0; j < 4; j++)
  25.                 {  
  26.                     block = src + ((x + j) + (y + i) * buffWidth) * 4; 
  27.                     *(dst     ) = *(block + 3);  //Alpha
  28.                     *(dst + 32) = *(block + 1);  //Green
  29.                     dst++;
  30.                     *(dst     ) = *(block);      //Red
  31.                     *(dst + 32) = *(block + 2);  //Blue
  32.                     dst++;
  33.                 }
  34.             }
  35.             dst+=32;
  36.         }  
  37.     }
  38.    
  39.     /*for(y = 0;  y < buffHeight; y+=4)
  40.     {
  41.         for(x = 0; x < buffWidth; x+=4)
  42.         {  
  43.             for(i = 0; i < 4; i++)
  44.             {  
  45.                 for(j = 0; j < 4; j++)
  46.                 {  
  47.                     block = *(uint32_t *)(src + ((x + j) + ((y + i) * buffWidth)) * 4);
  48.                     *(dst++) = (block) & 0xFF;
  49.                     *(dst++) = (block>>24) & 0xFF;
  50.                 }
  51.             }
  52.             for(i = 0; i < 4; i++)
  53.             {  
  54.                 for(j = 0; j < 4; j++)
  55.                 {
  56.                     block = *(uint32_t *)(src + ((x + j) + ((y + i) * buffWidth)) * 4);
  57.                     *(dst++) = (block>>16) & 0xFF;
  58.                     *(dst++) = (block>>8) & 0xFF;
  59.                 }
  60.             }
  61.         }
  62.     }*/
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement