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@1:cf60b60a1b5b, 2012-05-04 (annotated)
- Committer:
- stretch
- Date:
- Fri May 04 06:25:41 2012 +0000
- Revision:
- 1:cf60b60a1b5b
- Parent:
- 0:3058939fa37c
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 | Bitmap (); |
| stretch | 0:3058939fa37c | 39 | |
| stretch | 0:3058939fa37c | 40 | /** |
| stretch | 0:3058939fa37c | 41 | * Load an image into the bitmap. |
| stretch | 0:3058939fa37c | 42 | * |
| stretch | 0:3058939fa37c | 43 | * @return true if the image is successfully loaded |
| stretch | 0:3058939fa37c | 44 | */ |
| stretch | 0:3058939fa37c | 45 | bool openImg(char* filename); |
| stretch | 0:3058939fa37c | 46 | |
| stretch | 0:3058939fa37c | 47 | /** |
| stretch | 0:3058939fa37c | 48 | * Change the row we're looking at. |
| stretch | 0:3058939fa37c | 49 | * |
| stretch | 0:3058939fa37c | 50 | * @return true if successful. |
| stretch | 0:3058939fa37c | 51 | */ |
| stretch | 0:3058939fa37c | 52 | bool setRow(int row); |
| stretch | 0:3058939fa37c | 53 | |
| stretch | 0:3058939fa37c | 54 | /** |
| stretch | 0:3058939fa37c | 55 | * Get whether we should draw a pixel at the given spot |
| stretch | 0:3058939fa37c | 56 | * |
| stretch | 0:3058939fa37c | 57 | * @param pixel The pixel to check |
| stretch | 0:3058939fa37c | 58 | * @param reversed Whether to reverse the pixel |
| stretch | 0:3058939fa37c | 59 | * @return true if there's a pixel. |
| stretch | 0:3058939fa37c | 60 | */ |
| stretch | 0:3058939fa37c | 61 | bool isPixel(int pixel, bool reversed); |
| stretch | 0:3058939fa37c | 62 | bool isPixel(int pixel); |
| stretch | 0:3058939fa37c | 63 | |
| stretch | 0:3058939fa37c | 64 | /** |
| stretch | 0:3058939fa37c | 65 | * Get whether it's a blank row |
| stretch | 0:3058939fa37c | 66 | * |
| stretch | 0:3058939fa37c | 67 | * @return true if there are no pixels in the row |
| stretch | 0:3058939fa37c | 68 | */ |
| stretch | 0:3058939fa37c | 69 | bool isBlankRow(void); |
| stretch | 0:3058939fa37c | 70 | |
| stretch | 0:3058939fa37c | 71 | /** |
| stretch | 0:3058939fa37c | 72 | * Return the height of the bitmap |
| stretch | 0:3058939fa37c | 73 | * |
| stretch | 0:3058939fa37c | 74 | * @return height |
| stretch | 0:3058939fa37c | 75 | */ |
| stretch | 0:3058939fa37c | 76 | int getHeight(); |
| stretch | 0:3058939fa37c | 77 | |
| stretch | 0:3058939fa37c | 78 | /** |
| stretch | 0:3058939fa37c | 79 | * Return the width of the bitmap |
| stretch | 0:3058939fa37c | 80 | * |
| stretch | 0:3058939fa37c | 81 | * @return width |
| stretch | 0:3058939fa37c | 82 | */ |
| stretch | 0:3058939fa37c | 83 | int getWidth(); |
| stretch | 0:3058939fa37c | 84 | |
| stretch | 0:3058939fa37c | 85 | /** |
| stretch | 0:3058939fa37c | 86 | * Close the image when we're done with it |
| stretch | 0:3058939fa37c | 87 | * |
| stretch | 0:3058939fa37c | 88 | * @return true if properly closed |
| stretch | 0:3058939fa37c | 89 | */ |
| stretch | 0:3058939fa37c | 90 | bool closeImg(void); |
| stretch | 0:3058939fa37c | 91 | |
| stretch | 0:3058939fa37c | 92 | private: |
| stretch | 0:3058939fa37c | 93 | FILE * fp; |
| stretch | 0:3058939fa37c | 94 | bool loaded; |
| stretch | 0:3058939fa37c | 95 | long offset, width, height, row_size, row_num; |
| stretch | 0:3058939fa37c | 96 | char * row_data; |
| stretch | 0:3058939fa37c | 97 | |
| stretch | 0:3058939fa37c | 98 | /** |
| stretch | 0:3058939fa37c | 99 | * Get the pixel at a position |
| stretch | 0:3058939fa37c | 100 | * @param pixel column |
| stretch | 0:3058939fa37c | 101 | * |
| stretch | 0:3058939fa37c | 102 | * @return true if the pixel is black |
| stretch | 0:3058939fa37c | 103 | */ |
| stretch | 0:3058939fa37c | 104 | bool pixel(int column); |
| stretch | 0:3058939fa37c | 105 | |
| stretch | 0:3058939fa37c | 106 | }; |
| stretch | 0:3058939fa37c | 107 | #endif |