Width/height of a buffer

BlitzPlus Forums/BlitzPlus Programming/Width/height of a buffer

Timjo(Posted 2008) [#1]
Is there a way to determine the width/height of any given gfx buffer without knowing what type of buffer it is - ie canvas/image/graphics ? I know I can use imagewidth/height for an image and clientwidth/height for the others - but I'd like a single solution for all types so I can pass any gfx buffer's handle to a routine and work out the size.
I have seen in the docs the commands lockedpitch/format/pixels - and I think these might be the commands to use - but I'm not sure how to interpret the values these commands return. Any help gratefully received. Thanks... Tim.


Snarkbait(Posted 2008) [#2]
You know, I tried playing around with lockedPixels() and could not get it to work... anyone know?


Floyd(Posted 2008) [#3]
LockedPitch tells how much memory is used for each horizontal row in an image buffer, but not how many pixels it represents.

Say you had a small image, 17 x something, and were using 16-bit graphics. That's 2 bytes per pixel. So one row needs 17 * 2 = 34 bytes of memory. But your graphics card might need to align this on an 8-byte boundary, due to restrictions on the way it accesses memory.

In this case 34 will be rounded up to 40, the next multiple of 8. Here the pitch is 40.
Each row then consists of 34 bytes of pixel data, followed by 6 bytes of unused space. The pitch would also be 40 if the image width is 18, 19 or 20.


Timjo(Posted 2008) [#4]
Thanks Floyd - I'll go back and see if I can make sense of those figures again. I Should be able to sort things out now. Thanks again...Tim.