BodyTetrisWrapper.ImageUtils.ImageSubset C# (CSharp) Method

ImageSubset() public static method

public static ImageSubset ( byte pixels, int w, int h, int X1, int Y1, int X2, int Y2 ) : byte[]
pixels byte
w int
h int
X1 int
Y1 int
X2 int
Y2 int
return byte[]
        public static byte[] ImageSubset(byte[] pixels, int w, int h, int X1, int Y1, int X2, int Y2)
        {
            //w,h are size of whole image, X1,Y1,X2,Y2 are the subset
            byte[] newPixels = new byte[3*(X2-X1)*(Y2-Y1)];

            int oldIndex = 0;
            int newIndex = 0;

            for (int y = Y1; y < Y2; y++)
            {
                for (int x = X1; x < X2; x++)
                {

                    oldIndex = 3*(x + y * w);
                    newIndex = 3*((x - X1) + (y - Y1) * (X2 - X1));
                    //Console.WriteLine("x: " + x + " y: " + y + " old: " + oldIndex + " new: " + newIndex);

                    newPixels[newIndex] = pixels[oldIndex];
                    newPixels[newIndex + 1] = pixels[oldIndex + 1];
                    newPixels[newIndex + 2] = pixels[oldIndex + 2];

                }
            }

            return newPixels;
        }