LBitmapBase::StartDithering

#include "ltwrappr.h"

virtual L_INT LBitmapBase::StartDithering(pPalette, uColors)

LPRGBQUAD pPalette;

/* pointer to the palette*/

L_UINT uColors;

/* number of colors used in the palette*/

Initializes the buffered dithering of a class object's bitmap. The dithering is then carried out by the LBitmapBase::DitherLine function and a callback function that you supply. It is ended by the LBitmapBase::StopDithering function. (Dithering is the process of using error diffusion to reduce the number of colors in an image.)

Parameter

Description

pPalette

Pointer to the palette that the LBitmapBase::DitherLine function will use for dithering. You can specify your own palette, or use NULL for LEAD's fixed palette.

uColors

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 255.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

The following flow chart shows how the functions relate to each other:

image\dithbuf.gif

Required DLLs and Libraries

LTDIS
LTFIL

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Elements:

LBitmapBase::DitherLine, LBitmapBase::StopDithering, Class Members

Topics:

Raster Image Functions: Doing Color Expansion or Reduction

 

Raster Image Functions: Doing Color Space Conversions

Example

/* This example dithers each line in one bitmap and writes it to another bitmap */
LBitmapBase LeadBitmap, TmpBitmap;   /* to hold the loaded image */
LBuffer  InBuf, OutBuf;
RGBQUAD FixedPalette[256]; /* Fixed palette */
int i; /* Loop counter */

/* Load the input bitmap, at 24 bits per pixel */
TmpBitmap.Load (TEXT("IMAGE3.CMP"), 24, ORDER_BGR);
   /* Create the new bitmap */
LeadBitmap.Create(TmpBitmap.GetWidth(),TmpBitmap.GetHeight(),
8,           /* 8 bits per pixel */
              0,          /* Color order is not used */
              NULL,    /* Use the fixed palette */
              TmpBitmap.GetViewPerspective());
   /* Allocate the input buffer for 24-bit data */
InBuf.Reallocate(TmpBitmap.GetBytesPerLine());
/* Allocate the output buffer for 8-bit data */
OutBuf.Reallocate(TmpBitmap.GetBytesPerLine());
/* Get the LEAD fixed palette for an 8-bit image */
TmpBitmap.GetFixedPalette(FixedPalette, 8);
   /* Set the dithering method */
TmpBitmap.SetDitheringMethod ( STEVENSON_ARCE_DITHERING);
   /* Initialize the dithering process */
TmpBitmap.StartDithering(FixedPalette, 256);
   /* Use DitherLine to process each row in the bitmap */
LeadBitmap.Access();
TmpBitmap.Access();
   for(i=0; i < TmpBitmap.GetHeight(); i++)
   {
      TmpBitmap.GetRow(&InBuf, i);
      TmpBitmap.DitherLine(&InBuf, &OutBuf);
      LeadBitmap.PutRow(OutBuf, i);
   }
   TmpBitmap.Release();
   LeadBitmap.Release();

   /* End the dithering process */
   TmpBitmap.StopDithering();