Code

Fix change in revision 9947 to be consistent with rest of the codebase.
[inkscape.git] / src / livarot / AlphaLigne.h
1 /*
2  *  AlphaLigne.h
3  *  nlivarot
4  *
5  *  Created by fred on Fri Jul 25 2003.
6  *  public domain
7  *
8  */
10 #ifndef my_alpha_ligne
11 #define my_alpha_ligne
13 #include "LivarotDefs.h"
15 /*
16  * pixel coverage of a line, libart style: each pixel coverage is obtained from the coverage of the previous one by
17  * adding a delta given by a step. the goal is to have only a limited number of positions where the delta != 0, so that
18  * you only have to store a limited number of steps.
19  */
21 // a step
22 typedef struct alpha_step {
23         int           x;     // position
24         float         delta; // increase or decrease in pixel coverage with respect to the coverage of the previous pixel
25 } alpha_step;
28 class AlphaLigne {
29 public:
30   // bounds of the line
31   // necessary since the visible portion of the canvas is bounded, and you need to compute
32   // the value of the pixel "just before the visible portion of the line"
33         int          min,max;
34         int          length;
36   // before is the step containing the delta relative to a pixel infinitely far on the left of the line
37   // thus the initial pixel coverage is before.delta
38         alpha_step   before,after;
39   // array of steps
40         int          nbStep,maxStep;
41         alpha_step*  steps;
42         
43   // bounds of the portion of the line that has received some coverage
44         int          curMin,curMax;
46   // iMin and iMax are the bounds of the visible portion of the line
47         AlphaLigne(int iMin,int iMax);
48     virtual ~AlphaLigne(void);
50   // empties the line
51         void             Reset(void);
52   
53   // add some coverage.
54   // pente is (eval-sval)/(epos-spos), because you can compute it once per edge, and thus spare the
55   // CPU some potentially costly divisions
56         int              AddBord(float spos,float sval,float epos,float eval,float iPente);
57   // version where you don't have the pente parameter
58         int              AddBord(float spos,float sval,float epos,float eval);
60   // sorts the steps in increasing order. needed before you raster the line
61         void             Flatten(void);
62         
63   // debug dump of the steps
64         void                                             Affiche(void);
66   // private
67         void             AddRun(int st,float pente);
69   // raster the line in the buffer given in "dest", with the rasterization primitive worker
70   // worker() is given the color parameter each time it is called. the type of the function is 
71   // defined in LivarotDefs.h
72         void             Raster(raster_info &dest,void* color,RasterInRunFunc worker);
73         
74   // also private. that's the comparison function given to qsort()
75         static int       CmpStep(const void * p1, const void * p2) {
76                 alpha_step* d1=(alpha_step*)p1;
77                 alpha_step* d2=(alpha_step*)p2;
78                 return  d1->x - d2->x ;
79         };
80 };
83 #endif