Index: trunk/Build/Utils/Quantize.cc =================================================================== --- trunk.orig/Build/Utils/Quantize.cc 2008-02-27 11:32:28.000000000 +0100 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,181 +0,0 @@ -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#include "HImage.h" -#include "Quantize.h" - - -CQuantizer::CQuantizer (UINT nMaxColors, UINT nColorBits) -{ - m_pTree = NULL; - m_nLeafCount = 0; - for (int i=0; i<=(int) nColorBits; i++) - m_pReducibleNodes[i] = NULL; - m_nMaxColors = nMaxColors; - m_nColorBits = nColorBits; -} - -CQuantizer::~CQuantizer () -{ - if (m_pTree != NULL) - DeleteTree (&m_pTree); -} - -BOOLEAN CQuantizer::ProcessImage(BYTE* pData, int iWidth, int iHeight) -{ - BYTE* pbBits; - BYTE r, g, b; - int i, j; - - - pbBits = (BYTE*)pData; - for (i=0; i m_nMaxColors) - ReduceTree (m_nColorBits, &m_nLeafCount, m_pReducibleNodes); - } - //Padding - //pbBits ++; - } - return TRUE; -} - - -void CQuantizer::AddColor (NODE** ppNode, BYTE r, BYTE g, BYTE b, - UINT nColorBits, UINT nLevel, UINT* pLeafCount, NODE** pReducibleNodes) -{ - static BYTE mask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; - - // - // If the node doesn't exist, create it. - // - if (*ppNode == NULL) - *ppNode = CreateNode (nLevel, nColorBits, pLeafCount, - pReducibleNodes); - - // - // Update color information if it's a leaf node. - // - if ((*ppNode)->bIsLeaf) { - (*ppNode)->nPixelCount++; - (*ppNode)->nRedSum += r; - (*ppNode)->nGreenSum += g; - (*ppNode)->nBlueSum += b; - } - - // - // Recurse a level deeper if the node is not a leaf. - // - else { - int shift = 7 - nLevel; - int nIndex = (((r & mask[nLevel]) >> shift) << 2) | - (((g & mask[nLevel]) >> shift) << 1) | - ((b & mask[nLevel]) >> shift); - AddColor (&((*ppNode)->pChild[nIndex]), r, g, b, nColorBits, - nLevel + 1, pLeafCount, pReducibleNodes); - } -} - -NODE* CQuantizer::CreateNode (UINT nLevel, UINT nColorBits, UINT* pLeafCount, - NODE** pReducibleNodes) -{ - NODE* pNode; - - pNode = new NODE; - if (pNode == NULL) - return NULL; - - pNode->bIsLeaf = (nLevel == nColorBits) ? TRUE : FALSE; - if (pNode->bIsLeaf) - (*pLeafCount)++; - else { - pNode->pNext = pReducibleNodes[nLevel]; - pReducibleNodes[nLevel] = pNode; - } - return pNode; -} - -void CQuantizer::ReduceTree (UINT nColorBits, UINT* pLeafCount, - NODE** pReducibleNodes) -{ - int i; - // - // Find the deepest level containing at least one reducible node. - // - for (i = nColorBits - 1; i > 0 && pReducibleNodes[i] == NULL; i--) {} - - // - // Reduce the node most recently added to the list at level i. - // - NODE* pNode = pReducibleNodes[i]; - pReducibleNodes[i] = pNode->pNext; - - UINT nRedSum = 0; - UINT nGreenSum = 0; - UINT nBlueSum = 0; - UINT nChildren = 0; - - for (i=0; i<8; i++) { - if (pNode->pChild[i] != NULL) { - nRedSum += pNode->pChild[i]->nRedSum; - nGreenSum += pNode->pChild[i]->nGreenSum; - nBlueSum += pNode->pChild[i]->nBlueSum; - pNode->nPixelCount += pNode->pChild[i]->nPixelCount; - delete pNode->pChild[i]; - pNode->pChild[i] = NULL; - nChildren++; - } - } - - pNode->bIsLeaf = TRUE; - pNode->nRedSum = nRedSum; - pNode->nGreenSum = nGreenSum; - pNode->nBlueSum = nBlueSum; - *pLeafCount -= (nChildren - 1); -} - -void CQuantizer::DeleteTree (NODE** ppNode) -{ - for (int i=0; i<8; i++) { - if ((*ppNode)->pChild[i] != NULL) - DeleteTree (&((*ppNode)->pChild[i])); - } - delete *ppNode; - *ppNode = NULL; -} - - -void CQuantizer::GetPaletteColors(NODE* pTree, SGPPaletteEntry* prgb, UINT* pIndex) -{ - if (pTree->bIsLeaf) { - prgb[*pIndex].peRed = pTree->nRedSum / pTree->nPixelCount; - prgb[*pIndex].peGreen = pTree->nGreenSum / pTree->nPixelCount; - prgb[*pIndex].peBlue = pTree->nBlueSum / pTree->nPixelCount; - prgb[*pIndex].peFlags = 0; - (*pIndex)++; - } - else { - for (int i=0; i<8; i++) { - if (pTree->pChild[i] != NULL) - GetPaletteColors (pTree->pChild[i], prgb, pIndex); - } - } -} - -UINT CQuantizer::GetColorCount () -{ - return m_nLeafCount; -} - - -void CQuantizer::GetColorTable(SGPPaletteEntry* prgb) -{ - UINT nIndex = 0; - GetPaletteColors (m_pTree, prgb, &nIndex); -} Index: trunk/Build/Utils/Quantize.h =================================================================== --- trunk.orig/Build/Utils/Quantize.h 2008-02-27 11:32:31.000000000 +0100 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,44 +0,0 @@ -#ifndef __QUANTIZE_H_ -#define __QUANTIZE_H_ - -#include "Types.h" - - -typedef struct _NODE { - BOOLEAN 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; - -class CQuantizer -{ -protected: - NODE* m_pTree; - UINT m_nLeafCount; - NODE* m_pReducibleNodes[9]; - UINT m_nMaxColors; - UINT m_nColorBits; - -public: - CQuantizer (UINT nMaxColors, UINT nColorBits); - virtual ~CQuantizer (); - BOOLEAN ProcessImage(BYTE* pData, int iWidth, int iHeight); - UINT GetColorCount (); - void GetColorTable(SGPPaletteEntry* prgb); - -protected: - void AddColor (NODE** ppNode, BYTE r, BYTE g, BYTE b, UINT nColorBits, - UINT nLevel, UINT* pLeafCount, NODE** pReducibleNodes); - NODE* CreateNode (UINT nLevel, UINT nColorBits, UINT* pLeafCount, - NODE** pReducibleNodes); - void ReduceTree (UINT nColorBits, UINT* pLeafCount, - NODE** pReducibleNodes); - void DeleteTree (NODE** ppNode); - void GetPaletteColors(NODE* pTree, SGPPaletteEntry* prgb, UINT* pIndex); -}; - -#endif Index: trunk/Build/Utils/Quantize_Wrap.cc =================================================================== --- trunk.orig/Build/Utils/Quantize_Wrap.cc 2008-02-27 11:32:34.000000000 +0100 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,74 +0,0 @@ -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif - -#include "HImage.h" -#include "Types.h" -#include "Quantize.h" -#include "Quantize_Wrap.h" - - -typedef struct -{ - UINT8 r; - UINT8 g; - UINT8 b; - -} RGBValues; - - -static void MapPalette(UINT8* const pDest, const UINT8* const pSrc, const INT16 sWidth, const INT16 sHeight, const INT16 sNumColors, const SGPPaletteEntry* pTable); - - -BOOLEAN QuantizeImage( UINT8 *pDest, UINT8 *pSrc, INT16 sWidth, INT16 sHeight, SGPPaletteEntry *pPalette ) -{ - INT16 sNumColors; - - // FIRST CREATE PALETTE - CQuantizer q( 255, 6 ); - - q.ProcessImage( pSrc, sWidth, sHeight ); - - sNumColors = q.GetColorCount(); - - memset( pPalette, 0, sizeof( SGPPaletteEntry ) * 256 ); - - q.GetColorTable(pPalette); - - // THEN MAP IMAGE TO PALETTE - // OK, MAPIT! - MapPalette( pDest, pSrc, sWidth, sHeight, sNumColors, pPalette ); - - return( TRUE ); -} - - -static void MapPalette(UINT8* const pDest, const UINT8* const pSrc, const INT16 sWidth, const INT16 sHeight, const INT16 sNumColors, const SGPPaletteEntry* pTable) -{ - const RGBValues* const pRGBData = (const RGBValues*)pSrc; - for (INT32 cX = 0; cX < sWidth; ++cX) - { - for (INT32 cY = 0; cY < sHeight; ++cY) - { - // OK, FOR EACH PALETTE ENTRY, FIND CLOSEST - INT32 best = 0; - UINT32 lowest_dist = 9999999; - for (INT32 cnt = 0; cnt < sNumColors; ++cnt) - { - const INT32 dr = pRGBData[cY * sWidth + cX].r - pTable[cnt].peRed; - const INT32 dg = pRGBData[cY * sWidth + cX].g - pTable[cnt].peGreen; - const INT32 db = pRGBData[cY * sWidth + cX].b - pTable[cnt].peBlue; - const UINT32 dist = dr * dr + dg * dg + db * db; - if (dist < lowest_dist) - { - lowest_dist = dist; - best = cnt; - } - } - - // Now we have the lowest value - // Set into dest - pDest[cY * sWidth + cX] = best; - } - } -} Index: trunk/Build/Utils/Quantize_Wrap.h =================================================================== --- trunk.orig/Build/Utils/Quantize_Wrap.h 2008-02-27 11:32:37.000000000 +0100 +++ /dev/null 1970-01-01 00:00:00.000000000 +0000 @@ -1,15 +0,0 @@ -#ifndef __QUANTIZE_WRAP_H -#define __QUANTIZE_WRAP_H - - -#ifdef __cplusplus -extern "C" { -#endif - -BOOLEAN QuantizeImage( UINT8 *pDest, UINT8 *pSrc, INT16 sWidth, INT16 sHeight, SGPPaletteEntry *pPalette ); - -#ifdef __cplusplus -} -#endif - -#endif Index: trunk/Makefile =================================================================== --- trunk.orig/Makefile 2008-02-27 11:31:40.000000000 +0100 +++ trunk/Makefile 2008-02-27 11:32:08.000000000 +0100 @@ -97,8 +97,6 @@ CCFLAGS += -Wimplicit-int CCFLAGS += -Wsequence-point -override CXXFLAGS += $(CFLAGS) - override LDFLAGS += $(LDFLAGS_SDL) override LDFLAGS += -lm @@ -398,8 +396,6 @@ SRCS += Build/Utils/Multi_Language_Graphic_Utils.c SRCS += Build/Utils/Music_Control.c SRCS += Build/Utils/PopUpBox.c -SRCS += Build/Utils/Quantize.cc -SRCS += Build/Utils/Quantize_Wrap.cc SRCS += Build/Utils/STIConvert.c SRCS += Build/Utils/Slider.c SRCS += Build/Utils/Sound_Control.c @@ -473,24 +469,16 @@ $(BINARY): $(OBJS) @echo '===> LD $@' - $(Q)$(CXX) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $@ + $(Q)$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $@ .c.o: @echo '===> CC $<' $(Q)$(CC) $(CCFLAGS) -c $< -o $@ -.cc.o: - @echo '===> CXX $<' - $(Q)$(CXX) $(CXXFLAGS) -c $< -o $@ - .c.d: @echo '===> DEP $<' $(Q)$(CC) $(CCFLAGS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:%.d=%.o):#' > $@ -.cc.d: - @echo '===> DEP $<' - $(Q)$(CXX) $(CXXFLAGS) -MM $< | sed 's#^$(@F:%.d=%.o):#$@ $(@:%.d=%.o):#' > $@ - clean distclean: @echo '===> CLEAN' $(Q)rm -fr $(DEPS) $(OBJS) $(BINARY)