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

touchgfx::Scanline class

@class Scanline Scanline.hpp touchgfx/canvas_widget_renderer/Scanline.hpp This class is used to transfer data from class Outline (or a similar one) to the rendering buffer. This class is used to transfer data from class Outline (or a similar one) to the rendering buffer. It's organized very simple. The class stores information of horizontal spans to render it into a pixel-map buffer. Each span has initial X, length, and an array of bytes that determine the alpha values for each pixel. So, the restriction of using this class is 256 levels of Anti-Aliasing, which is quite enough for any practical purpose. Before using this class you should know the minimal and maximal pixel coordinates of your scanline. The protocol of using is: 1. reset() 2. addCell() / addSpan() - accumulate scanline. You pass y coordinate into these functions in order to make scanline know the last Y. Before calling addCell() / addSpan() you should check with method isReady(y) if the last Y has changed. It also checks if the scanline is not empty. When forming one scanline the next x coordinate must be always greater than the last stored one, i.e. it works only with ordered coordinates. 3. If the current scanline isReady() you should render it and then call resetSpans() before adding new cells/spans. 4. Rendering: Scanline provides an iterator class that allows you to extract the spans and the cover values for each pixel. Be aware that clipping has not been done yet, so you should perform it yourself. Use Scanline::iterator to render spans: ------------------------------------------------------------------------- int baseX = scanline.getBaseX(); // base X. Should be added to the span's X // "scanline" is a const reference to the // scanline passed in. int y = scanline.y(); // y coordinate of the scanline ...Perform vertical clipping here... Scanline::iterator span(scanline); unsigned char* row = renderingBuffer->row(y); // The the address of the beginning // of the current row unsigned num_spans = scanline.getNumSpans(); // Number of spans. It's guaranteed that // numSpans is always greater than 0. do { int x = span.next() + baseX; // The beginning X of the span const int8u covers* = span.getCovers(); // The array of the cover values int numPix = span.getNumPix(); // Number of pixels of the span. // Always greater than 0, still we // should use "int" instead of // "unsigned" because it's more // convenient for clipping ...Perform horizontal clipping here... ...you have x, covers, and pix_Fromcount... unsigned char* dst = row + x; // Calculate the start address of the row. // In this case we assume a simple // grayscale image 1-byte per pixel. do { *dst++ = *covers++; // Hypotetical rendering. } while (--numPix); } while (--numSpans); // numSpans cannot be 0, so this loop is quite safe The question is: why should we accumulate the whole scanline when we could render just separate spans when they're ready? That's because using the scanline is in general faster. When is consists of more than one span the conditions for the processor cash system are better, because switching between two different areas of memory (that can be large ones) occurs less frequently.

Syntax

class Scanline { public:     class iterator     {     public:         iterator(const Scanline& scanline) :             covers(scanline.covers),             curCount(scanline.counts),             curStartIndex(scanline.startIndices)         {         }         int next()         {             ++curCount;             ++curStartIndex;             return int(*curStartIndex);         }         int getNumPix() const         {             return int(*curCount);         }         const uint8_t* getCovers() const         {             return covers + *curStartIndex;         }     private:         const uint8_t*  covers;         const uint16_t* curCount;         const uint16_t* curStartIndex;     };     friend class iterator;     Scanline();     virtual ~Scanline() { }     void reset();     void resetSpans();     void addCell(int x, int y, unsigned cover);     void addSpan(int x, int y, unsigned len, unsigned cover);     int isReady(int y) const;     int getY() const     {         return lastY;     }     unsigned getNumSpans() const     {         return numSpans;     } private:     Scanline(const Scanline&);     const Scanline& operator = (const Scanline&);     int       lastX;     int       lastY;     unsigned  numSpans;     uint16_t* curStartIndex;     uint16_t* curCount;     uint8_t*  covers;     uint16_t* startIndices;     uint16_t* counts; };

Fields

lastX

No summary provided. Read more...

lastY

No summary provided. Read more...

numSpans

No summary provided. Read more...

curStartIndex

No summary provided. Read more...

curCount

No summary provided. Read more...

covers

No summary provided. Read more...

startIndices

No summary provided. Read more...

counts

No summary provided. Read more...

Methods

addSpan()

@fn void Scanline::addSpan(int x, int y, unsigned len, unsigned cover); Adds a span of cells to the current Scanline. Adds a span of cells to the current Scanline. Works like calling addCell() len times. Read more...

isReady() const

@fn int Scanline::isReady(int y) const; Checks if a Scanline is ready for rendering. Checks if a Scanline is ready for rendering. A Scanline is ready for rendering when the y coordinate has changed. Since all the cells are sorted, a change in the y coordinate means that we have moved to the next Scanline and thus the collected data for the Scanline must be rendered before we register cells for the next Scanline. Read more...

getY() const

@fn int Scanline::getY() const Gets y coordinate, i.e. the vertical offset of the Scanline. Gets y coordinate, i.e. the vertical offset of the Scanline. This allows easy positioning of the Outline. The y coordinate is setup through function reset(). Read more...

getNumSpans() const

@fn unsigned Scanline::getNumSpans() const Gets number spans in the Scanline. Gets number spans in the Scanline. Read more...

operator=()

No summary provided. Read more...

reset()

@fn void Scanline::reset(); Resets the Scanline object in preparation for the handling the next Scanline. Resets the Scanline object in preparation for the handling the next Scanline. Read more...

resetSpans()

@fn void Scanline::resetSpans(); Resets the spans in preparation for the next Scanline. Resets the spans in preparation for the next Scanline. Identical to calling reset() without changing the dx_ and dy_ parameters from the previous call to reset(). Read more...

addCell()

@fn void Scanline::addCell(int x, int y, unsigned cover); Adds a single cell to the current Scanline. Adds a single cell to the current Scanline. Works just like invoking addSpan() with a len=1. Read more...