Click here to Skip to main content
15,893,722 members
Articles / Containers / Virtual Machine

TOOL

Rate me:
Please Sign up or sign in to vote.
4.98/5 (52 votes)
23 Oct 200676 min read 231K   5.4K   147  
TOOL (Tiny Object Oriented Language) is an easily-embedded, object-oriented, C++-like-language interpreter. The purpose of this article is to introduce the TOOL interpreter and language from the perspective of a person who has a desire to include a scripting solution as part of his project.
// Quantize.h
//
// CQuantizer Class : MSJ : Wicked Code 1997 : By Jeff Prosise
//
#ifndef __QUANTIZE_H__
#define __QUANTIZE_H__

typedef struct _NODE
{
    BOOL bIsLeaf;               // TRUE if node has no children
    UINT nPixelCount;           // Number of pixels represented by this leaf
    UINT nRedSum;               // Sum of red components
    UINT nGreenSum;             // Sum of green components
    UINT nBlueSum;              // Sum of blue components
    struct _NODE* pChild[8];    // Pointers to child nodes
    struct _NODE* pNext;        // Pointer to next reducible node
} NODE;

typedef NODE* PNODE;

class CQuantizer
{
protected:
    PNODE m_pTree;
    UINT  m_nLeafCount;
    PNODE m_pReducibleNodes[9];
    UINT  m_nMaxColors;
    UINT  m_nColorBits;

public:
    CQuantizer(UINT nMaxColors, UINT nColorBits);
    virtual ~CQuantizer();
	BOOL ProcessImage(HANDLE hImage);
	UINT GetColorCount();
    void GetColorTable(RGBQUAD* prgb);

protected:
    int GetLeftShiftCount(DWORD dwVal);
    int GetRightShiftCount(DWORD dwVal);
    void AddColor(PNODE* ppNode, BYTE r, BYTE g, BYTE b, UINT nColorBits,
        UINT nLevel, UINT* pLeafCount, PNODE* pReducibleNodes);
    PNODE CreateNode(UINT nLevel, UINT nColorBits, UINT* pLeafCount,
        PNODE* pReducibleNodes);
    void ReduceTree(UINT nColorBits, UINT* pLeafCount,
        PNODE* pReducibleNodes);
    void DeleteTree(PNODE* ppNode);
    void GetPaletteColors (PNODE pTree, RGBQUAD* prgb, UINT* pIndex);
};

#endif // __QUANTIZE_H__

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions