LBitmapBase::StartDithering

Summary

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

Syntax

#include "ltwrappr.h"

virtual L_INT LBitmapBase::StartDithering(pPalette, uColors)

Parameters

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

L_UINT 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

Value Meaning
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

Platforms

Win32, x64.

See Also

Functions

Topics

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 (MAKE_IMAGE_PATH(TEXT("ImageProcessingDemo\\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; 
} 

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.