VinnoVisual.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System.Collections.Generic;
  2. using System.IO;
  3. namespace fis.Vid.Visuals
  4. {
  5. public class VinnoVisual
  6. {
  7. /// <summary>
  8. /// Gets or sets the Display mode of this image.
  9. /// </summary>
  10. public VinnoDisplayMode DisplayMode { get; set; }
  11. /// <summary>
  12. /// Gets the visual type of this Visual.
  13. /// </summary>
  14. protected VinnoVisualType VisualType;
  15. /// <summary>
  16. /// Gets or sets the Indicator of this Visual.
  17. /// </summary>
  18. public VinnoVisualIndicator Indicator { get; set; }
  19. /// <summary>
  20. /// Gets or set the active mode type of this visual.
  21. /// </summary>
  22. public VinnoModeType ActiveModeType { get; set; }
  23. /// <summary>
  24. /// Gets all modse of this visual.
  25. /// </summary>
  26. public IList<VinnoMode> Modes { get; }
  27. public VinnoVisual()
  28. {
  29. ActiveModeType = VinnoModeType.Undefined;
  30. Modes = new List<VinnoMode>();
  31. //Default is A
  32. Indicator = VinnoVisualIndicator.A;
  33. //Default is Normal
  34. DisplayMode = VinnoDisplayMode.Normal;
  35. }
  36. public virtual byte[] ToBytes()
  37. {
  38. byte[] result;
  39. using (var stream = new MemoryStream())
  40. {
  41. var writer = new VinnoStreamWriter(stream);
  42. writer.WriteByte((byte)VisualType);
  43. writer.WriteByte((byte)DisplayMode);
  44. writer.WriteByte((byte)Indicator);
  45. writer.WriteByte((byte)ActiveModeType);
  46. writer.WriteByte((byte)Modes.Count);
  47. foreach (var mode in Modes)
  48. {
  49. writer.WriteBytes(mode.ToBytes());
  50. }
  51. result = stream.ToArray();
  52. }
  53. return result;
  54. }
  55. public static VinnoVisual FromBytes(byte[] bytes)
  56. {
  57. VinnoVisual result = null;
  58. using (var stream = new MemoryStream(bytes))
  59. {
  60. stream.Position = 0;
  61. var reader = new VinnoStreamReader(stream);
  62. var visualType = (VinnoVisualType)reader.ReadByte();
  63. if (visualType == VinnoVisualType.V2D)
  64. {
  65. result = Vinno2DVisual.FromBytes(bytes);
  66. }
  67. if (visualType == VinnoVisualType.V3D)
  68. {
  69. result = Vinno3DVisual.FromBytes(bytes);
  70. }
  71. }
  72. return result;
  73. }
  74. }
  75. }