diff --git a/src/ImageSharp/Formats/Jxl/Processing/JxlImageOperations.cs b/src/ImageSharp/Formats/Jxl/Processing/JxlImageOperations.cs index f1b50596f..c62f6a403 100644 --- a/src/ImageSharp/Formats/Jxl/Processing/JxlImageOperations.cs +++ b/src/ImageSharp/Formats/Jxl/Processing/JxlImageOperations.cs @@ -46,6 +46,47 @@ internal static class JxlImageOperations return false; } - + if (!from.IsRectangleInside(rectFrom)) + { + return false; + } + + if (!to.IsRectangleInside(rectTo)) + { + return false; + } + + if (rectFrom.Width == 0) + { + return true; + } + + for (int y = 0; y < rectFrom.Height; y++) + { + Span rowFrom = from.GetRow(rectFrom, y); + Span rowTo = to.GetRow(rectTo, y); + rowFrom.CopyTo(rowTo); + } + + return true; + } + + public static bool CopyImageTo(Rectangle rectFrom, JxlImage3 from, Rectangle rectTo, JxlImage3 to) + where T : unmanaged + { + if (rectFrom != rectTo) + { + return false; + } + + for (int plane = 0; plane < 3; plane++) + { + if (!CopyImageTo(rectFrom, from.Plane(plane), rectTo, to.Plane(plane))) + { + return false; + } + } + + return true; } }