LBitmap::ShiftData

Summary

Selects a specified number of bits from an 8, 12 or 16-bit grayscale bitmap into a mask and places the mask in a new 8, 12 or 16-bit grayscale bitmap.

Syntax

#include "ltwrappr.h"

virtual L_INT LBitmap::ShiftData (pSrcBitmap, uSrcLowBit, uSrcHighBit, uDstLowBit, uDstBitsPerPixel, uFlags = 0)

virtual L_INT LBitmap::ShiftData (plSrcBitmap, uSrcLowBit, uSrcHighBit, uDstLowBit, uDstBitsPerPixel, uFlags = 0)

Parameters

pBITMAPHANDLE pSrcBitmap

Pointer to the source bitmap that will contain the result of the function. The user should free the bitmap before passing it to the function.

L_UINT uSrcLowBit

Position of the start bit that will construct the mask. The position is a zero-based number.

L_UINT uSrcHighBit

Position of the end bit. This is inclusive (it is part of the mask). The value should not be less than uSrcLowBit. You can also pass -1, which is interpreted as "highest bit" (pSrcBitmap->BitsPerPixel - 1).

L_UINT uDstLowBit

The bit position where the selected mask will be copied into the pDstBitmap.

L_UINT uDstBitsPerPixel

Bits per pixel for the destination bitmap. The allowed values are 8, 12, or 16

LBitmapBase *plSrcBitmap

Pointer to the source bitmap object that will contain the result of the function. The user should free the bitmap before passing it to the function.

L_UINT32 uFlags

Reserved for future use. Must be 0.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

The function is used mainly as a visualization aid. You can select certain bits of the supported type bitmap and display them in another bitmap.

You can use this function for other purposes than visualization. For example, lets say you loaded a 16-bit file that has the pixels in Motorola format (where the high and low bytes are swapped). You can swap the high and low 8 bits for each pixel by calling this function twice and OR-ing the results.

The pDstBitmap should not be allocated when calling this function. You should free the allocated bitmap before calling this function. When the function returns successfully the pDstBitmap will be an 8, 12 or 16-bit grayscale.

For 8, 12 and 16-bit grayscale bitmaps, the uSrcLowBit can range from 0 to 7, 0 to 11, and 0 to 15 respectively. However if this value exceeded the range then the function will not return an error, and the pDstBitmap will be a pure black bitmap.

The uSrcHighBit must be greater than or equal to uSrcLowBit. The function will return an invalid parameter error if uSrcHighBit < uSrcLowBit.

The uDstLowBit can range from 0 to uDstBitsPerPixel - 1. If you pass greater values for uDstLowBit, the function will not return an error, but pDstBitmap will become a pure black bitmap.

The following example shows you how to treat a 16-bit grayscale bitmap:

In a16-bit grayscale bitmap, the bits are ordered as b15 b14 b13 ... b2 b1 b0. You can choose the bit from where to start moving the bits.

For example, if the mask starts at the fourth bit (b3), with a length equal to 6 bits, the destination starting position is 4 and we want to create an 8-bit destination bitmap:

uSrcLowBit = 3
uSrcHighBit = 8
uDstLowBit = 4
uDstBitsPerPixel = 8

Source bitmap (pSrcBitmap):


b15 b14 b13 b12 b11 b10 b9 |b8 b7 b6 b5 b4 b3| b2 b1 b0


0 1 1 0 1 1 1 0 1 0 0 1 1 1 0 1

Destination bitmap (pDstBitmap):


|b7 b6 b5 b4| b3 b2 b1 b0

0 0 1 1 0 0 0 0

You can notice that b7 and b8 of pSrcBitmap are truncated in the bitmap object since there is no space for them.

To update a status bar or detect a user interrupt during execution of this function, refer to LBase::EnableStatusCallback.

This function supports 8, 12 and 16-bit grayscale bitmaps only. Support for 12 and 16-bit grayscale images are available only in the Document/Medical toolkits. It also can process the whole image or a region of the image. If a bitmap has a region, the effect is applied only to the region.

This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.

Shift Data Function - Before

Shift Data Function - Before

Shift Data Function - After

Shift Data Function - After

View additional platform support for this Shift Data function.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

L_INT LBitmap__ShiftDataExample(LBitmap *pLeadBitmap, LBitmap *pSrcBitmap)  
{ 
   L_INT nRet; 
   /* This example applies Shifting. */ 
   /* Move 5 bits starting from bit 2 into the high 8-bits of the destination bitmap */ 
   nRet =pLeadBitmap->ShiftData (pSrcBitmap,  
                                 2 /* uSrcLowBit */,  
                                 6 /* uSrcHighBit*/,  
                                 3 /* uDstLowBit */,  
                                 8 /* uDstBitsPerPixel */ ); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   pLeadBitmap->Free (); 
 
   // Now we have the resulting image in pLeadBitmap 
    
   return SUCCESS; 
} 
Help Version 22.0.2023.2.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C++ Class Library Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.