#include "l_bitmap.h"
L_LTKRN_API L_INT L_ConvertBufferExt2(pBuffer, nWidth, nBitsPerPixelSrc, nBitsPerPixelDst, nOrderSrc, nOrderDst, pPaletteSrc, pPaletteDst, pPaletteSrc16, pPaletteDst16, uFlags, uLowBit, uHighBit)
Converts data in the specified buffer to the specified bits per pixel and color order. You can convert from any bits per pixel to any bits per pixel.
Pointer to the input buffer.
Image width, in pixels.
Input bits per pixel. Possible values are 1, 2, 3, 4, 5, 6, 7, 8, 16, 24, 32, 48, and 64.
Output bits per pixel. Use 0 for 8-bit grayscale.
The input color order. Possible values are:
Value | Meaning |
---|---|
ORDER_RGB | [0] The input colors are in red-green-blue order. |
ORDER_BGR | [1] The input colors are in blue-green-red order. |
ORDER_GRAY | [2] The input is grayscale. |
ORDER_ROMM | [5] The input colors are in ROMM order. ROMM only supports 24 and 48-bit images. |
0 | The data is 8 bits per pixel or less. |
The output color order. Possible values are:
Value | Meaning |
---|---|
ORDER_RGB | [0] The output colors are in red-green-blue order. |
ORDER_BGR | [1] The output colors are in blue-green-red order. |
ORDER_GRAY | [2] The output is grayscale. |
ORDER_ROMM | [5] The output colors are in ROMM order. ROMM only supports 24 and 48-bit images. |
0 | The data is 8 bits per pixel or less. |
Pointer to the palette for the existing data, before conversion. If the data is converted from 16 or 24 bits per pixel, use NULL for no palette.
Pointer to the palette for the converted data. If the data is converted to 16 or 24 bits per pixel color, use NULL for no palette.
Pointer to the 16-bit LUT for the existing data, before conversion. If the data is converted from 16 or 24 bits per pixel, use NULL for no palette.
Reserved for future use. Pass NULL.
Flags indicating whether to treat 16 bit data as grayscale or color. Possible values are:
Value | Meaning |
---|---|
CVT_SRCGRAY | [0x0001] Source buffer has grayscale data. |
CVT_DSTGRAY | [0x0002] Destination buffer has grayscale data. |
CVT_SRCUSEBITS | [0x0003] uLowBit and uHighBit apply to the source bitmap. |
CVT_SRCDSTBITS | [0x0004] uLowBit and uHighBit apply to the destination bitmap. |
CVT_DSTUSEBITS | [0x0008] uLowBit and uHighBit apply to the destination bitmap. |
CVT_USEALPHA | [0x0010] Use the alpha channel data (if present). |
CVT_ALPHAINIT | [0x0020] Initialize the alpha channel (for 32 or 64-bit color images) to all ones (0xFF for 8-bit alpha channels and 0xFFFF for 16-bit alpha channels). Without this flag, a created alpha channel initializes to zeros. |
CVT_SIGNED | [0x0100] Treat image data as signed data during conversion. |
Value indicating the low bit in the source buffer, if the source buffer contains grayscale data.
Value indicating the high bit in the source buffer, if the source buffer contains grayscale data.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
Note: This function will also work for 12, 16 and 32-bit grayscale images, but only in the Document and Medical Imaging toolkits. If you attempt to use this function with a 12, 16 or 32-bit grayscale image, but you do not have a Medical Imaging edition, you will receive an error.
The conversion uses only one buffer, which must be large enough to hold the data before and after conversion.
Image data that is 8 bits per pixel or less must use a palette, and this function can use such data as input, output, or both. Therefore, you may need to specify the palette for the input, or for the output, or both.
If either nBitsPerPixelSrc
or nBitsPerPixelDst
is 16 or 32, uFlags
is used to determine whether the data should be treated as color or grayscale.
If nBitsPerPixelSrc is 12, it is assumed to be grayscale. However, the uFlags parameter should also reflect that it is grayscale for future compatibility.
If the source is grayscale (other than 32-bit), pPaletteSrc
can be set to a palette. The palette should contain N entries. If the source uses uLowBit
and uHighBit
, then N equals 2 raised to the power of (uHighBit - uLowBit + 1). Otherwise, N equals 2 raised to the power of nBitsPerPixelSrc. Note that if the source is 32-bit grayscale, the value of the pPaletteSrc parameter will be ignored
uFlags supersedes nOrderSrc
and nOrderDst
. If you specify ORDER_BGR for nOrderSrc, but use CVT_SRCGRAY in uFlags, it will be assumed that the source buffer contains grayscale data.
pPaletteSrc16
is used only if the source is grayscale. In this case, if pPaletteSrc16 is not NULL, it will supersede the pPaletteSrc parameter. So, if you pass both pPaletteSrc and pPaletteSrc16, pPaletteSrc16 will be used.
Required DLLs and Libraries
Win32, x64, Linux.
This example loads a temporary bitmap at 24 bits per pixel, creates a new 16-bit grayscale image, and uses L_ConvertBufferExt2 to convert data from the temporary bitmap to the new one.
L_INT ConvertBufferExt2Example(HWND hWnd)
{
L_INT nRet;
BITMAPHANDLE LeadBitmap; /* Bitmap handle for the final image */
BITMAPHANDLE TmpBitmap; /* Bitmap handle to hold the input image */
L_UCHAR* pBuf; /* Buffer to hold the row */
HGLOBAL hBuf; /* Handle to the buffer */
L_INT i; /* Loop counter */
/* Load the bitmap, at 24 bits per pixel */
nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Image3.cmp")), &TmpBitmap, sizeof(BITMAPHANDLE), 24, 0, NULL, NULL);
if(nRet != SUCCESS)
return nRet;
/* Create a new 16-bit grayscale bitmap */
nRet = L_CreateBitmap(&LeadBitmap, sizeof(BITMAPHANDLE), TYPE_CONV, TmpBitmap.Width, TmpBitmap.Height,
16, ORDER_GRAY, NULL, TmpBitmap.ViewPerspective, NULL, 0);
if(nRet != SUCCESS)
return nRet;
/* Allocate and lock the buffer */
hBuf = GlobalAlloc(GMEM_MOVEABLE,max(LeadBitmap.BytesPerLine, TmpBitmap.BytesPerLine));
pBuf = (L_UCHAR*)GlobalLock( hBuf );
/* Process each row from TmpBitmap to LeadBitmap */
L_AccessBitmap(&LeadBitmap);
L_AccessBitmap(&TmpBitmap);
for(i=0; i < TmpBitmap.Height; i++)
{
nRet =(L_INT) L_GetBitmapRow(&TmpBitmap, pBuf, i, TmpBitmap.BytesPerLine);
if(nRet < 1)
return nRet;
nRet = L_ConvertBufferExt2(pBuf, TmpBitmap.Width,
TmpBitmap.BitsPerPixel, LeadBitmap.BitsPerPixel,
TmpBitmap.Order, LeadBitmap.Order, NULL, NULL, NULL, NULL,
CVT_DSTGRAY, 0, 15);
if(nRet != SUCCESS)
return nRet;
nRet = (L_INT )L_PutBitmapRow(&LeadBitmap, pBuf, i, LeadBitmap.BytesPerLine);
if(nRet < 1)
return nRet;
}
L_ReleaseBitmap(&LeadBitmap);
L_ReleaseBitmap(&TmpBitmap);
/* Free memory that we no longer need */
GlobalUnlock(hBuf);
GlobalFree(hBuf);
nRet = L_SaveBitmap(MAKE_IMAGE_PATH(TEXT("Result.BMP")), &LeadBitmap, FILE_BMP, 24, 0, NULL);
if(nRet != SUCCESS)
return nRet;
/* Free the temporary bitmap */
if(TmpBitmap.Flags.Allocated)
L_FreeBitmap(&TmpBitmap);
if(LeadBitmap.Flags.Allocated)
L_FreeBitmap(&LeadBitmap);
/* Force paint palette creation */
SendMessage (hWnd, WM_QUERYNEWPALETTE, 0, 0L);
return SUCCESS;
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document