Class ColorPacker

3DS Max Plug-In SDK

Class ColorPacker

See Also: Palettes, Class Quantizer.

class ColorPacker

Description:

Methods of this class are used for packing colors into a 256 color paletted representation. Create an instance of this class using BMMNewColorPacker() described below. All methods of this class are implemented by the system.

Prototype:

ColorPacker *BMMNewColorPacker(int w, BMM_Color_48 *pal, int npal, BYTE* remap=NULL);

Remarks:

This is called to create an instance of a ColorPacker. When done, be sure to call ColorPacker::DeleteThis().

Parameters:

int w

The width of bitmap to be packed.

BMM_Color_48 *pal

The palette to use.

int npal

The number of entries in the palette.

BYTE* remap=NULL

This is a 256 byte table that maps the numbers into another number. This is used so the palette may be rearranged in Windows order. To make palettes for Windows, the best thing to do is to put the colors in so that colors that Windows uses are either left alone, or they are occupied by the colors that are least important in the image. This is because Windows will come along and alter these colors. This is the first 10 colors and the last 10 colors.

The quantizer creates a palette from 0-239, where 0 is the most used color and 239 is the least used. The color packer uses 0-239 as well, and it operates most efficiently when the colors are sorted as the quantizer orders them.

What can be done is to use FixPaletteForWindows() to rearrange the colors for the Windows palette. This creates the remap table passed to this method. Then as a last step the remap table is used to reorganize the palette. Below is the documentation for the global function FixPaletteForWindows(). Sample code that uses these APIs is in \MAXSDK\SAMPLES\IO\FLIC\FLIC.CPP.

Prototype:

void FixPaletteForWindows(BMM_Color_48 *pal, BMM_Color_48 *newpal,int ncols, BYTE *remap=NULL);

Remarks:

Rearranges the palette pal (which has colors 0..ncols-1 occupied, in descending order of frequency), into newpal so that the colors 10-245 are populated first, then 0-9, then 246-255. Sets the optional array remap to map the old palette index values to the new ones.

Parameters:

BMM_Color_48 *pal

The palette to rearrange.

BMM_Color_48 *newpal

The rearranged palette.

int ncols

The number of colors in the palette.

BYTE *remap=NULL

An array that maps the old palette index values to the new ones.

Methods:

Prototype:

virtual void DeleteThis()=0;

Remarks:

This method is called to delete the ColorPacker when you are done with it.

Prototype:

virtual void EnableDither(BOOL onoff)=0;

Remarks:

This method is used to enable dithering of the packed pixels. It defaults to the 3ds max default.

Parameters:

BOOL onoff

TRUE to enable dithering; FALSE to disable.

Prototype:

virtual void PropogateErrorBetweenLines(BOOL onoff)=0;

Remarks:

This method controls the propagation of error between lines. For static images this is best left to default to on. For animated images, it is better to set this to off and not propagate the error between lines. This defaults to ON.

Parameters:

BOOL onoff

TRUE to enable error propagation between lines; FALSE to disable.

Prototype:

virtual void PackLine(BMM_Color_64* in, BYTE *out, int w)=0;

Remarks:

Packs the specified line of pixels into the 256 color representation.

Parameters:

BMM_Color_64* in

The line of pixels to pack.

BYTE *out

The result, the output pixels.

int w

The number of pixels in the line.

Prototype:

virtual void PackLine(BMM_Color_48* in, BYTE *out, int w)=0;

Remarks:

Packs the specified line of pixels into the 256 color representation.

Parameters:

BMM_Color_48* in

The line of pixels to pack.

BYTE *out

The result, the output pixels.

int w

The number of pixels in the line.