Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Drawing;
- namespace DashViewer.Dash
- {
- public class FontFile : IArchiveFile
- {
- public Archive.FileType Type { get; private set; }
- public string FriendlyType { get { return "Font file"; } }
- public int Offset { get; private set; }
- public string Path { get; private set; }
- public int TrueSize { get; private set; }
- public byte[] Data { get; private set; }
- public Color[][] Palettes { get; private set; }
- public Bitmap[] Images { get; private set; }
- public FontFile(Archive arc, Archive.FileType type, string path, int ofs, Program.LoaderCallbackDelegate lcd)
- {
- Type = type;
- Offset = ofs;
- Path = path;
- TrueSize = Helpers.ReadInt(arc.Data, ofs + 4, true);
- int filelen = Helpers.RoundUp((TrueSize + Archive.Padding), Archive.Padding);
- Data = new byte[filelen];
- Buffer.BlockCopy(arc.Data, ofs, Data, 0, Data.Length);
- Palettes = new Color[5][];
- Palettes[0] = new Color[4];
- Palettes[0][0] = Color.FromArgb(0, 0, 0);
- Palettes[0][1] = Color.FromArgb(216, 216, 216);
- Palettes[0][2] = Color.FromArgb(120, 120, 120);
- Palettes[0][3] = Color.FromArgb(32, 32, 32);
- int rofs = 0x8700;
- for (int i = 1; i < Palettes.GetLength(0); i++)
- {
- if (lcd != null) lcd(string.Format("{0}: Loading palettes...", System.IO.Path.GetFileName(Path)));
- Palettes[i] = new Color[4];
- for (int j = 0; j < Palettes[i].Length; j++)
- {
- Palettes[i][j] = Helpers.ConvertFromRGBA5551(Helpers.ReadUShort(arc.Data, ofs + rofs, true));
- rofs += 2;
- }
- rofs += 24;
- }
- int imgw = 256;
- int imgh = 512;
- int blockw = 128;
- int blockh = 32;
- Images = new Bitmap[Palettes.GetLength(0)];
- for (int i = 0; i < Images.Length; i++)
- {
- if (lcd != null) lcd(string.Format("{0}: Creating image for palette {1}...", System.IO.Path.GetFileName(Path), i));
- rofs = 0x800;
- Images[i] = new Bitmap(imgw, imgh);
- for (int y = 0; y < imgh; y += blockh) for (int x = 0; x < imgw; x += blockw)
- for (int by = 0; by < blockh; by++) for (int bx = 0; bx < blockw; bx += 2)
- {
- byte r = Data[rofs];
- int idx1 = (r & 0x3);
- int idx2 = ((r & 0x30) >> 4);
- if (y + by > 256)
- {
- idx1 = ((r >> 2) & 0x3);
- idx2 = (((r >> 2) & 0x30) >> 4);
- }
- ((Bitmap)Images[i]).SetPixel(x + bx, y + by, Palettes[i][idx1]);
- ((Bitmap)Images[i]).SetPixel(x + bx + 1, y + by, Palettes[i][idx2]);
- rofs++;
- if (rofs == 0x8800) rofs -= 0x8000;
- }
- //if (Images[i] != null) Images[i].Save(string.Format(@"C:\MMLTEST_0x{0:X}_{1}.png", Offset, i), System.Drawing.Imaging.ImageFormat.Png);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement