MultPixelProgram.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Drawing;
  5. using HNWD.Pregrant.Common;
  6. using System.IO;
  7. namespace HNWD.LatticeScreen.Server
  8. {
  9. internal class MultPixelProgram : ProgramBase
  10. {
  11. private ushort[] pdata;
  12. private ushort WriteIndex = 0;
  13. public MultPixelProgram(LedLatticeScreen ledLatticeScreen)
  14. : base()
  15. {
  16. this.ledLatticeScreen = ledLatticeScreen;
  17. }
  18. public override void SetEntity(Pregrant.Model.WD_ProgramInfo wd_ProgramInfo)
  19. {
  20. base.SetEntity(wd_ProgramInfo);
  21. byte[] byteArray = Convert.FromBase64String(GZipCompress.Decompress(this.wd_ProgramInfo.PROGRAM_MATRIX));
  22. Bitmap img = (Bitmap)System.Drawing.Image.FromStream(new MemoryStream(byteArray));
  23. this.pdata = new ushort[this.ledLatticeScreen.Width * this.ledLatticeScreen.Height * 2];
  24. this.WriteIndex = 0;
  25. for (ushort i = 0; i < img.Width; i++)
  26. {
  27. for (ushort j = 0; j < img.Height; j++)
  28. {
  29. if (Color.Black.ToArgb() == img.GetPixel(i, j).ToArgb())
  30. {
  31. pdata[WriteIndex] = i;
  32. WriteIndex++;
  33. pdata[WriteIndex] = j;
  34. WriteIndex++;
  35. }
  36. }
  37. }
  38. }
  39. public override void PlayWithErase()
  40. {
  41. this.ledLatticeScreen.JHErase();
  42. ushort leng = 1200 / 2;
  43. int ntimes = WriteIndex % leng == 0 ? WriteIndex / leng : WriteIndex / leng + 1;
  44. int x = 0;
  45. int lengdata = leng;
  46. while (x < ntimes)
  47. {
  48. if (x == ntimes - 1)
  49. {
  50. leng = (ushort)(WriteIndex % leng - 2);
  51. }
  52. this.responseByLedCommand = LedControl.JHDrawMultPixel(this.ledLatticeScreen.hdl, pdata.Skip(lengdata * x + 2).Take(leng).ToArray(), (ushort)(leng / 2));
  53. this.ResponseMessage(true);
  54. x++;
  55. }
  56. }
  57. public override void PlayWithoutErase()
  58. {
  59. ushort leng = 1200 / 2;
  60. int ntimes = WriteIndex % leng == 0 ? WriteIndex / leng : WriteIndex / leng + 1;
  61. int x = 0;
  62. int lengdata = leng;
  63. while (x < ntimes)
  64. {
  65. if (x == ntimes - 1)
  66. {
  67. leng = (ushort)(WriteIndex % leng - 2);
  68. }
  69. this.responseByLedCommand = LedControl.JHDrawMultPixel(this.ledLatticeScreen.hdl, pdata.Skip(lengdata * x + 2).Take(leng).ToArray(), (ushort)(leng / 2));
  70. this.ResponseMessage(true);
  71. x++;
  72. }
  73. }
  74. }
  75. }