public static MagitekResult CopyPixels(IndexedImage source, DirectImage dest, Point sourceStart, Point destStart, int copyWidth, int copyHeight) { var dimensionResult = CanCopyPixelDimensions(source, dest, sourceStart, destStart, copyWidth, copyHeight); if (dimensionResult.Value is MagitekResult.Failed) { return(dimensionResult); } if (ImageRegionContainsInvalidElements(source, sourceStart, copyWidth, copyHeight)) { return(new MagitekResult.Failed($"Source image copy region contains blank elements")); } if (ImageRegionContainsInvalidElements(dest, destStart, copyWidth, copyHeight)) { return(new MagitekResult.Failed($"Destination image paste region contains blank elements")); } for (int y = 0; y < copyHeight; y++) { for (int x = 0; x < copyWidth; x++) { var color = source.GetPixelColor(x + sourceStart.X, y + sourceStart.Y); dest.SetPixel(x + destStart.X, y + destStart.Y, color); } } return(MagitekResult.SuccessResult); }
private static void ApplyRemapByExactPaletteColors(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 color = source.GetPixelColor(x + sourceStart.X, y + sourceStart.Y); dest.SetPixel(x + destStart.X, y + destStart.Y, color); } } }
private static MagitekResult CanRemapByExactPaletteColors(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 color = source.GetPixelColor(x + sourceStart.X, y + sourceStart.Y); if (dest.CanSetPixel(x + destStart.X, y + destStart.Y, color).Value is MagitekResult.Failed) { var el = dest.GetElementAtPixel(x + destStart.X, y + destStart.Y); var palName = el?.Palette?.Name ?? "Default"; 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); }