private void AllocateCellsIfRequired() { if (m_cells == null || (m_num_used_cells + 1) >= m_cells.Capacity()) { if (m_num_used_cells >= (int)cell_block_scale_e.cell_block_limit) { return; } uint new_num_allocated_cells = m_num_used_cells + (uint)cell_block_scale_e.cell_block_size; VectorPOD <CellAA> new_cells = new VectorPOD <CellAA>(new_num_allocated_cells); if (m_cells != null) { new_cells.CopyFrom(m_cells); } m_cells = new_cells; } }
//======================================================render_scanline_aa private static void GenerateAndRenderSingleScanline(IScanlineCache sl, IPixelFormat ren, SpanAllocator alloc, ISpanGenerator<T> span_gen) { int y = sl.Y; uint num_spans = sl.NumSpans; ScanlineSpan scanlineSpan = sl.Begin(); byte[] ManagedCoversArray = sl.Covers; unsafe { fixed (byte* pCovers = ManagedCoversArray) { for (; ; ) { int x = scanlineSpan.X; int len = scanlineSpan.Len; if (len < 0) len = -len; if (tempSpanColors.Capacity() < len) { tempSpanColors.Allocate((uint)(len)); } fixed (RGBA_Bytes* pColors = tempSpanColors.Array) { span_gen.Generate(pColors, x, y, (uint)len); #if use_timers blend_color_hspan.Start(); #endif ren.BlendColorHSpan(x, y, (uint)len, pColors, (scanlineSpan.Len < 0) ? null : &pCovers[scanlineSpan.CoverIndex], pCovers[scanlineSpan.CoverIndex]); #if use_timers blend_color_hspan.Stop(); #endif } if (--num_spans == 0) break; scanlineSpan = sl.GetNextScanlineSpan(); } } } }
// Returns the number of styles public uint SweepStyles() { for (; ;) { if (m_scan_y > m_Rasterizer.MaxY) { return(0); } int num_cells = (int)m_Rasterizer.ScanlineNumCells((uint)m_scan_y); CellAA[] cells; uint cellOffset = 0; int curCellOffset; m_Rasterizer.ScanlineCells((uint)m_scan_y, out cells, out cellOffset); uint num_styles = (uint)(m_max_style - m_min_style + 2); uint style_id; int styleOffset = 0; m_cells.Allocate((uint)num_cells * 2, 256); // Each cell can have two styles m_ast.Capacity(num_styles, 64); m_asm.Allocate((num_styles + 7) >> 3, 8); m_asm.Zero(); if (num_cells > 0) { // Pre-add zero (for no-fill style, that is, -1). // We need that to ensure that the "-1 style" would go first. m_asm.Array[0] |= 1; m_ast.Add(0); m_styles.Array[styleOffset].start_cell = 0; m_styles.Array[styleOffset].num_cells = 0; m_styles.Array[styleOffset].last_x = -0x7FFFFFFF; m_sl_start = cells[0].X; m_sl_len = (uint)(cells[num_cells - 1].X - m_sl_start + 1); while (num_cells-- != 0) { curCellOffset = (int)cellOffset++; AddStyle(cells[curCellOffset].Left); AddStyle(cells[curCellOffset].Right); } // Convert the Y-histogram into the array of starting indexes uint i; uint start_cell = 0; StyleInfo[] stylesArray = m_styles.Array; for (i = 0; i < m_ast.Size(); i++) { int IndexToModify = (int)m_ast[i]; uint v = stylesArray[IndexToModify].start_cell; stylesArray[IndexToModify].start_cell = start_cell; start_cell += v; } num_cells = (int)m_Rasterizer.ScanlineNumCells((uint)m_scan_y); m_Rasterizer.ScanlineCells((uint)m_scan_y, out cells, out cellOffset); while (num_cells-- > 0) { curCellOffset = (int)cellOffset++; style_id = (uint)((cells[curCellOffset].Left < 0) ? 0 : cells[curCellOffset].Left - m_min_style + 1); styleOffset = (int)style_id; if (cells[curCellOffset].X == stylesArray[styleOffset].last_x) { cellOffset = stylesArray[styleOffset].start_cell + stylesArray[styleOffset].num_cells - 1; unchecked { cells[cellOffset].Area += cells[curCellOffset].Area; cells[cellOffset].Cover += cells[curCellOffset].Cover; } } else { cellOffset = stylesArray[styleOffset].start_cell + stylesArray[styleOffset].num_cells; cells[cellOffset].X = cells[curCellOffset].X; cells[cellOffset].Area = cells[curCellOffset].Area; cells[cellOffset].Cover = cells[curCellOffset].Cover; stylesArray[styleOffset].last_x = cells[curCellOffset].X; stylesArray[styleOffset].num_cells++; } style_id = (uint)((cells[curCellOffset].Right < 0) ? 0 : cells[curCellOffset].Right - m_min_style + 1); styleOffset = (int)style_id; if (cells[curCellOffset].X == stylesArray[styleOffset].last_x) { cellOffset = stylesArray[styleOffset].start_cell + stylesArray[styleOffset].num_cells - 1; unchecked { cells[cellOffset].Area -= cells[curCellOffset].Area; cells[cellOffset].Cover -= cells[curCellOffset].Cover; } } else { cellOffset = stylesArray[styleOffset].start_cell + stylesArray[styleOffset].num_cells; cells[cellOffset].X = cells[curCellOffset].X; cells[cellOffset].Area = -cells[curCellOffset].Area; cells[cellOffset].Cover = -cells[curCellOffset].Cover; stylesArray[styleOffset].last_x = cells[curCellOffset].X; stylesArray[styleOffset].num_cells++; } } } if (m_ast.Size() > 1) { break; } ++m_scan_y; } ++m_scan_y; if (m_layer_order != LayerOrder.Unsorted) { VectorPODRangeAdaptor ra = new VectorPODRangeAdaptor(m_ast, 1, m_ast.Size() - 1); if (m_layer_order == LayerOrder.Direct) { QuickSortRangeAdaptorUint m_QSorter = new QuickSortRangeAdaptorUint(); m_QSorter.Sort(ra); //quick_sort(ra, uint_greater); } else { throw new System.NotImplementedException(); //QuickSort_range_adaptor_uint m_QSorter = new QuickSort_range_adaptor_uint(); //m_QSorter.Sort(ra); //quick_sort(ra, uint_less); } } return(m_ast.Size() - 1); }