Quantizer.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #if !defined(QUANTIZER_H_)
  2. #define QUANTIZER_H_
  3. struct NODE
  4. {
  5. BOOL bIsLeaf;
  6. long nPixelCount;
  7. long nRedSum;
  8. long nGreenSum;
  9. long nBlueSum;
  10. UINT nColorIndex;
  11. NODE* pChild[8];
  12. NODE* pNext;
  13. };
  14. class CQuantizer
  15. {
  16. public:
  17. CQuantizer(UINT nMaxColors, UINT nColorBits);
  18. ~CQuantizer();
  19. BOOL ProcessImage(HANDLE hImage);
  20. UINT GetColorCount();
  21. void SetColorTable(RGBQUAD* prgb);
  22. BOOL GetColorIndex(BYTE r, BYTE g, BYTE b, UINT* pColorIndex);
  23. protected:
  24. void AddColor(NODE** ppNode, BYTE r, BYTE g, BYTE b,
  25. UINT nColorBits, UINT nLevel, UINT* pLeafCount, NODE** pReducibleNodes);
  26. void* CreateNode(UINT nLevel, UINT nColorBits, UINT* pLeafCount,
  27. NODE** pReducibleNodes);
  28. void ReduceTree(UINT nColorBits, UINT* pLeafCount,
  29. NODE** pReducibleNodes);
  30. void DeleteTree(NODE** ppNode);
  31. void GetPaletteColors(NODE* pTree, RGBQUAD* prgb, UINT* pIndex);
  32. BOOL FindColorIndex(NODE* pNode, BYTE r, BYTE g, BYTE b, int nLevel, UINT* pColorIndex);
  33. BYTE GetPixelIndex(long x, long y, int nbit, long effwdt, BYTE* pimage);
  34. int m_nColorBits;
  35. UINT m_nLeafCount;
  36. int m_nMaxColors;
  37. NODE* m_pTree;
  38. NODE* m_pReducibleNodes[9];
  39. };
  40. class CRGBQuantizer : public CQuantizer
  41. {
  42. public:
  43. CRGBQuantizer(UINT nMaxColors, UINT nColorBits);
  44. BOOL ProcessImageRGB(BYTE* pRGBData, UINT nWidth, UINT nHeight);
  45. };
  46. class CBitmapQuantizer : public CQuantizer
  47. {
  48. public:
  49. CBitmapQuantizer(UINT nMaxColors, UINT nColorBits);
  50. BOOL ProcessImageBitmap(HBITMAP hBmp);
  51. };
  52. #endif