Skip to main content

LCD2bpp

platform/driver/lcd/LCD2bpp.hpp

This class contains the various low-level drawing routines for drawing bitmaps, texts and rectangles on 2 bits per pixel gray scale displays.

See: LCD

Note: All coordinates are expected to be in absolute coordinates!

Inherits from: LCD

Public Functions

virtual uint8_tbitDepth() const
Number of bits per pixel used by the display.
virtual voidblitCopy(const uint16_t * sourceData, const Rect & source, const Rect & blitRect, uint8_t alpha, bool hasTransparentPixels)
Blits (directly copies) a block of data to the framebuffer, performing alpha blending (and tranparency keying) as specified.
virtual voidblitCopy(const uint8_t * sourceData, Bitmap::BitmapFormat sourceFormat, const Rect & source, const Rect & blitRect, uint8_t alpha, bool hasTransparentPixels)
Blits (directly copies) a block of data to the framebuffer, performing alpha blending (and tranparency keying) as specified.
virtual voidcopyAreaFromTFTToClientBuffer(const Rect & region)
Copies part of the displayed framebuffer to current framebuffer.
virtual uint16_t *copyFrameBufferRegionToMemory(const Rect & visRegion, const Rect & absRegion, const BitmapId bitmapId)
Copies part of the framebuffer to the data section of a bitmap.
virtual RectcopyFrameBufferRegionToMemory(const Rect & visRegion, const Rect & absRegion, uint8_t * dst, int16_t dstWidth, int16_t dstHeight)
Copies part of the framebuffer to memory.
virtual voiddrawPartialBitmap(const Bitmap & bitmap, int16_t x, int16_t y, const Rect & rect, uint8_t alpha =255, bool useOptimized =true)
Draws all (or a part) of a bitmap.
voidenableTextureMapperAll()
Enables the texture mappers for all image formats.
voidenableTextureMapperGRAY2()
Enables the texture mappers for GRAY2 image format.
voidenableTextureMapperGRAY2_BilinearInterpolation()
Enables the texture mappers for GRAY2 image format.
voidenableTextureMapperGRAY2_NearestNeighbor()
Enables the texture mappers for GRAY2 image format.
virtual voidfillBuffer(uint8_t *const destination, uint16_t pixelStride, const Rect & rect, const colortype color, const uint8_t alpha)
Draws a filled rectangle in destination memory using the specified color and opacity.
virtual voidfillRect(const Rect & rect, colortype color, uint8_t alpha =255)
Draws a filled rectangle in the framebuffer in the specified color and opacity.
virtual Bitmap::BitmapFormatframebufferFormat() const
Framebuffer format used by the display.
virtual uint16_tframebufferStride() const
Framebuffer stride in bytes.
LCD2bpp()
FORCE_INLINE_FUNCTION uint16_tgetFramebufferStride()
Framebuffer stride in bytes.
FORCE_INLINE_FUNCTION uint8_tgetNativeColor(colortype color)
Generates a color representation to be used on the LCD, based on 24 bit RGB values.
FORCE_INLINE_FUNCTION uint8_tgetNativeColorFromRGB(uint8_t red, uint8_t green, uint8_t blue)
Generates a color representation to be used on the LCD, based on 24 bit RGB values.
FORCE_INLINE_FUNCTION uint8_tgetPixel(const uint16_t * addr, int offset)
Get pixel from buffer/image.
FORCE_INLINE_FUNCTION uint8_tgetPixel(const uint8_t * addr, int offset)
Get pixel from buffer/image.
FORCE_INLINE_FUNCTION voidsetPixel(uint16_t * addr, int offset, uint8_t value)
Set pixel in buffer.
FORCE_INLINE_FUNCTION voidsetPixel(uint8_t * addr, int offset, uint8_t value)
Set pixel in buffer.
FORCE_INLINE_FUNCTION intshiftVal(int offset)
Shift value to get the right pixel in a byte.

Protected Functions

voidcopyRect(const uint8_t srcAddress, uint16_t srcStride, uint8_t srcPixelOffset, uint8_t RESTRICT dstAddress, uint16_t dstStride, uint8_t dstPixelOffset, uint16_t width, uint16_t height) const
Copies a rectangular area.
virtual voiddrawGlyph(uint16_t wbuf16, Rect widgetArea, int16_t x, int16_t y, uint16_t offsetX, uint16_t offsetY, const Rect & invalidatedArea, const GlyphNode glyph, const uint8_t * glyphData, uint8_t byteAlignRow, colortype color, uint8_t bitsPerPixel, uint8_t alpha, TextRotation rotation)
Private version of draw-glyph with explicit destination buffer pointer argument.
virtual DrawTextureMapScanLineBase *getTextureMapperDrawScanLine(const TextureSurface & texture, RenderingVariant renderVariant, uint8_t alpha)
Gets pointer to object that can draw a scan line which allows for highly specialized and optimized implementation.
voidblitCopyAlphaPerPixel(const uint16_t sourceData16, const uint8_t sourceAlphaData, const Rect & source, const Rect & blitRect, uint8_t alpha)
Blit a 2D source-array to the framebuffer performing alpha-blending per pixel as specified Performs always a software blend.
intnextLine(bool rotatedDisplay, TextRotation textRotation)
Find out how much to advance in the display buffer to get to the next line.
intnextPixel(bool rotatedDisplay, TextRotation textRotation)
Find out how much to advance in the display buffer to get to the next pixel.

Protected Attributes

const uint8_talphaBlend
The alpha lookup table to avoid arithmetics when alpha blending.

Additional inherited members

Public Classes inherited from LCD

structStringVisuals
The visual elements when writing a string.

Protected Classes inherited from LCD

classDrawTextureMapScanLineBase
Base class for drawing scanline by the texture mapper.

Public Functions inherited from LCD

voiddrawString(Rect widgetArea, const Rect & invalidatedArea, const StringVisuals & stringVisuals, const Unicode::UnicodeChar * format, ... )
Draws the specified Unicode string.
virtual voiddrawTextureMapQuad(const DrawingSurface & dest, const Point3D * vertices, const TextureSurface & texture, const Rect & absoluteRect, const Rect & dirtyAreaAbsolute, RenderingVariant renderVariant, uint8_t alpha =255, uint16_t subDivisionSize =12)
Texture map quad.
virtual voiddrawTextureMapTriangle(const DrawingSurface & dest, const Point3D * vertices, const TextureSurface & texture, const Rect & absoluteRect, const Rect & dirtyAreaAbsolute, RenderingVariant renderVariant, uint8_t alpha =255, uint16_t subDivisionSize =12)
Texture map triangle.
colortypegetDefaultColor() const
Gets default color previously set using setDefaultColor.
LCD()
Initializes a new instance of the LCD class.
virtual voidsetDefaultColor(colortype color)
Sets default color as used by alpha level only bitmap formats, e.g.
voidsetVectorFontRenderer(VectorFontRenderer * renderer)
Set the vector font renderer.
virtual boolsupportDynamicBitmapDrawing(const Bitmap::BitmapFormat format)
Check if LCD support dynamic bitmap drawing.
virtual ~LCD()
Finalizes an instance of the LCD class.
FORCE_INLINE_FUNCTION uint8_tdiv255(uint16_t num)
Approximates an integer division of a 16bit value by 255.
FORCE_INLINE_FUNCTION uint32_tdiv255g(uint32_t pixelxAlpha)
Divides the green component of pixelxAlpha by 255.
FORCE_INLINE_FUNCTION uint32_tdiv255rb(uint32_t pixelxAlpha)
Divides the red and blue components of pixelxAlpha by 255.

Protected Functions inherited from LCD

voiddrawStringLTR(const Rect & widgetArea, const Rect & invalidatedArea, const StringVisuals & visuals, const Unicode::UnicodeChar * format, va_list pArg)
Draws the specified Unicode string.
voiddrawStringRTL(const Rect & widgetArea, const Rect & invalidatedArea, const StringVisuals & visuals, const Unicode::UnicodeChar * format, va_list pArg)
Draws the specified Unicode string.
virtual voiddrawTextureMapScanLine(const DrawingSurface & dest, const Gradients & gradients, const Edge leftEdge, const Edge rightEdge, const TextureSurface & texture, const Rect & absoluteRect, const Rect & dirtyAreaAbsolute, RenderingVariant renderVariant, uint8_t alpha, uint16_t subDivisionSize)
Draw scan line.
FORCE_INLINE_FUNCTION uint8_tgetAlphaFromA4(const uint16_t * data, uint32_t offset)
Gets alpha from A4 image at given offset.
uint16_tgetNumLines(TextProvider & textProvider, WideTextAction wideTextAction, TextDirection textDirection, const Font * font, int16_t width)
Gets number of lines for a given text taking word wrap into consideration.
intrealX(const Rect & widgetArea, int16_t x, int16_t y, TextRotation rotation)
Find the real, absolute x coordinate of a point inside a widget with regards to rotation.
intrealY(const Rect & widgetArea, int16_t x, int16_t y, TextRotation rotation)
Find the real, absolute y coordinate of a point inside a widget with regards to rotation.
voidrotateRect(Rect & rect, const Rect & canvas, const TextRotation rotation)
Rotate a rectangle inside another rectangle.
uint16_tstringWidth(TextProvider & textProvider, const Font & font, const int numChars, TextDirection textDirection)
Find string width of the given number of ligatures read from the given TextProvider.

Protected Attributes inherited from LCD

colortypedefaultColor
Default Color to use when displaying transparency-only elements, e.g. A4 bitmaps.
const uint16_tnewLine
NewLine value.

Public Functions Documentation

bitDepth

virtual uint8_t bitDepth()const

Number of bits per pixel used by the display.

Returns:

The number of bits per pixel.

Reimplements: touchgfx::LCD::bitDepth

blitCopy

virtual void blitCopy(const uint16_t *sourceData ,
const Rect &source ,
const Rect &blitRect ,
uint8_talpha ,
boolhasTransparentPixels
)

Blits (directly copies) a block of data to the framebuffer, performing alpha blending (and tranparency keying) as specified.

Performs a software blend if HAL does not support BLIT_COPY_WITH_ALPHA and alpha != 255 (solid).

Parameters:
sourceDataThe source array pointer (points to the beginning of the data). The sourceData must be stored in a format suitable for the selected display.
sourceThe position and dimensions of the source. The x and y of this rect should both be 0.
blitRectA rectangle describing what region of the sourceData is to be copied to the framebuffer.
alphaThe alpha value to use for blending ranging from 0=invisible to 255=solid=no blending.
hasTransparentPixelsIf true, this data copy contains transparent pixels and require hardware support for that to be enabled.

Reimplements: touchgfx::LCD::blitCopy

blitCopy

virtual void blitCopy(const uint8_t *sourceData ,
Bitmap::BitmapFormatsourceFormat ,
const Rect &source ,
const Rect &blitRect ,
uint8_talpha ,
boolhasTransparentPixels
)

Blits (directly copies) a block of data to the framebuffer, performing alpha blending (and tranparency keying) as specified.

Performs a software blend if HAL does not support BLIT_COPY_WITH_ALPHA and alpha < 255 (solid).

If the display does not support the specified sourceFormat, an assert will be raised.

Parameters:
sourceDataThe source array pointer (points to the beginning of the data). The sourceData must be stored in a format suitable for the selected display.
sourceFormatThe bitmap format used in the source data.
sourceThe position and dimensions of the source. The x and y of this rect should both be 0.
blitRectA rectangle describing what region of the sourceData is to be copied to the framebuffer.
alphaThe alpha value to use for blending ranging from 0=invisible to 255=solid=no blending.
hasTransparentPixelsIf true, this data copy contains transparent pixels and require hardware support for that to be enabled.

Reimplements: touchgfx::LCD::blitCopy

copyAreaFromTFTToClientBuffer

virtual void copyAreaFromTFTToClientBuffer(const Rect &region)

Copies part of the displayed framebuffer to current framebuffer.

The region given is the absolute region on screen.

Parameters:
regionA rectangle describing what region of the displayed framebuffer is to be copied to the framebuffer.
Note

The copy is performed only when double buffering is enabled. Otherwise the given region in current framebuffer is left untouched.

Reimplements: touchgfx::LCD::copyAreaFromTFTToClientBuffer

copyFrameBufferRegionToMemory

virtual uint16_t * copyFrameBufferRegionToMemory(const Rect &visRegion ,
const Rect &absRegion ,
const BitmapIdbitmapId
)

Copies part of the framebuffer to the data section of a bitmap.

The bitmap must be a dynamic bitmap or animation storage (BITMAP_ANIMATION_STORAGE). The two regions given are the visible region and the absolute region on screen. This is used to copy only a part of the framebuffer. This might be the case if a SnapshotWidget is placed inside a Container where parts of the SnapshowWidget is outside the area defined by the Container. The visible region must be completely inside the absolute region.

Parameters:
visRegionThe visible region.
absRegionThe absolute region.
bitmapIdIdentifier for the bitmap.
Returns:

Null if it fails, else a pointer to the data in the given bitmap.

Note

There is only one instance of animation storage. The content of the bitmap data /animation storage outside the given region is left untouched.

See also:

Reimplements: touchgfx::LCD::copyFrameBufferRegionToMemory

copyFrameBufferRegionToMemory

virtual Rect copyFrameBufferRegionToMemory(const Rect &visRegion ,
const Rect &absRegion ,
uint8_t *dst ,
int16_tdstWidth ,
int16_tdstHeight
)

Copies part of the framebuffer to memory.

The memory is assumed to have the same format as the framebuffer. The two regions given are the visible region and the absolute region on screen. This is used to copy only a part of the framebuffer. This might be the case if a SnapshotWidget is placed inside a Container where parts of the SnapshowWidget is outside the area defined by the Container. The visible region must be completely inside the absolute region.

Parameters:
visRegionThe visible region.
absRegionThe absolute region.
dstDestination memory in same format as the framebuffer.
dstWidthWidth of the destination.
dstHeightHeight of the destination.
Returns:

The rect that was actually copied to the destination buffer.

Note

There is only one instance of animation storage. The content of the bitmap data /animation storage outside the given region is left untouched.

See also:

Reimplements: touchgfx::LCD::copyFrameBufferRegionToMemory

drawPartialBitmap

virtual void drawPartialBitmap(const Bitmap &bitmap ,
int16_tx ,
int16_ty ,
const Rect &rect ,
uint8_talpha =255,
booluseOptimized =true
)

Draws all (or a part) of a bitmap.

The coordinates of the corner of the bitmap is given in (x, y) and rect describes which part of the bitmap should be drawn. The bitmap can be drawn as it is or more or less transparent depending on the value of alpha. The value of alpha is independent of the transparency of the individual pixels of the given bitmap.

Parameters:
bitmapThe bitmap to draw.
xThe absolute x coordinate to place (0, 0) of the bitmap on the screen.
yThe absolute y coordinate to place (0, 0) of the bitmap on the screen.
rectA rectangle describing what region of the bitmap is to be drawn.
alpha(Optional) Optional alpha value ranging from 0=invisible to 255=solid. Default is 255 (solid).
useOptimized(Optional) if false, do not attempt to substitute (parts of) this bitmap with faster fillrects.

Reimplements: touchgfx::LCD::drawPartialBitmap

enableTextureMapperAll

Enables the texture mappers for all image formats.

This allows drawing any image using Bilinear Interpolation and Nearest Neighbor algorithms, but might use a lot of memory for the drawing algorithms.

enableTextureMapperGRAY2

Enables the texture mappers for GRAY2 image format.

This allows drawing GRAY2 images using Bilinear Interpolation and Nearest Neighbor algorithms.

See also:

enableTextureMapperGRAY2_BilinearInterpolation

Enables the texture mappers for GRAY2 image format.

This allows drawing GRAY2 images using Bilinear Interpolation algorithm.

See also:

enableTextureMapperGRAY2_NearestNeighbor

Enables the texture mappers for GRAY2 image format.

This allows drawing GRAY2 images using Nearest Neighbor algorithm.

See also:

fillBuffer

virtual void fillBuffer(uint8_t *constdestination ,
uint16_tpixelStride ,
const Rect &rect ,
const colortypecolor ,
const uint8_talpha
)

Draws a filled rectangle in destination memory using the specified color and opacity.

The destination memory must have the same format as the display framebuffer. By default the rectangle will be drawn as a solid box. The rectangle can be drawn with transparency by specifying alpha from 0=invisible to 255=solid.

Parameters:
destinationThe start of the memory area to fill.
pixelStrideThe pixel stride, i.e. number of pixels in a row.
rectThe rectangle to fill absolute coordinates.
colorThe rectangle color.
alphaThe rectangle opacity, from 0=invisible to 255=solid.
Note

The pixelStride is rounded up to nearest whole bytes for displays with more than one pixel per byte (LCD1bpp, LCD2bpp and LCD4bpp)

Reimplements: touchgfx::LCD::fillBuffer

fillRect

virtual void fillRect(const Rect &rect ,
colortypecolor ,
uint8_talpha =255
)

Draws a filled rectangle in the framebuffer in the specified color and opacity.

By default the rectangle will be drawn as a solid box. The rectangle can be drawn with transparency by specifying alpha from 0=invisible to 255=solid.

Parameters:
rectThe rectangle to draw in absolute display coordinates.
colorThe rectangle color.
alpha(Optional) The rectangle opacity, from 0=invisible to 255=solid.
See also:

Reimplements: touchgfx::LCD::fillRect

framebufferFormat

virtual Bitmap::BitmapFormat framebufferFormat()const

Framebuffer format used by the display.

Returns:

Reimplements: touchgfx::LCD::framebufferFormat

framebufferStride

virtual uint16_t framebufferStride()const

Framebuffer stride in bytes.

The distance (in bytes) from the start of one framebuffer row, to the next.

Returns:

The number of bytes in one framebuffer row.

Reimplements: touchgfx::LCD::framebufferStride

LCD2bpp

getFramebufferStride

static FORCE_INLINE_FUNCTION uint16_t getFramebufferStride()

Framebuffer stride in bytes.

The distance (in bytes) from the start of one framebuffer row, to the next.

Returns:

The number of bytes in one framebuffer row.

getNativeColor

static FORCE_INLINE_FUNCTION uint8_t getNativeColor(colortypecolor)

Generates a color representation to be used on the LCD, based on 24 bit RGB values.

Parameters:
colorThe color.
Returns:

The color representation depending on LCD color format.

getNativeColorFromRGB

static FORCE_INLINE_FUNCTION uint8_t getNativeColorFromRGB(uint8_tred ,
uint8_tgreen ,
uint8_tblue
)

Generates a color representation to be used on the LCD, based on 24 bit RGB values.

Parameters:
redValue of the red part (0-255).
greenValue of the green part (0-255).
blueValue of the blue part (0-255).
Returns:

The color representation depending on LCD color format.

getPixel

static FORCE_INLINE_FUNCTION uint8_t getPixel(const uint16_t *addr ,
intoffset
)

Get pixel from buffer/image.

Parameters:
addrThe address.
offsetThe offset.
Returns:

The pixel value.

getPixel

static FORCE_INLINE_FUNCTION uint8_t getPixel(const uint8_t *addr ,
intoffset
)

Get pixel from buffer/image.

Parameters:
addrThe address.
offsetThe offset.
Returns:

The pixel value.

setPixel

static FORCE_INLINE_FUNCTION void setPixel(uint16_t *addr ,
intoffset ,
uint8_tvalue
)

Set pixel in buffer.

Parameters:
addrThe address.
offsetThe offset.
valueThe value.

setPixel

static FORCE_INLINE_FUNCTION void setPixel(uint8_t *addr ,
intoffset ,
uint8_tvalue
)

Set pixel in buffer.

Parameters:
addrThe address.
offsetThe offset.
valueThe value.

shiftVal

static FORCE_INLINE_FUNCTION int shiftVal(intoffset)

Shift value to get the right pixel in a byte.

Parameters:
offsetThe offset.
Returns:

The shift value.

Protected Functions Documentation

copyRect

void copyRect(const uint8_t *srcAddress ,const
uint16_tsrcStride ,const
uint8_tsrcPixelOffset ,const
uint8_t *RESTRICTdstAddress ,const
uint16_tdstStride ,const
uint8_tdstPixelOffset ,const
uint16_twidth ,const
uint16_theightconst
)const

Copies a rectangular area.

Parameters:
srcAddressSource address (byte address).
srcStrideSource stride (number of bytes to advance to next line).
srcPixelOffsetSource pixel offset (first pixel in first source byte).
dstAddressIf destination address (byte address).
dstStrideDestination stride (number of bytes to advance to next line).
dstPixelOffsetDestination pixel offset (first pixel in destination byte).
widthThe width of area (in pixels).
heightThe height of area (in pixels).

drawGlyph

virtual void drawGlyph(uint16_t *wbuf16 ,
RectwidgetArea ,
int16_tx ,
int16_ty ,
uint16_toffsetX ,
uint16_toffsetY ,
const Rect &invalidatedArea ,
const GlyphNode *glyph ,
const uint8_t *glyphData ,
uint8_tbyteAlignRow ,
colortypecolor ,
uint8_tbitsPerPixel ,
uint8_talpha ,
TextRotationrotation
)

Private version of draw-glyph with explicit destination buffer pointer argument.

For all parameters (except the buffer pointer) see the public function drawString().

Parameters:
wbuf16The destination (frame) buffer to draw to.
widgetAreaThe canvas to draw the glyph inside.
xHorizontal offset to start drawing the glyph.
yVertical offset to start drawing the glyph.
offsetXHorizontal offset in the glyph to start drawing from.
offsetYVertical offset in the glyph to start drawing from.
invalidatedAreaThe area to draw inside.
glyphSpecifications of the glyph to draw.
glyphDataData containing the actual glyph (dense format)
byteAlignRowEach row of glyph data starts in a new byte.
colorThe color of the glyph.
bitsPerPixelBit depth of the glyph.
alphaThe transparency of the glyph.
rotationRotation to do before drawing the glyph.

Reimplements: touchgfx::LCD::drawGlyph

getTextureMapperDrawScanLine

virtual DrawTextureMapScanLineBase * getTextureMapperDrawScanLine(const TextureSurface &texture ,
RenderingVariantrenderVariant ,
uint8_talpha
)

Gets pointer to object that can draw a scan line which allows for highly specialized and optimized implementation.

Parameters:
textureThe texture Surface.
renderVariantThe render variant.
alphaThe global alpha.
Returns:

Null if it fails, else the pointer to the texture mapper draw scan line object.

Reimplements: touchgfx::LCD::getTextureMapperDrawScanLine

blitCopyAlphaPerPixel

static void blitCopyAlphaPerPixel(const uint16_t *sourceData16 ,
const uint8_t *sourceAlphaData ,
const Rect &source ,
const Rect &blitRect ,
uint8_talpha
)

Blit a 2D source-array to the framebuffer performing alpha-blending per pixel as specified Performs always a software blend.

Parameters:
sourceData16The source-array pointer (points to the beginning of the data). The sourceData must be stored as 2bpp GRAY2 values.
sourceAlphaDataThe alpha channel array pointer (points to the beginning of the data)
sourceThe location and dimensions of the source.
blitRectA rectangle describing what region is to be drawn.
alphaThe alpha value to use for blending applied to the whole image (255 = solid, no blending)

nextLine

static int nextLine(boolrotatedDisplay ,
TextRotationtextRotation
)

Find out how much to advance in the display buffer to get to the next line.

Parameters:
rotatedDisplayIs the display running in portrait mode?
textRotationRotation to perform.
Returns:

How much to advance to get to the next line.

nextPixel

static int nextPixel(boolrotatedDisplay ,
TextRotationtextRotation
)

Find out how much to advance in the display buffer to get to the next pixel.

Parameters:
rotatedDisplayIs the display running in portrait mode?
textRotationRotation to perform.
Returns:

How much to advance to get to the next pixel.

Protected Attributes Documentation

alphaBlend

const uint8_t alphaBlend

The alpha lookup table to avoid arithmetics when alpha blending.