Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of RA8875 by
GraphicsDisplay.h
00001 /* mbed GraphicsDisplay Display Library Base Class 00002 * Copyright (c) 2007-2009 sford 00003 * Released under the MIT License: http://mbed.org/license/mit 00004 * 00005 * A library for providing a common base class for Graphics displays 00006 * To port a new display, derive from this class and implement 00007 * the constructor (setup the display), pixel (put a pixel 00008 * at a location), width and height functions. Everything else 00009 * (locate, printf, putc, cls, window, putp, fill, blit, blitbit) 00010 * will come for free. You can also provide a specialised implementation 00011 * of window and putp to speed up the results 00012 */ 00013 00014 #ifndef MBED_GRAPHICSDISPLAY_H 00015 #define MBED_GRAPHICSDISPLAY_H 00016 #include "Bitmap.h" 00017 #include "TextDisplay.h" 00018 00019 // GraphicsDisplay has one "soft font" which is in a different format 00020 // then the primary font rendering api - see set_font(...). This is 00021 // therefore deprecated, but preserved for a time for backward 00022 // compatibility. 00023 // #define LOCALFONT 00024 00025 00026 /// The GraphicsDisplay class 00027 /// 00028 /// This graphics display class supports both graphics and text operations. 00029 /// Typically, a subclass is derived from this which has localizations to 00030 /// adapt to a specific hardware platform (e.g. a display controller chip), 00031 /// that overrides methods in here to either add more capability or perhaps 00032 /// to improve performance, by leveraging specific hardware capabilities. 00033 /// 00034 class GraphicsDisplay : public TextDisplay 00035 { 00036 public: 00037 /// The constructor 00038 GraphicsDisplay(const char* name); 00039 00040 /// Draw a pixel in the specified color. 00041 /// 00042 /// @note this method must be supported in the derived class. 00043 /// 00044 /// @param x is the horizontal offset to this pixel. 00045 /// @param y is the vertical offset to this pixel. 00046 /// @param color defines the color for the pixel. 00047 /// @returns success/failure code. @see RetCode_t. 00048 /// 00049 virtual RetCode_t pixel(loc_t x, loc_t y, color_t color) = 0; 00050 00051 /// Write a stream of pixels to the display. 00052 /// 00053 /// @note this method must be supported in the derived class. 00054 /// 00055 /// @param p is a pointer to a color_t array to write. 00056 /// @param count is the number of pixels to write. 00057 /// @param x is the horizontal position on the display. 00058 /// @param y is the vertical position on the display. 00059 /// @returns success/failure code. @see RetCode_t. 00060 /// 00061 virtual RetCode_t pixelStream(color_t * p, uint32_t count, loc_t x, loc_t y) = 0; 00062 00063 /// Get a pixel from the display. 00064 /// 00065 /// @note this method must be supported in the derived class. 00066 /// 00067 /// @param x is the horizontal offset to this pixel. 00068 /// @param y is the vertical offset to this pixel. 00069 /// @returns the pixel. see @color_t 00070 /// 00071 virtual color_t getPixel(loc_t x, loc_t y) = 0; 00072 00073 /// Get a stream of pixels from the display. 00074 /// 00075 /// @note this method must be supported in the derived class. 00076 /// 00077 /// @param p is a pointer to a color_t array to accept the stream. 00078 /// @param count is the number of pixels to read. 00079 /// @param x is the horizontal offset to this pixel. 00080 /// @param y is the vertical offset to this pixel. 00081 /// @returns success/failure code. @see RetCode_t. 00082 /// 00083 virtual RetCode_t getPixelStream(color_t * p, uint32_t count, loc_t x, loc_t y) = 0; 00084 00085 /// get the screen width in pixels 00086 /// 00087 /// @note this method must be supported in the derived class. 00088 /// 00089 /// @returns screen width in pixels. 00090 /// 00091 virtual uint16_t width() = 0; 00092 00093 /// get the screen height in pixels 00094 /// 00095 /// @note this method must be supported in the derived class. 00096 /// 00097 /// @returns screen height in pixels. 00098 /// 00099 virtual uint16_t height() = 0; 00100 00101 /// Prepare the controller to write binary data to the screen by positioning 00102 /// the memory cursor. 00103 /// 00104 /// @note this method must be supported in the derived class. 00105 /// 00106 /// @param x is the horizontal position in pixels (from the left edge) 00107 /// @param y is the vertical position in pixels (from the top edge) 00108 /// @returns success/failure code. @see RetCode_t. 00109 /// 00110 virtual RetCode_t SetGraphicsCursor(loc_t x, loc_t y) = 0; 00111 00112 /// Prepare the controller to read binary data from the screen by positioning 00113 /// the memory read cursor. 00114 /// 00115 /// @param x is the horizontal position in pixels (from the left edge) 00116 /// @param y is the vertical position in pixels (from the top edge) 00117 /// @returns success/failure code. @see RetCode_t. 00118 /// 00119 virtual RetCode_t SetGraphicsCursorRead(loc_t x, loc_t y) = 0; 00120 00121 /// Draw a filled rectangle in the specified color 00122 /// 00123 /// @note As a side effect, this changes the current 00124 /// foreground color for subsequent operations. 00125 /// 00126 /// @note this method must be supported in the derived class. 00127 /// 00128 /// @param x1 is the horizontal start of the line. 00129 /// @param y1 is the vertical start of the line. 00130 /// @param x2 is the horizontal end of the line. 00131 /// @param y2 is the vertical end of the line. 00132 /// @param color defines the foreground color. 00133 /// @param fillit is optional to NOFILL the rectangle. default is FILL. 00134 /// @returns success/failure code. @see RetCode_t. 00135 /// 00136 virtual RetCode_t fillrect(loc_t x1, loc_t y1, loc_t x2, loc_t y2, 00137 color_t color, fill_t fillit = FILL) = 0; 00138 00139 00140 virtual RetCode_t WriteCommand(unsigned char command, unsigned int data = 0xFFFF) = 0; 00141 virtual RetCode_t WriteData(unsigned char data) = 0; 00142 00143 /// Set the window, which controls where items are written to the screen. 00144 /// 00145 /// When something hits the window width, it wraps back to the left side 00146 /// and down a row. If the initial write is outside the window, it will 00147 /// be captured into the window when it crosses a boundary. 00148 /// 00149 /// @param x is the left edge in pixels. 00150 /// @param y is the top edge in pixels. 00151 /// @param w is the window width in pixels. 00152 /// @param h is the window height in pixels. 00153 /// @returns success/failure code. @see RetCode_t. 00154 /// 00155 virtual RetCode_t window(loc_t x, loc_t y, dim_t w, dim_t h); 00156 00157 /// Clear the screen. 00158 /// 00159 /// The behavior is to clear the whole screen. 00160 /// 00161 /// @returns success/failure code. @see RetCode_t. 00162 /// 00163 virtual RetCode_t cls(); 00164 00165 00166 virtual void WindowMax(void); 00167 00168 /// method to put a single color pixel to the screen. 00169 /// 00170 /// This method may be called as many times as necessary after 00171 /// @see _StartGraphicsStream() is called, and it should be followed 00172 /// by _EndGraphicsStream. 00173 /// 00174 /// @param pixel is a color value to be put on the screen. 00175 /// @returns error code. 00176 /// 00177 virtual RetCode_t putp(color_t pixel); 00178 00179 00180 virtual void fill(int x, int y, int w, int h, color_t color); 00181 virtual void blit(int x, int y, int w, int h, const int * color); 00182 00183 /// This method transfers one character from the external font data 00184 /// to the screen. 00185 /// 00186 /// @note the font data is in a special format as generate by 00187 /// the mikroe font creator. \\ 00188 /// See http://www.mikroe.com/glcd-font-creator/ 00189 /// 00190 /// @param x is the horizontal pixel coordinate 00191 /// @param y is the vertical pixel coordinate 00192 /// @param fontTable is the base of the table which has the metrics 00193 /// @param fontChar is the start of that record in the table for the char (e.g. 'A' - 'Z') 00194 /// @returns how far the cursor should advance to the right in pixels 00195 /// 00196 virtual int fontblit(int x, int y, const unsigned char * fontTable, const unsigned char * fontChar); 00197 00198 /// This method returns the color value from a palette. 00199 /// 00200 /// This method accepts a pointer to a Bitmap color palette, which 00201 /// is a table in memory composed of RGB Quad values (r, g, b, 0), 00202 /// and an index into that table. It then extracts the color information 00203 /// and downsamples it to a color_t value which it returns. 00204 /// 00205 /// @note This method probably has very little value outside of 00206 /// the internal methods for reading BMP files. 00207 /// 00208 /// @param colorPalette is the handle to the color palette to use. 00209 /// @param i is the index into the color palette. 00210 /// @returns the color in color_t format. 00211 /// 00212 color_t RGBQuadToRGB16(RGBQUAD * colorPalette, uint16_t i); 00213 00214 /// This method converts a 16-bit color value into a 24-bit RGB Quad. 00215 /// 00216 /// @param c is the 16-bit color. @see color_t 00217 /// @returns an RGBQUAD value. @see RGBQUAD 00218 /// 00219 RGBQUAD RGB16ToRGBQuad(color_t c); 00220 00221 /// This method attempts to render a specified graphics image file at 00222 /// the specified screen location. 00223 /// 00224 /// This supports several variants of the following file types: 00225 /// \li Bitmap file format, 00226 /// \li Icon file format. 00227 /// 00228 /// @note The specified image width and height, when adjusted for the 00229 /// x and y origin, must fit on the screen, or the image will not 00230 /// be shown (it does not clip the image). 00231 /// 00232 /// @note The file extension is tested, and if it ends in a supported 00233 /// format, the appropriate handler is called to render that image. 00234 /// 00235 /// @param x is the horizontal pixel coordinate 00236 /// @param y is the vertical pixel coordinate 00237 /// @param FileName refers to the fully qualified path and file on 00238 /// a mounted file system. 00239 /// @returns success or error code. 00240 /// 00241 RetCode_t RenderImageFile(loc_t x, loc_t y, const char *FileName); 00242 00243 /// This method reads a disk file that is in bitmap format and 00244 /// puts it on the screen. 00245 /// 00246 /// Supported formats: 00247 /// \li 4-bit color format (16 colors) 00248 /// \li 8-bit color format (256 colors) 00249 /// \li 16-bit color format (65k colors) 00250 /// \li compression: no. 00251 /// 00252 /// @note This is a slow operation, typically due to the use of 00253 /// the file system, and partially because bmp files 00254 /// are stored from the bottom up, and the memory is written 00255 /// from the top down; as a result, it constantly 'seeks' 00256 /// on the file system for the next row of information. 00257 /// 00258 /// As a performance test, a sample picture was timed. A family picture 00259 /// was converted to Bitmap format; shrunk to 352 x 272 pixels and save 00260 /// in 8-bit color format. The resulting file size was 94.5 KByte. 00261 /// The SPI port interface was set to 20 MHz. 00262 /// The original bitmap rendering software was purely in software, 00263 /// pushing 1 pixel at a time to the write function, which did use SPI 00264 /// hardware (not pin wiggling) to transfer commands and data to the 00265 /// display. Then, the driver was improved to leverage the capability 00266 /// of the derived display driver. As a final check, instead of the 00267 /// [known slow] local file system, a randomly chosen USB stick was 00268 /// used. The performance results are impressive (but depend on the 00269 /// listed factors). 00270 /// 00271 /// \li 34 seconds, LocalFileSystem, Software Rendering 00272 /// \li 9 seconds, LocalFileSystem, Hardware Rending for RA8875 00273 /// \li 3 seconds, MSCFileSystem, Hardware Rendering for RA8875 00274 /// 00275 /// @param x is the horizontal pixel coordinate 00276 /// @param y is the vertical pixel coordinate 00277 /// @param Name_BMP is the filename on the mounted file system. 00278 /// @returns success or error code. 00279 /// 00280 RetCode_t RenderBitmapFile(loc_t x, loc_t y, const char *Name_BMP); 00281 00282 00283 /// This method reads a disk file that is in ico format and 00284 /// puts it on the screen. 00285 /// 00286 /// Reading the disk is slow, but a typical icon file is small 00287 /// so it should be ok. 00288 /// 00289 /// @note An Icon file can have more than one icon in it. This 00290 /// implementation only processes the first image in the file. 00291 /// 00292 /// @param x is the horizontal pixel coordinate 00293 /// @param y is the vertical pixel coordinate 00294 /// @param Name_ICO is the filename on the mounted file system. 00295 /// @returns success or error code. 00296 /// 00297 RetCode_t RenderIconFile(loc_t x, loc_t y, const char *Name_ICO); 00298 00299 00300 /// This method captures the specified area as a 24-bit bitmap file. 00301 /// 00302 /// Even though this is a 16-bit display, the stored image is in 00303 /// 24-bit format. 00304 /// 00305 /// @param x is the left edge of the region to capture 00306 /// @param y is the top edge of the region to capture 00307 /// @param w is the width of the region to capture 00308 /// @param h is the height of the region to capture. 00309 /// @return success or error code. 00310 /// 00311 RetCode_t PrintScreen(loc_t x, loc_t y, dim_t w, dim_t h, const char *Name_BMP); 00312 00313 /// prints one character at the specified coordinates. 00314 /// 00315 /// This will print the character at the specified pixel coordinates. 00316 /// 00317 /// @param x is the horizontal offset in pixels. 00318 /// @param y is the vertical offset in pixels. 00319 /// @param value is the character to print. 00320 /// @returns number of pixels to index to the right if a character was printed, 0 otherwise. 00321 /// 00322 virtual int character(int x, int y, int value); 00323 00324 /// get the number of colums based on the currently active font 00325 /// 00326 /// @returns number of columns. 00327 /// 00328 virtual int columns(void); 00329 00330 /// get the number of rows based on the currently active font 00331 /// 00332 /// @returns number of rows. 00333 /// 00334 virtual int rows(void); 00335 00336 /// Select a bitmap font (provided by the user) for all subsequent text 00337 /// rendering. 00338 /// 00339 /// This API permits selection of a special memory mapped font, which 00340 /// enables the presentation of many font sizes and styles, including 00341 /// proportional fonts. 00342 /// 00343 /// @note Tool to create the fonts is accessible from its creator 00344 /// available at http://www.mikroe.com. 00345 /// Hint: Change the data to an array of type char[]. 00346 /// 00347 /// This special font array has a 4-byte header, followed by 00348 /// the data: 00349 /// \li the number of bytes per char 00350 /// \li the vertical size in pixels for each character 00351 /// \li the horizontal size in pixels for each character 00352 /// \li the number of bytes per vertical line (width of the array) 00353 /// \li the subsequent records are the font information. 00354 /// 00355 /// @param font is a pointer to a specially formed font array. 00356 /// NULL, or the omission of this parameter will restore the default 00357 /// font capability, which may use the display controllers hardware 00358 /// font (if available), or no font. 00359 /// @returns error code. 00360 /// 00361 virtual RetCode_t set_font(const unsigned char * font = NULL); 00362 00363 protected: 00364 00365 /// Pure virtual method indicating the start of a graphics stream. 00366 /// 00367 /// This is called prior to a stream of pixel data being sent. 00368 /// This may cause register configuration changes in the derived 00369 /// class in order to prepare the hardware to accept the streaming 00370 /// data. 00371 /// 00372 /// @note this method must be supported in the derived class. 00373 /// 00374 /// @returns error code. 00375 /// 00376 virtual RetCode_t _StartGraphicsStream(void) = 0; 00377 00378 /// Pure virtual method indicating the end of a graphics stream. 00379 /// 00380 /// This is called to conclude a stream of pixel data that was sent. 00381 /// This may cause register configuration changes in the derived 00382 /// class in order to stop the hardware from accept the streaming 00383 /// data. 00384 /// 00385 /// @note this method must be supported in the derived class. 00386 /// 00387 /// @returns error code. 00388 /// 00389 virtual RetCode_t _EndGraphicsStream(void) = 0; 00390 00391 /// Protected method to render an image given a file handle and 00392 /// coordinates. 00393 /// 00394 /// @param x is the horizontal pixel coordinate 00395 /// @param y is the vertical pixel coordinate 00396 /// @param w is the image width restriction, or zero to permit full image width. 00397 /// @param h is the image height restriction, or zero to permit full image height. 00398 /// @param fileOffset is the offset into the file where the image data starts 00399 /// @param Image is the filename stream already opened for the data. 00400 /// @returns success or error code. 00401 /// 00402 RetCode_t _RenderBitmap(loc_t x, loc_t y, uint32_t fileOffset, FILE * Image); 00403 00404 #ifdef LOCALFONT 00405 virtual int blitbit(int x, int y, int w, int h, const char * color); 00406 #endif 00407 00408 const unsigned char * font; ///< reference to an external font somewhere in memory 00409 00410 // pixel location 00411 short _x; 00412 short _y; 00413 00414 // window location 00415 short _x1; 00416 short _x2; 00417 short _y1; 00418 short _y2; 00419 }; 00420 00421 #endif 00422
Generated on Tue Jul 12 2022 21:36:16 by
1.7.2
