L_GetBitmapClipSegments

#include "l_bitmap.h"

L_LTDIS_API L_INT L_GetBitmapClipSegments(pBitmap, nRow, pSegmentBuffer, puSegmentCount)

pBITMAPHANDLE pBitmap;

/* pointer to the bitmap handle */

L_INT nRow;

/* number of the row */

L_UINT* pSegmentBuffer;

/* pointer to a buffer */

L_UINT* puSegmentCount;

/* pointer to a variable to be updated */

Gets the segments contained in the region for a particular row.

Parameter

Description

pBitmap

Pointer to the bitmap handle referencing the bitmap.

nRow

The number of the row for which to get the segments. The first row is 0, and the last row is 1 less than the bitmap height.

pSegmentBuffer

Pointer to the buffer to be updated with the segments from row nRow contained in the region. This buffer should be large enough to contain twice as many values as indicated in *puSegmentCount.

puSegmentCount

Address of a variable to be updated with the number of segments from row nRow that are contained in the region.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

To use this function, first call L_GetBitmapRgnBounds with pXForm set to NULL, to get the bitmap boundaries. The bounding rectangle will indicate which rows are contained in the region. Go through all the rows contained in the region to get the segments contained in the region.

The segments are returned as an array of pairs of horizontal offsets. The first point in the pair is the beginning of the segment (it is contained in the region). The last point in the pair is the end of the segment. To follow the Windows rules, the end of the segment is the first point NOT CONTAINED in the region.

In most regions, there will be one segment per row. However, some regions can have 0, 1, 2 or more segments.

For example, assume that for a particular row there are two segments. pSegmentBuffer will be filled with 4 values. Lets call them x0, x1, x2, x3. In this case:

image\sqrblit.gif portion from 0 to x0 1 is OUTSIDE the region

image\sqrblit.gif portion from x0 to x1 - 1 is INSIDE the region

image\sqrblit.gif portion from x1 to x2 1 is OUTSIDE the region

image\sqrblit.gif portion from x2 to x3 1 is INSIDE the region

image\sqrblit.gif portion from x3 to pBitmap->Width 1 is OUTSIDE the region

It is recommended that you allocate a buffer large enough to hold all the possible segments. To get the maximum number of segments, call L_GetBitmapClipSegmentsMax. Allocate an array of unsigned values that can contain the largest number of segments. See the example for more details.

Required DLLs and Libraries

LTDIS

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Windows 2000 / XP/Vista.

See Also

Functions:

L_GetBitmapRgnBounds, L_GetBitmapClipSegmentsMax

Topics:

Raster Image Functions: Creating and Using a Region

 

Working with the Existing Bitmap Region

Example

This example will set the pixels from the first row inside the region to black.

 L_INT GetBitmapClipSegmentsExample(pBITMAPHANDLE pBitmap)
{
   L_INT nRet;
   L_UINT   uSegments;
   L_UINT*  pSegments;
   RECT     rcClip;
   L_UINT   i, j;

   // get the maximum number of elements in a row, so I know how big the array of segments should be
   nRet = L_GetBitmapClipSegmentsMax(pBitmap, &uSegments);
   if(nRet != SUCCESS)
      return nRet;

   // allocate an array large enough to store the maximum number of segments. Note that 
   //    L_GetBitmapClipSegmentsMax took into account that each segment has two extremities.
   pSegments = (L_UINT *)GlobalAllocPtr(GMEM_MOVEABLE, uSegments * sizeof(L_UINT));
   if(!pSegments)
      return ERROR_NO_MEMORY ;  // not enough memory!!

   // get the region bounds, so I know which is the first row
   nRet = L_GetBitmapRgnBounds(pBitmap, NULL, &rcClip);
   if(nRet != SUCCESS)
      return nRet;

   // get the segments for the first row
   nRet = L_GetBitmapClipSegments(pBitmap, rcClip.top, pSegments, &uSegments);
   if(nRet != SUCCESS)
      return nRet;

   // do something with the segments.
   // to keep this example simple, we will set the pixels in the segment to 0
   for(i = 0; i < uSegments; i++)
      for(j = pSegments[i * 2]; j < pSegments[i * 2 + 1]; j++)
      {
          nRet = L_PutPixelColor(pBitmap, rcClip.top, j, 0);
         if(nRet != SUCCESS)
            return nRet;
      }

   // free the segments array
   GlobalFreePtr(pSegments);
   return SUCCESS;
}