private static void ApplyExactColorRemapPixels(DirectImage source, IndexedImage dest, Point sourceStart, Point destStart, int copyWidth, int copyHeight) { for (int y = 0; y < copyHeight; y++) { for (int x = 0; x < copyWidth; x++) { var color = source.GetPixel(x + sourceStart.X, y + sourceStart.Y); dest.SetPixel(x + destStart.X, y + destStart.Y, color); } } }
/// <summary> /// Tries to set a pixel's palette index at the specified pixel coordinate /// </summary> /// <param name="x">x-coordinate in pixel coordinates</param> /// <param name="y">y-coordinate in pixel coordinates</param> /// <param name="color">Palette index of color</param> /// <returns>True if set, false if not set</returns> public static MagitekResult TrySetPixel(this IndexedImage image, int x, int y, ColorRgba32 color) { var result = image.CanSetPixel(x, y, color); if (result.Value is MagitekResult.Success) { image.SetPixel(x, y, color); } return(result); }
//private static MagitekResult CanRemapByAnyIndex(IndexedImage source, IndexedImage dest, Point sourceStart, Point destStart, int copyWidth, int copyHeight) //{ // for (int y = 0; y < copyHeight; y++) // { // for (int x = 0; x < copyWidth; x++) // { // } // } // return MagitekResult.SuccessResult; //} private static void ApplyRemapByExactIndex(IndexedImage source, IndexedImage dest, Point sourceStart, Point destStart, int copyWidth, int copyHeight) { for (int y = 0; y < copyHeight; y++) { for (int x = 0; x < copyWidth; x++) { var index = source.GetPixel(x + sourceStart.X, y + sourceStart.Y); dest.SetPixel(x + destStart.X, y + destStart.Y, index); } } }
/// <summary> /// Fills the surrounding, contiguous color area with a new color /// </summary> /// <param name="x">x-coordinate to start at in pixel coordinates</param> /// <param name="y">y-coordinate to start at in pixel coordinates</param> /// <param name="fillIndex">Palette index to fill with</param> /// <returns>True if any pixels were modified</returns> public static bool FloodFill(this IndexedImage image, int x, int y, byte fillIndex) { bool isModified = false; var replaceIndex = image.GetPixel(x, y); var startingPalette = image.GetElementAtPixel(x, y).Value.Palette; if (fillIndex == replaceIndex) { return(false); } var openNodes = new Stack <(int x, int y)>(); openNodes.Push((x, y)); while (openNodes.Count > 0) { var nodePosition = openNodes.Pop(); if (nodePosition.x >= 0 && nodePosition.x < image.Width && nodePosition.y >= 0 && nodePosition.y < image.Height) { var nodeColor = image.GetPixel(nodePosition.x, nodePosition.y); if (nodeColor == replaceIndex) { var destPalette = image.GetElementAtPixel(nodePosition.x, nodePosition.y).Value.Palette; if (ReferenceEquals(startingPalette, destPalette)) { isModified = true; image.SetPixel(nodePosition.x, nodePosition.y, fillIndex); openNodes.Push((nodePosition.x - 1, nodePosition.y)); openNodes.Push((nodePosition.x + 1, nodePosition.y)); openNodes.Push((nodePosition.x, nodePosition.y - 1)); openNodes.Push((nodePosition.x, nodePosition.y + 1)); } } } } return(isModified); }