From 8dd899ad4c93f2f850c5b082e5a74a85f2aa5130 Mon Sep 17 00:00:00 2001 From: Gerhard Roethlin Date: Mon, 8 Oct 2018 10:49:46 +0200 Subject: [PATCH] Adding support for OpenEXR with non-(0,0) windows OpenEXRs semantics for interpreting target frame buffers for reading requires offsetting the input data pointer in such a way that the first window pixel, applying the passed stride, again leads to the start of the data buffer. --- wrap/exr-wrap.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wrap/exr-wrap.cpp b/wrap/exr-wrap.cpp index 2ebe072..3bce9ca 100644 --- a/wrap/exr-wrap.cpp +++ b/wrap/exr-wrap.cpp @@ -120,7 +120,12 @@ EXRImage loadEXRRaw(char const * buffer, std::size_t size) { auto const & name = it.name(); image.planes[name].resize(image.width * image.height); - fb.insert(name, Slice(FLOAT, (char*)image.planes[name].data(), strideX, strideY)); + // OpenEXR needs to be passed a pointer that, when the window is applied, + // leads to the start of the data buffer, even if that pointer is illegal + auto startOffset = window.min.x + window.min.y * image.width; + fb.insert(name, Slice(FLOAT, + reinterpret_cast(image.planes[name].data() - startOffset), + strideX, strideY)); } file.setFrameBuffer(fb); file.readPixels(window.min.y, window.max.y);