Microbug / MicroBitDAL_SB2_TEST

Fork of MicroBitDALImageRewrite by Joe Finney

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MicroBitImage.h Source File

MicroBitImage.h

00001 /**
00002   * Class definition for a MicroBitImage.
00003   *
00004   * An MicroBitImage is a simple bitmap representation of an image.
00005   */
00006   
00007 #ifndef MICROBIT_IMAGE_H
00008 #define MICROBIT_IMAGE_H
00009 
00010 #include "mbed.h"
00011 
00012 class MicroBitImage
00013 {
00014     int width;              // Width of the bitmap, in pixels.
00015     int height;             // Height of the bitmap, in pixels.
00016     
00017     /**
00018       * Internal constructor support function. 
00019       */
00020     void init(int x, int y, uint8_t *bitmap);
00021     
00022     public:
00023     uint8_t *bitmap;        // 2D array representing the bitmap image.    
00024     
00025     /**
00026       * Copy Constructor. 
00027       * Clone an existing MicroBitImage.
00028       * 
00029       * @param image The MicroBitImage to clone.
00030       */
00031     MicroBitImage(MicroBitImage &image);
00032     
00033     /**
00034       * Constructor. 
00035       * Create a blank bitmap representation of a given size.
00036       * 
00037       * @param x the width of the image.
00038       * @param y the height of the image.     
00039       */
00040     MicroBitImage(int x, int y);
00041 
00042     /**
00043       * Constructor. 
00044       * Create a bitmap representation of a given size.
00045       * 
00046       * @param x the width of the image.
00047       * @param y the height of the image.
00048       * @param bitmap a 2D array representing the image.
00049       *     
00050       */
00051     MicroBitImage(int x, int y, uint8_t *bitmap);
00052 
00053     /**
00054       * Destructor. 
00055       * Removes buffer resources held by the instance.
00056       */
00057     ~MicroBitImage();
00058 
00059 
00060     /**
00061       * Clears all pixels in this image
00062       */
00063     void clear();
00064 
00065     /**
00066       * Sets the pixel at the given co-ordinates to a given value.
00067       * @param x The co-ordinate of the pixel to change w.r.t. top left origin.
00068       * @param y The co-ordinate of the pixel to change w.r.t. top left origin.
00069       * @param value The new value of the pixel.
00070       */
00071     void setPixelValue(int x , int y, uint8_t value);
00072 
00073     /**
00074       * Determined the value of a given pixel.
00075       * @return The value assigned to the givne pixel location
00076       */
00077     uint8_t getPixelValue(int x , int y);
00078 
00079     /**
00080       * Replaces the content of this image with that of a given 
00081       * 2D array representing the image.
00082       * Origin is in the top left corner of the image.
00083       *
00084       * @param x the width of the image.
00085       * @param y the height of the image.
00086       * @param bitmap a 2D array representing the image.
00087       *     
00088       */
00089     void printImage(int x, int y, uint8_t *bitmap);
00090     
00091     /**
00092       * Pastes a given bitmap at the given co-ordinates.
00093       * Any pixels in the relvant area of this image are replaced.
00094       * 
00095       * @param image The MicroBiImage to paste.
00096       * @param x The leftmost X co-ordinate in this image where the given image should be pasted.
00097       * @param y The uppermost Y co-ordinate in this image where the given image should be pasted.
00098       * @param alpha set to 1 if transparency clear pixels in given image should be treated as transparent. Set to 0 otherwise.
00099       */
00100     void paste(MicroBitImage &image, int x, int y, int alpha);
00101  
00102      /**
00103       * Prints a character to the display at the given location
00104       *
00105       * @param c The character to display.
00106       * @param x The x co-ordinate of on the image to place the top left of the character
00107       * @param y The y co-ordinate of on the image to place the top left of the character
00108       */
00109     void print(char c, int x, int y);
00110  
00111     /**
00112       * Shifts the pixels in this Image a given number of pixels to the Left.
00113       *
00114       * @param n The number of pixels to shift.
00115       */
00116     void shiftLeft(int n);
00117 
00118     /**
00119       * Shifts the pixels in this Image a given number of pixels to the Right.
00120       *
00121       * @param n The number of pixels to shift.
00122       */
00123     void shiftRight(int n);
00124     
00125     /**
00126       * Shifts the pixels in this Image a given number of pixels to Upward.
00127       *
00128       * @param n The number of pixels to shift.
00129       */
00130     void shiftUp(int n);
00131     
00132     /**
00133       * Shifts the pixels in this Image a given number of pixels to Downward.
00134       *
00135       * @param n The number of pixels to shift.
00136       */
00137     void shiftDown(int n);
00138 
00139     /**
00140       * Gets the width of this image.
00141       *
00142       * @return The width of this image.
00143       */
00144     int getWidth();
00145 
00146     /**
00147       * Gets the height of this image.
00148       *
00149       * @return The height of this image.
00150       */
00151     int getHeight();
00152 };
00153 
00154 #endif
00155