Initializes the buffered dithering of a bitmap. The dithering is then carried out by the L_DitherLine function and a function that you supply. It is ended by the L_StopDithering function. (Dithering is the process of using error diffusion to reduce the number of colors in an image.)
#include "l_bitmap.h"
L_LTKRN_API L_INT L_StartDithering(pBitmap, pPalette, uColors)
Pointer to the bitmap handle that has all the information about the input image. The bitmap does not have to exist, but the information must be complete. The DitheringMethod field in the bitmap handle specifies the dithering method to be used for color reduction.
Pointer to the palette that the L_DitherLine function will use for dithering. You can specify your own palette, or use NULL for LEAD's fixed palette.
Number of colors used in the palette. If the palette contains more colors, only the first uColors colors are used. Valid values are 2 to 256.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
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.
The following flow chart shows how the functions relate to each other:
Before calling this function, the following fields must be specified in the bitmap handle:
Bitmap.Width
Bitmap.Height
Bitmap.BitsPerPixel
Bitmap.ColorOrder if BitsPerPixel is greater than 8
Bitmap.DitheringMethod if BitsPerPixel is less than 16
Win32, x64, Linux.
This example dithers each line in one bitmap and writes it to another bitmap.
L_INT StartDitheringExample(pBITMAPHANDLE pBitmap)
{
L_INT nRet;
L_UCHAR* pInBuf; /* Buffer to hold the input row */
HGLOBAL hInBuf; /* Handle to the input buffer */
L_UCHAR* pOutBuf; /* Buffer to hold the output row */
HGLOBAL hOutBuf; /* Handle to the output buffer */
BITMAPHANDLE TmpBitmap; /* Bitmap containing input data */
RGBQUAD FixedPalette[256]; /* Fixed palette */
L_INT i; /* Loop counter */
/* Load the input bitmap, at 24 bits per pixel */
nRet = L_LoadBitmap (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\Image3.cmp")), &TmpBitmap, sizeof(BITMAPHANDLE), 24, ORDER_BGR, NULL, NULL);
if(nRet != SUCCESS)
return nRet;
/* Allocate the input buffer for 24-bit data */
hInBuf = GlobalAlloc(GMEM_MOVEABLE, TmpBitmap.Width * 3);
pInBuf = (L_UCHAR *)GlobalLock( hInBuf );
/* Allocate the output buffer for 8-bit data */
hOutBuf = GlobalAlloc(GMEM_MOVEABLE, TmpBitmap.Width);
pOutBuf = (L_UCHAR *)GlobalLock( hOutBuf );
/* Get the LEAD fixed palette for an 8-bit image */
L_GetFixedPalette(FixedPalette, 8);
/* Create the new bitmap */
if(pBitmap->Flags.Allocated)
L_FreeBitmap(pBitmap);
nRet = L_CreateBitmap(pBitmap,
sizeof(BITMAPHANDLE),
TYPE_CONV,
TmpBitmap.Width,
TmpBitmap.Height,
8, /* 8 bits per pixel */
0, /* Color order is not used */
NULL, /* Use the fixed palette */
TmpBitmap.ViewPerspective, NULL, 0);
if(nRet != SUCCESS)
return nRet;
/* Set the dithering method */
TmpBitmap.DitheringMethod = STEVENSON_ARCE_DITHERING;
/* Initialize the dithering process */
nRet = L_StartDithering(&TmpBitmap, FixedPalette, 256);
if(nRet != SUCCESS)
return nRet;
/* Use L_DitherLine to process each row in the bitmap */
L_AccessBitmap(pBitmap);
L_AccessBitmap(&TmpBitmap);
for(i=0; i < TmpBitmap.Height; i++)
{
nRet =(L_INT)L_GetBitmapRow(&TmpBitmap, pInBuf, i, TmpBitmap.BytesPerLine);
if(nRet < 1)
return nRet;
nRet = L_DitherLine(&TmpBitmap, pInBuf, pOutBuf);
if(nRet != SUCCESS)
return nRet;
nRet = (L_INT)L_PutBitmapRow(pBitmap, pOutBuf, i, pBitmap->BytesPerLine);
if(nRet < 1)
return nRet;
}
L_ReleaseBitmap(&TmpBitmap);
L_ReleaseBitmap(pBitmap);
L_FreeBitmap(&TmpBitmap);
/* End the dithering process */
nRet = L_StopDithering(&TmpBitmap);
if(nRet != SUCCESS)
return nRet;
/* Free memory that we no longer need */
GlobalFree(hInBuf);
GlobalFree(hOutBuf);
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