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

Functions:

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

L_INT LBitmapBase__StartDitheringExample()
{
   L_INT nRet;
   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("%UserProfile%\\My Documents\\LEADTOOLS Images\\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 */
   nRet =InBuf.Reallocate(TmpBitmap.GetBytesPerLine());
   if(nRet !=SUCCESS)
      return nRet;
   /* Allocate the output buffer for 8-bit data */
   nRet =OutBuf.Reallocate(TmpBitmap.GetBytesPerLine());
   if(nRet !=SUCCESS)
      return nRet;
   /* Get the LEAD fixed palette for an 8-bit image */
   nRet =TmpBitmap.GetFixedPalette(FixedPalette, 8);
   if(nRet !=SUCCESS)
      return nRet;
   /* Set the dithering method */
   TmpBitmap.SetDitheringMethod ( STEVENSON_ARCE_DITHERING);
   /* Initialize the dithering process */
   nRet =TmpBitmap.StartDithering(FixedPalette, 256);
   if(nRet !=SUCCESS)
      return nRet;
   /* Use DitherLine to process each row in the bitmap */
   nRet =LeadBitmap.Access();
   if(nRet !=SUCCESS)
      return nRet;
   nRet =TmpBitmap.Access();
   if(nRet !=SUCCESS)
      return nRet;
   for(i=0; i < TmpBitmap.GetHeight(); i++)
   {
      nRet =(L_INT)TmpBitmap.GetRow(&InBuf, i);
      if(nRet < 1)
         return nRet;
      nRet =TmpBitmap.DitherLine(&InBuf, &OutBuf);
      if(nRet !=SUCCESS)
         return nRet;
     nRet = (L_INT)LeadBitmap.PutRow(OutBuf, i);
     if(nRet < 1)
        return nRet;
   }
   nRet =TmpBitmap.Release();
   if(nRet !=SUCCESS)
      return nRet;
   nRet =LeadBitmap.Release();
   if(nRet !=SUCCESS)
      return nRet;
   /* End the dithering process */
   nRet =TmpBitmap.StopDithering();
   if(nRet !=SUCCESS)
      return nRet;
   return SUCCESS;
}