| Customize Help

Accessing a MIL buffer directly

If needed, a MIL buffer's contents can be accessed directly. For instance, if you want to calculate the average value of the pixels in your image, you could create a custom algorithm. The algorithm could be applied directly to the buffer without having to copy the contents of the MIL buffer into a user-allocated array using MbufGet(). This would be more efficient and might improve the performance of the custom algorithm.

To access the MIL buffer directly, you need to know the buffer's address, pitch, depth, size, and format. When dealing with image buffers, the format includes whether the image buffer is packed or planar, as well as its color format. The pitch is the number of pixels between the beginning of any two adjacent lines of the buffer data. The pitch can differ from the width of the buffer, especially when dealing with child buffers, where the pitch of the child is the pitch of the parent buffer. For this reason, we recommend you always inquire the pitch (using MbufInquire() with M_PITCH). To inquire the pitch in bytes, use M_PITCH_BYTE.

You can inquire the address of a parent or child buffer using MbufInquire() with M_HOST_ADDRESS or M_PHYSICAL_ADDRESS. For an image buffer, the returned address will be the address of the top left-most pixel in the parent or child image buffer, respectively.

The following example shows how to inquire and use the Host address when accessing a monochrome buffer, a color packed buffer, and a color planar buffer.