TIM_OVERTURE.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System.IO;
  2. using System.Linq;
  3. namespace OpenVIII
  4. {
  5. /// <summary>
  6. /// TIM data for overture textures.
  7. /// </summary>
  8. /// <remarks>
  9. /// The reason for this is the lack of header, And allows compatablility with other objects that
  10. /// use TIMs.
  11. /// </remarks>
  12. public sealed class TIM_OVERTURE : TIM2
  13. {
  14. public TIM_OVERTURE(byte[] buffer, uint offset = 0) : base() => _Init(buffer, offset);
  15. public TIM_OVERTURE(BinaryReader br, uint offset = 0) : base() => _Init(br, offset);
  16. private TIM_OVERTURE()
  17. {
  18. }
  19. private new void _Init(byte[] buffer, uint offset)
  20. {
  21. this.buffer = buffer;
  22. using (BinaryReader br = new BinaryReader(new MemoryStream(buffer)))
  23. {
  24. Init(br, offset);
  25. }
  26. }
  27. private new void _Init(BinaryReader br, uint offset)
  28. {
  29. trimExcess = true;
  30. br.BaseStream.Seek(offset, SeekOrigin.Begin);
  31. buffer = br.ReadBytes((int)(br.BaseStream.Length - br.BaseStream.Position));
  32. using (BinaryReader br2 = new BinaryReader(new MemoryStream(buffer)))
  33. Init(br2, 0);
  34. }
  35. private new void Init(BinaryReader br, uint offset)
  36. {
  37. bpp = 16;
  38. timOffset = offset;
  39. ReadParameters(br);
  40. }
  41. private new void ReadParameters(BinaryReader br)
  42. {
  43. br.BaseStream.Seek(timOffset, SeekOrigin.Begin);
  44. texture.ImageOrgX = br.ReadUInt16();
  45. texture.ImageOrgY = br.ReadUInt16();
  46. texture.Width = br.ReadUInt16();
  47. texture.Height = br.ReadUInt16();
  48. texture.ImageSize = (uint)(br.BaseStream.Length - timOffset);
  49. texture.ImageDataSize = (int)(br.BaseStream.Length - br.BaseStream.Position);
  50. textureDataPointer = (uint)br.BaseStream.Position;
  51. br.BaseStream.Seek(timOffset, SeekOrigin.Begin);
  52. if (trimExcess)
  53. buffer = buffer.Skip((int)timOffset).Take((int)(texture.ImageDataSize + textureDataPointer - timOffset)).ToArray();
  54. }
  55. ///// <summary>
  56. ///// Splash is 640x400 16BPP typical TIM with palette of ggg bbbbb a rrrrr gg
  57. ///// </summary>
  58. ///// <param name="buffer">raw 16bpp image</param>
  59. ///// <returns>Texture2D</returns>
  60. ///// <remarks>
  61. ///// These files are just the image data with no header and no clut data. Tim class doesn't
  62. ///// handle this.
  63. ///// </remarks>
  64. //public static Texture2D Overture(byte[] buffer)
  65. //{
  66. // using (MemoryStream ms = new MemoryStream(buffer))
  67. // using (BinaryReader br = new BinaryReader(ms))
  68. // {
  69. // //var ImageOrgX = BitConverter.ToUInt16(buffer, 0x00);
  70. // //var ImageOrgY = BitConverter.ToUInt16(buffer, 0x02);
  71. // ms.Seek(0x04, SeekOrigin.Begin);
  72. // ushort Width = br.ReadUInt16();
  73. // ushort Height = br.ReadUInt16();
  74. // Texture2D splashTex = new Texture2D(Memory.graphics.GraphicsDevice, Width, Height, false, SurfaceFormat.Color);
  75. // lock (splashTex)
  76. // {
  77. // Color[] rgbBuffer = new Color[Width * Height];
  78. // for (int i = 0; i < rgbBuffer.Length && ms.Position + 2 < ms.Length; i++)
  79. // {
  80. // rgbBuffer[i] = ABGR1555toRGBA32bit(br.ReadUInt16(), true);
  81. // }
  82. // splashTex.SetData(rgbBuffer);
  83. // }
  84. // return splashTex;
  85. // }
  86. //}
  87. }
  88. }