주요 내용으로 건너뛰기

TextureMapper

The TextureMapper widget displays a transformed image. It can be used to generate effects where an image should be rotated in two or three dimensions.

The image can be freely scaled and rotated in three dimensions. The scaling and rotation is done around the adjustable origin. A virtual camera is applied to the rendered image yielding a perspective impression. The amount of perspective impression can be adjusted. The transformed image is clipped according to the dimensions of the TextureMapper widget. In order to make the image fully visible the TextureMapper should be large enough to accommodate the transformed image, which may be larger than the raw image.

See: Widget

Note:

  • The drawing of this widget is not trivial and typically has a significant performance penalty. The number of pixels drawn, the presence of global alpha or per pixel alpha inflicts the computation and should be considered.
  • This widget does not support 1 bit per pixel color depth.

Inherits from: Image, Widget, Drawable

Inherited by: AnimationTextureMapper

Public Types

enumRenderingAlgorithm { NEAREST_NEIGHBOR, BILINEAR_INTERPOLATION }
Rendering algorithm to use when scaling the bitmap.

Public Functions

virtual voiddraw(const Rect & invalidatedArea) const
Draw this drawable.
virtual floatgetBitmapPositionX() const
Gets bitmap position x coordinate.
virtual floatgetBitmapPositionY() const
Gets bitmap position y coordinate.
virtual floatgetCameraDistance() const
Gets camera distance.
virtual floatgetCameraX() const
Gets camera x coordinate.
virtual floatgetCameraY() const
Gets camera y coordinate.
virtual floatgetOrigoX() const
Gets transformation origo x coordinate.
virtual floatgetOrigoY() const
Gets transformation origo y coordinate.
virtual floatgetOrigoZ() const
Gets transformation origo z coordinate.
virtual RenderingAlgorithmgetRenderingAlgorithm() const
Gets the algorithm used when rendering.
virtual floatgetScale() const
Gets the scale of the image.
virtual RectgetSolidRect() const
Get (the largest possible) rectangle that is guaranteed to be solid (opaque).
virtual floatgetX0() const
Get the x coordinate of the top left corner of the transformed bitmap.
virtual floatgetX1() const
Get the x coordinate of the top right corner of the transformed bitmap.
virtual floatgetX2() const
Get the x coordinate of the bottom right of the transformed bitmap.
virtual floatgetX3() const
Get the x coordinate of the bottom left corner of the transformed bitmap.
virtual floatgetXAngle() const
Get the x angle.
virtual floatgetY0() const
Get the y coordinate of the top left corner of the transformed bitmap.
virtual floatgetY1() const
Get the y coordinate of the top right corner of the transformed bitmap.
virtual floatgetY2() const
Get the y coordinate of the bottom right corner of the transformed bitmap.
virtual floatgetY3() const
Get the y coordinate of the bottom left corner of the transformed bitmap.
virtual floatgetYAngle() const
Get the y angle.
virtual floatgetZ0() const
Get the z coordinate of the top left corner of the transformed bitmap.
virtual floatgetZ1() const
Get the z coordinate of the top right corner of the transformed bitmap.
virtual floatgetZ2() const
Get the z coordinate of the bottom right corner of the transformed bitmap.
virtual floatgetZ3() const
Get the z coordinate of the bottom left corner of the transformed bitmap.
virtual floatgetZAngle() const
Get the z angle.
voidinvalidateBoundingRect() const
Invalidate the bounding rectangle of the transformed bitmap.
virtual voidsetAngles(float newXAngle, float newYAngle, float newZAngle)
Sets the angles of the image.
virtual voidsetBitmap(const Bitmap & bitmap)
Sets the bitmap for this TextureMapper and updates the width and height of this widget to match those of the Bitmap.
virtual voidsetBitmapPosition(float x, float y)
Sets the position of the bitmap within the TextureMapper.
virtual voidsetBitmapPosition(int x, int y)
Sets the position of the bitmap within the TextureMapper.
virtual voidsetCamera(float x, float y)
Sets the camera coordinate.
virtual voidsetCameraDistance(float d)
Sets camera distance.
virtual voidsetOrigo(float x, float y)
Sets the transformation origo (center) in two dimensions.
virtual voidsetOrigo(float x, float y, float z)
Sets the transformation origo (center).
virtual voidsetRenderingAlgorithm(RenderingAlgorithm algorithm)
Sets the render algorithm to be used.
virtual voidsetScale(float newScale)
Sets the scale of the image.
virtual voidsetXAngle(float newXAngle)
Sets the x angle.
virtual voidsetYAngle(float newYAngle)
Sets the y angle.
virtual voidsetZAngle(float newZAngle)
Sets the z angle.
TextureMapper(const Bitmap & bitmap =Bitmap())
Constructs a new TextureMapper with a default alpha value of 255 (solid) and a default Bitmap (undefined) if none is specified.
virtual voidupdateAngles(float newXAngle, float newYAngle, float newZAngle)
Updates the angles of the image.
virtual voidupdateScale(float newScale)
Updates the scale of the image.
virtual voidupdateXAngle(float newXAngle)
Updates the x angle.
virtual voidupdateYAngle(float newYAngle)
Updates the y angle.
virtual voidupdateZAngle(float newZAngle)
Updates the z angle.

Protected Functions

voidapplyTransformation()
Transform the bitmap using the supplied origo, scale, rotation and camera.
voiddrawQuad(const Rect & invalidatedArea, uint16_t fb, const float triangleXs, const float triangleYs, const float triangleZs, const float triangleUs, const float triangleVs) const
The TextureMapper will draw the transformed bitmap by drawing one transformed quad.
RectgetBoundingRect() const
Gets bounding rectangle of the transformed bitmap.
RenderingVariantlookupRenderVariant() const
Returns the rendering variant based on the bitmap format, alpha value and rendering algorithm.

Protected Attributes

floatcameraDistance
The camera distance.
RenderingAlgorithmcurrentRenderingAlgorithm
The current rendering algorithm.
floatimageX0
The coordinate for the image points.
floatimageX1
The coordinate for the image points.
floatimageX2
The coordinate for the image points.
floatimageX3
The coordinate for the image points.
floatimageY0
The coordinate for the image points.
floatimageY1
The coordinate for the image points.
floatimageY2
The coordinate for the image points.
floatimageY3
The coordinate for the image points.
floatimageZ0
The coordinate for the image points.
floatimageZ1
The coordinate for the image points.
floatimageZ2
The coordinate for the image points.
floatimageZ3
The coordinate for the image points.
floatscale
The scale.
uint16_tsubDivisionSize
The size of the affine sub divisions.
floatxAngle
The angle x.
floatxBitmapPosition
The bitmap position x.
floatxCamera
The camera x coordinate.
floatxOrigo
The origo x coordinate.
floatyAngle
The angle y.
floatyBitmapPosition
The bitmap position y.
floatyCamera
The camera y coordinate.
floatyOrigo
The origo y coordinate.
floatzAngle
The angle z.
floatzOrigo
The origo z coordinate.
const intMINIMAL_CAMERA_DISTANCE
The minimal camera distance.

Additional inherited members

Public Functions inherited from Image

uint8_tgetAlpha() const
Gets the current alpha value of the widget.
BitmapgetBitmap() const
Gets the Bitmap currently assigned to the Image widget.
BitmapIdgetBitmapId() const
Gets the BitmapId currently assigned to the Image widget.
Image(const Bitmap & bitmap =Bitmap())
Constructs a new Image with a default alpha value of 255 (solid) and a default Bitmap (undefined) if none is specified.
voidsetAlpha(uint8_t newAlpha)
Sets the opacity (alpha value).

Protected Attributes inherited from Image

uint8_talpha
The Alpha for this image.
Bitmapbitmap
The Bitmap to display.

Public Functions inherited from Widget

virtual voidgetLastChild(int16_t x, int16_t y, Drawable ** last)
Since a Widget is only one Drawable, Widget::getLastChild simply yields itself as result, but only if the Widget isVisible and isTouchable.

Public Functions inherited from Drawable

virtual voidchildGeometryChanged()
This function can be called on parent nodes to signal that the size or position of one or more of its children has changed.
Drawable()
Initializes a new instance of the Drawable class.
voiddrawToDynamicBitmap(BitmapId id)
Render the Drawable object into a dynamic bitmap.
RectgetAbsoluteRect() const
Helper function for obtaining the rectangle this Drawable covers, expressed in absolute coordinates.
virtual Drawable *getFirstChild()
Function for obtaining the first child of this drawable if any.
int16_tgetHeight() const
Gets the height of this Drawable.
virtual voidgetLastChild(int16_t x, int16_t y, Drawable ** last) =0
Function for obtaining the the last child of this drawable that intersects with the specified point.
Drawable *getNextSibling()
Gets the next sibling node.
Drawable *getParent() const
Returns the parent node.
const Rect &getRect() const
Gets the rectangle this Drawable covers, in coordinates relative to its parent.
virtual RectgetSolidRectAbsolute()
Helper function for obtaining the largest solid rect (as implemented by getSolidRect()) expressed in absolute coordinates.
virtual voidgetVisibleRect(Rect & rect) const
Function for finding the visible part of this drawable.
int16_tgetWidth() const
Gets the width of this Drawable.
int16_tgetX() const
Gets the x coordinate of this Drawable, relative to its parent.
int16_tgetY() const
Gets the y coordinate of this Drawable, relative to its parent.
virtual voidhandleClickEvent(const ClickEvent & event)
Defines the event handler interface for ClickEvents.
virtual voidhandleDragEvent(const DragEvent & event)
Defines the event handler interface for DragEvents.
virtual voidhandleGestureEvent(const GestureEvent & event)
Defines the event handler interface for GestureEvents.
virtual voidhandleTickEvent()
Called periodically by the framework if the Drawable instance has subscribed to timer ticks.
virtual voidinvalidate() const
Tell the framework that this entire Drawable needs to be redrawn.
virtual voidinvalidateRect(Rect & invalidatedArea) const
Request that a region of this drawable is redrawn.
boolisTouchable() const
Gets whether this Drawable receives touch events or not.
boolisVisible() const
Gets whether this Drawable is visible.
virtual voidmoveRelative(int16_t x, int16_t y)
Moves the drawable.
virtual voidmoveTo(int16_t x, int16_t y)
Moves the drawable.
virtual voidsetHeight(int16_t height)
Sets the height of this drawable.
voidsetPosition(const Drawable & drawable)
Sets the position of the Drawable to the same as the given Drawable.
voidsetPosition(int16_t x, int16_t y, int16_t width, int16_t height)
Sets the size and position of this Drawable, relative to its parent.
voidsetTouchable(bool touch)
Controls whether this Drawable receives touch events or not.
voidsetVisible(bool vis)
Controls whether this Drawable should be visible.
virtual voidsetWidth(int16_t width)
Sets the width of this drawable.
voidsetWidthHeight(const Bitmap & bitmap)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(const Drawable & drawable)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(const Rect & rect)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
voidsetWidthHeight(int16_t width, int16_t height)
Sets the dimensions (width and height) of the Drawable without changing the x and y coordinates).
virtual voidsetX(int16_t x)
Sets the x coordinate of this Drawable, relative to its parent.
voidsetXY(const Drawable & drawable)
Sets the x and y coordinates of this Drawable.
voidsetXY(int16_t x, int16_t y)
Sets the x and y coordinates of this Drawable, relative to its parent.
virtual voidsetY(int16_t y)
Sets the y coordinate of this Drawable, relative to its parent.
virtual voidtranslateRectToAbsolute(Rect & r) const
Helper function for converting a region of this Drawable to absolute coordinates.
virtual ~Drawable()
Finalizes an instance of the Drawable class.

Protected Attributes inherited from Drawable

Drawable *nextSibling
Pointer to the next Drawable.
Drawable *parent
Pointer to this drawable's parent.
Rectrect
The coordinates of this Drawable, relative to its parent.
booltouchable
True if this drawable should receive touch events.
boolvisible
True if this drawable should be drawn.

Public Types Documentation

RenderingAlgorithm

Rendering algorithm to use when scaling the bitmap.

NEAREST_NEIGHBORFast but not a very good image quality. Good for fast animations.
BILINEAR_INTERPOLATIONSlower but better image quality. Good for static representation of a scaled image.

Public Functions Documentation

draw

virtual void draw(const Rect &invalidatedArea)

Draw this drawable.

It is a requirement that the draw implementation does not draw outside the region specified by invalidatedArea.

Parameters:
invalidatedAreaThe sub-region of this drawable that needs to be redrawn, expressed in coordinates relative to its parent (e.g. for a complete redraw, invalidatedArea will be (0, 0, width, height).

Reimplements: touchgfx::Image::draw

getBitmapPositionX

virtual float getBitmapPositionX()const

Gets bitmap position x coordinate.

Returns:

The bitmap position x coordinate.

See also:

getBitmapPositionY

virtual float getBitmapPositionY()const

Gets bitmap position y coordinate.

Returns:

The bitmap position y coordinate.

See also:

getCameraDistance

virtual float getCameraDistance()const

Gets camera distance.

Returns:

The camera distance.

See also:

getCameraX

virtual float getCameraX()const

Gets camera x coordinate.

Returns:

The camera x coordinate.

See also:

getCameraY

virtual float getCameraY()const

Gets camera y coordinate.

Returns:

The camera y coordinate.

See also:

getOrigoX

virtual float getOrigoX()const

Gets transformation origo x coordinate.

Returns:

The transformation origo x coordinate.

See also:

getOrigoY

virtual float getOrigoY()const

Gets transformation origo y coordinate.

Returns:

The transformation origo y coordinate.

See also:

getOrigoZ

virtual float getOrigoZ()const

Gets transformation origo z coordinate.

Returns:

The transformation origo z coordinate.

See also:

getRenderingAlgorithm

virtual RenderingAlgorithm getRenderingAlgorithm()const

Gets the algorithm used when rendering.

Returns:

The algorithm used when rendering.

getScale

virtual float getScale()const

Gets the scale of the image.

Returns:

The scale.

See also:

getSolidRect

virtual Rect getSolidRect()const

Get (the largest possible) rectangle that is guaranteed to be solid (opaque).

This information is important, as any Drawable underneath the solid area does not need to be drawn.

Returns:

The solid rectangle part of the Drawable.

Note

The rectangle returned must be relative to upper left corner of the Drawable, meaning that a completely solid widget should return the full size Rect(0, 0, getWidth(), getHeight()). If no area can be guaranteed to be solid, an empty Rect(0, 0, 0, 0) must be returned. Failing to return the correct rectangle may result in errors on the display.

Reimplements: touchgfx::Image::getSolidRect

getX0

virtual float getX0()const

Get the x coordinate of the top left corner of the transformed bitmap.

Returns:

The X0 coordinate.

getX1

virtual float getX1()const

Get the x coordinate of the top right corner of the transformed bitmap.

Returns:

The X1 coordinate.

getX2

virtual float getX2()const

Get the x coordinate of the bottom right of the transformed bitmap.

Returns:

The X2 coordinate.

getX3

virtual float getX3()const

Get the x coordinate of the bottom left corner of the transformed bitmap.

Returns:

The X3 coordinate.

getXAngle

virtual float getXAngle()const

Get the x angle.

Returns:

The x angle.

See also:

getY0

virtual float getY0()const

Get the y coordinate of the top left corner of the transformed bitmap.

Returns:

The Y0 coordinate.

getY1

virtual float getY1()const

Get the y coordinate of the top right corner of the transformed bitmap.

Returns:

The Y1 coordinate.

getY2

virtual float getY2()const

Get the y coordinate of the bottom right corner of the transformed bitmap.

Returns:

The Y2 coordinate.

getY3

virtual float getY3()const

Get the y coordinate of the bottom left corner of the transformed bitmap.

Returns:

The Y3 coordinate.

getYAngle

virtual float getYAngle()const

Get the y angle.

Returns:

The y angle.

See also:

getZ0

virtual float getZ0()const

Get the z coordinate of the top left corner of the transformed bitmap.

Returns:

The Z0 coordinate.

getZ1

virtual float getZ1()const

Get the z coordinate of the top right corner of the transformed bitmap.

Returns:

The Z1 coordinate.

getZ2

virtual float getZ2()const

Get the z coordinate of the bottom right corner of the transformed bitmap.

Returns:

The Z2 coordinate.

getZ3

virtual float getZ3()const

Get the z coordinate of the bottom left corner of the transformed bitmap.

Returns:

The Z3 coordinate.

getZAngle

virtual float getZAngle()const

Get the z angle.

Returns:

The z angle.

See also:

invalidateBoundingRect

Invalidate the bounding rectangle of the transformed bitmap.

See also:

setAngles

virtual void setAngles(floatnewXAngle ,
floatnewYAngle ,
floatnewZAngle
)

Sets the angles of the image.

Parameters:
newXAngleThe new x Angle.
newYAngleThe new y Angle.
newZAngleThe new x Angle.
Note

The area covered by the image before/after changing the angles is NOT invalidated.

See also:

setBitmap

virtual void setBitmap(const Bitmap &bitmap)

Sets the bitmap for this TextureMapper and updates the width and height of this widget to match those of the Bitmap.

Parameters:
bitmapThe bitmap instance.
Note

The user code must call invalidate() in order to update the image on the display.

Reimplements: touchgfx::Image::setBitmap

setBitmapPosition

virtual void setBitmapPosition(floatx ,
floaty
)

Sets the position of the bitmap within the TextureMapper.

The bitmap is clipped with respect to the dimensions of the TextureMapper widget.

Parameters:
xThe x coordinate.
yThe y coordinate.
See also:

setBitmapPosition

virtual void setBitmapPosition(intx ,
inty
)

Sets the position of the bitmap within the TextureMapper.

The bitmap is clipped with respect to the dimensions of the TextureMapper widget.

Parameters:
xThe x coordinate.
yThe y coordinate.
See also:

setCamera

virtual void setCamera(floatx ,
floaty
)

Sets the camera coordinate.

Parameters:
xThe x coordinate for the camera.
yThe y coordinate for the camera.
See also:

setCameraDistance

virtual void setCameraDistance(floatd)

Sets camera distance.

If the given value is below TextureMapper::MINIMAL_CAMERA_DISTANCE, it will be set to TextureMapper::MINIMAL_CAMERA_DISTANCE.

Parameters:
dThe new camera distance.
See also:

setOrigo

virtual void setOrigo(floatx ,
floaty
)

Sets the transformation origo (center) in two dimensions.

Leaves the z coordinate untouched.

Parameters:
xThe x coordinate.
yThe y coordinate.
See also:

setOrigo

virtual void setOrigo(floatx ,
floaty ,
floatz
)

Sets the transformation origo (center).

Parameters:
xThe x coordinate.
yThe y coordinate.
zThe z coordinate.
See also:

setRenderingAlgorithm

virtual void setRenderingAlgorithm(RenderingAlgorithmalgorithm)

Sets the render algorithm to be used.

Default setting is NEAREST_NEIGHBOR.

Parameters:
algorithmThe algorithm to use when rendering.

setScale

virtual void setScale(floatnewScale)

Sets the scale of the image.

Parameters:
newScaleThe new scale value.
See also:

setXAngle

virtual void setXAngle(floatnewXAngle)

Sets the x angle.

Parameters:
newXAngleThe new x angle.
Note

The area covered by the image before/after changing the angle is NOT invalidated.

See also:

setYAngle

virtual void setYAngle(floatnewYAngle)

Sets the y angle.

Parameters:
newYAngleThe new y angle.
Note

The area covered by the image before/after changing the angle is NOT invalidated.

See also:

setZAngle

virtual void setZAngle(floatnewZAngle)

Sets the z angle.

Parameters:
newZAngleThe new z angle.
Note

The area covered by the image before/after changing the angle is NOT invalidated.

See also:

TextureMapper

TextureMapper(const Bitmap &bitmap =Bitmap())

Constructs a new TextureMapper with a default alpha value of 255 (solid) and a default Bitmap (undefined) if none is specified.

If a Bitmap is passed to the constructor, the width and height of this widget is set to those of the bitmap.

Parameters:
bitmap(Optional) The bitmap to display.
See also:

updateAngles

virtual void updateAngles(floatnewXAngle ,
floatnewYAngle ,
floatnewZAngle
)

Updates the angles of the image.

The area covered by the image before and after changing the angles is invalidated, which is the smallest required rectangle.

Parameters:
newXAngleThe new x Angle.
newYAngleThe new y Angle.
newZAngleThe new x Angle.
See also:

updateScale

virtual void updateScale(floatnewScale)

Updates the scale of the image.

This implies invalidating the area covered by the texture mapper.

Parameters:
newScaleThe new scale value.
See also:

updateXAngle

virtual void updateXAngle(floatnewXAngle)

Updates the x angle.

Parameters:
newXAngleThe new x angle.
See also:

updateYAngle

virtual void updateYAngle(floatnewYAngle)

Updates the y angle.

Parameters:
newYAngleThe new y angle.
See also:

updateZAngle

virtual void updateZAngle(floatnewZAngle)

Updates the z angle.

Parameters:
newZAngleThe new z angle.
See also:

Protected Functions Documentation

applyTransformation

Transform the bitmap using the supplied origo, scale, rotation and camera.

This method is called by all the methods that manipulate origo, scale, rotation and camera.

drawQuad

void drawQuad(const Rect &invalidatedArea ,const
uint16_t *fb ,const
const float *triangleXs ,const
const float *triangleYs ,const
const float *triangleZs ,const
const float *triangleUs ,const
const float *triangleVsconst
)const

The TextureMapper will draw the transformed bitmap by drawing one transformed quad.

The quad is drawn from the points 0,1,2,3 using the x,y,z values from each point along with the u,v coordinates in the bitmap associated with each point.

Parameters:
invalidatedAreaThe invalidated area.
fbThe framebuffer.
triangleXsThe triangle xs.
triangleYsThe triangle ys.
triangleZsThe triangle zs.
triangleUsThe triangle us.
triangleVsThe triangle vs.

getBoundingRect

Rect getBoundingRect()const

Gets bounding rectangle of the transformed bitmap.

This is the smallest possible rectangle which covers the image of the bitmap after applying scale and rotation.

Returns:

The bounding rectangle.

lookupRenderVariant

RenderingVariant lookupRenderVariant()const

Returns the rendering variant based on the bitmap format, alpha value and rendering algorithm.

Returns:

The RenderingVariant.

Protected Attributes Documentation

cameraDistance

float cameraDistance

The camera distance.

currentRenderingAlgorithm

RenderingAlgorithm currentRenderingAlgorithm

The current rendering algorithm.

imageX0

float imageX0

The coordinate for the image points.

imageX1

float imageX1

The coordinate for the image points.

imageX2

float imageX2

The coordinate for the image points.

imageX3

float imageX3

The coordinate for the image points.

imageY0

float imageY0

The coordinate for the image points.

imageY1

float imageY1

The coordinate for the image points.

imageY2

float imageY2

The coordinate for the image points.

imageY3

float imageY3

The coordinate for the image points.

imageZ0

float imageZ0

The coordinate for the image points.

imageZ1

float imageZ1

The coordinate for the image points.

imageZ2

float imageZ2

The coordinate for the image points.

imageZ3

float imageZ3

The coordinate for the image points.

scale

float scale

The scale.

subDivisionSize

uint16_t subDivisionSize

The size of the affine sub divisions.

xAngle

float xAngle

The angle x.

xBitmapPosition

float xBitmapPosition

The bitmap position x.

xCamera

float xCamera

The camera x coordinate.

xOrigo

float xOrigo

The origo x coordinate.

yAngle

float yAngle

The angle y.

yBitmapPosition

float yBitmapPosition

The bitmap position y.

yCamera

float yCamera

The camera y coordinate.

yOrigo

float yOrigo

The origo y coordinate.

zAngle

float zAngle

The angle z.

zOrigo

float zOrigo

The origo z coordinate.

MINIMAL_CAMERA_DISTANCE

const int MINIMAL_CAMERA_DISTANCE = 1

The minimal camera distance.