1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

OpenGL: Return image BitmapData in JUCE order rather than native order

JUCE convention is that BitmapData holds the lines of the image ordered
from top to bottom, but OpenGL orders lines in the reverse direction.
By returning a negative line stride, we can iterate lines in the
expected order as long as we always increment the current pointer
position by the line stride after processing each line.
This commit is contained in:
reuk 2025-05-15 19:23:32 +01:00
parent 9f4aef4053
commit 1fcdd29bf9
No known key found for this signature in database

View file

@ -85,11 +85,15 @@ public:
auto releaser = std::make_unique<DataReleaser> (this, Rectangle { x, y, bitmapData.width, bitmapData.height }, mode);
bitmapData.data = (uint8*) releaser->data.get();
bitmapData.size = (size_t) bitmapData.width
* (size_t) bitmapData.height
* sizeof (PixelARGB);
bitmapData.lineStride = (bitmapData.width * bitmapData.pixelStride + 3) & ~3;
const auto unsignedLineStride = (((size_t) bitmapData.width * (size_t) bitmapData.pixelStride + 3) & ~((size_t) 3));
bitmapData.lineStride = -((int) unsignedLineStride);
bitmapData.size = (size_t) bitmapData.height * unsignedLineStride;
// OpenGL mapped textures are stored in lines from bottom-to-top, but JUCE expects lines to
// be ordered top-to-bottom.
// The data pointer points to the beginning of the *last* line, and lineStride steps backwards
// through the lines.
bitmapData.data = (uint8*) releaser->data.get() + (ptrdiff_t) bitmapData.size + (ptrdiff_t) bitmapData.lineStride;
bitmapData.dataReleaser = std::move (releaser);