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.cpp@2:6d2a681c5cdf, 2012-04-18 (annotated)
- Committer:
- stvnrhodes
- Date:
- Wed Apr 18 22:32:47 2012 +0000
- Revision:
- 2:6d2a681c5cdf
- Child:
- 3:328a79795feb
Still for Adam
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stvnrhodes | 2:6d2a681c5cdf | 1 | #include "Bitmap.h" |
stvnrhodes | 2:6d2a681c5cdf | 2 | |
stvnrhodes | 2:6d2a681c5cdf | 3 | #define OFFSET_LOCATION 0x0a |
stvnrhodes | 2:6d2a681c5cdf | 4 | #define WIDTH_LOCATION 0x12 |
stvnrhodes | 2:6d2a681c5cdf | 5 | #define HEIGHT_LOCATION 0x16 |
stvnrhodes | 2:6d2a681c5cdf | 6 | |
stvnrhodes | 2:6d2a681c5cdf | 7 | bool Bitmap::isPixel(int pixel) { |
stvnrhodes | 2:6d2a681c5cdf | 8 | if (pixel > width) { return false; } |
stvnrhodes | 2:6d2a681c5cdf | 9 | if ((row_data[pixel/32]>>(pixel%32)) & 0x01) { return true; } |
stvnrhodes | 2:6d2a681c5cdf | 10 | else { return false; } |
stvnrhodes | 2:6d2a681c5cdf | 11 | } |
stvnrhodes | 2:6d2a681c5cdf | 12 | |
stvnrhodes | 2:6d2a681c5cdf | 13 | Bitmap::Bitmap () { |
stvnrhodes | 2:6d2a681c5cdf | 14 | loaded = false; |
stvnrhodes | 2:6d2a681c5cdf | 15 | fp = NULL; |
stvnrhodes | 2:6d2a681c5cdf | 16 | row_data = NULL; |
stvnrhodes | 2:6d2a681c5cdf | 17 | } |
stvnrhodes | 2:6d2a681c5cdf | 18 | |
stvnrhodes | 2:6d2a681c5cdf | 19 | bool Bitmap::openImg(char* filename) { |
stvnrhodes | 2:6d2a681c5cdf | 20 | if (fp != NULL) { |
stvnrhodes | 2:6d2a681c5cdf | 21 | fclose(fp); |
stvnrhodes | 2:6d2a681c5cdf | 22 | free(row_data); |
stvnrhodes | 2:6d2a681c5cdf | 23 | } |
stvnrhodes | 2:6d2a681c5cdf | 24 | printf("Opening\n\r"); |
stvnrhodes | 2:6d2a681c5cdf | 25 | fp = fopen(filename, "rb"); |
stvnrhodes | 2:6d2a681c5cdf | 26 | loaded = true; |
stvnrhodes | 2:6d2a681c5cdf | 27 | printf("Opened\n\r"); |
stvnrhodes | 2:6d2a681c5cdf | 28 | fseek(fp, OFFSET_LOCATION, SEEK_SET); |
stvnrhodes | 2:6d2a681c5cdf | 29 | fread((char *) &offset, 1, 4, fp); |
stvnrhodes | 2:6d2a681c5cdf | 30 | fseek(fp, WIDTH_LOCATION, SEEK_SET); |
stvnrhodes | 2:6d2a681c5cdf | 31 | fread((char *) &width, 1, 4, fp); |
stvnrhodes | 2:6d2a681c5cdf | 32 | fread(&height, sizeof(long), 1, fp); |
stvnrhodes | 2:6d2a681c5cdf | 33 | fseek(fp, HEIGHT_LOCATION, SEEK_SET); |
stvnrhodes | 2:6d2a681c5cdf | 34 | printf("%x,%x,%x\n\r", offset, width, height); |
stvnrhodes | 2:6d2a681c5cdf | 35 | row_size = (width % 32) ? (width / 32) + 1 : width / 32; |
stvnrhodes | 2:6d2a681c5cdf | 36 | row_data = (long *) malloc(row_size * sizeof(long)); |
stvnrhodes | 2:6d2a681c5cdf | 37 | return true; |
stvnrhodes | 2:6d2a681c5cdf | 38 | } |
stvnrhodes | 2:6d2a681c5cdf | 39 | |
stvnrhodes | 2:6d2a681c5cdf | 40 | bool Bitmap::setRow(int row) { |
stvnrhodes | 2:6d2a681c5cdf | 41 | if (loaded) { |
stvnrhodes | 2:6d2a681c5cdf | 42 | row_num = row; |
stvnrhodes | 2:6d2a681c5cdf | 43 | fseek(fp, offset + row * row_size, SEEK_SET); |
stvnrhodes | 2:6d2a681c5cdf | 44 | for (int i = 0; i < row_size; i++) { |
stvnrhodes | 2:6d2a681c5cdf | 45 | fscanf(fp,"%4ld", row_data + i); |
stvnrhodes | 2:6d2a681c5cdf | 46 | printf("%4ld\n\r", row_data[i]); |
stvnrhodes | 2:6d2a681c5cdf | 47 | } |
stvnrhodes | 2:6d2a681c5cdf | 48 | return true; |
stvnrhodes | 2:6d2a681c5cdf | 49 | } else { |
stvnrhodes | 2:6d2a681c5cdf | 50 | return false; |
stvnrhodes | 2:6d2a681c5cdf | 51 | } |
stvnrhodes | 2:6d2a681c5cdf | 52 | } |
stvnrhodes | 2:6d2a681c5cdf | 53 | |
stvnrhodes | 2:6d2a681c5cdf | 54 | bool Bitmap::closeImg(void) { |
stvnrhodes | 2:6d2a681c5cdf | 55 | fclose(fp); |
stvnrhodes | 2:6d2a681c5cdf | 56 | free(row_data); |
stvnrhodes | 2:6d2a681c5cdf | 57 | return true; |
stvnrhodes | 2:6d2a681c5cdf | 58 | } |
stvnrhodes | 2:6d2a681c5cdf | 59 | |
stvnrhodes | 2:6d2a681c5cdf | 60 | int Bitmap::getHeight() { |
stvnrhodes | 2:6d2a681c5cdf | 61 | return height; |
stvnrhodes | 2:6d2a681c5cdf | 62 | } |
stvnrhodes | 2:6d2a681c5cdf | 63 | |
stvnrhodes | 2:6d2a681c5cdf | 64 | int Bitmap::getWidth() { |
stvnrhodes | 2:6d2a681c5cdf | 65 | return width; |
stvnrhodes | 2:6d2a681c5cdf | 66 | } |
stvnrhodes | 2:6d2a681c5cdf | 67 |