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.
Diff: Bitmap.cpp
- Revision:
- 0:3058939fa37c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Bitmap.cpp Sat Apr 28 21:08:58 2012 +0000
@@ -0,0 +1,73 @@
+#include "Bitmap.h"
+#define OFFSET_LOCATION 0x0a
+#define WIDTH_LOCATION 0x12
+#define HEIGHT_LOCATION 0x16
+
+bool Bitmap::isPixel(int pixel, bool reversed) {
+ if (pixel >= width) { return false; }
+ if (reversed) { pixel = width - pixel - 1; }
+ if ((row_data[pixel/(8*sizeof(char))]>>(8*sizeof(char)-(pixel%(8*sizeof(char)))-1)) & 0x01) { return false; }
+ else { return true; }
+}
+
+bool Bitmap::isPixel(int pixel) {
+ return isPixel(pixel, false);
+}
+
+bool Bitmap::isBlankRow(void) {
+ for (int i = 0; i < width; i++) {
+ if (isPixel(i))
+ return false;
+ }
+ return true;
+}
+
+Bitmap::Bitmap () {
+ loaded = false;
+ fp = NULL;
+ row_data = NULL;
+}
+
+bool Bitmap::openImg(char* filename) {
+ if (fp != NULL) {
+ fclose(fp);
+ free(row_data);
+ }
+ fp = fopen(filename, "rb");
+ loaded = true;
+ fseek(fp, OFFSET_LOCATION, SEEK_SET);
+ fread((char *) &offset, 1, 4, fp);
+ fseek(fp, WIDTH_LOCATION, SEEK_SET);
+ fread((char *) &width, 1, 4, fp);
+ fread(&height, sizeof(long), 1, fp);
+ fseek(fp, HEIGHT_LOCATION, SEEK_SET);
+ row_size = (width % 32) ? 4 * ((width / 32) + 1) : 4 * (width / 32);
+ row_data = (char *) malloc(row_size * sizeof(char));
+ return true;
+}
+
+bool Bitmap::setRow(int row) {
+ if (loaded) {
+ row_num = row;
+ fseek(fp, offset + row * row_size*sizeof(char), SEEK_SET);
+ fread(row_data, sizeof(char), row_size, fp);
+ return true;
+ } else {
+ return false;
+ }
+}
+
+bool Bitmap::closeImg(void) {
+ fclose(fp);
+ free(row_data);
+ return true;
+}
+
+int Bitmap::getHeight() {
+ return height;
+}
+
+int Bitmap::getWidth() {
+ return width;
+}
+
\ No newline at end of file