Ejemplo n.º 1
0
            public override byte[] Serialize(bool partofsomethingelse)
            {
                int  currentIndex = 0, length = 0;
                bool hasmetacomponents = false;

                byte[]        thischunk, scratch1, scratch2;
                List <byte[]> pieces = new List <byte[]>();
                GCHandle      h;
                IntPtr        ptr;
                int           x__size;

                //serials
                hasmetacomponents |= false;
                if (serials == null)
                {
                    serials = new string[0];
                }
                pieces.Add(BitConverter.GetBytes(serials.Length));
                for (int i = 0; i < serials.Length; i++)
                {
                    //serials[i]
                    if (serials[i] == null)
                    {
                        serials[i] = "";
                    }
                    scratch1  = Encoding.ASCII.GetBytes((string)serials[i]);
                    thischunk = new byte[scratch1.Length + 4];
                    scratch2  = BitConverter.GetBytes(scratch1.Length);
                    Array.Copy(scratch1, 0, thischunk, 4, scratch1.Length);
                    Array.Copy(scratch2, thischunk, 4);
                    pieces.Add(thischunk);
                }
                //images
                hasmetacomponents |= false;
                if (images == null)
                {
                    images = new Messages.sensor_msgs.Image[0];
                }
                pieces.Add(BitConverter.GetBytes(images.Length));
                for (int i = 0; i < images.Length; i++)
                {
                    //images[i]
                    if (images[i] == null)
                    {
                        images[i] = new Messages.sensor_msgs.Image();
                    }
                    pieces.Add(images[i].Serialize(true));
                }
                //combine every array in pieces into one array and return it
                int __a_b__f = pieces.Sum((__a_b__c) => __a_b__c.Length);
                int __a_b__e = 0;

                byte[] __a_b__d = new byte[__a_b__f];
                foreach (var __p__ in pieces)
                {
                    Array.Copy(__p__, 0, __a_b__d, __a_b__e, __p__.Length);
                    __a_b__e += __p__.Length;
                }
                return(__a_b__d);
            }
Ejemplo n.º 2
0
            public override byte[] Serialize(bool partofsomethingelse)
            {
                int  currentIndex = 0, length = 0;
                bool hasmetacomponents = false;

                byte[]        thischunk, scratch1, scratch2;
                List <byte[]> pieces = new List <byte[]>();
                GCHandle      h;
                IntPtr        ptr;
                int           x__size;

                //serial
                if (serial == null)
                {
                    serial = "";
                }
                scratch1  = Encoding.ASCII.GetBytes((string)serial);
                thischunk = new byte[scratch1.Length + 4];
                scratch2  = BitConverter.GetBytes(scratch1.Length);
                Array.Copy(scratch1, 0, thischunk, 4, scratch1.Length);
                Array.Copy(scratch2, thischunk, 4);
                pieces.Add(thischunk);
                //totalFrameCount
                scratch1 = new byte[Marshal.SizeOf(typeof(int))];
                h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
                Marshal.StructureToPtr(totalFrameCount, h.AddrOfPinnedObject(), false);
                h.Free();
                pieces.Add(scratch1);
                //images
                hasmetacomponents |= false;
                if (images == null)
                {
                    images = new Messages.sensor_msgs.Image[0];
                }
                pieces.Add(BitConverter.GetBytes(images.Length));
                for (int i = 0; i < images.Length; i++)
                {
                    //images[i]
                    if (images[i] == null)
                    {
                        images[i] = new Messages.sensor_msgs.Image();
                    }
                    pieces.Add(images[i].Serialize(true));
                }
                //combine every array in pieces into one array and return it
                int __a_b__f = pieces.Sum((__a_b__c) => __a_b__c.Length);
                int __a_b__e = 0;

                byte[] __a_b__d = new byte[__a_b__f];
                foreach (var __p__ in pieces)
                {
                    Array.Copy(__p__, 0, __a_b__d, __a_b__e, __p__.Length);
                    __a_b__e += __p__.Length;
                }
                return(__a_b__d);
            }
Ejemplo n.º 3
0
            public override void Randomize()
            {
                int    arraylength = -1;
                Random rand        = new Random();
                int    strlength;

                byte[] strbuf, myByte;

                //serials
                arraylength = rand.Next(10);
                if (serials == null)
                {
                    serials = new string[arraylength];
                }
                else
                {
                    Array.Resize(ref serials, arraylength);
                }
                for (int i = 0; i < serials.Length; i++)
                {
                    //serials[i]
                    strlength = rand.Next(100) + 1;
                    strbuf    = new byte[strlength];
                    rand.NextBytes(strbuf);  //fill the whole buffer with random bytes
                    for (int __x__ = 0; __x__ < strlength; __x__++)
                    {
                        if (strbuf[__x__] == 0) //replace null chars with non-null random ones
                        {
                            strbuf[__x__] = (byte)(rand.Next(254) + 1);
                        }
                    }
                    strbuf[strlength - 1] = 0; //null terminate
                    serials[i]            = Encoding.ASCII.GetString(strbuf);
                }
                //images
                arraylength = rand.Next(10);
                if (images == null)
                {
                    images = new Messages.sensor_msgs.Image[arraylength];
                }
                else
                {
                    Array.Resize(ref images, arraylength);
                }
                for (int i = 0; i < images.Length; i++)
                {
                    //images[i]
                    images[i] = new Messages.sensor_msgs.Image();
                    images[i].Randomize();
                }
            }
Ejemplo n.º 4
0
            public override void Deserialize(byte[] serializedMessage, ref int currentIndex)
            {
                int  arraylength       = -1;
                bool hasmetacomponents = false;
                int  piecesize         = 0;

                byte[] thischunk, scratch1, scratch2;
                IntPtr h;
                object __thing;

                //serials
                hasmetacomponents |= false;
                arraylength        = BitConverter.ToInt32(serializedMessage, currentIndex);
                currentIndex      += Marshal.SizeOf(typeof(System.Int32));
                if (serials == null)
                {
                    serials = new string[arraylength];
                }
                else
                {
                    Array.Resize(ref serials, arraylength);
                }
                for (int i = 0; i < serials.Length; i++)
                {
                    //serials[i]
                    serials[i]    = "";
                    piecesize     = BitConverter.ToInt32(serializedMessage, currentIndex);
                    currentIndex += 4;
                    serials[i]    = Encoding.ASCII.GetString(serializedMessage, currentIndex, piecesize);
                    currentIndex += piecesize;
                }
                //images
                hasmetacomponents |= false;
                arraylength        = BitConverter.ToInt32(serializedMessage, currentIndex);
                currentIndex      += Marshal.SizeOf(typeof(System.Int32));
                if (images == null)
                {
                    images = new Messages.sensor_msgs.Image[arraylength];
                }
                else
                {
                    Array.Resize(ref images, arraylength);
                }
                for (int i = 0; i < images.Length; i++)
                {
                    //images[i]
                    images[i] = new Messages.sensor_msgs.Image(serializedMessage, ref currentIndex);
                }
            }
Ejemplo n.º 5
0
            public override void Deserialize(byte[] serializedMessage, ref int currentIndex)
            {
                int  arraylength       = -1;
                bool hasmetacomponents = false;
                int  piecesize         = 0;

                byte[] thischunk, scratch1, scratch2;
                IntPtr h;
                object __thing;

                //serial
                serial        = "";
                piecesize     = BitConverter.ToInt32(serializedMessage, currentIndex);
                currentIndex += 4;
                serial        = Encoding.ASCII.GetString(serializedMessage, currentIndex, piecesize);
                currentIndex += piecesize;
                //totalFrameCount
                piecesize = Marshal.SizeOf(typeof(int));
                h         = IntPtr.Zero;
                if (serializedMessage.Length - currentIndex != 0)
                {
                    h = Marshal.AllocHGlobal(piecesize);
                    Marshal.Copy(serializedMessage, currentIndex, h, piecesize);
                }
                if (h == IntPtr.Zero)
                {
                    throw new Exception("Memory allocation failed");
                }
                totalFrameCount = (int)Marshal.PtrToStructure(h, typeof(int));
                Marshal.FreeHGlobal(h);
                currentIndex += piecesize;
                //images
                hasmetacomponents |= false;
                arraylength        = BitConverter.ToInt32(serializedMessage, currentIndex);
                currentIndex      += Marshal.SizeOf(typeof(System.Int32));
                if (images == null)
                {
                    images = new Messages.sensor_msgs.Image[arraylength];
                }
                else
                {
                    Array.Resize(ref images, arraylength);
                }
                for (int i = 0; i < images.Length; i++)
                {
                    //images[i]
                    images[i] = new Messages.sensor_msgs.Image(serializedMessage, ref currentIndex);
                }
            }
Ejemplo n.º 6
0
        int ConvertBitmapToMat(System.Drawing.Bitmap bmpImg, out Messages.sensor_msgs.Image Img)
        {
            int retVal = 0;

            Img = new Messages.sensor_msgs.Image();

            if (bmpImg.PixelFormat == System.Drawing.Imaging.PixelFormat.Format8bppIndexed)  // 灰度图像
            {
                //锁定Bitmap数据
                System.Drawing.Imaging.BitmapData bmpData = bmpImg.LockBits(
                    new System.Drawing.Rectangle(0, 0, bmpImg.Width, bmpImg.Height),
                    System.Drawing.Imaging.ImageLockMode.ReadWrite, bmpImg.PixelFormat);


                Byte[] data = new Byte[bmpData.Stride * bmpData.Height];
                Marshal.Copy(bmpData.Scan0, data, 0, bmpData.Stride * bmpData.Height);
                for (int i = 0; i < data.Length; i++)
                {
                    data[i] = (byte)(data[i]);
                }
                Img.height   = Convert.ToUInt32(bmpData.Height);
                Img.width    = Convert.ToUInt32(bmpData.Width);
                Img.step     = Convert.ToUInt32(bmpData.Stride);
                Img.encoding = "mono8";
                Img.data     = data;
                bmpImg.UnlockBits(bmpData);
            }
            else
            {
                Bitmap b1 = KiResizeImage(bmpImg, bmpImg.Width / 3, bmpImg.Height / 3, 0);
                Bitmap b  = RGB2Gray(b1);
                System.Drawing.Imaging.BitmapData bmpData = b.LockBits(
                    new System.Drawing.Rectangle(0, 0, b.Width, b.Height),
                    System.Drawing.Imaging.ImageLockMode.ReadWrite, b.PixelFormat);
                Byte[] data = new Byte[bmpData.Stride * bmpData.Height];
                Marshal.Copy(bmpData.Scan0, data, 0, bmpData.Stride * bmpData.Height);
                Img.height   = Convert.ToUInt32(b.Height);
                Img.width    = Convert.ToUInt32(b.Width);
                Img.step     = Convert.ToUInt32(bmpData.Stride);
                Img.encoding = "mono8";
                Img.data     = data;
                b.UnlockBits(bmpData);
            }
            //解锁Bitmap数据
            return(retVal);
        }
Ejemplo n.º 7
0
 public void PubMapImgR(Bitmap src)
 {
     Messages.sensor_msgs.Image dst = new Messages.sensor_msgs.Image();
     ConvertBitmapToMat(src, out dst);
     imager.publish(dst);
 }