📄 agg_rasterizer_scanline_aa.cpp
字号:
first = 0; incr = -1; } x_from = x1; //render_hline(ey1, x_from, fy1, x_from, first); delta = first - fy1; m_cur_cell.add_cover(delta, two_fx * delta); ey1 += incr; set_cur_cell(ex, ey1); delta = first + first - poly_base_size; area = two_fx * delta; while(ey1 != ey2) { //render_hline(ey1, x_from, poly_base_size - first, x_from, first); m_cur_cell.set_cover(delta, area); ey1 += incr; set_cur_cell(ex, ey1); } //render_hline(ey1, x_from, poly_base_size - first, x_from, fy2); delta = fy2 - poly_base_size + first; m_cur_cell.add_cover(delta, two_fx * delta); return; } //ok, we have to render several hlines p = (poly_base_size - fy1) * dx; first = poly_base_size; if(dy < 0) { p = fy1 * dx; first = 0; incr = -1; dy = -dy; } delta = p / dy; mod = p % dy; if(mod < 0) { delta--; mod += dy; } x_from = x1 + delta; render_hline(ey1, x1, fy1, x_from, first); ey1 += incr; set_cur_cell(x_from >> poly_base_shift, ey1); if(ey1 != ey2) { p = poly_base_size * dx; lift = p / dy; rem = p % dy; if(rem < 0) { lift--; rem += dy; } mod -= dy; while(ey1 != ey2) { delta = lift; mod += rem; if (mod >= 0) { mod -= dy; delta++; } x_to = x_from + delta; render_hline(ey1, x_from, poly_base_size - first, x_to, first); x_from = x_to; ey1 += incr; set_cur_cell(x_from >> poly_base_shift, ey1); } } render_hline(ey1, x_from, poly_base_size - first, x2, fy2); } //------------------------------------------------------------------------ void outline_aa::move_to(int x, int y) { if(m_sorted) reset(); set_cur_cell(x >> poly_base_shift, y >> poly_base_shift); m_cur_x = x; m_cur_y = y; } //------------------------------------------------------------------------ void outline_aa::line_to(int x, int y) { render_line(m_cur_x, m_cur_y, x, y); m_cur_x = x; m_cur_y = y; m_sorted = false; } //------------------------------------------------------------------------ enum { qsort_threshold = 9 }; //------------------------------------------------------------------------ template <class T> static AGG_INLINE void swap_cells(T* a, T* b) { T temp = *a; *a = *b; *b = temp; } //------------------------------------------------------------------------ template <class T> static AGG_INLINE bool less_than(T* a, T* b) { return (*a)->packed_coord < (*b)->packed_coord; } //------------------------------------------------------------------------ void outline_aa::qsort_cells(cell_aa** start, unsigned num) { cell_aa** stack[80]; cell_aa*** top; cell_aa** limit; cell_aa** base; limit = start + num; base = start; top = stack; for (;;) { int len = int(limit - base); cell_aa** i; cell_aa** j; cell_aa** pivot; if(len > qsort_threshold) { // we use base + len/2 as the pivot pivot = base + len / 2; swap_cells(base, pivot); i = base + 1; j = limit - 1; // now ensure that *i <= *base <= *j if(less_than(j, i)) { swap_cells(i, j); } if(less_than(base, i)) { swap_cells(base, i); } if(less_than(j, base)) { swap_cells(base, j); } for(;;) { do i++; while( less_than(i, base) ); do j--; while( less_than(base, j) ); if ( i > j ) { break; } swap_cells(i, j); } swap_cells(base, j); // now, push the largest sub-array if(j - base > limit - i) { top[0] = base; top[1] = j; base = i; } else { top[0] = i; top[1] = limit; limit = j; } top += 2; } else { // the sub-array is small, perform insertion sort j = base; i = j + 1; for(; i < limit; j = i, i++) { for(; less_than(j + 1, j); j--) { swap_cells(j + 1, j); if (j == base) { break; } } } if(top > stack) { top -= 2; base = top[0]; limit = top[1]; } else { break; } } } } //------------------------------------------------------------------------ void outline_aa::sort_cells() { if(m_num_cells == 0) return; if(m_num_cells > m_sorted_size) { delete [] m_sorted_cells; m_sorted_size = m_num_cells; m_sorted_cells = new cell_aa* [m_num_cells + 1]; } cell_aa** sorted_ptr = m_sorted_cells; cell_aa** block_ptr = m_cells; cell_aa* cell_ptr; unsigned nb = m_num_cells >> cell_block_shift; unsigned i; while(nb--) { cell_ptr = *block_ptr++; i = cell_block_size; while(i--) { *sorted_ptr++ = cell_ptr++; } } cell_ptr = *block_ptr++; i = m_num_cells & cell_block_mask; while(i--) { *sorted_ptr++ = cell_ptr++; } m_sorted_cells[m_num_cells] = 0; qsort_cells(m_sorted_cells, m_num_cells); m_min_y = m_sorted_cells[0]->y; m_max_y = m_sorted_cells[m_num_cells - 1]->y; } //------------------------------------------------------------------------ const cell_aa* const* outline_aa::cells() { //Perform sort only the first time. if(!m_sorted) { add_cur_cell(); sort_cells(); m_sorted = true; } return m_sorted_cells; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -