Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.09 KB | None | 0 0
  1. void ImageToTile2bppPlanar(Image &img, int sx, int sy, u8 *dest)
  2. {
  3.     // look up table that turns palette into snes values
  4.     static u8 lut[16] = {0, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0};
  5.  
  6.     for(int y = 0; y < 8; y++)
  7.     {
  8.         u8 row[2] = {0,0};
  9.         for(int x = 0; x < 8; x++)
  10.         {
  11.             row[0] <<= 1;
  12.             row[1] <<= 1;
  13.             u8 p = lut[img.GetPixelAt(x + sx, y + sy)];
  14.             row[0] |= p&1;
  15.             row[1] |= p>>1;
  16.         }
  17.         dest[0] = row[0];
  18.         dest[1] = row[1];
  19.         dest+=2;
  20.     }
  21. }
  22.  
  23. void DrawKernelData(LPCTSTR in_name, LPCTSTR out_name, LPCTSTR tile_name, int tile_count, int skip = 0)
  24. {
  25.     extern u8 vwf_tbl8[], vwf_tbl8_1[];
  26.     u8 buffer[4096];
  27.     CText text(in_name);
  28.     int count=text.GetCount();
  29.  
  30.     Image canvas, font, fontt;
  31.  
  32.     font.LoadFromFile(font8_name);
  33.     fontt.LoadFromFile(font8t_name);
  34.     canvas.Create(tile_count * 8, count * 8, 4, font.palette);
  35.  
  36.     for(int y = 0, sy = canvas.height; y < sy; y++)
  37.         for(int x = 0, sx = canvas.width; x < sx; x++)
  38.             canvas.SetPixelAt(x, y, 1);
  39.  
  40.     // parse and draw
  41.     for(int i=0; i<count; i++)
  42.     {
  43.         int size=EncodeString(text.GetString(i),buffer);
  44.  
  45.         if( size == skip) continue;
  46.  
  47.         int x = 0;
  48.         for(int j = skip;; j++)
  49.         {
  50.             u8 ch = buffer[j];
  51.             if(ch == 0) break;
  52.             ch -= 0x40;
  53.             x += vwf_tbl8[ch];
  54.         }
  55.  
  56.         if(x > tile_count * 8)
  57.         {
  58.             x = 0;
  59.             for(int j = skip;; j++)
  60.             {
  61.                 u8 ch = buffer[j];
  62.                 if(ch == 0) break;
  63.                 ch -= 0x40;
  64.                 canvas.BitBlit(&fontt, (ch % 16) * 8, (ch / 16) * 8, 8, 8, x, i * 8, Image::dir_normal);
  65.                 x += vwf_tbl8_1[ch];
  66.             }
  67.         }
  68.         else
  69.         {
  70.             x = 0;
  71.             for(int j = skip;; j++)
  72.             {
  73.                 u8 ch = buffer[j];
  74.                 if(ch == 0) break;
  75.                 ch -= 0x40;
  76.                 canvas.BitBlit(&font, (ch % 16) * 8, (ch / 16) * 8, 8, 8, x, i * 8, Image::dir_normal);
  77.                 x += vwf_tbl8[ch];
  78.             }
  79.         }
  80.  
  81.        
  82.     }
  83.  
  84.     canvas.SaveBitmap(out_name);
  85.  
  86.     u8 *dest = new u8[tile_count * 16 * count]; // allocate enough 2BPP tiles
  87.     u8 *dd = dest;
  88.     for(int i = 0; i < count; i++)
  89.         for(int j = 0; j < tile_count; j++, dd += 16)
  90.             ImageToTile2bppPlanar(canvas, j * 8, i * 8, dd);
  91.     FlushFile(tile_name, dest, tile_count * 16 * count);
  92.     delete[] dest;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement