Ejemplo n.º 1
0
        /// <summary>
        /// Reads pixels data into single array of pixels with new stride equal to <paramref name="width"/>.
        /// </summary>
        /// <typeparam name="T">Type of the pixel.</typeparam>
        /// <param name="width">Bitmap width.</param>
        /// <param name="height">Bitmap height.</param>
        /// <param name="data">Pointer to start of bitmap data.</param>
        /// <param name="stride">Row stride in bytes.</param>
        /// <param name="channels">Number of channels in the image.</param>
        /// <returns>Array of image pixels.</returns>
        private static T[] ReadPixels <T>(int width, int height, NakedPointer data, int stride, int channels)
        {
            int pixelByteSize = System.Runtime.InteropServices.Marshal.SizeOf <T>();

            if (stride <= 0 || stride == pixelByteSize * channels * width)
            {
                return(new CodeArray <T>(data, width * height * channels).ToArray());
            }
            else
            {
                T[] result      = new T[width * height * channels];
                int rowElements = width * channels;

                for (int y = 0, j = 0; y < height; y++)
                {
                    CodeArray <T> array = new CodeArray <T>(data.AdjustPointer(stride * y), rowElements);

                    for (int x = 0; x < rowElements; x++, j++)
                    {
                        result[j] = array[x];
                    }
                }

                return(result);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Reads the string from CodeArray.
 /// </summary>
 /// <param name="codeArray">The code array.</param>
 /// <returns>Read string from CodeArray.</returns>
 public static string ReadString(this CodeArray <char> codeArray)
 {
     if (codeArray.variable != null)
     {
         return(UserType.ReadString(codeArray.variable.GetCodeType().Module.Process, codeArray.variable.GetPointerAddress(), (int)codeArray.variable.GetCodeType().ElementType.Size, codeArray.Length));
     }
     else
     {
         return(new string(codeArray.ToArray()));
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Reads the memory buffer from CodeArray.
 /// </summary>
 /// <param name="codeArray">The code array.</param>
 /// <returns>Read memory buffer from CodeArray.</returns>
 public static MemoryBuffer ReadMemory(this CodeArray <byte> codeArray)
 {
     return(Debugger.ReadMemory(codeArray.variable, (uint)codeArray.Length));
 }