libpromeki main
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
PaintEngine Class Reference

2D drawing engine for rendering primitives onto images. More...

#include <paintengine.h>

Classes

class  Impl
 Abstract implementation backend for PaintEngine. More...
 

Public Types

using Ptr = SharedPtr< PaintEngine >
 Shared pointer type for PaintEngine.
 
using Pixel = List< uint8_t >
 Opaque pixel value optimized for the underlying format.
 
using PointList = List< Point2Di32 >
 List of 2D points used for batch drawing operations.
 
using AlphaList = List< float >
 List of per-point alpha values used for compositing.
 

Public Member Functions

 PaintEngine ()
 Constructs a PaintEngine with a default (no-op) implementation.
 
 PaintEngine (Impl *impl)
 Constructs a PaintEngine that takes ownership of the given Impl.
 
const PixelFormatpixelFormat () const
 Returns the pixel format of the underlying implementation.
 
Pixel createPixel (const uint16_t *comps, size_t compCount) const
 Creates a Pixel from an array of component values.
 
Pixel createPixel (uint16_t c1) const
 Creates a Pixel from a single component value.
 
Pixel createPixel (uint16_t c1, uint16_t c2) const
 Creates a Pixel from two component values.
 
Pixel createPixel (uint16_t c1, uint16_t c2, uint16_t c3) const
 Creates a Pixel from three component values.
 
Pixel createPixel (uint16_t c1, uint16_t c2, uint16_t c3, uint16_t c4) const
 Creates a Pixel from four component values.
 
size_t drawPoints (const Pixel &pixel, const Point2Di32 *points, size_t pointCount) const
 Draws points onto the surface.
 
size_t drawPoints (const Pixel &pixel, const PointList &points) const
 Draws points from a PointList onto the surface.
 
size_t compositePoints (const Pixel &pixel, const Point2Di32 *points, const float *alphas, size_t pointCount) const
 Composites points onto the surface with per-point alpha.
 
size_t compositePoints (const Pixel &pixel, const PointList &points, const AlphaList &alphas) const
 Composites points from lists onto the surface with per-point alpha.
 
size_t drawLines (const Pixel &pixel, const Line2Di32 *lines, size_t lineCount) const
 Draws multiple line segments onto the surface.
 
size_t drawLine (const Pixel &pixel, const Line2Di32 &line) const
 Draws a single line segment onto the surface.
 
size_t drawLine (const Pixel &pixel, int x1, int y1, int x2, int y2) const
 Draws a single line segment specified by endpoint coordinates.
 
bool fill (const Pixel &pixel)
 Fills the entire surface with a single pixel value.
 
size_t drawRect (const Pixel &pixel, const Rect< int32_t > &rect) const
 Draws a rectangle outline.
 
size_t fillRect (const Pixel &pixel, const Rect< int32_t > &rect) const
 Fills a rectangle with a solid color.
 
size_t drawCircle (const Pixel &pixel, const Point2Di32 &center, int radius) const
 Draws a circle outline.
 
size_t fillCircle (const Pixel &pixel, const Point2Di32 &center, int radius) const
 Fills a circle with a solid color.
 
size_t drawEllipse (const Pixel &pixel, const Point2Di32 &center, const Size2Du32 &size) const
 Draws an ellipse outline.
 
size_t fillEllipse (const Pixel &pixel, const Point2Di32 &center, const Size2Du32 &size) const
 Fills an ellipse with a solid color.
 
bool blit (const Point2Di32 &destTopLeft, const Image &src, const Point2Di32 &srcTopLeft=Point2Di32(0, 0), const Size2Du32 &srcSize=Size2Du32()) const
 Blits a rectangular region from a source image onto the surface.
 

Static Public Member Functions

static PointList plotLine (int x1, int y1, int x2, int y2)
 Plots a line using Bresenham's algorithm.
 

Detailed Description

2D drawing engine for rendering primitives onto images.

PaintEngine provides a pixel-format-aware interface for drawing points, lines, filling surfaces, and blitting images. It delegates to a polymorphic Impl that is specific to the underlying pixel format.

Constructor & Destructor Documentation

◆ PaintEngine()

PaintEngine::PaintEngine ( Impl impl)
inline

Constructs a PaintEngine that takes ownership of the given Impl.

Parameters
implPointer to a heap-allocated Impl subclass.

Member Function Documentation

◆ blit()

bool PaintEngine::blit ( const Point2Di32 destTopLeft,
const Image src,
const Point2Di32 srcTopLeft = Point2Di32(0, 0),
const Size2Du32 srcSize = Size2Du32() 
) const
inline

Blits a rectangular region from a source image onto the surface.

Parameters
destTopLeftTop-left corner on the destination surface.
srcSource image to copy from.
srcTopLeftTop-left corner of the source region (default: origin).
srcSizeSize of the source region (default: entire source).
Returns
true on success, false on failure.

◆ compositePoints() [1/2]

size_t PaintEngine::compositePoints ( const Pixel pixel,
const Point2Di32 points,
const float alphas,
size_t  pointCount 
) const
inline

Composites points onto the surface with per-point alpha.

Parameters
pixelThe pixel value to composite.
pointsArray of points.
alphasArray of alpha values, one per point.
pointCountNumber of points in the arrays.
Returns
The number of points actually composited.

◆ compositePoints() [2/2]

size_t PaintEngine::compositePoints ( const Pixel pixel,
const PointList points,
const AlphaList alphas 
) const
inline

Composites points from lists onto the surface with per-point alpha.

Parameters
pixelThe pixel value to composite.
pointsList of points.
alphasList of alpha values, one per point.
Returns
The number of points actually composited.

◆ createPixel() [1/5]

Pixel PaintEngine::createPixel ( const uint16_t comps,
size_t  compCount 
) const
inline

Creates a Pixel from an array of component values.

Parameters
compsArray of component values.
compCountNumber of components in the array.
Returns
A Pixel suitable for drawing on this engine.

◆ createPixel() [2/5]

Pixel PaintEngine::createPixel ( uint16_t  c1) const
inline

Creates a Pixel from a single component value.

Parameters
c1The component value.
Returns
A Pixel suitable for drawing on this engine.

◆ createPixel() [3/5]

Pixel PaintEngine::createPixel ( uint16_t  c1,
uint16_t  c2 
) const
inline

Creates a Pixel from two component values.

Parameters
c1First component value.
c2Second component value.
Returns
A Pixel suitable for drawing on this engine.

◆ createPixel() [4/5]

Pixel PaintEngine::createPixel ( uint16_t  c1,
uint16_t  c2,
uint16_t  c3 
) const
inline

Creates a Pixel from three component values.

Parameters
c1First component value.
c2Second component value.
c3Third component value.
Returns
A Pixel suitable for drawing on this engine.

◆ createPixel() [5/5]

Pixel PaintEngine::createPixel ( uint16_t  c1,
uint16_t  c2,
uint16_t  c3,
uint16_t  c4 
) const
inline

Creates a Pixel from four component values.

Parameters
c1First component value.
c2Second component value.
c3Third component value.
c4Fourth component value.
Returns
A Pixel suitable for drawing on this engine.

◆ drawCircle()

size_t PaintEngine::drawCircle ( const Pixel pixel,
const Point2Di32 center,
int  radius 
) const
inline

Draws a circle outline.

Parameters
pixelThe pixel value to draw with.
centerCenter of the circle.
radiusRadius in pixels.
Returns
The number of points drawn.

◆ drawEllipse()

size_t PaintEngine::drawEllipse ( const Pixel pixel,
const Point2Di32 center,
const Size2Du32 size 
) const
inline

Draws an ellipse outline.

Parameters
pixelThe pixel value to draw with.
centerCenter of the ellipse.
sizeHalf-widths (rx, ry) of the ellipse.
Returns
The number of points drawn.

◆ drawLine() [1/2]

size_t PaintEngine::drawLine ( const Pixel pixel,
const Line2Di32 line 
) const
inline

Draws a single line segment onto the surface.

Parameters
pixelThe pixel value to draw with.
lineThe line segment to draw.
Returns
The number of points drawn.

◆ drawLine() [2/2]

size_t PaintEngine::drawLine ( const Pixel pixel,
int  x1,
int  y1,
int  x2,
int  y2 
) const
inline

Draws a single line segment specified by endpoint coordinates.

Parameters
pixelThe pixel value to draw with.
x1X coordinate of the start point.
y1Y coordinate of the start point.
x2X coordinate of the end point.
y2Y coordinate of the end point.
Returns
The number of points drawn.

◆ drawLines()

size_t PaintEngine::drawLines ( const Pixel pixel,
const Line2Di32 lines,
size_t  lineCount 
) const
inline

Draws multiple line segments onto the surface.

Parameters
pixelThe pixel value to draw with.
linesArray of line segments.
lineCountNumber of line segments in the array.
Returns
The number of points drawn.

◆ drawPoints() [1/2]

size_t PaintEngine::drawPoints ( const Pixel pixel,
const Point2Di32 points,
size_t  pointCount 
) const
inline

Draws points onto the surface.

Parameters
pixelThe pixel value to draw.
pointsArray of points to draw.
pointCountNumber of points in the array.
Returns
The number of points actually drawn.

◆ drawPoints() [2/2]

size_t PaintEngine::drawPoints ( const Pixel pixel,
const PointList points 
) const
inline

Draws points from a PointList onto the surface.

Parameters
pixelThe pixel value to draw.
pointsList of points to draw.
Returns
The number of points actually drawn.

◆ drawRect()

size_t PaintEngine::drawRect ( const Pixel pixel,
const Rect< int32_t > &  rect 
) const
inline

Draws a rectangle outline.

Parameters
pixelThe pixel value to draw with.
rectThe rectangle to draw.
Returns
The number of points drawn.

◆ fill()

bool PaintEngine::fill ( const Pixel pixel)
inline

Fills the entire surface with a single pixel value.

Parameters
pixelThe pixel value to fill with.
Returns
true on success, false on failure.

◆ fillCircle()

size_t PaintEngine::fillCircle ( const Pixel pixel,
const Point2Di32 center,
int  radius 
) const
inline

Fills a circle with a solid color.

Parameters
pixelThe pixel value to fill with.
centerCenter of the circle.
radiusRadius in pixels.
Returns
The number of points drawn.

◆ fillEllipse()

size_t PaintEngine::fillEllipse ( const Pixel pixel,
const Point2Di32 center,
const Size2Du32 size 
) const
inline

Fills an ellipse with a solid color.

Parameters
pixelThe pixel value to fill with.
centerCenter of the ellipse.
sizeHalf-widths (rx, ry) of the ellipse.
Returns
The number of points drawn.

◆ fillRect()

size_t PaintEngine::fillRect ( const Pixel pixel,
const Rect< int32_t > &  rect 
) const
inline

Fills a rectangle with a solid color.

Parameters
pixelThe pixel value to fill with.
rectThe rectangle to fill.
Returns
The number of points drawn.

◆ pixelFormat()

const PixelFormat * PaintEngine::pixelFormat ( ) const
inline

Returns the pixel format of the underlying implementation.

Returns
Pointer to the PixelFormat.

◆ plotLine()

static PointList PaintEngine::plotLine ( int  x1,
int  y1,
int  x2,
int  y2 
)
static

Plots a line using Bresenham's algorithm.

Parameters
x1X coordinate of the start point.
y1Y coordinate of the start point.
x2X coordinate of the end point.
y2Y coordinate of the end point.
Returns
A list of points along the rasterized line.

The documentation for this class was generated from the following file: