예제 #1
0
        /// <summary>
        /// Sets the raw byte value of a Hid feature code.
        /// </summary>
        /// <param name="featureCode">The Hid feature code to set.</param>
        /// <param name="value">The value to set.</param>
        /// <returns></returns>
        /// <remarks></remarks>
        public bool HidSetFeature(byte featureCode, byte[] value)
        {
            bool HidSetFeatureRet = default;
            var  hfile            = HidFeatures.OpenHid(this);

            if (hfile == IntPtr.Zero)
            {
                return(false);
            }
            var mm = new MemPtr();

            mm.Alloc(value.Length + 1);
            mm.FromByteArray(value, 1L);
            mm.ByteAt(0L) = featureCode;
            if (!UsbLibHelpers.HidD_SetFeature(hfile, mm, (int)mm.Length))
            {
                HidSetFeatureRet = false;
            }
            else
            {
                HidSetFeatureRet = true;
            }

            mm.Free();
            HidFeatures.CloseHid(hfile);
            return(HidSetFeatureRet);
        }
예제 #2
0
        /// <summary>
        /// Create a transparency mask from the transparent bits in an image.
        /// </summary>
        /// <param name="hBits">A pointer to the memory address of the bitmap bits.</param>
        /// <param name="hMask">A pointer to the memory address of the mask bits.</param>
        /// <param name="Width">The width of the image.</param>
        /// <param name="Height">The height of the image.</param>
        /// <remarks></remarks>
        private void _setMask(MemPtr hBits, MemPtr hMask, int Width, int Height)
        {
            // this never changes
            int numBits = 32;

            int x;
            int y;

            byte bit;

            int d;
            int e;
            int f;

            double move = numBits / 8d;

            int stride = (int)(Width * (numBits / 8d));
            int msize  = (int)(Math.Max(32, Width) * Height / 8d);
            int isize  = (int)(Width * Height * (numBits / 8d));

            byte[] bb;
            byte[] imgb;

            imgb = new byte[isize];
            bb   = new byte[msize];

            Marshal.Copy(hBits.Handle, imgb, 0, isize);

            for (y = 0; y < Height; y++)
            {
                d = y * stride;

                for (x = 0; x < Width; x++)
                {
                    f = (int)(d + x * move);
                    e = (int)Math.Floor(x / 8d);

                    bit = (byte)(7 - x % 8);

                    if (imgb[f + 3] == 0)
                    {
                        bb[e] = (byte)(bb[e] | 1 << bit);
                    }
                }
            }

            // MemCpy(hMask.Handle, bb, msize)

            hMask.FromByteArray(bb, 0L);
        }