TerminalLiveDataBytes.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace fis.media.Helpers
  7. {
  8. public class TerminalLiveDataBytes
  9. {
  10. private byte[] _terminalData;
  11. private byte[] _cameraData;
  12. /// <summary>
  13. /// Terminal data ARGB
  14. /// </summary>
  15. public byte[] TerminalData => _terminalData;
  16. /// <summary>
  17. /// Camera data ARGB
  18. /// </summary>
  19. public byte[] CameraData => _cameraData;
  20. /// <summary>
  21. /// Update terminal and camera data size
  22. /// </summary>
  23. /// <param name="terminalBytes"></param>
  24. public void Update(byte[] source, int terminalBytes, int cameraBytes, int terminalWidth, int terminalHeight, int realWidth)
  25. {
  26. if (_terminalData == null)
  27. {
  28. _terminalData = new byte[terminalBytes];
  29. }
  30. else if (terminalBytes != _terminalData.Length)
  31. {
  32. Array.Resize(ref _terminalData, terminalBytes);
  33. }
  34. Parallel.For(0, terminalHeight, row =>
  35. {
  36. Array.Copy(source, row * realWidth * 4, _terminalData, row * terminalWidth * 4, terminalWidth * 4);
  37. });
  38. if (_cameraData == null)
  39. {
  40. _cameraData = new byte[cameraBytes];
  41. }
  42. else if (cameraBytes != _cameraData.Length)
  43. {
  44. Array.Resize(ref _cameraData, cameraBytes);
  45. }
  46. if (realWidth > 1920)//Workaround fix ,due to TX will change 1920 to 1936
  47. {
  48. Parallel.For(0, 160, row =>
  49. {
  50. Array.Copy(source, terminalHeight * realWidth * 4 + row * realWidth * 4, _cameraData, row * 1920 * 4, 1920 * 4);
  51. });
  52. }
  53. else
  54. {
  55. Array.Copy(source, realWidth * terminalHeight * 4, _cameraData, 0, cameraBytes);
  56. }
  57. }
  58. }
  59. }