L_ConvertBuffer

#include "l_bitmap.h"

L_LTKRN_API L_INT L_ConvertBuffer(pBuffer, nWidth, nBitsPerPixelSrc, nBitsPerPixelDst, nOrderSrc, nOrderDst, pPaletteSrc, pPaletteDst)

L_UCHAR* pBuffer;

pointer to the input buffer

L_INT nWidth;

image width, in pixels

L_INT nBitsPerPixelSrc;

input bits per pixel

L_INT nBitsPerPixelDst;

output bits per pixel

L_INT nOrderSrc;

input color order

L_INT nOrderDst;

output color order

L_RGBQUAD* pPaletteSrc;

pointer to the palette for the existing data

L_RGBQUAD* pPaletteDst;

pointer to the palette for the converted data

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.

Parameter Description
pBuffer Pointer to the input buffer.
nWidth Image width, in pixels.
nBitsPerPixelSrc Input bits per pixel. Possible values are 1, 2, 3, 4, 5, 6, 7, 8, 16, 24, 32, 48, and 64.
nBitsPerPixelDst Output bits per pixel. Use 0 for 8-bit grayscale.
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 Document and Medical Imaging toolkits.
  0 The data is 8 bits per pixel or less.
  ORDER_ROMM [5] The input colors are in ROMM order. ROMM only supports 24 and 48-bit images.
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 Document and Medical Imaging toolkits.
  0 The data is 8 bits per pixel or less.
  ORDER_ROMM [5] The output colors are in ROMM order. ROMM only supports 24 and 48-bit images.
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.
pPaletteDst Pointer to the palette for the converted data. If the data is converted to 16 or 24 bits per pixel, use NULL for no palette.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Support for 12, 16 and 32-bit grayscale images is only available in the Document and Medical Imaging toolkits.

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.

Required DLLs and Libraries

LTKRN

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

Win32, x64, Linux.

See Also

Functions:

L_StartDithering, L_DitherLine, L_StopDithering,

 

L_ConvertBufferExt

Topics:

Raster Image Functions: Doing Color Expansion or Reduction

 

Raster Image Functions: Doing Color Space Conversions

Example

This example loads a temporary bitmap at 8 bits per pixel, creates a new bitmap at 16 bits per pixel, and uses L_ConvertBuffer to convert data from the temporary bitmap to the new one.

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName 
L_INT ConvertBufferExample(HWND hWnd) 
{ 
   L_INT nRet; 
   BITMAPHANDLE   LeadBitmap;          /* Bitmap handle for the final image */ 
   RGBQUAD        FixedPalette[256];   /* Temporary palette */ 
   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 8 bits per pixel */ 
   nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Image3.cmp")), &TmpBitmap, sizeof(BITMAPHANDLE), 8, 0, NULL, NULL); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Create a new 16-bit bitmap */ 
   nRet = L_CreateBitmap(&LeadBitmap, sizeof(BITMAPHANDLE), TYPE_CONV, TmpBitmap.Width, TmpBitmap.Height, 
   16, ORDER_BGR, NULL, TmpBitmap.ViewPerspective, NULL, 0); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Get the LEAD fixed palette for an 8-bit image */ 
   nRet = L_GetFixedPalette(FixedPalette, 8); 
   if(nRet != SUCCESS) 
      return nRet; 
   /* Allocate and lock the buffer */ 
   hBuf = GlobalAlloc(GMEM_MOVEABLE,LeadBitmap.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_ConvertBuffer(pBuf, TmpBitmap.Width, 
      TmpBitmap.BitsPerPixel, LeadBitmap.BitsPerPixel, 
      TmpBitmap.Order, LeadBitmap.Order, FixedPalette, NULL); 
      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 Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Raster Imaging C API Help