22//  Anti-Grain Geometry - Version 2.4
33//  Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
44// 
5- //  Permission to copy, use, modify, sell and distribute this software  
6- //  is granted provided this copyright notice appears in all copies.  
5+ //  Permission to copy, use, modify, sell and distribute this software
6+ //  is granted provided this copyright notice appears in all copies.
77//  This software is provided "as is" without express or implied
88//  warranty, and with no claim as to its suitability for any purpose.
99// 
1010// ----------------------------------------------------------------------------
1111// 
12- //  The author gratefully acknowleges the support of David Turner,  
13- //  Robert Wilhelm, and Werner Lemberg - the authors of the FreeType  
12+ //  The author gratefully acknowleges the support of David Turner,
13+ //  Robert Wilhelm, and Werner Lemberg - the authors of the FreeType
1414//  libray - in producing this work. See http://www.freetype.org for details.
1515// 
1616// ----------------------------------------------------------------------------
1919//           http://www.antigrain.com
2020// ----------------------------------------------------------------------------
2121// 
22- //  Adaptation for 32-bit screen coordinates has been sponsored by  
22+ //  Adaptation for 32-bit screen coordinates has been sponsored by
2323//  Liberty Technology Systems, Inc., visit http://lib-sys.com
2424// 
2525//  Liberty Technology Systems, Inc. is the provider of
2626//  PostScript and PDF technology for software developers.
27- //   
27+ // 
2828// ----------------------------------------------------------------------------
2929#ifndef  AGG_RASTERIZER_CELLS_AA_INCLUDED
3030#define  AGG_RASTERIZER_CELLS_AA_INCLUDED 
@@ -49,7 +49,7 @@ namespace agg
4949            cell_block_size  = 1  << cell_block_shift,
5050            cell_block_mask  = cell_block_size - 1 ,
5151            cell_block_pool  = 256 ,
52-             cell_block_limit = 1024 
52+             cell_block_limit = 4096 
5353        };
5454
5555        struct  sorted_y 
@@ -76,19 +76,19 @@ namespace agg
7676
7777        void  sort_cells ();
7878
79-         unsigned  total_cells () const   
79+         unsigned  total_cells () const 
8080        {
8181            return  m_num_cells;
8282        }
8383
84-         unsigned  scanline_num_cells (unsigned  y) const   
85-         {  
86-             return  m_sorted_y[y - m_min_y].num ;  
84+         unsigned  scanline_num_cells (unsigned  y) const 
85+         {
86+             return  m_sorted_y[y - m_min_y].num ;
8787        }
8888
8989        const  cell_type* const * scanline_cells (unsigned  y) const 
90-         {  
91-             return  m_sorted_cells.data () + m_sorted_y[y - m_min_y].start ;  
90+         {
91+             return  m_sorted_cells.data () + m_sorted_y[y - m_min_y].start ;
9292        }
9393
9494        bool  sorted () const  { return  m_sorted; }
@@ -101,7 +101,7 @@ namespace agg
101101        void  add_curr_cell ();
102102        void  render_hline (int  ey, int  x1, int  y1, int  x2, int  y2);
103103        void  allocate_block ();
104-          
104+ 
105105    private: 
106106        unsigned                 m_num_blocks;
107107        unsigned                 m_max_blocks;
@@ -124,7 +124,7 @@ namespace agg
124124
125125
126126    // ------------------------------------------------------------------------
127-     template <class  Cell >  
127+     template <class  Cell >
128128    rasterizer_cells_aa<Cell>::~rasterizer_cells_aa ()
129129    {
130130        if (m_num_blocks)
@@ -140,7 +140,7 @@ namespace agg
140140    }
141141
142142    // ------------------------------------------------------------------------
143-     template <class  Cell >  
143+     template <class  Cell >
144144    rasterizer_cells_aa<Cell>::rasterizer_cells_aa() :
145145        m_num_blocks (0 ),
146146        m_max_blocks(0 ),
@@ -161,10 +161,10 @@ namespace agg
161161    }
162162
163163    // ------------------------------------------------------------------------
164-     template <class  Cell >  
164+     template <class  Cell >
165165    void  rasterizer_cells_aa<Cell>::reset()
166166    {
167-         m_num_cells = 0 ;  
167+         m_num_cells = 0 ;
168168        m_curr_block = 0 ;
169169        m_curr_cell.initial ();
170170        m_style_cell.initial ();
@@ -176,7 +176,7 @@ namespace agg
176176    }
177177
178178    // ------------------------------------------------------------------------
179-     template <class  Cell >  
179+     template <class  Cell >
180180    AGG_INLINE void  rasterizer_cells_aa<Cell>::add_curr_cell()
181181    {
182182        if (m_curr_cell.area  | m_curr_cell.cover )
@@ -192,7 +192,7 @@ namespace agg
192192    }
193193
194194    // ------------------------------------------------------------------------
195-     template <class  Cell >  
195+     template <class  Cell >
196196    AGG_INLINE void  rasterizer_cells_aa<Cell>::set_curr_cell(int  x, int  y)
197197    {
198198        if (m_curr_cell.not_equal (x, y, m_style_cell))
@@ -207,9 +207,9 @@ namespace agg
207207    }
208208
209209    // ------------------------------------------------------------------------
210-     template <class  Cell >  
211-     AGG_INLINE void  rasterizer_cells_aa<Cell>::render_hline(int  ey,  
212-                                                             int  x1, int  y1,  
210+     template <class  Cell >
211+     AGG_INLINE void  rasterizer_cells_aa<Cell>::render_hline(int  ey,
212+                                                             int  x1, int  y1,
213213                                                            int  x2, int  y2)
214214    {
215215        int  ex1 = x1 >> poly_subpixel_shift;
@@ -305,14 +305,14 @@ namespace agg
305305    }
306306
307307    // ------------------------------------------------------------------------
308-     template <class  Cell >  
308+     template <class  Cell >
309309    AGG_INLINE void  rasterizer_cells_aa<Cell>::style(const  cell_type& style_cell)
310-     {  
311-         m_style_cell.style (style_cell);  
310+     {
311+         m_style_cell.style (style_cell);
312312    }
313313
314314    // ------------------------------------------------------------------------
315-     template <class  Cell >  
315+     template <class  Cell >
316316    void  rasterizer_cells_aa<Cell>::line(int  x1, int  y1, int  x2, int  y2)
317317    {
318318        enum  dx_limit_e { dx_limit = 16384  << poly_subpixel_shift };
@@ -358,7 +358,7 @@ namespace agg
358358
359359        // Vertical line - we have to calculate start and end cells,
360360        // and then - the common values of the area and coverage for
361-         // all cells of the line. We know exactly there's only one  
361+         // all cells of the line. We know exactly there's only one
362362        // cell, so, we don't have to call render_hline().
363363        incr  = 1 ;
364364        if (dx == 0 )
@@ -463,15 +463,15 @@ namespace agg
463463    }
464464
465465    // ------------------------------------------------------------------------
466-     template <class  Cell >  
466+     template <class  Cell >
467467    void  rasterizer_cells_aa<Cell>::allocate_block()
468468    {
469469        if (m_curr_block >= m_num_blocks)
470470        {
471471            if (m_num_blocks >= m_max_blocks)
472472            {
473-                 cell_type** new_cells =  
474-                     pod_allocator<cell_type*>::allocate (m_max_blocks +  
473+                 cell_type** new_cells =
474+                     pod_allocator<cell_type*>::allocate (m_max_blocks +
475475                                                        cell_block_pool);
476476
477477                if (m_cells)
@@ -483,7 +483,7 @@ namespace agg
483483                m_max_blocks += cell_block_pool;
484484            }
485485
486-             m_cells[m_num_blocks++] =  
486+             m_cells[m_num_blocks++] =
487487                pod_allocator<cell_type>::allocate (cell_block_size);
488488
489489        }
@@ -513,7 +513,7 @@ namespace agg
513513    void  qsort_cells (Cell** start, unsigned  num)
514514    {
515515        Cell**  stack[80 ];
516-         Cell*** top;  
516+         Cell*** top;
517517        Cell**  limit;
518518        Cell**  base;
519519
@@ -538,7 +538,7 @@ namespace agg
538538                i = base + 1 ;
539539                j = limit - 1 ;
540540
541-                 //  now ensure that *i <= *base <= *j  
541+                 //  now ensure that *i <= *base <= *j
542542                if ((*j)->x  < (*i)->x )
543543                {
544544                    swap_cells (i, j);
@@ -619,7 +619,7 @@ namespace agg
619619
620620
621621    // ------------------------------------------------------------------------
622-     template <class  Cell >  
622+     template <class  Cell >
623623    void  rasterizer_cells_aa<Cell>::sort_cells()
624624    {
625625        if (m_sorted) return ; // Perform sort only the first time.
@@ -636,9 +636,9 @@ namespace agg
636636// for(unsigned nc = 0; nc < m_num_cells; nc++)
637637// {
638638//     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 ||  
639+ //     if(cell->x < m_min_x ||
640+ //        cell->y < m_min_y ||
641+ //        cell->x > m_max_x ||
642642//        cell->y > m_max_y)
643643//     {
644644//         cell = cell; // Breakpoint here
@@ -660,19 +660,21 @@ namespace agg
660660        {
661661            cell_ptr = *block_ptr++;
662662            i = cell_block_size;
663-             while (i--)  
663+             while (i--)
664664            {
665665                m_sorted_y[cell_ptr->y  - m_min_y].start ++;
666666                ++cell_ptr;
667667            }
668668        }
669669
670-         cell_ptr = *block_ptr++;
671670        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;
671+         if  (i) {
672+           cell_ptr = *block_ptr++;
673+           while (i--)
674+             {
675+               m_sorted_y[cell_ptr->y  - m_min_y].start ++;
676+               ++cell_ptr;
677+             }
676678        }
677679
678680        //  Convert the Y-histogram into the array of starting indexes
@@ -691,23 +693,25 @@ namespace agg
691693        {
692694            cell_ptr = *block_ptr++;
693695            i = cell_block_size;
694-             while (i--)  
696+             while (i--)
695697            {
696698                sorted_y& curr_y = m_sorted_y[cell_ptr->y  - m_min_y];
697699                m_sorted_cells[curr_y.start  + curr_y.num ] = cell_ptr;
698700                ++curr_y.num ;
699701                ++cell_ptr;
700702            }
701703        }
702-         
703-         cell_ptr = *block_ptr++;
704+ 
704705        i = m_num_cells & cell_block_mask;
705-         while (i--) 
706-         {
707-             sorted_y& curr_y = m_sorted_y[cell_ptr->y  - m_min_y];
708-             m_sorted_cells[curr_y.start  + curr_y.num ] = cell_ptr;
709-             ++curr_y.num ;
710-             ++cell_ptr;
706+         if  (i) {
707+           cell_ptr = *block_ptr++;
708+           while (i--)
709+             {
710+               sorted_y& curr_y = m_sorted_y[cell_ptr->y  - m_min_y];
711+               m_sorted_cells[curr_y.start  + curr_y.num ] = cell_ptr;
712+               ++curr_y.num ;
713+               ++cell_ptr;
714+             }
711715        }
712716
713717        //  Finally arrange the X-arrays
0 commit comments