brw1

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

GraphicsDisplay Class Reference

The GraphicsDisplay class. More...

#include <GraphicsDisplay.h>

Inherits TextDisplay.

Inherited by RA8875.

Public Member Functions

 GraphicsDisplay (const char *name)
 The constructor.
virtual RetCode_t pixel (loc_t x, loc_t y, color_t color)=0
 Draw a pixel in the specified color.
virtual RetCode_t pixelStream (color_t *p, uint32_t count, loc_t x, loc_t y)=0
 Write a stream of pixels to the display.
virtual color_t getPixel (loc_t x, loc_t y)=0
 Get a pixel from the display.
virtual RetCode_t getPixelStream (color_t *p, uint32_t count, loc_t x, loc_t y)=0
 Get a stream of pixels from the display.
virtual uint16_t width ()=0
 get the screen width in pixels
virtual uint16_t height ()=0
 get the screen height in pixels
virtual RetCode_t SetGraphicsCursor (loc_t x, loc_t y)=0
 Prepare the controller to write binary data to the screen by positioning the memory cursor.
virtual RetCode_t SetGraphicsCursorRead (loc_t x, loc_t y)=0
 Prepare the controller to read binary data from the screen by positioning the memory read cursor.
virtual RetCode_t fillrect (loc_t x1, loc_t y1, loc_t x2, loc_t y2, color_t color, fill_t fillit=FILL)=0
 Draw a filled rectangle in the specified color.
virtual RetCode_t window (loc_t x, loc_t y, dim_t w, dim_t h)
 Set the window, which controls where items are written to the screen.
virtual RetCode_t cls (uint16_t layers=0)
 Clear the screen.
virtual RetCode_t WindowMax (void)
 method to set the window region to the full screen.
virtual RetCode_t _putp (color_t pixel)
 method to put a single color pixel to the screen.
virtual RetCode_t fill (int x, int y, int w, int h, color_t color)
 method to fill a region.
virtual int fontblit (int x, int y, const unsigned char *fontTable, const unsigned char *fontChar)
 This method transfers one character from the external font data to the screen.
color_t RGBQuadToRGB16 (RGBQUAD *colorPaletteArray, uint16_t index)
 This method returns the color value from a palette.
RGBQUAD RGB16ToRGBQuad (color_t c)
 This method converts a 16-bit color value into a 24-bit RGB Quad.
RetCode_t RenderImageFile (loc_t x, loc_t y, const char *FileName)
 This method attempts to render a specified graphics image file at the specified screen location.
RetCode_t RenderBitmapFile (loc_t x, loc_t y, const char *Name_BMP)
 This method reads a disk file that is in bitmap format and puts it on the screen.
RetCode_t RenderIconFile (loc_t x, loc_t y, const char *Name_ICO)
 This method reads a disk file that is in ico format and puts it on the screen.
virtual int character (int x, int y, int value)
 prints one character at the specified coordinates.
virtual int columns (void)
 get the number of colums based on the currently active font
virtual int rows (void)
 get the number of rows based on the currently active font
virtual RetCode_t set_font (const unsigned char *font=NULL)
 Select a bitmap font (provided by the user) for all subsequent text rendering.
virtual bool claim (FILE *stream)
 redirect output from a stream (stoud, sterr) to display
virtual RetCode_t locate (textloc_t column, textloc_t row)=0
 locate the cursor at a character position.
virtual RetCode_t foreground (color_t color)=0
 set the foreground color
virtual RetCode_t background (color_t color)=0
 set the background color

Protected Member Functions

virtual RetCode_t _StartGraphicsStream (void)=0
 Pure virtual method indicating the start of a graphics stream.
virtual RetCode_t _EndGraphicsStream (void)=0
 Pure virtual method indicating the end of a graphics stream.
RetCode_t _RenderBitmap (loc_t x, loc_t y, uint32_t fileOffset, FILE *Image)
 Protected method to render an image given a file handle and coordinates.

Protected Attributes

const unsigned char * font
 reference to an external font somewhere in memory

Detailed Description

The GraphicsDisplay class.

This graphics display class supports both graphics and text operations. Typically, a subclass is derived from this which has localizations to adapt to a specific hardware platform (e.g. a display controller chip), that overrides methods in here to either add more capability or perhaps to improve performance, by leveraging specific hardware capabilities.

Definition at line 34 of file GraphicsDisplay.h.


Constructor & Destructor Documentation

GraphicsDisplay ( const char *  name )

The constructor.

Definition at line 183 of file GraphicsDisplay.cpp.


Member Function Documentation

virtual RetCode_t _EndGraphicsStream ( void   ) [protected, pure virtual]

Pure virtual method indicating the end of a graphics stream.

This is called to conclude a stream of pixel data that was sent. This may cause register configuration changes in the derived class in order to stop the hardware from accept the streaming data.

Note:
this method must be supported in the derived class.
Returns:
error code.

Implemented in RA8875.

RetCode_t _putp ( color_t  pixel ) [virtual]

method to put a single color pixel to the screen.

This method may be called as many times as necessary after

See also:
_StartGraphicsStream() is called, and it should be followed by _EndGraphicsStream.
Parameters:
[in]pixelis a color value to be put on the screen.
Returns:
success/failure code.
See also:
RetCode_t.

Reimplemented in RA8875.

Definition at line 236 of file GraphicsDisplay.cpp.

RetCode_t _RenderBitmap ( loc_t  x,
loc_t  y,
uint32_t  fileOffset,
FILE *  Image 
) [protected]

Protected method to render an image given a file handle and coordinates.

Parameters:
[in]xis the horizontal pixel coordinate
[in]yis the vertical pixel coordinate
[in]wis the image width restriction, or zero to permit full image width.
[in]his the image height restriction, or zero to permit full image height.
[in]fileOffsetis the offset into the file where the image data starts
[in]Imageis the filename stream already opened for the data.
Returns:
success or error code.

Definition at line 359 of file GraphicsDisplay.cpp.

virtual RetCode_t _StartGraphicsStream ( void   ) [protected, pure virtual]

Pure virtual method indicating the start of a graphics stream.

This is called prior to a stream of pixel data being sent. This may cause register configuration changes in the derived class in order to prepare the hardware to accept the streaming data.

Note:
this method must be supported in the derived class.
Returns:
error code.

Implemented in RA8875.

virtual RetCode_t background ( color_t  color ) [pure virtual, inherited]

set the background color

Note:
this method may be overridden in a derived class.
Parameters:
[in]coloris color to use for background drawing.
Returns:
error code.

Implemented in RA8875.

int character ( int  x,
int  y,
int  value 
) [virtual]

prints one character at the specified coordinates.

This will print the character at the specified pixel coordinates.

Parameters:
[in]xis the horizontal offset in pixels.
[in]yis the vertical offset in pixels.
[in]valueis the character to print.
Returns:
number of pixels to index to the right if a character was printed, 0 otherwise.

Implements TextDisplay.

Definition at line 196 of file GraphicsDisplay.cpp.

bool claim ( FILE *  stream ) [virtual, inherited]

redirect output from a stream (stoud, sterr) to display

Note:
this method may be overridden in a derived class.
Parameters:
[in]streamthat shall be redirected to the TextDisplay
Returns:
true if the claim succeeded.

Definition at line 95 of file TextDisplay.cpp.

RetCode_t cls ( uint16_t  layers = 0 ) [virtual]

Clear the screen.

The behavior is to clear the whole screen.

Parameters:
[in]layersis ignored, but supports maintaining the same API for the graphics layer.
Returns:
success/failure code.
See also:
RetCode_t.

Implements TextDisplay.

Reimplemented in RA8875.

Definition at line 256 of file GraphicsDisplay.cpp.

int columns ( void   ) [virtual]

get the number of colums based on the currently active font

Returns:
number of columns.

Implements TextDisplay.

Reimplemented in RA8875.

Definition at line 555 of file GraphicsDisplay.cpp.

RetCode_t fill ( int  x,
int  y,
int  w,
int  h,
color_t  color 
) [virtual]

method to fill a region.

This method fills a region with the specified color.

Parameters:
[in]xis the left-edge of the region.
[in]yis the top-edge of the region.
[in]wspecifies the width of the region.
[in]hspecifies the height of the region.
Returns:
success/failure code.
See also:
RetCode_t.

Definition at line 251 of file GraphicsDisplay.cpp.

virtual RetCode_t fillrect ( loc_t  x1,
loc_t  y1,
loc_t  x2,
loc_t  y2,
color_t  color,
fill_t  fillit = FILL 
) [pure virtual]

Draw a filled rectangle in the specified color.

Note:
As a side effect, this changes the current foreground color for subsequent operations.
this method must be supported in the derived class.
Parameters:
[in]x1is the horizontal start of the line.
[in]y1is the vertical start of the line.
[in]x2is the horizontal end of the line.
[in]y2is the vertical end of the line.
[in]colordefines the foreground color.
[in]fillitis optional to NOFILL the rectangle. default is FILL.
Returns:
success/failure code.
See also:
RetCode_t.

Implemented in RA8875.

int fontblit ( int  x,
int  y,
const unsigned char *  fontTable,
const unsigned char *  fontChar 
) [virtual]

This method transfers one character from the external font data to the screen.

Note:
the font data is in a special format as generate by the mikroe font creator. \ See http://www.mikroe.com/glcd-font-creator/
Parameters:
[in]xis the horizontal pixel coordinate
[in]yis the vertical pixel coordinate
[in]fontTableis the base of the table which has the metrics
[in]fontCharis the start of that record in the table for the char (e.g. 'A' - 'Z')
Returns:
how far the cursor should advance to the right in pixels

Definition at line 298 of file GraphicsDisplay.cpp.

virtual RetCode_t foreground ( color_t  color ) [pure virtual, inherited]

set the foreground color

Note:
this method may be overridden in a derived class.
Parameters:
[in]coloris color to use for foreground drawing.
Returns:
error code.

Implemented in RA8875.

virtual color_t getPixel ( loc_t  x,
loc_t  y 
) [pure virtual]

Get a pixel from the display.

Note:
this method must be supported in the derived class.
Parameters:
[in]xis the horizontal offset to this pixel.
[in]yis the vertical offset to this pixel.
Returns:
the pixel. see

Implemented in RA8875.

virtual RetCode_t getPixelStream ( color_t *  p,
uint32_t  count,
loc_t  x,
loc_t  y 
) [pure virtual]

Get a stream of pixels from the display.

Note:
this method must be supported in the derived class.
Parameters:
[out]pis a pointer to a color_t array to accept the stream.
[in]countis the number of pixels to read.
[in]xis the horizontal offset to this pixel.
[in]yis the vertical offset to this pixel.
Returns:
success/failure code.
See also:
RetCode_t.

Implemented in RA8875.

virtual uint16_t height (  ) [pure virtual]

get the screen height in pixels

Note:
this method must be supported in the derived class.
Returns:
screen height in pixels.

Implemented in RA8875.

RetCode_t locate ( textloc_t  column,
textloc_t  row 
) [pure virtual, inherited]

locate the cursor at a character position.

Based on the currently active font, locate the cursor on screen.

Note:
this method may be overridden in a derived class.
Parameters:
[in]columnis the horizontal offset from the left side.
[in]rowis the vertical offset from the top.
Returns:
error code.

Implemented in RA8875.

Definition at line 68 of file TextDisplay.cpp.

virtual RetCode_t pixel ( loc_t  x,
loc_t  y,
color_t  color 
) [pure virtual]

Draw a pixel in the specified color.

Note:
this method must be supported in the derived class.
Parameters:
[in]xis the horizontal offset to this pixel.
[in]yis the vertical offset to this pixel.
[in]colordefines the color for the pixel.
Returns:
success/failure code.
See also:
RetCode_t.

Implemented in RA8875.

virtual RetCode_t pixelStream ( color_t *  p,
uint32_t  count,
loc_t  x,
loc_t  y 
) [pure virtual]

Write a stream of pixels to the display.

Note:
this method must be supported in the derived class.
Parameters:
[in]pis a pointer to a color_t array to write.
[in]countis the number of pixels to write.
[in]xis the horizontal position on the display.
[in]yis the vertical position on the display.
Returns:
success/failure code.
See also:
RetCode_t.

Implemented in RA8875.

RetCode_t RenderBitmapFile ( loc_t  x,
loc_t  y,
const char *  Name_BMP 
)

This method reads a disk file that is in bitmap format and puts it on the screen.

Supported formats:

  • 4-bit color format (16 colors)
  • 8-bit color format (256 colors)
  • 16-bit color format (65k colors)
  • compression: no.
Note:
This is a slow operation, typically due to the use of the file system, and partially because bmp files are stored from the bottom up, and the memory is written from the top down; as a result, it constantly 'seeks' on the file system for the next row of information.

As a performance test, a sample picture was timed. A family picture was converted to Bitmap format; shrunk to 352 x 272 pixels and save in 8-bit color format. The resulting file size was 94.5 KByte. The SPI port interface was set to 20 MHz. The original bitmap rendering software was purely in software, pushing 1 pixel at a time to the write function, which did use SPI hardware (not pin wiggling) to transfer commands and data to the display. Then, the driver was improved to leverage the capability of the derived display driver. As a final check, instead of the [known slow] local file system, a randomly chosen USB stick was used. The performance results are impressive (but depend on the listed factors).

  • 34 seconds, LocalFileSystem, Software Rendering
  • 9 seconds, LocalFileSystem, Hardware Rending for RA8875
  • 3 seconds, MSCFileSystem, Hardware Rendering for RA8875
Parameters:
[in]xis the horizontal pixel coordinate
[in]yis the vertical pixel coordinate
[in]Name_BMPis the filename on the mounted file system.
Returns:
success or error code.

Definition at line 491 of file GraphicsDisplay.cpp.

RetCode_t RenderIconFile ( loc_t  x,
loc_t  y,
const char *  Name_ICO 
)

This method reads a disk file that is in ico format and puts it on the screen.

Reading the disk is slow, but a typical icon file is small so it should be ok.

Note:
An Icon file can have more than one icon in it. This implementation only processes the first image in the file.
Parameters:
[in]xis the horizontal pixel coordinate
[in]yis the vertical pixel coordinate
[in]Name_ICOis the filename on the mounted file system.
Returns:
success or error code.

Definition at line 517 of file GraphicsDisplay.cpp.

RetCode_t RenderImageFile ( loc_t  x,
loc_t  y,
const char *  FileName 
)

This method attempts to render a specified graphics image file at the specified screen location.

This supports several variants of the following file types:

  • Bitmap file format,
  • Icon file format.
Note:
The specified image width and height, when adjusted for the x and y origin, must fit on the screen, or the image will not be shown (it does not clip the image).
The file extension is tested, and if it ends in a supported format, the appropriate handler is called to render that image.
Parameters:
[in]xis the horizontal pixel coordinate
[in]yis the vertical pixel coordinate
[in]FileNamerefers to the fully qualified path and file on a mounted file system.
Returns:
success or error code.

Definition at line 480 of file GraphicsDisplay.cpp.

RGBQUAD RGB16ToRGBQuad ( color_t  c )

This method converts a 16-bit color value into a 24-bit RGB Quad.

RRRR RGGG GGGB BBBB.

Parameters:
[in]cis the 16-bit color.
See also:
color_t.
Returns:
an RGBQUAD value.
See also:
RGBQUAD

Definition at line 347 of file GraphicsDisplay.cpp.

color_t RGBQuadToRGB16 ( RGBQUAD *  colorPaletteArray,
uint16_t  index 
)

This method returns the color value from a palette.

This method accepts a pointer to a Bitmap color palette, which is a table in memory composed of RGB Quad values (r, g, b, 0), and an index into that table. It then extracts the color information and downsamples it to a color_t value which it returns.

Note:
This method probably has very little value outside of the internal methods for reading BMP files.
Parameters:
[in]colorPaletteArrayis the handle to the color palette array to use.
[in]indexis the index into the color palette.
Returns:
the color in color_t format.

Definition at line 336 of file GraphicsDisplay.cpp.

int rows ( void   ) [virtual]

get the number of rows based on the currently active font

Returns:
number of rows.

Implements TextDisplay.

Reimplemented in RA8875.

Definition at line 560 of file GraphicsDisplay.cpp.

RetCode_t set_font ( const unsigned char *  font = NULL ) [virtual]

Select a bitmap font (provided by the user) for all subsequent text rendering.

This API permits selection of a special memory mapped font, which enables the presentation of many font sizes and styles, including proportional fonts.

Note:
Tool to create the fonts is accessible from its creator available at http://www.mikroe.com. Hint: Change the data to an array of type char[].

This special font array has a 4-byte header, followed by the data:

  • the number of bytes per char
  • the vertical size in pixels for each character
  • the horizontal size in pixels for each character
  • the number of bytes per vertical line (width of the array)
  • the subsequent records are the font information.
Parameters:
[in]fontis a pointer to a specially formed font array. NULL, or the omission of this parameter will restore the default font capability, which may use the display controllers hardware font (if available), or no font.
Returns:
error code.

Reimplemented in RA8875.

Definition at line 189 of file GraphicsDisplay.cpp.

virtual RetCode_t SetGraphicsCursor ( loc_t  x,
loc_t  y 
) [pure virtual]

Prepare the controller to write binary data to the screen by positioning the memory cursor.

Note:
this method must be supported in the derived class.
Parameters:
[in]xis the horizontal position in pixels (from the left edge)
[in]yis the vertical position in pixels (from the top edge)
Returns:
success/failure code.
See also:
RetCode_t.

Implemented in RA8875.

virtual RetCode_t SetGraphicsCursorRead ( loc_t  x,
loc_t  y 
) [pure virtual]

Prepare the controller to read binary data from the screen by positioning the memory read cursor.

Parameters:
[in]xis the horizontal position in pixels (from the left edge)
[in]yis the vertical position in pixels (from the top edge)
Returns:
success/failure code.
See also:
RetCode_t.

Implemented in RA8875.

virtual uint16_t width (  ) [pure virtual]

get the screen width in pixels

Note:
this method must be supported in the derived class.
Returns:
screen width in pixels.

Implemented in RA8875.

RetCode_t window ( loc_t  x,
loc_t  y,
dim_t  w,
dim_t  h 
) [virtual]

Set the window, which controls where items are written to the screen.

When something hits the window width, it wraps back to the left side and down a row. If the initial write is outside the window, it will be captured into the window when it crosses a boundary.

Parameters:
[in]xis the left edge in pixels.
[in]yis the top edge in pixels.
[in]wis the window width in pixels.
[in]his the window height in pixels.
Returns:
success/failure code.
See also:
RetCode_t.

Reimplemented in RA8875.

Definition at line 218 of file GraphicsDisplay.cpp.

RetCode_t WindowMax ( void   ) [virtual]

method to set the window region to the full screen.

This restores the 'window' to the full screen, so that other operations (

See also:
cls) would clear the whole screen.
Returns:
success/failure code.
See also:
RetCode_t.

Definition at line 231 of file GraphicsDisplay.cpp.


Field Documentation

const unsigned char* font [protected]

reference to an external font somewhere in memory

Definition at line 414 of file GraphicsDisplay.h.