123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System.Collections.Generic;
- using System.IO;
- namespace fis.Vid.Visuals
- {
- public class VinnoVisual
- {
- /// <summary>
- /// Gets or sets the Display mode of this image.
- /// </summary>
- public VinnoDisplayMode DisplayMode { get; set; }
- /// <summary>
- /// Gets the visual type of this Visual.
- /// </summary>
- protected VinnoVisualType VisualType;
- /// <summary>
- /// Gets or sets the Indicator of this Visual.
- /// </summary>
- public VinnoVisualIndicator Indicator { get; set; }
- /// <summary>
- /// Gets or set the active mode type of this visual.
- /// </summary>
- public VinnoModeType ActiveModeType { get; set; }
- /// <summary>
- /// Gets all modse of this visual.
- /// </summary>
- public IList<VinnoMode> Modes { get; }
- public VinnoVisual()
- {
- ActiveModeType = VinnoModeType.Undefined;
- Modes = new List<VinnoMode>();
- //Default is A
- Indicator = VinnoVisualIndicator.A;
- //Default is Normal
- DisplayMode = VinnoDisplayMode.Normal;
- }
- public virtual byte[] ToBytes()
- {
- byte[] result;
- using (var stream = new MemoryStream())
- {
- var writer = new VinnoStreamWriter(stream);
- writer.WriteByte((byte)VisualType);
- writer.WriteByte((byte)DisplayMode);
- writer.WriteByte((byte)Indicator);
- writer.WriteByte((byte)ActiveModeType);
- writer.WriteByte((byte)Modes.Count);
- foreach (var mode in Modes)
- {
- writer.WriteBytes(mode.ToBytes());
- }
- result = stream.ToArray();
- }
- return result;
- }
- public static VinnoVisual FromBytes(byte[] bytes)
- {
- VinnoVisual result = null;
- using (var stream = new MemoryStream(bytes))
- {
- stream.Position = 0;
- var reader = new VinnoStreamReader(stream);
- var visualType = (VinnoVisualType)reader.ReadByte();
- if (visualType == VinnoVisualType.V2D)
- {
- result = Vinno2DVisual.FromBytes(bytes);
- }
- if (visualType == VinnoVisualType.V3D)
- {
- result = Vinno3DVisual.FromBytes(bytes);
- }
- }
- return result;
- }
- }
- }
|