Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void ImageToTile2bppPlanar(Image &img, int sx, int sy, u8 *dest)
- {
- // look up table that turns palette into snes values
- static u8 lut[16] = {0, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0};
- for(int y = 0; y < 8; y++)
- {
- u8 row[2] = {0,0};
- for(int x = 0; x < 8; x++)
- {
- row[0] <<= 1;
- row[1] <<= 1;
- u8 p = lut[img.GetPixelAt(x + sx, y + sy)];
- row[0] |= p&1;
- row[1] |= p>>1;
- }
- dest[0] = row[0];
- dest[1] = row[1];
- dest+=2;
- }
- }
- void DrawKernelData(LPCTSTR in_name, LPCTSTR out_name, LPCTSTR tile_name, int tile_count, int skip = 0)
- {
- extern u8 vwf_tbl8[], vwf_tbl8_1[];
- u8 buffer[4096];
- CText text(in_name);
- int count=text.GetCount();
- Image canvas, font, fontt;
- font.LoadFromFile(font8_name);
- fontt.LoadFromFile(font8t_name);
- canvas.Create(tile_count * 8, count * 8, 4, font.palette);
- for(int y = 0, sy = canvas.height; y < sy; y++)
- for(int x = 0, sx = canvas.width; x < sx; x++)
- canvas.SetPixelAt(x, y, 1);
- // parse and draw
- for(int i=0; i<count; i++)
- {
- int size=EncodeString(text.GetString(i),buffer);
- if( size == skip) continue;
- int x = 0;
- for(int j = skip;; j++)
- {
- u8 ch = buffer[j];
- if(ch == 0) break;
- ch -= 0x40;
- x += vwf_tbl8[ch];
- }
- if(x > tile_count * 8)
- {
- x = 0;
- for(int j = skip;; j++)
- {
- u8 ch = buffer[j];
- if(ch == 0) break;
- ch -= 0x40;
- canvas.BitBlit(&fontt, (ch % 16) * 8, (ch / 16) * 8, 8, 8, x, i * 8, Image::dir_normal);
- x += vwf_tbl8_1[ch];
- }
- }
- else
- {
- x = 0;
- for(int j = skip;; j++)
- {
- u8 ch = buffer[j];
- if(ch == 0) break;
- ch -= 0x40;
- canvas.BitBlit(&font, (ch % 16) * 8, (ch / 16) * 8, 8, 8, x, i * 8, Image::dir_normal);
- x += vwf_tbl8[ch];
- }
- }
- }
- canvas.SaveBitmap(out_name);
- u8 *dest = new u8[tile_count * 16 * count]; // allocate enough 2BPP tiles
- u8 *dd = dest;
- for(int i = 0; i < count; i++)
- for(int j = 0; j < tile_count; j++, dd += 16)
- ImageToTile2bppPlanar(canvas, j * 8, i * 8, dd);
- FlushFile(tile_name, dest, tile_count * 16 * count);
- delete[] dest;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement