12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- using System;
- using System.Linq;
- using System.Text;
- using System.Drawing;
- using HNWD.Pregrant.Common;
- using System.IO;
- namespace HNWD.LatticeScreen.Server
- {
- internal class MultPixelProgram : ProgramBase
- {
- private ushort[] pdata;
- private ushort WriteIndex = 0;
- public MultPixelProgram(LedLatticeScreen ledLatticeScreen)
- : base()
- {
- this.ledLatticeScreen = ledLatticeScreen;
- }
- public override void SetEntity(Pregrant.Model.WD_ProgramInfo wd_ProgramInfo)
- {
- base.SetEntity(wd_ProgramInfo);
- byte[] byteArray = Convert.FromBase64String(GZipCompress.Decompress(this.wd_ProgramInfo.PROGRAM_MATRIX));
- Bitmap img = (Bitmap)System.Drawing.Image.FromStream(new MemoryStream(byteArray));
- this.pdata = new ushort[this.ledLatticeScreen.Width * this.ledLatticeScreen.Height * 2];
- this.WriteIndex = 0;
- for (ushort i = 0; i < img.Width; i++)
- {
- for (ushort j = 0; j < img.Height; j++)
- {
- if (Color.Black.ToArgb() == img.GetPixel(i, j).ToArgb())
- {
- pdata[WriteIndex] = i;
- WriteIndex++;
- pdata[WriteIndex] = j;
- WriteIndex++;
- }
- }
- }
- }
- public override void PlayWithErase()
- {
- this.ledLatticeScreen.JHErase();
- ushort leng = 1200 / 2;
- int ntimes = WriteIndex % leng == 0 ? WriteIndex / leng : WriteIndex / leng + 1;
- int x = 0;
- int lengdata = leng;
- while (x < ntimes)
- {
- if (x == ntimes - 1)
- {
- leng = (ushort)(WriteIndex % leng - 2);
- }
- this.responseByLedCommand = LedControl.JHDrawMultPixel(this.ledLatticeScreen.hdl, pdata.Skip(lengdata * x + 2).Take(leng).ToArray(), (ushort)(leng / 2));
- this.ResponseMessage(true);
- x++;
- }
- }
- public override void PlayWithoutErase()
- {
- ushort leng = 1200 / 2;
- int ntimes = WriteIndex % leng == 0 ? WriteIndex / leng : WriteIndex / leng + 1;
- int x = 0;
- int lengdata = leng;
- while (x < ntimes)
- {
- if (x == ntimes - 1)
- {
- leng = (ushort)(WriteIndex % leng - 2);
- }
- this.responseByLedCommand = LedControl.JHDrawMultPixel(this.ledLatticeScreen.hdl, pdata.Skip(lengdata * x + 2).Take(leng).ToArray(), (ushort)(leng / 2));
- this.ResponseMessage(true);
- x++;
- }
- }
- }
- }
|