LBuffer::ConvertBuffer

Summary

Converts data in the class object's buffer to the specified bits per pixel and color order. You can convert from any bits per pixel to any bits per pixel.

Syntax

#include "ltwrappr.h"

virtual L_INT LBuffer::ConvertBuffer(nWidth, nBitsPerPixelSrc, nBitsPerPixelDst, nOrderSrc, nOrderDst, pPaletteSrc, pPaletteDst, uFlags=0, uLowBit=0, uHighBit=0)

Parameters

L_INT nWidth

Image width, in pixels.

L_INT nBitsPerPixelSrc

Input bits per pixel. Possible values are 1, 2, 3, 4, 5, 6, 7, 8, 16, 24, 32, 48, and 64.

L_INT nBitsPerPixelDst

Output bits per pixel. Use 0 for 8-bit grayscale.

L_INT nOrderSrc

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] 12, 16 or 32-bit grayscale image. 12, 16 and 32-bit grayscale images are only supported in the Document/Medical toolkits.
0 The data is 8 bits per pixel or less.

L_INT nOrderDst

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] 12, 16 or 32-bit grayscale image. 12, 16 and 32-bit grayscale images are only supported in the Document/Medical toolkits.
0 The data is 8 bits per pixel or less.

LPRGBQUAD pPaletteSrc

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.

LPRGBQUAD pPaletteDst

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.

L_UINT uFlags

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 [0x0004] 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.

L_INT uLowBit

Value indicating the low bit in the source buffer, if the source buffer contains grayscale data.

L_INT uHighBit

Value indicating the high bit in the source buffer, if the source buffer contains grayscale data.

Returns

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

Comments

Note: This function will also work for 12, 16 and 32-bit grayscale images, but only in the Document/Medical 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, pPaletteSrc is 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.

Required DLLs and Libraries

Platforms

Win32, x64.

See Also

Functions

Topics

Example

L_INT LBuffer__ConvertBufferExample(LBitmapBase  * pLeadBitmap) 
{ 
   L_INT nRet; 
   LBuffer LeadBuffer ; 
   LBitmapBase TmpBitmap ; 
 
   nRet =TmpBitmap.Load(MAKE_IMAGE_PATH(TEXT("image2.cmp"))) ; 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   nRet =pLeadBitmap->Access(); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   for (L_INT i = 0; i< TmpBitmap.GetHeight(); i++) 
   { 
 
      nRet =(L_INT)pLeadBitmap->GetRow(&LeadBuffer,i) ; 
      if(nRet < 1) 
         return nRet; 
 
      nRet =LeadBuffer.ConvertBuffer(pLeadBitmap->GetWidth(),TmpBitmap.GetBitsPerPixel(), 
                                     pLeadBitmap->GetBitsPerPixel(),TmpBitmap.GetColorOrder(), 
                                     pLeadBitmap->GetColorOrder(), NULL, NULL, CVT_DSTGRAY, 0, 15) ; 
      if(nRet !=SUCCESS) 
         return nRet; 
 
      nRet =(L_INT)pLeadBitmap->PutRow(LeadBuffer,i) ; 
      if(nRet < 1) 
         return nRet; 
 
   } 
 
   nRet =pLeadBitmap->Release(); 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   nRet =LeadBuffer.Free() ; 
   if(nRet !=SUCCESS) 
      return nRet; 
 
   return SUCCESS; 
} 
Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 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.