Advertisement
Guest User

Untitled

a guest
May 30th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Drawing;
  6.  
  7. namespace DashViewer.Dash
  8. {
  9. public class FontFile : IArchiveFile
  10. {
  11. public Archive.FileType Type { get; private set; }
  12. public string FriendlyType { get { return "Font file"; } }
  13. public int Offset { get; private set; }
  14. public string Path { get; private set; }
  15. public int TrueSize { get; private set; }
  16. public byte[] Data { get; private set; }
  17.  
  18. public Color[][] Palettes { get; private set; }
  19. public Bitmap[] Images { get; private set; }
  20.  
  21. public FontFile(Archive arc, Archive.FileType type, string path, int ofs, Program.LoaderCallbackDelegate lcd)
  22. {
  23. Type = type;
  24. Offset = ofs;
  25. Path = path;
  26.  
  27. TrueSize = Helpers.ReadInt(arc.Data, ofs + 4, true);
  28. int filelen = Helpers.RoundUp((TrueSize + Archive.Padding), Archive.Padding);
  29.  
  30. Data = new byte[filelen];
  31. Buffer.BlockCopy(arc.Data, ofs, Data, 0, Data.Length);
  32.  
  33. Palettes = new Color[5][];
  34. Palettes[0] = new Color[4];
  35. Palettes[0][0] = Color.FromArgb(0, 0, 0);
  36. Palettes[0][1] = Color.FromArgb(216, 216, 216);
  37. Palettes[0][2] = Color.FromArgb(120, 120, 120);
  38. Palettes[0][3] = Color.FromArgb(32, 32, 32);
  39. int rofs = 0x8700;
  40. for (int i = 1; i < Palettes.GetLength(0); i++)
  41. {
  42. if (lcd != null) lcd(string.Format("{0}: Loading palettes...", System.IO.Path.GetFileName(Path)));
  43.  
  44. Palettes[i] = new Color[4];
  45. for (int j = 0; j < Palettes[i].Length; j++)
  46. {
  47. Palettes[i][j] = Helpers.ConvertFromRGBA5551(Helpers.ReadUShort(arc.Data, ofs + rofs, true));
  48. rofs += 2;
  49. }
  50. rofs += 24;
  51. }
  52.  
  53. int imgw = 256;
  54. int imgh = 512;
  55. int blockw = 128;
  56. int blockh = 32;
  57.  
  58. Images = new Bitmap[Palettes.GetLength(0)];
  59. for (int i = 0; i < Images.Length; i++)
  60. {
  61. if (lcd != null) lcd(string.Format("{0}: Creating image for palette {1}...", System.IO.Path.GetFileName(Path), i));
  62.  
  63. rofs = 0x800;
  64. Images[i] = new Bitmap(imgw, imgh);
  65. for (int y = 0; y < imgh; y += blockh) for (int x = 0; x < imgw; x += blockw)
  66. for (int by = 0; by < blockh; by++) for (int bx = 0; bx < blockw; bx += 2)
  67. {
  68. byte r = Data[rofs];
  69. int idx1 = (r & 0x3);
  70. int idx2 = ((r & 0x30) >> 4);
  71. if (y + by > 256)
  72. {
  73. idx1 = ((r >> 2) & 0x3);
  74. idx2 = (((r >> 2) & 0x30) >> 4);
  75. }
  76. ((Bitmap)Images[i]).SetPixel(x + bx, y + by, Palettes[i][idx1]);
  77. ((Bitmap)Images[i]).SetPixel(x + bx + 1, y + by, Palettes[i][idx2]);
  78. rofs++;
  79. if (rofs == 0x8800) rofs -= 0x8000;
  80. }
  81.  
  82. //if (Images[i] != null) Images[i].Save(string.Format(@"C:\MMLTEST_0x{0:X}_{1}.png", Offset, i), System.Drawing.Imaging.ImageFormat.Png);
  83. }
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement