| Customize Help

Rearranging areas in your grabbed image



If one or more areas appear out of order in your grabbed image (for example, when using a camera that returns nonsequential data), you might need to rearrange one or more areas in your grabbed image. Rather than creating multiple child buffers and performing multiple copies, you can use MimRearrange(). This function copies specified areas from a newly grabbed image to a specified destination image. MimRearrange() might save some processing time and overhead when compared to multiple child buffer copy operations.

The MimRearrange() function uses a rearrangement image processing context to store processing settings. You must set up the rearrangement image processing context with the offsets of the required areas in the source image buffer, the offsets of the target areas in the destination image buffer, and the size of each area. Only the specified areas of the source image are copied from the source image to the areas specified in the destination image. The rest of the source image is ignored and not copied. The source and destination image buffers need not be of the same size, but must be equal to or larger than the largest supplied source and destination coordinates.

You can copy areas or rows of the source image. In the following example, two areas are copied from the source image to the destination image.

In the above illustration, you would have to set up the rearrangement image processing context with the following:

Area

Array with the X-offsets of the source areas

Array with the Y-offsets of the source areas

Array with the X-offsets of the target areas

Array with the Y-offsets of the target areas

Array with the X- size of the areas

Array with the Y- size of the areas

1

20

39

0

72

72

39

2

60

93

0

0

139

136

Before calling MimRearrange(), you must first set up the rearrangement image processing context by performing the following:

  1. Allocate a rearrangement image processing context, using MimAlloc() with M_REARRANGE_CONTEXT.

  2. Set the processing mode, using MimControl() with M_MODE. The processing mode indicates how to perform the operation. If the processing mode is set to lines mode, each area is a single horizontal line. If the mode is set to rectangles mode, each area is a single rectangle.

  3. Allocate 4 or 6 arrays with the same number of entries. When copying lines, only 4 arrays are required. When copying rectangles, 6 arrays are required. There should be one entry for every area to be rearranged.

  4. Set up 2 arrays with the offsets of the areas in the source image: one array for the X-offset and one array for the Y-offset. Then, load these arrays into the context, using MimPut() with M_XY_SOURCE. If copying lines, the X-coordinate of all the (x, y) values must be set to 0.

  5. Set up 2 arrays with the offsets of the areas in the destination image: one array for the X-offset and one array for the Y-offset. Then, load these arrays into the context, using MimPut() with M_XY_DESTINATION. If copying lines, the X-coordinate of all the (x, y) values must be set to 0. The destination offset arrays must contain the same number of elements as the source offset arrays.

  6. If copying rectangles, set up 2 arrays with the sizes of the areas: one array for the dimension in X and one array for the dimension in Y. Then, load these arrays into the context, using MimPut() with M_XY_SIZE. If copying lines, you should not specify the size of the areas, otherwise an error is reported. By default, all lines (rows) are 1 pixel high and as wide as the source image.

  7. Preprocess the context by calling MimRearrange() with M_PREPROCESS. Both the source and/or destination image buffers can be set to M_NULL. If, however, the source or destination image buffer is provided, it should be a typical source or destination image buffer, respectively, and it will be used by the preprocess operation to better optimize future calls. If the preprocess operation is not done explicitly, it will be done when MimRearrange() is first called.