L_ShiftBitmapData

#include "l_bitmap.h"

L_INT EXT_FUNCTION 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, let’s 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 signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

Required DLLs and Libraries

LTIMG

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 95 / 98 / Me, Windows 2000 / XP.

See Also

Functions:

L_SelectBitmapData, L_ColorizeGrayBitmap, L_AdjustBitmapTint, L_ColorHalfToneBitmap

Topics:

Raster Image Functions: Modifying Intensity Values

 

Grayscale Images

 

Color Halftone and Halftone Images

 

Raster Image Functions: Correcting Colors

Example

/* This example loads a bitmap and applies Shifing. */
 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 */
L_LoadBitmap
 (TEXT("IMAGE1.CMP"), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGRORGRAY, NULL, NULL); 

/* Move 5 bits starting from bit 2 into the high bits of the destination bitmap */
L_ShiftBitmapData
 (&DstBitmap, &LeadBitmap,
2 /* uSrcLowBit */, 
6 /* uSrcHighBit*/, 
3 /* uDstLowBit */, 
8 /* uDstBitsPerPixel */ ); 

L_FreeBitmap
 (&LeadBitmap); 

// Now we have the resulting image in DstBitmap