| 621 | //------------------------------------------------------------------------ |
| 622 | template<class Cell> |
| 623 | void rasterizer_cells_aa<Cell>::sort_cells() |
| 624 | { |
| 625 | if(m_sorted) return; //Perform sort only the first time. |
| 626 | |
| 627 | add_curr_cell(); |
| 628 | m_curr_cell.x = 0x7FFFFFFF; |
| 629 | m_curr_cell.y = 0x7FFFFFFF; |
| 630 | m_curr_cell.cover = 0; |
| 631 | m_curr_cell.area = 0; |
| 632 | |
| 633 | if(m_num_cells == 0) return; |
| 634 | |
| 635 | // DBG: Check to see if min/max works well. |
| 636 | //for(unsigned nc = 0; nc < m_num_cells; nc++) |
| 637 | //{ |
| 638 | // cell_type* cell = m_cells[nc >> cell_block_shift] + (nc & cell_block_mask); |
| 639 | // if(cell->x < m_min_x || |
| 640 | // cell->y < m_min_y || |
| 641 | // cell->x > m_max_x || |
| 642 | // cell->y > m_max_y) |
| 643 | // { |
| 644 | // cell = cell; // Breakpoint here |
| 645 | // } |
| 646 | //} |
| 647 | // Allocate the array of cell pointers |
| 648 | m_sorted_cells.allocate(m_num_cells, 16); |
| 649 | |
| 650 | // Allocate and zero the Y array |
| 651 | m_sorted_y.allocate(m_max_y - m_min_y + 1, 16); |
| 652 | m_sorted_y.zero(); |
| 653 | |
| 654 | // Create the Y-histogram (count the numbers of cells for each Y) |
| 655 | cell_type** block_ptr = m_cells; |
| 656 | cell_type* cell_ptr; |
| 657 | unsigned nb = m_num_cells >> cell_block_shift; |
| 658 | unsigned i; |
| 659 | while(nb--) |
| 660 | { |
| 661 | cell_ptr = *block_ptr++; |
| 662 | i = cell_block_size; |
| 663 | while(i--) |
| 664 | { |
| 665 | m_sorted_y[cell_ptr->y - m_min_y].start++; |
| 666 | ++cell_ptr; |
| 667 | } |
| 668 | } |
| 669 | |
| 670 | cell_ptr = *block_ptr++; |
| 671 | i = m_num_cells & cell_block_mask; |
| 672 | while(i--) |
| 673 | { |
| 674 | m_sorted_y[cell_ptr->y - m_min_y].start++; |
| 675 | ++cell_ptr; |
| 676 | } |
| 677 | |
| 678 | // Convert the Y-histogram into the array of starting indexes |
| 679 | unsigned start = 0; |
| 680 | for(i = 0; i < m_sorted_y.size(); i++) |
no test coverage detected