LBitmapRgn::GetClipSegments

#include "ltwrappr.h"

virtual L_INT LBitmapRgn::GetClipSegments(nRow, pSegmentBuffer, puSegmentCount)

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

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 height of the class object's associated bitmap.

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 filled values in the pSegmentBuffer.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

To use this function, first call LBitmapRgn::SetRgnXForm with pXform set to NULL, and then use LBitmapRgn::GetRgnBounds to get the boundaries of the class objects associated bitmap. 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 and puSegmentCount will be filled with the value 4. Lets call them x0, x1, x2, x3. In this case:

It is recommended that you allocate a buffer large enough to hold all the possible segments. To get the maximum number of segments, call LBitmapRgn::GetClipSegmentsMax. 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

Win32, x64.

See Also

Functions:

LBitmapRgn::GetClipSegmentsMax, LBitmapRgn::GetRgnBounds, LBitmapRgn::SetRgnXForm, Class Members

Topics:

Raster Image Functions: Creating and Using a Region

 

Working with the Existing Bitmap Region

Example

The following example sets the pixels of the first row inside a region to black.

L_INT LBitmapRgn__GetClipSegmentsExample(LBitmapBase & Bitmap, L_TCHAR * pszFile) 
{ 
   L_INT nRet; 
   LBitmapRgn Region; 
   L_UINT uSegments; 
   L_UINT * pSegments; 
   RECT rcRegion, rcClip; 
   nRet =Bitmap.Load(pszFile); 
   if(nRet !=SUCCESS) 
      return nRet; 
   Region.SetBitmap(&Bitmap); 
   SetRect(&rcRegion, 
   Bitmap.GetWidth() / 4, 
   Bitmap.GetHeight() / 4, 
   3 * Bitmap.GetWidth() / 4, 
   3 * Bitmap.GetHeight() / 4); 
   nRet =Region.SetRgnRect(&rcRegion); 
   if(nRet !=SUCCESS) 
      return nRet; 
   // Get the maximum number of elements in a row, so we 
   // know how big the array of segments should be. 
   nRet =Region.GetClipSegmentsMax(&uSegments); 
   if(nRet !=SUCCESS) 
      return nRet; 
   // Allocate an array large enough to store the maximum 
   // number of segments. Note that LBitmapRgn::GetClipSegmentsMax 
   // took into account that each segment has two extremities. 
   pSegments = (L_UINT *) GlobalAllocPtr(GMEM_MOVEABLE, 
   uSegments * sizeof(L_UINT)); 
   if(!pSegments) 
      return -1; // Not enough memory! 
   // Get the region bounds, so we know the first row 
   nRet =Region.SetRgnXForm(NULL); 
   if(nRet !=SUCCESS) 
      return nRet; 
   nRet =Region.GetRgnBounds(&rcClip); 
   if(nRet !=SUCCESS) 
      return nRet; 
   // Get the segments for the first row 
   nRet =Region.GetClipSegments(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 segments to 0. 
   for (L_UINT i = 0; i < uSegments; i+=2) 
   for (L_UINT j = pSegments[i]; j < pSegments[i + 1]; j++) 
   { 
      nRet =Bitmap.PutPixelColor(rcClip.top, j, 0); 
      if(nRet !=SUCCESS) 
         return nRet; 
   } 
   // Free the segments array 
   GlobalFreePtr(pSegments); 
   return SUCCESS; 
} 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C++ Class Library Help