/// <summary> /// returns frame /// </summary> /// <param name="i">number of frame, starts from 0</param> /// <returns></returns> private IList <Color> GetElement(int i) { List <Color> retVal = new List <Color>(FrameLength); int offset = headerLength + i * FrameLength * 3; for (int j = 0; j < FrameLength; j++) { switch (format) { case Format.SD01A: retVal.Add(Color.FromArgb( ByteReverse.ReverseWithLookupTable(_data[offset + j * 3 + 1]), ByteReverse.ReverseWithLookupTable(_data[offset + j * 3 + 2]), ByteReverse.ReverseWithLookupTable(_data[offset + j * 3 + 0]) )); break; case Format.SD01B: retVal.Add(Color.FromArgb( _data[offset + j * 3 + 1], _data[offset + j * 3 + 2], _data[offset + j * 3 + 0] )); break; } } return(retVal.AsReadOnly()); }
/// <summary> /// sets color of one diode /// </summary> /// <param name="frame">frame number</param> /// <param name="diode">diode number</param> /// <param name="color">color to set</param> public void SetDiodeColor(int frame, int diode, Color color) { if (frame < 0 || frame >= NumberOfFrames) { throw new IndexOutOfRangeException(); } if (diode < 0 || diode >= FrameLength || diode >= diodeMax) { throw new IndexOutOfRangeException(); } int offset = headerLength + frame * FrameLength * 3; switch (format) { case Format.SD01A: _data[offset + diode * 3 + 1] = ByteReverse.ReverseWithLookupTable((byte)color.R); _data[offset + diode * 3 + 2] = ByteReverse.ReverseWithLookupTable((byte)color.G); _data[offset + diode * 3 + 0] = ByteReverse.ReverseWithLookupTable((byte)color.B); break; case Format.SD01B: _data[offset + diode * 3 + 1] = (byte)color.R; _data[offset + diode * 3 + 2] = (byte)color.G; _data[offset + diode * 3 + 0] = (byte)color.B; break; } }
/// <summary> /// Create new programm. /// </summary> /// <param name="frames">Number of frames</param> /// <param name="fillColor">initial color</param> /// <param name="frameLength">number of diodes in frame.</param> public FileParser(int frames, Color fillColor, int frameLength = 1024, Format f = Format.SD01A) { format = f; if (frames < 0 || frames > 65535) { throw new NotSupportedException("Frames parameter mest be not negative and greater than 65535"); } var data = new byte[headerLength + frameLength * frames * 3]; data[0] = (byte)((frames & 0xFF00) >> 8); data[1] = (byte)(frames & 0xFF); switch (format) { case Format.SD01A: data[2] = 0x68; data[3] = 0x03; data[4] = 0x06; data[5] = 0x06; break; case Format.SD01B: data[2] = 0x98; data[3] = 0x13; data[4] = 0x06; data[5] = 0x14; break; } for (int i = 6; i < headerLength; i++) { data[i] = 0x55; } for (int i = 0; i < frames * frameLength; i++) { Color color = (i % frameLength) < diodeMax ? fillColor : Color.Black; switch (format) { case Format.SD01A: data[headerLength + i * 3 + 1] = ByteReverse.ReverseWithLookupTable((byte)color.R); data[headerLength + i * 3 + 2] = ByteReverse.ReverseWithLookupTable((byte)color.G); data[headerLength + i * 3 + 0] = ByteReverse.ReverseWithLookupTable((byte)color.B); break; case Format.SD01B: data[headerLength + i * 3 + 1] = (byte)color.R; data[headerLength + i * 3 + 2] = (byte)color.G; data[headerLength + i * 3 + 0] = (byte)color.B; break; } } InitFromData(data); }