public void Initialize() { _rootEntry = ColorEntry.Create(); _rootEntry->_prev = _rootEntry->_next = _rootEntry; _rootEntry->_box = Address; _colors = 0; }
private bool SelectColors(int targetColors) { int splitAxis; ColorBox * splitBox, boxPtr = _boxes; ARGBPixel * sPtr = _srcPixels; ColorEntry **gPtr = _groupTable; ColorEntry * entry; ushort id; //Create initial box boxPtr->Initialize(); _boxCount = 1; //Iterate through colors using ID generator for (int i = 0; i < _size; i++) { _idFunc(*sPtr++, &id); gPtr = _groupTable + id; if ((entry = *gPtr) == null) { *gPtr = entry = ColorEntry.Create(); _idConv(&id, out entry->_color); entry->_weight = 1; boxPtr->_rootEntry->InsertPrev(entry); } else { entry->_weight++; } } //If no quantization is necessary, then leave. if (boxPtr->_colors <= targetColors) { return(false); } //Update initial box boxPtr->Update(targetColors - 1); //Split until we reach desired colors while (_boxCount < targetColors) { //Find split candidate splitBox = ColorBox.FindSplit(_boxes, _boxCount, targetColors, out splitAxis); //Create new box (++boxPtr)->Initialize(); //Move colors from one box to another using split axis splitBox->Split(boxPtr, splitAxis); //Update boxes _boxCount++; splitBox->Update(targetColors - _boxCount); boxPtr->Update(targetColors - _boxCount); } return(true); }