From df1dadf7ba10a0447dad9808c8501299a3a19f5d Mon Sep 17 00:00:00 2001 From: "Adam D. Ruppe" Date: Sat, 26 Sep 2015 15:05:21 -0400 Subject: [PATCH] offset function --- simpledisplay.d | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/simpledisplay.d b/simpledisplay.d index 2fb5523..bd39b94 100644 --- a/simpledisplay.d +++ b/simpledisplay.d @@ -1917,6 +1917,19 @@ final class Image { } else static assert(0, "fill in this info for other OSes"); } + /// + int offsetForPixel(int x, int y) { + version(X11) { + auto offset = (y * width + x) * 4; + return offset; + } else version(Windows) { + auto itemsPerLine = ((cast(int) width * 3 + 3) / 4) * 4; + // remember, bmps are upside down + auto offset = itemsPerLine * (height - y - 1) + x * 3; + return offset; + } else static assert(0, "fill in this info for other OSes"); + } + /// int adjustmentForNextLine() { version(X11) {