
Home |
|
PegQuant
|

Examples |

Index |
|
|
|
 |
|
Overview | |
 |
|
The PegQuant class provides services which can be
used to generate a color histogram from multiple images in order to
create an optimal palette for the set of images.
The PegQuant class uses a form of Heckbert's
Median Cut color reduction algorithm. This class is only required
for applications that must dynamically determine optimal palettes.
Since most applications will use fixed palettes, this class will
rarely be used.
PegImageConvert derived classes use the PegQuant
member function AddColor() to create a histogram of color usage.
Once all images have been scanned, the PeqQuant() function
ReduceColors() is called to create an optimal
palette for use with the images.
 |
To use the PegQuant class with the image conversion classes,
your KwikPeg configuration must have the following option enabled: |
| |
Images: Color quantization |
|
|
PegImageConvert
PegBmpConvert
PegGifConvert
PegJpgConvert
PegPngConvert
Constructors:
 |
 |
PegQuant(void)
|
This constructor creates a PegQuant object
for use by a conversion object derived from the
PegImageConvert base class.
Public Functions:
 |
 |
void AddColor(
|
| |

WORD wRed,
|
| |

WORD wGreen,
|
| |

WORD wBlue)
|
This function adds the specified color to the histogram being created.
 |
 |
UCHAR *GetPalette(void)
|
This function returns a pointer
to the optimal color palette produced from the image color histogram.
 |
 |
WORD PalSize(void)
|
This function returns
the current number of colors in the palette.
 |
 |
WORD ReduceColors(
|
| |

SIGNED iLimit = 254)
|
This function creates an optimal palette from the color histogram
contained within the PegQuant object.
The palette will always contain the sixteen standard KwikPeg colors
as the first colors in the palette.
This function is usually not called until all colors for all images
have been added to the histogram.
Parameter iLimit sets the upper palette index limit.
iLimit must be >=16 and <255.
The following example
reads several graphic files and creates an optimal palette for use in displaying
the files. The palette is then installed in the screen driver
for use as the system palette. This example assumes that KwikPeg has been
configured to use the file access method for image conversion.
#define GIF1 "\\graphics\\tree.gif"
#define GIF2 "\\graphics\\house.gif"
#define BMP1 "\\graphics\\garage.bmp"
void MyWindow::CreatePalette(void)
{
PeqQuant *pQuant = new PegQuant();
CountColors(GIF1, PIC_TYPE_GIF, pQuant);
CountColors(GIF2, PIC_TYPE_GIF, pQuant);
CountColors(BMP1, PIC_TYPE_BMP, pQuant);
WORD wPalSize = pQuant->ReduceColors();
Screen()->SetPalette(pQuant->GetPalette(), wPalSize);
delete pQuant;
}
void MyWindow::CountColors(char *cPathName,
WORD wType,
PegQuant *pQuant)
{
PegFile *fSrc = new PegFile(cPathName, "r");
PegImageConvert *pConvert;
if (wType == PIC_TYPE_GIF)
{
pConvert = new PegGifConvert(0);
}
else
{
pConvert = new PegBmpConvert(0);
}
pConvert->ReadImage(fSrc);
pConvert->CountColors(pQuant);
pConvert->DestroyImages();
delete pConvert;
fSrc->close();
delete fSrc;
}