Microbug / MicroBitDAL_SB2_TEST

Fork of MicroBitDALImageRewrite by Joe Finney

Committer:
finneyj
Date:
Sun Apr 12 17:38:56 2015 +0000
Revision:
0:47d8ba08580f
Child:
5:8bf639bbedb5
First draft implementation of core functionality. Includes:; ;   - OO model of microBit device.;   - Flexible geometry LD matirx driver.;   - Lazy, instatiation free I/O; ; Please note this code is largely untested.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
finneyj 0:47d8ba08580f 1 /**
finneyj 0:47d8ba08580f 2 * Class definition for a MicroBitImage.
finneyj 0:47d8ba08580f 3 *
finneyj 0:47d8ba08580f 4 * An MicroBitImage is a simple bitmap representation of an image.
finneyj 0:47d8ba08580f 5 */
finneyj 0:47d8ba08580f 6
finneyj 0:47d8ba08580f 7 #ifndef MICROBIT_IMAGE_H
finneyj 0:47d8ba08580f 8 #define MICROBIT_IMAGE_H
finneyj 0:47d8ba08580f 9
finneyj 0:47d8ba08580f 10 #include "mbed.h"
finneyj 0:47d8ba08580f 11
finneyj 0:47d8ba08580f 12 class MicroBitImage
finneyj 0:47d8ba08580f 13 {
finneyj 0:47d8ba08580f 14 int width; // Width of the bitmap, in pixels.
finneyj 0:47d8ba08580f 15 int height; // Height of the bitmap, in pixels.
finneyj 0:47d8ba08580f 16 int **bitmap; // 2D array representing the bitmap image.
finneyj 0:47d8ba08580f 17
finneyj 0:47d8ba08580f 18 /**
finneyj 0:47d8ba08580f 19 * Internal constructor support function.
finneyj 0:47d8ba08580f 20 */
finneyj 0:47d8ba08580f 21 void init(int x, int y, int **bitmap);
finneyj 0:47d8ba08580f 22
finneyj 0:47d8ba08580f 23 public:
finneyj 0:47d8ba08580f 24
finneyj 0:47d8ba08580f 25
finneyj 0:47d8ba08580f 26 /**
finneyj 0:47d8ba08580f 27 * Constructor.
finneyj 0:47d8ba08580f 28 * Create a blank bitmap representation of a given size.
finneyj 0:47d8ba08580f 29 *
finneyj 0:47d8ba08580f 30 * @param x the width of the image.
finneyj 0:47d8ba08580f 31 * @param y the height of the image.
finneyj 0:47d8ba08580f 32 */
finneyj 0:47d8ba08580f 33 MicroBitImage(int x, int y);
finneyj 0:47d8ba08580f 34
finneyj 0:47d8ba08580f 35 /**
finneyj 0:47d8ba08580f 36 * Constructor.
finneyj 0:47d8ba08580f 37 * Create a bitmap representation of a given size.
finneyj 0:47d8ba08580f 38 *
finneyj 0:47d8ba08580f 39 * @param x the width of the image.
finneyj 0:47d8ba08580f 40 * @param y the height of the image.
finneyj 0:47d8ba08580f 41 * @param bitmap a 2D array representing the image.
finneyj 0:47d8ba08580f 42 *
finneyj 0:47d8ba08580f 43 */
finneyj 0:47d8ba08580f 44 MicroBitImage(int x, int y, int **bitmap);
finneyj 0:47d8ba08580f 45
finneyj 0:47d8ba08580f 46 /**
finneyj 0:47d8ba08580f 47 * Destructor.
finneyj 0:47d8ba08580f 48 * Removes buffer resources held by the instance.
finneyj 0:47d8ba08580f 49 */
finneyj 0:47d8ba08580f 50 ~MicroBitImage();
finneyj 0:47d8ba08580f 51
finneyj 0:47d8ba08580f 52
finneyj 0:47d8ba08580f 53 /**
finneyj 0:47d8ba08580f 54 * Clears all pixels in this image
finneyj 0:47d8ba08580f 55 */
finneyj 0:47d8ba08580f 56 void clear();
finneyj 0:47d8ba08580f 57
finneyj 0:47d8ba08580f 58 /**
finneyj 0:47d8ba08580f 59 * Sets the pixel at the given co-ordinates to a given value.
finneyj 0:47d8ba08580f 60 * @param x The co-ordinate of the pixel to change w.r.t. top left origin.
finneyj 0:47d8ba08580f 61 * @param y The co-ordinate of the pixel to change w.r.t. top left origin.
finneyj 0:47d8ba08580f 62 * @param value The new value of the pixel.
finneyj 0:47d8ba08580f 63 */
finneyj 0:47d8ba08580f 64 void setPixelValue(int x , int y, int value);
finneyj 0:47d8ba08580f 65
finneyj 0:47d8ba08580f 66 /**
finneyj 0:47d8ba08580f 67 * Determined the value of a given pixel.
finneyj 0:47d8ba08580f 68 * @return The value assigned to the givne pixel location
finneyj 0:47d8ba08580f 69 */
finneyj 0:47d8ba08580f 70 int getPixelValue(int x , int y);
finneyj 0:47d8ba08580f 71
finneyj 0:47d8ba08580f 72 /**
finneyj 0:47d8ba08580f 73 * Replaces the content of this image with that of a given
finneyj 0:47d8ba08580f 74 * 2D array representing the image.
finneyj 0:47d8ba08580f 75 * Origin is in the top left corner of the image.
finneyj 0:47d8ba08580f 76 *
finneyj 0:47d8ba08580f 77 * @param x the width of the image.
finneyj 0:47d8ba08580f 78 * @param y the height of the image.
finneyj 0:47d8ba08580f 79 * @param bitmap a 2D array representing the image.
finneyj 0:47d8ba08580f 80 *
finneyj 0:47d8ba08580f 81 */
finneyj 0:47d8ba08580f 82 void printImage(int x, int y, int **bitmap);
finneyj 0:47d8ba08580f 83
finneyj 0:47d8ba08580f 84 /**
finneyj 0:47d8ba08580f 85 * Pastes a given bitmap at the given co-ordinates.
finneyj 0:47d8ba08580f 86 * Any pixels in the relvant area of this image are replaced.
finneyj 0:47d8ba08580f 87 *
finneyj 0:47d8ba08580f 88 * @param image The MicroBiImage to paste.
finneyj 0:47d8ba08580f 89 * @param x The leftmost X co-ordinate in this image where the given image should be pasted.
finneyj 0:47d8ba08580f 90 * @param y The uppermost Y co-ordinate in this image where the given image should be pasted.
finneyj 0:47d8ba08580f 91 * @param alpha set to 1 if transparency clear pixels in given image should be treated as transparent. Set to 0 otherwise.
finneyj 0:47d8ba08580f 92 */
finneyj 0:47d8ba08580f 93 void paste(MicroBitImage *image, int x, int y, int alpha);
finneyj 0:47d8ba08580f 94
finneyj 0:47d8ba08580f 95 /**
finneyj 0:47d8ba08580f 96 * Prints a character to the display at the given location
finneyj 0:47d8ba08580f 97 *
finneyj 0:47d8ba08580f 98 * @param c The character to display.
finneyj 0:47d8ba08580f 99 * @param x The x co-ordinate of on the image to place the top left of the character
finneyj 0:47d8ba08580f 100 * @param y The y co-ordinate of on the image to place the top left of the character
finneyj 0:47d8ba08580f 101 */
finneyj 0:47d8ba08580f 102 void print(char c, int x, int y);
finneyj 0:47d8ba08580f 103
finneyj 0:47d8ba08580f 104 /**
finneyj 0:47d8ba08580f 105 * Shifts the pixels in this Image a given number of pixels to the Left.
finneyj 0:47d8ba08580f 106 *
finneyj 0:47d8ba08580f 107 * @param n The number of pixels to shift.
finneyj 0:47d8ba08580f 108 */
finneyj 0:47d8ba08580f 109 void shiftLeft(int n);
finneyj 0:47d8ba08580f 110
finneyj 0:47d8ba08580f 111 /**
finneyj 0:47d8ba08580f 112 * Shifts the pixels in this Image a given number of pixels to the Right.
finneyj 0:47d8ba08580f 113 *
finneyj 0:47d8ba08580f 114 * @param n The number of pixels to shift.
finneyj 0:47d8ba08580f 115 */
finneyj 0:47d8ba08580f 116 void shiftRight(int n);
finneyj 0:47d8ba08580f 117
finneyj 0:47d8ba08580f 118 /**
finneyj 0:47d8ba08580f 119 * Shifts the pixels in this Image a given number of pixels to Upward.
finneyj 0:47d8ba08580f 120 *
finneyj 0:47d8ba08580f 121 * @param n The number of pixels to shift.
finneyj 0:47d8ba08580f 122 */
finneyj 0:47d8ba08580f 123 void shiftUp(int n);
finneyj 0:47d8ba08580f 124
finneyj 0:47d8ba08580f 125 /**
finneyj 0:47d8ba08580f 126 * Shifts the pixels in this Image a given number of pixels to Downward.
finneyj 0:47d8ba08580f 127 *
finneyj 0:47d8ba08580f 128 * @param n The number of pixels to shift.
finneyj 0:47d8ba08580f 129 */
finneyj 0:47d8ba08580f 130 void shiftDown(int n);
finneyj 0:47d8ba08580f 131
finneyj 0:47d8ba08580f 132 /**
finneyj 0:47d8ba08580f 133 * Gets the width of this image.
finneyj 0:47d8ba08580f 134 *
finneyj 0:47d8ba08580f 135 * @return The width of this image.
finneyj 0:47d8ba08580f 136 */
finneyj 0:47d8ba08580f 137 int getWidth();
finneyj 0:47d8ba08580f 138
finneyj 0:47d8ba08580f 139 /**
finneyj 0:47d8ba08580f 140 * Gets the height of this image.
finneyj 0:47d8ba08580f 141 *
finneyj 0:47d8ba08580f 142 * @return The height of this image.
finneyj 0:47d8ba08580f 143 */
finneyj 0:47d8ba08580f 144 int getHeight();
finneyj 0:47d8ba08580f 145 };
finneyj 0:47d8ba08580f 146
finneyj 0:47d8ba08580f 147 #endif
finneyj 0:47d8ba08580f 148