/// <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 CanRemapByExactPaletteColors(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); if (dest.CanSetPixel(x + destStart.X, y + destStart.Y, color).Value is MagitekResult.Failed) { var palName = dest.GetElementAtPixel(x + destStart.X, y + destStart.Y)?.Palette?.Name ?? "Undefined"; return(new MagitekResult.Failed($"Destination image at (x: {destStart.X}, y: {destStart.Y}) with element palette '{palName}' could not be set to the source color ({color.A}, {color.R}, {color.G}, {color.B})")); } } } return(MagitekResult.SuccessResult); }
private static MagitekResult CanExactColorRemapPixels(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); var result = dest.CanSetPixel(x + destStart.X, y + destStart.Y, color); if (result.Value is MagitekResult.Failed) { return(result); } } } return(MagitekResult.SuccessResult); }