touchgfx::Rasterizer is only used within TouchGFX.
 
Symbols
loading...
Files
loading...

touchgfx::Rasterizer class

@class Rasterizer Rasterizer.hpp touchgfx/canvas_widget_renderer/Rasterizer.hpp Polygon Rasterizer that is used to render filled polygons with high-quality Anti- Aliasing. Polygon Rasterizer that is used to render filled polygons with high-quality Anti- Aliasing. Internally, by default, the class uses integer coordinates in format 24.8, i.e. 24 bits for integer part and 8 bits for fractional - see POLY_BASE_SHIFT. This class can be used in the following way: 1. setFillingRule(FillingRule fr) - optional. 2. reset() 3. moveTo(x, y) / lineTo(x, y) - make the polygon. One can create more than one contour, but each contour must consist of at least 3 vertices, i.e. moveTo(x1, y1); lineTo(x2, y2); lineTo(x3, y3); is the absolute minimum of vertices that define a triangle. The algorithm does not check either the number of vertices nor coincidence of their coordinates, but in the worst case it just won't draw anything. The order of the vertices (clockwise or counterclockwise) is important when using the non-zero filling rule (fill_non_zero). In this case the vertex order of all the contours must be the same if you want your intersecting polygons to be without "holes". You actually can use different vertices order. If the contours do not intersect each other the order is not important anyway. If they do, contours with the same vertex order will be rendered without "holes" while the intersecting contours with different orders will have "holes". setFillingRule() can be called anytime before "sweeping".

Syntax

class Rasterizer { public:     enum      {         POLY_BASE_SHIFT = 5,                            POLY_BASE_SIZE = 1 << POLY_BASE_SHIFT,          POLY_BASE_MASK = POLY_BASE_SIZE - 1         };     enum      {         AA_SHIFT = 8,                    AA_NUM = 1 << AA_SHIFT,          AA_MASK = AA_NUM - 1,            AA_2NUM = AA_NUM * 2,            AA_2MASK = AA_2NUM - 1       };     enum FillingRule     {         FILL_NON_ZERO,          FILL_EVEN_ODD       };     Rasterizer()         : fillingRule(FILL_NON_ZERO)     {     }     void reset()     {         outline.reset();     }     void setFillingRule(FillingRule fillingRule)     {         this->fillingRule = fillingRule;     }     void moveTo(int x, int y)     { #ifndef SIMULATOR         if (!outline.wasOutlineTooComplex()) #endif         {             outline.moveTo(x, y);         }     }     void lineTo(int x, int y)     { #ifndef SIMULATOR         if (!outline.wasOutlineTooComplex()) #endif         {             outline.lineTo(x, y);         }     }     unsigned calculateAlpha(int area) const     {         int cover = area >> (Rasterizer::POLY_BASE_SHIFT * 2 + 1 - AA_SHIFT);         if (cover < 0)         {             cover = -cover;         }         if (fillingRule == FILL_EVEN_ODD)         {             cover &= AA_2MASK;             if (cover > AA_NUM)             {                 cover = AA_2NUM - cover;             }         }         if (cover > AA_MASK)         {             cover = AA_MASK;         }         return cover;     }     template <class Renderer>     bool render(Renderer& r)     {         const Cell* cells = outline.getCells();         unsigned numCells = outline.getNumCells();         if (numCells == 0)         {             return true;         }         if (outline.wasOutlineTooComplex())         {             return false;         }         int x, y;         int cover;         int alpha;         int area;         scanline.reset();         cover = 0;         const Cell* curCell = cells++;         numCells--;         for (;;)         {             const Cell* startCell = curCell;             int coord = curCell->packedCoord();             x = curCell->x;             y = curCell->y;             area = startCell->area;             cover += startCell->cover;             while (numCells-- > 0)             {                 curCell = cells++;                 if (curCell->packedCoord() != coord)                 {                     break;                 }                 area += curCell->area;                 cover += curCell->cover;             }             if (area)             {                 alpha = calculateAlpha((cover << (Rasterizer::POLY_BASE_SHIFT + 1)) - area);                 if (alpha)                 {                     if (scanline.isReady(y))                     {                         r.render(scanline);                         scanline.resetSpans();                     }                     scanline.addCell(x, y, alpha);                 }                 x++;             }             if (numCells == unsigned(-1))             {                 break;             }             if (curCell->x > x)             {                 alpha = calculateAlpha(cover << (Rasterizer::POLY_BASE_SHIFT + 1));                 if (alpha)                 {                     if (scanline.isReady(y))                     {                         r.render(scanline);                         scanline.resetSpans();                     }                     scanline.addSpan(x, y, curCell->x - x, alpha);                 }             }         }         if (scanline.getNumSpans())         {             r.render(scanline);         }         return true;     }     void setMaxRenderY(int y)     {         outline.setMaxRenderY(y);     }     bool wasOutlineTooComplex()     {         return outline.wasOutlineTooComplex();     } private:     Rasterizer(const Rasterizer&);     const Rasterizer& operator=(const Rasterizer&);     Outline outline;              Scanline scanline;            FillingRule fillingRule;  };

Fields

outline

No summary provided. Read more...

scanline

No summary provided. Read more...

fillingRule

No summary provided. Read more...

Methods

reset()

@fn void Rasterizer::reset() Resets this object. Resets this object. Basically this is done by resetting the the Outline. Read more...

setFillingRule()

@fn void Rasterizer::setFillingRule(FillingRule fillingRule) Sets the filling rule to be used when rendering the outline. Sets the filling rule to be used when rendering the outline. Read more...

moveTo()

@fn void Rasterizer::moveTo(int x, int y) Move to. Move to. Read more...

lineTo()

@fn void Rasterizer::lineTo(int x, int y) Line to. Line to. Read more...

calculateAlpha() const

@fn unsigned Rasterizer::calculateAlpha(int area) const Calculates the alpha. Calculates the alpha. Read more...

render()

No summary provided. Read more...

setMaxRenderY()

@fn void Rasterizer::setMaxRenderY(int y) Sets maximum render y coordinate. Sets maximum render y coordinate. This is passed to the Outline to avoid registering any Cell that has a y coordinate less than zero of higher than the given y. Read more...

wasOutlineTooComplex()

@fn bool Rasterizer::wasOutlineTooComplex() Determines if we the outline was too complex to draw completely. Determines if we the outline was too complex to draw completely. Read more...

operator=()

@fn const Rasterizer& Rasterizer::operator=(const Rasterizer&); Assignment operator. Read more...

References

LocationReferrerScopeText
Rasterizer.hpp:58
class Rasterizer
CWRUtil.hpp:95touchgfx::CWRUtil::Q5::Q5()
Q5(const Q10 q10) : v(int(q10) / Rasterizer::POLY_BASE_SIZE) { }
CWRUtil.hpp:194touchgfx::CWRUtil::Q5::operator*() const
return Q5(muldiv(v, int(q15), Rasterizer::POLY_BASE_SIZE * Rasterizer::POLY_BASE_SIZE * Rasterizer::POLY_BASE_SIZE, remainder));
CWRUtil.hpp:245touchgfx::CWRUtil::Q5::operator/() const
return Q5(int(v) * Rasterizer::POLY_BASE_SIZE / q5.v);
CWRUtil.hpp:611touchgfx::CWRUtil::sine()
int16_t fraction = i % Rasterizer::POLY_BASE_SIZE;
CWRUtil.hpp:619touchgfx::CWRUtil::sine()
return Q15(muldiv(int(sineHigh - sineLow), fraction, Rasterizer::POLY_BASE_SIZE, remainder)) + sineLow;
CWRUtil.hpp:696touchgfx::CWRUtil::arcsine()
return 90 - arcsine(Q10(isqrt((1 << (Rasterizer::POLY_BASE_SHIFT * 4)) - int(q10) * int(q10))));
Canvas.hpp:174touchgfx::Canvas::rastouchgfx::Canvas
Rasterizer ras;
Rasterizer.hpp:187touchgfx::Rasterizer::calculateAlpha() const
int cover = area >> (Rasterizer::POLY_BASE_SHIFT * 2 + 1 - AA_SHIFT);
Rasterizer.hpp:349touchgfx::Rasterizer::Rasterizer()::#0touchgfx::Rasterizer::Rasterizer()
Rasterizer(const Rasterizer&);
Rasterizer.hpp:360touchgfx::Rasterizer::operator=()touchgfx::Rasterizer
const Rasterizer& operator=(const Rasterizer&);

Type Use

Variables of touchgfx::Rasterizer type
touchgfx::Rasterizer