public static VarTypeListModel DecodeByteArray(byte[] bytes) { VarTypeListModel Model = new VarTypeListModel(); int offset = 0; while (offset < bytes.Length) { // read name string length byte len = ByteArrayHandler.GetBytesFromArray(bytes, offset, 1, false)[0]; // get the VarType model int arrayLen = len + 2; byte[] byteArr = new byte[arrayLen]; Buffer.BlockCopy(bytes, offset, byteArr, 0, arrayLen); VarTypeModel m = VarTypeModel.DecodeByteArray(byteArr); offset += arrayLen; // add model Model.VarTypes.Add(m); } return(Model); }
private void ProcessMessage(byte[] messageBytes) { if (Encryptor != null) { messageBytes = Encryptor.DecryptBytes(messageBytes); if (messageBytes == null) { return; } } if (messageBytes[0] == 0) { var decodedString = Encoding.UTF8.GetString(messageBytes.Skip(1).ToArray()); var messages = Utilities.SplitJSON(decodedString); foreach (var message in messages) { ProcessJSONString(message); } } else { if (ByteArrayHandler == null) { ByteArrayHandler = this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance). FirstOrDefault(mi => mi.Name == "ReceiveByteArray"); } ByteArrayHandler.Invoke(this, new object[] { messageBytes.ToArray() }); } return; }
private void Start() { BattleRoyaleClientMatchModel matchModel = matchModelStorage.GetMatchModel(); UdpSendUtils udpSendUtils = udpManager.CreateConnection(matchModel); PingStatisticsStorage pingStatisticsStorage = new PingStatisticsStorage(udpSendUtils); clientMatchSimulation = new ClientMatchSimulation(battleUiController, udpSendUtils, matchModel, pingStatisticsStorage); var playersStorage = clientMatchSimulation.GetPlayersStorage(); var transformStorage = clientMatchSimulation.GetTransformStorage(); var healthPointsStorage = clientMatchSimulation.GetHealthPointsStorage(); var maxHealthPointsMessagePackStorage = clientMatchSimulation.GetMaxHealthPointsMessagePackStorage(); IKillMessageStorage killMessageStorage = clientMatchSimulation.GetKillMessageStorage(); var messageWrapperHandler = new MessageWrapperHandler(udpSendUtils, matchModel.MatchId, transformStorage, playersStorage, healthPointsStorage, maxHealthPointsMessagePackStorage, pingStatisticsStorage, killMessageStorage); IByteArrayHandler byteArrayHandler = new ByteArrayHandler(messageWrapperHandler); udpManager.StartListening(byteArrayHandler); }
public static BTInputModel DecodeByteArray(byte[] bytes) { byte Key = bytes[0]; ushort Value = BitConverter.ToUInt16(ByteArrayHandler.GetBytesFromArray(bytes, 1, 2, false), 0); return(new BTInputModel { Value = Value, Key = Key }); }
internal static byte[] GetVarBytes() { var varTypeList = GetVarTypes(); List <ByteArrayModel> Bytes = new List <ByteArrayModel>(); // loop through var types, create values foreach (VarTypeModel VarType in varTypeList.VarTypes) { switch (VarType.VarType) { case VarTypeEnum.uint8: Bytes.Add(new ByteArrayModel { Bytes = new byte[] { 200 }, isString = false }); break; case VarTypeEnum.uint16: Bytes.Add(new ByteArrayModel { Bytes = BitConverter.GetBytes((ushort)765), isString = false }); break; case VarTypeEnum.uint32: Bytes.Add(new ByteArrayModel { Bytes = BitConverter.GetBytes((uint)11765), isString = false }); break; case VarTypeEnum.int8: Bytes.Add(new ByteArrayModel { Bytes = new byte[] { 200 }, isString = false }); break; case VarTypeEnum.int16: Bytes.Add(new ByteArrayModel { Bytes = BitConverter.GetBytes((short)365), isString = false }); break; case VarTypeEnum.int32: Bytes.Add(new ByteArrayModel { Bytes = BitConverter.GetBytes(i), isString = false }); break; } } i++; byte[] bytes = ByteArrayHandler.ConstructByteArray(Bytes); return(bytes); }
public byte[] GetByteArray() { List <ByteArrayModel> bList = new List <ByteArrayModel>(); // create byte array list bList.Add(new ByteArrayModel { Bytes = new byte[] { Key }, isString = false }); bList.Add(new ByteArrayModel { Bytes = BitConverter.GetBytes(Value), isString = true }); return(ByteArrayHandler.ConstructByteArray(bList)); }
public static VarTypeModel DecodeByteArray(byte[] bytes) { int offset = 0; // read name string length byte len = ByteArrayHandler.GetBytesFromArray(bytes, offset, 1, false)[0]; offset++; // get name string string name = Encoding.ASCII.GetString(ByteArrayHandler.GetBytesFromArray(bytes, offset, len, true)); offset += len; // get var type byte varType = ByteArrayHandler.GetBytesFromArray(bytes, offset, 1, false)[0]; offset++; // create model VarTypeModel m = new VarTypeModel { Name = name, VarType = (VarTypeEnum)varType }; return(m); }
public byte[] GetByteArray() { List <ByteArrayModel> bList = new List <ByteArrayModel>(); // get string bytes byte[] str = Encoding.ASCII.GetBytes(Name); // get length byte len = Convert.ToByte(str.Length); // create byte array list bList.Add(new ByteArrayModel { Bytes = new byte[] { len }, isString = false }); bList.Add(new ByteArrayModel { Bytes = str, isString = true }); bList.Add(new ByteArrayModel { Bytes = new byte[] { (byte)VarType }, isString = false }); return(ByteArrayHandler.ConstructByteArray(bList)); }
private static unsafe IArrayHandler <byte> NonMaximalSuppression(GradientImage magImage) { int nrows = magImage.Rows; int ncols = magImage.Columns; int rowcount, colcount, count; float[,] magVals = magImage.ExtractChannel(0); float[,] gradxVals = magImage.ExtractChannel(2); float[,] gradyVals = magImage.ExtractChannel(3); byte[] data = new byte[nrows * ncols]; fixed(byte *result = data) { fixed(float *mag = magVals, gradx = gradxVals, grady = gradyVals) { float *magrowptr, magptr; float *gxrowptr, gxptr; float *gyrowptr, gyptr; float z1, z2; float m00, gx, gy; float mag1, mag2, xperp, yperp; byte * resultrowptr, resultptr; /**************************************************************************** * Zero the edges of the result image. ****************************************************************************/ for (count = 0, resultrowptr = result, resultptr = result + ncols * (nrows - 1); count < ncols; resultptr++, resultrowptr++, count++) { *resultrowptr = *resultptr = 0; } for (count = 0, resultptr = result, resultrowptr = result + ncols - 1; count < nrows; count++, resultptr += ncols, resultrowptr += ncols) { *resultptr = *resultrowptr = 0; } /**************************************************************************** * Suppress non-maximum points. ****************************************************************************/ for (rowcount = 1, magrowptr = mag + ncols + 1, gxrowptr = gradx + ncols + 1, gyrowptr = grady + ncols + 1, resultrowptr = result + ncols + 1; rowcount < nrows - 2; rowcount++, magrowptr += ncols, gyrowptr += ncols, gxrowptr += ncols, resultrowptr += ncols) { for (colcount = 1, magptr = magrowptr, gxptr = gxrowptr, gyptr = gyrowptr, resultptr = resultrowptr; colcount < ncols - 2; colcount++, magptr++, gxptr++, gyptr++, resultptr++) { m00 = *magptr; gx = *gxptr; gy = *gyptr; if (m00 == 0) { *resultptr = NOEDGE; continue; } else { xperp = -(gx = *gxptr) / ((float)m00); yperp = (gy = *gyptr) / ((float)m00); } if (gx >= 0) { if (gy >= 0) { if (gx >= gy) { /* 111 */ /* Left point */ z1 = *(magptr - 1); z2 = *(magptr - ncols - 1); mag1 = (m00 - z1) * xperp + (z2 - z1) * yperp; /* Right point */ z1 = *(magptr + 1); z2 = *(magptr + ncols + 1); mag2 = (m00 - z1) * xperp + (z2 - z1) * yperp; } else { /* 110 */ /* Left point */ z1 = *(magptr - ncols); z2 = *(magptr - ncols - 1); mag1 = (z1 - z2) * xperp + (z1 - m00) * yperp; /* Right point */ z1 = *(magptr + ncols); z2 = *(magptr + ncols + 1); mag2 = (z1 - z2) * xperp + (z1 - m00) * yperp; } } else { if (gx >= -gy) { /* 101 */ /* Left point */ z1 = *(magptr - 1); z2 = *(magptr + ncols - 1); mag1 = (m00 - z1) * xperp + (z1 - z2) * yperp; /* Right point */ z1 = *(magptr + 1); z2 = *(magptr - ncols + 1); mag2 = (m00 - z1) * xperp + (z1 - z2) * yperp; } else { /* 100 */ /* Left point */ z1 = *(magptr + ncols); z2 = *(magptr + ncols - 1); mag1 = (z1 - z2) * xperp + (m00 - z1) * yperp; /* Right point */ z1 = *(magptr - ncols); z2 = *(magptr - ncols + 1); mag2 = (z1 - z2) * xperp + (m00 - z1) * yperp; } } } else { if ((gy = *gyptr) >= 0) { if (-gx >= gy) { /* 011 */ /* Left point */ z1 = *(magptr + 1); z2 = *(magptr - ncols + 1); mag1 = (z1 - m00) * xperp + (z2 - z1) * yperp; /* Right point */ z1 = *(magptr - 1); z2 = *(magptr + ncols - 1); mag2 = (z1 - m00) * xperp + (z2 - z1) * yperp; } else { /* 010 */ /* Left point */ z1 = *(magptr - ncols); z2 = *(magptr - ncols + 1); mag1 = (z2 - z1) * xperp + (z1 - m00) * yperp; /* Right point */ z1 = *(magptr + ncols); z2 = *(magptr + ncols - 1); mag2 = (z2 - z1) * xperp + (z1 - m00) * yperp; } } else { if (-gx > -gy) { /* 001 */ /* Left point */ z1 = *(magptr + 1); z2 = *(magptr + ncols + 1); mag1 = (z1 - m00) * xperp + (z1 - z2) * yperp; /* Right point */ z1 = *(magptr - 1); z2 = *(magptr - ncols - 1); mag2 = (z1 - m00) * xperp + (z1 - z2) * yperp; } else { /* 000 */ /* Left point */ z1 = *(magptr + ncols); z2 = *(magptr + ncols + 1); mag1 = (z2 - z1) * xperp + (m00 - z1) * yperp; /* Right point */ z1 = *(magptr - ncols); z2 = *(magptr - ncols - 1); mag2 = (z2 - z1) * xperp + (m00 - z1) * yperp; } } } /* Now determine if the current point is a maximum point */ if ((mag1 > 0.0) || (mag2 > 0.0)) { *resultptr = NOEDGE; } else { if (mag2 == 0.0) { *resultptr = NOEDGE; } else { *resultptr = POSSIBLE_EDGE; } } } } } } ByteArrayHandler handler = new ByteArrayHandler(nrows, ncols, 1); fixed(byte *dst = handler.RawArray) { byte *dstPtr = dst; int length = nrows * ncols; for (int pos = 0; pos < length; pos++) { *dstPtr++ = data[pos]; } } //MonochromeImage mono = new MonochromeImage(nrows, ncols); //for (int r = 0; r < nrows; r++) // for (int c = 0; c < ncols; c++) // mono[r, c] = handler[r, c, 0]; //mono.ToRGB().Save("cannyNMS.bmp"); return(handler); }