Texture2DWrapper.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using System.IO;
  4. namespace OpenVIII
  5. {
  6. public class Texture2DWrapper : Texture_Base
  7. {
  8. #region Fields
  9. private Texture2D tex;
  10. #endregion Fields
  11. #region Constructors
  12. public Texture2DWrapper(Texture2D tex) => this.tex = tex;
  13. #endregion Constructors
  14. #region Properties
  15. public override byte GetBytesPerPixel => 4;
  16. public override int GetClutCount => 0;
  17. public override int GetClutSize => 0;
  18. public override int GetColorsCountPerPalette => 0;
  19. public override int GetHeight => tex?.Height ?? 0;
  20. public override int GetOrigX => 0;
  21. public override int GetOrigY => 0;
  22. public override int GetWidth => tex?.Width ?? 0;
  23. #endregion Properties
  24. #region Methods
  25. public static implicit operator Texture2D(Texture2DWrapper right) => right.tex;
  26. public static implicit operator Texture2DWrapper(Texture2D right) => new Texture2DWrapper(right);
  27. public override void ForceSetClutColors(ushort newNumOfColours)
  28. {; }
  29. public override void ForceSetClutCount(ushort newClut)
  30. {; }
  31. public override Color[] GetClutColors(ushort clut) => null;
  32. public override Texture2D GetTexture() => tex;
  33. public override Texture2D GetTexture(Color[] colors = null) => tex;
  34. public override Texture2D GetTexture(ushort? clut = null) => tex;
  35. public override void Load(byte[] buffer, uint offset = 0) => throw new System.NotImplementedException("This class must use Load(Texture2D)");
  36. public void Load(Texture2D tex) => this.tex = tex;
  37. public override void Save(string path)
  38. {
  39. using (FileStream fs = File.Create(path))
  40. tex.SaveAsPng(fs, tex.Width, tex.Height);
  41. }
  42. public override void SaveCLUT(string path)
  43. { // no clut data.
  44. }
  45. #endregion Methods
  46. }
  47. }