From 6978d1f2dde91ec4865ea9731a20931362363450 Mon Sep 17 00:00:00 2001 From: Elias Batek Date: Mon, 7 Oct 2024 00:17:36 +0200 Subject: [PATCH] Implement clockwise rotation --- pixmappaint.d | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pixmappaint.d b/pixmappaint.d index 2ac1603..20314f3 100644 --- a/pixmappaint.d +++ b/pixmappaint.d @@ -1648,6 +1648,32 @@ void cropInplace(ref Pixmap source, Size targetSize, Point offset = Point(0, 0)) source = src.extractToPixmap(source); } +/++ + Rotates an image by 90° clockwise. + + $(PITFALL + This function does not work in place. + Do not attempt to pass Pixmaps sharing the same buffer for both source + and target. Such would lead to a bad result with heavy artifacts. + ) + +/ +void rotateClockwise(const Pixmap source, Pixmap target) @nogc { + debug assert(source.data.length == target.data.length); + + const area = source.data.length; + const rowLength = source.size.height; + ptrdiff_t cursor = -1; + + foreach (px; source.data) { + cursor += rowLength; + if (cursor > area) { + cursor -= (area + 1); + } + + target.data[cursor] = px; + } +} + @safe pure nothrow @nogc: // ==== Blending functions ====