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.
Bitmap.h@0:3058939fa37c, 2012-04-28 (annotated)
- Committer:
- stretch
- Date:
- Sat Apr 28 21:08:58 2012 +0000
- Revision:
- 0:3058939fa37c
- Child:
- 1:cf60b60a1b5b
Initial Public Release
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| stretch | 0:3058939fa37c | 1 | /** |
| stretch | 0:3058939fa37c | 2 | * @author Steven Rhodes |
| stretch | 0:3058939fa37c | 3 | * |
| stretch | 0:3058939fa37c | 4 | * @section LICENSE |
| stretch | 0:3058939fa37c | 5 | * |
| stretch | 0:3058939fa37c | 6 | * Copyright (c) 2012 Steven Rhodes |
| stretch | 0:3058939fa37c | 7 | * |
| stretch | 0:3058939fa37c | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| stretch | 0:3058939fa37c | 9 | * of this software and associated documentation files (the "Software"), to deal |
| stretch | 0:3058939fa37c | 10 | * in the Software without restriction, including without limitation the rights |
| stretch | 0:3058939fa37c | 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| stretch | 0:3058939fa37c | 12 | * copies of the Software, and to permit persons to whom the Software is |
| stretch | 0:3058939fa37c | 13 | * furnished to do so, subject to the following conditions: |
| stretch | 0:3058939fa37c | 14 | * |
| stretch | 0:3058939fa37c | 15 | * The above copyright notice and this permission notice shall be included in |
| stretch | 0:3058939fa37c | 16 | * all copies or substantial portions of the Software. |
| stretch | 0:3058939fa37c | 17 | * |
| stretch | 0:3058939fa37c | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| stretch | 0:3058939fa37c | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| stretch | 0:3058939fa37c | 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| stretch | 0:3058939fa37c | 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| stretch | 0:3058939fa37c | 22 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| stretch | 0:3058939fa37c | 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| stretch | 0:3058939fa37c | 24 | * THE SOFTWARE. |
| stretch | 0:3058939fa37c | 25 | |
| stretch | 0:3058939fa37c | 26 | */ |
| stretch | 0:3058939fa37c | 27 | |
| stretch | 0:3058939fa37c | 28 | #ifndef BITMAP_H |
| stretch | 0:3058939fa37c | 29 | #define BITMAP_H |
| stretch | 0:3058939fa37c | 30 | |
| stretch | 0:3058939fa37c | 31 | #include "mbed.h" |
| stretch | 0:3058939fa37c | 32 | |
| stretch | 0:3058939fa37c | 33 | class Bitmap { |
| stretch | 0:3058939fa37c | 34 | public: |
| stretch | 0:3058939fa37c | 35 | /** |
| stretch | 0:3058939fa37c | 36 | * Constructor to deal with bitmap |
| stretch | 0:3058939fa37c | 37 | * |
| stretch | 0:3058939fa37c | 38 | * @param tx mbed pin to use for tx line of Serial interface |
| stretch | 0:3058939fa37c | 39 | * @param rx mbed pin to use for rx line of Serial interface |
| stretch | 0:3058939fa37c | 40 | * @param ssid ssid of the adhoc network which will be created |
| stretch | 0:3058939fa37c | 41 | */ |
| stretch | 0:3058939fa37c | 42 | Bitmap (); |
| stretch | 0:3058939fa37c | 43 | |
| stretch | 0:3058939fa37c | 44 | /** |
| stretch | 0:3058939fa37c | 45 | * Load an image into the bitmap. |
| stretch | 0:3058939fa37c | 46 | * |
| stretch | 0:3058939fa37c | 47 | * @return true if the image is successfully loaded |
| stretch | 0:3058939fa37c | 48 | */ |
| stretch | 0:3058939fa37c | 49 | bool openImg(char* filename); |
| stretch | 0:3058939fa37c | 50 | |
| stretch | 0:3058939fa37c | 51 | /** |
| stretch | 0:3058939fa37c | 52 | * Change the row we're looking at. |
| stretch | 0:3058939fa37c | 53 | * |
| stretch | 0:3058939fa37c | 54 | * @return true if successful. |
| stretch | 0:3058939fa37c | 55 | */ |
| stretch | 0:3058939fa37c | 56 | bool setRow(int row); |
| stretch | 0:3058939fa37c | 57 | |
| stretch | 0:3058939fa37c | 58 | /** |
| stretch | 0:3058939fa37c | 59 | * Get whether we should draw a pixel at the given spot |
| stretch | 0:3058939fa37c | 60 | * |
| stretch | 0:3058939fa37c | 61 | * @param pixel The pixel to check |
| stretch | 0:3058939fa37c | 62 | * @param reversed Whether to reverse the pixel |
| stretch | 0:3058939fa37c | 63 | * @return true if there's a pixel. |
| stretch | 0:3058939fa37c | 64 | */ |
| stretch | 0:3058939fa37c | 65 | bool isPixel(int pixel, bool reversed); |
| stretch | 0:3058939fa37c | 66 | bool isPixel(int pixel); |
| stretch | 0:3058939fa37c | 67 | |
| stretch | 0:3058939fa37c | 68 | /** |
| stretch | 0:3058939fa37c | 69 | * Get whether it's a blank row |
| stretch | 0:3058939fa37c | 70 | * |
| stretch | 0:3058939fa37c | 71 | * @return true if there are no pixels in the row |
| stretch | 0:3058939fa37c | 72 | */ |
| stretch | 0:3058939fa37c | 73 | bool isBlankRow(void); |
| stretch | 0:3058939fa37c | 74 | |
| stretch | 0:3058939fa37c | 75 | /** |
| stretch | 0:3058939fa37c | 76 | * Return the height of the bitmap |
| stretch | 0:3058939fa37c | 77 | * |
| stretch | 0:3058939fa37c | 78 | * @return height |
| stretch | 0:3058939fa37c | 79 | */ |
| stretch | 0:3058939fa37c | 80 | int getHeight(); |
| stretch | 0:3058939fa37c | 81 | |
| stretch | 0:3058939fa37c | 82 | /** |
| stretch | 0:3058939fa37c | 83 | * Return the width of the bitmap |
| stretch | 0:3058939fa37c | 84 | * |
| stretch | 0:3058939fa37c | 85 | * @return width |
| stretch | 0:3058939fa37c | 86 | */ |
| stretch | 0:3058939fa37c | 87 | int getWidth(); |
| stretch | 0:3058939fa37c | 88 | |
| stretch | 0:3058939fa37c | 89 | /** |
| stretch | 0:3058939fa37c | 90 | * Close the image when we're done with it |
| stretch | 0:3058939fa37c | 91 | * |
| stretch | 0:3058939fa37c | 92 | * @return true if properly closed |
| stretch | 0:3058939fa37c | 93 | */ |
| stretch | 0:3058939fa37c | 94 | bool closeImg(void); |
| stretch | 0:3058939fa37c | 95 | |
| stretch | 0:3058939fa37c | 96 | private: |
| stretch | 0:3058939fa37c | 97 | FILE * fp; |
| stretch | 0:3058939fa37c | 98 | bool loaded; |
| stretch | 0:3058939fa37c | 99 | long offset, width, height, row_size, row_num; |
| stretch | 0:3058939fa37c | 100 | char * row_data; |
| stretch | 0:3058939fa37c | 101 | |
| stretch | 0:3058939fa37c | 102 | /** |
| stretch | 0:3058939fa37c | 103 | * Get the pixel at a position |
| stretch | 0:3058939fa37c | 104 | * @param pixel column |
| stretch | 0:3058939fa37c | 105 | * |
| stretch | 0:3058939fa37c | 106 | * @return true if the pixel is black |
| stretch | 0:3058939fa37c | 107 | */ |
| stretch | 0:3058939fa37c | 108 | bool pixel(int column); |
| stretch | 0:3058939fa37c | 109 | |
| stretch | 0:3058939fa37c | 110 | }; |
| stretch | 0:3058939fa37c | 111 | #endif |