1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /** @file 3 * TODO: insert short description here 4 *//* 5 * Authors: 6 * see git history 7 * Fred 8 * 9 * Copyright (C) 2018 Authors 10 * Released under GNU GPL v2+, read the file 'COPYING' for more information. 11 */ 12 13 #ifndef my_alpha_ligne 14 #define my_alpha_ligne 15 16 #include "LivarotDefs.h" 17 18 /* 19 * pixel coverage of a line, libart style: each pixel coverage is obtained from the coverage of the previous one by 20 * adding a delta given by a step. the goal is to have only a limited number of positions where the delta != 0, so that 21 * you only have to store a limited number of steps. 22 */ 23 24 // a step 25 struct alpha_step { 26 int x; // position 27 float delta; // increase or decrease in pixel coverage with respect to the coverage of the previous pixel 28 }; 29 30 31 class AlphaLigne { 32 public: 33 // bounds of the line 34 // necessary since the visible portion of the canvas is bounded, and you need to compute 35 // the value of the pixel "just before the visible portion of the line" 36 int min,max; 37 int length; 38 39 // before is the step containing the delta relative to a pixel infinitely far on the left of the line 40 // thus the initial pixel coverage is before.delta 41 alpha_step before,after; 42 // array of steps 43 int nbStep,maxStep; 44 alpha_step* steps; 45 46 // bounds of the portion of the line that has received some coverage 47 int curMin,curMax; 48 49 // iMin and iMax are the bounds of the visible portion of the line 50 AlphaLigne(int iMin,int iMax); 51 virtual ~AlphaLigne(); 52 53 // empties the line 54 void Reset(); 55 56 // add some coverage. 57 // pente is (eval-sval)/(epos-spos), because you can compute it once per edge, and thus spare the 58 // CPU some potentially costly divisions 59 int AddBord(float spos,float sval,float epos,float eval,float iPente); 60 // version where you don't have the pente parameter 61 int AddBord(float spos,float sval,float epos,float eval); 62 63 // sorts the steps in increasing order. needed before you raster the line 64 void Flatten(); 65 66 // debug dump of the steps 67 void Affiche(); 68 69 // private 70 void AddRun(int st,float pente); 71 72 // raster the line in the buffer given in "dest", with the rasterization primitive worker 73 // worker() is given the color parameter each time it is called. the type of the function is 74 // defined in LivarotDefs.h 75 void Raster(raster_info &dest,void* color,RasterInRunFunc worker); 76 77 // also private. that's the comparison function given to qsort() CmpStep(const void * p1,const void * p2)78 static int CmpStep(const void * p1, const void * p2) { 79 alpha_step* d1=(alpha_step*)p1; 80 alpha_step* d2=(alpha_step*)p2; 81 return d1->x - d2->x ; 82 }; 83 }; 84 85 86 #endif 87 88