public static IPixelViewModel Crop(IPixelViewModel pixels, int left, int top, int right, int bottom) { var(width, height) = (pixels.PixelWidth - left - right, pixels.PixelHeight - top - bottom); Debug.Assert(width % 8 == 0, $"Cropped image must still have a width/height that's a multiple of 8, but width was {width}."); Debug.Assert(height % 8 == 0, $"Cropped image must still have a width/height that's a multiple of 8, but height was {height}."); var pixelData = new short[width * height]; for (int y = 0; y < height; y++) { var originalDataStart = pixels.PixelWidth * (y + top) + left; if (originalDataStart < 0) { continue; } var croppedDataStart = width * y; Array.Copy(pixels.PixelData, originalDataStart, pixelData, croppedDataStart, width); } return(new ReadonlyPixelViewModel(new SpriteFormat(4, width / 8, height / 8, string.Empty), pixelData)); }
public static IPixelViewModel DuplicateDown(IPixelViewModel pixels, int count) { if (count == 1) { return(pixels); } Debug.Assert(count > 0, $"Cannot duplicate {count} times."); var pixelData = new short[pixels.PixelWidth * pixels.PixelHeight * count]; for (int y = 0; y < pixels.PixelHeight; y++) { var originalDataStart = pixels.PixelWidth * y; for (int i = 0; i < count; i++) { var newDataStart = pixels.PixelWidth * y + pixels.PixelData.Length * i; Array.Copy(pixels.PixelData, originalDataStart, pixelData, newDataStart, pixels.PixelWidth); } } return(new ReadonlyPixelViewModel(new SpriteFormat(4, pixels.PixelWidth / 8, pixels.PixelHeight / 8 * count, string.Empty), pixelData)); }