L_ShiftBitmapData
#include "l_bitmap.h"
L_LTIMGCOR_API L_INT L_ShiftBitmapData(pDstBitmap, pSrcBitmap, uSrcLowBit, uSrcHighBit, uDstLowBit, uDstBitsPerPixel)
pBITMAPHANDLE pDstBitmap; |
/* pointer to the destination bitmap handle */ |
pBITMAPHANDLE pSrcBitmap; |
/* pointer to the source bitmap handle */ |
L_UINT uSrcLowBit; |
/* position of the starting bit of the mask */ |
L_UINT uSrcHighBit; |
/* length of the mask */ |
L_UINT uDstLowBit; |
/* placement of the mask in pDstBitmap */ |
L_UINT uDstBitsPerPixel; |
/* bits per pixel for the destination bitmap */ |
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. This function is available in the Medical toolkits.
Parameter |
Description |
pDstBitmap |
Pointer to the destination bitmap that will contain the result of the function. The user should free the bitmap before passing it to the function. |
pSrcBitmap |
Pointer to the source bitmap handle referencing the 8, 12 or 16-bit grayscale bitmap. pSrcBitmap will not be affected. |
uSrcLowBit |
Position of the start bit that will construct the mask. The position is a zero-based number. |
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). |
uDstLowBit |
The bit position where the selected mask will be copied into the pDstBitmap. |
uDstBitsPerPixel |
Bits per pixel for the destination bitmap. The allowed values are 8, 12, or 16 |
Returns
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 pDstBitmap since there is no space for them.
To update a status bar or detect a user interrupt during execution of this function, refer to L_SetStatusCallback.
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.
Required DLLs and Libraries
LTIMGCOR 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_SelectBitmapData, L_ColorizeGrayBitmap, L_AdjustBitmapTint, L_ColorHalfToneBitmap |
Topics: |
|
|
|
|
|
|
Example
This example loads a bitmap and applies Shifing.
L_INT ShiftBitmapDataExample(L_VOID) { L_INT nRet; BITMAPHANDLE LeadBitmap; /* Bitmap handle to hold the loaded image. */ BITMAPHANDLE DstBitmap; /* Bitmap handle to hold the result. */ /* Load the bitmap, keeping the bits per pixel of the file */ nRet = L_LoadBitmap (TEXT("C:\\Program Files\\LEAD Technologies\\LEADTOOLS 15\\Images\\GrayIMAGE1.tif"), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL); if(nRet !=SUCCESS) return nRet; /* Move 5 bits starting from bit 2 into the high bits of the destination bitmap */ nRet = L_ShiftBitmapData (&DstBitmap, &LeadBitmap, 2 /* uSrcLowBit */, 6 /* uSrcHighBit*/, 3 /* uDstLowBit */, 8 /* uDstBitsPerPixel */ ); if(nRet !=SUCCESS) return nRet; // Now we have the resulting image in DstBitmap nRet = L_SaveBitmap(TEXT("C:\\Program Files\\LEAD Technologies\\LEADTOOLS 15\\Images\\Result.BMP"), &DstBitmap, FILE_BMP, 24, 0, NULL); if(nRet !=SUCCESS) return nRet; if(DstBitmap.Flags.Allocated) L_FreeBitmap(&DstBitmap); //free bitmap if(LeadBitmap.Flags.Allocated) L_FreeBitmap(&LeadBitmap); return SUCCESS; }