Forked para SNOCC
Fork of RA8875 by
GraphicsDisplay.cpp@72:ecffe56af969, 2014-10-11 (annotated)
- Committer:
- WiredHome
- Date:
- Sat Oct 11 17:24:29 2014 +0000
- Revision:
- 72:ecffe56af969
- Parent:
- 69:636867df24a1
- Child:
- 79:544eb4964795
Documentation updates only.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dreschpe | 0:de9d1462a835 | 1 | /* mbed GraphicsDisplay Display Library Base Class |
dreschpe | 0:de9d1462a835 | 2 | * Copyright (c) 2007-2009 sford |
dreschpe | 0:de9d1462a835 | 3 | * Released under the MIT License: http://mbed.org/license/mit |
WiredHome | 32:0e4f2ae512e2 | 4 | * |
WiredHome | 34:c99ec28fac66 | 5 | * Derivative work by D.Smart 2014 |
dreschpe | 0:de9d1462a835 | 6 | */ |
WiredHome | 19:3f82c1161fd2 | 7 | |
dreschpe | 0:de9d1462a835 | 8 | #include "GraphicsDisplay.h" |
WiredHome | 31:c72e12cd5c67 | 9 | #include "Bitmap.h" |
WiredHome | 42:7cbdfd2bbfc5 | 10 | #include "string.h" |
dreschpe | 0:de9d1462a835 | 11 | |
WiredHome | 42:7cbdfd2bbfc5 | 12 | //#define DEBUG "GD" |
WiredHome | 29:422616aa04bd | 13 | // ... |
WiredHome | 29:422616aa04bd | 14 | // INFO("Stuff to show %d", var); // new-line is automatically appended |
WiredHome | 29:422616aa04bd | 15 | // |
WiredHome | 29:422616aa04bd | 16 | #if (defined(DEBUG) && !defined(TARGET_LPC11U24)) |
WiredHome | 29:422616aa04bd | 17 | #define INFO(x, ...) std::printf("[INF %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); |
WiredHome | 29:422616aa04bd | 18 | #define WARN(x, ...) std::printf("[WRN %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); |
WiredHome | 29:422616aa04bd | 19 | #define ERR(x, ...) std::printf("[ERR %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); |
WiredHome | 40:04aa280dfa39 | 20 | static void HexDump(char * title, uint8_t * p, int count) |
WiredHome | 31:c72e12cd5c67 | 21 | { |
WiredHome | 31:c72e12cd5c67 | 22 | int i; |
WiredHome | 31:c72e12cd5c67 | 23 | char buf[100] = "0000: "; |
WiredHome | 31:c72e12cd5c67 | 24 | |
WiredHome | 31:c72e12cd5c67 | 25 | if (*title) |
WiredHome | 31:c72e12cd5c67 | 26 | INFO("%s", title); |
WiredHome | 31:c72e12cd5c67 | 27 | for (i=0; i<count; ) { |
WiredHome | 31:c72e12cd5c67 | 28 | sprintf(buf + strlen(buf), "%02X ", *(p+i)); |
WiredHome | 31:c72e12cd5c67 | 29 | if ((++i & 0x0F) == 0x00) { |
WiredHome | 31:c72e12cd5c67 | 30 | INFO("%s", buf); |
WiredHome | 31:c72e12cd5c67 | 31 | if (i < count) |
WiredHome | 31:c72e12cd5c67 | 32 | sprintf(buf, "%04X: ", i); |
WiredHome | 31:c72e12cd5c67 | 33 | else |
WiredHome | 31:c72e12cd5c67 | 34 | buf[0] = '\0'; |
WiredHome | 31:c72e12cd5c67 | 35 | } |
WiredHome | 31:c72e12cd5c67 | 36 | } |
WiredHome | 31:c72e12cd5c67 | 37 | if (strlen(buf)) |
WiredHome | 31:c72e12cd5c67 | 38 | INFO("%s", buf); |
WiredHome | 31:c72e12cd5c67 | 39 | } |
WiredHome | 29:422616aa04bd | 40 | #else |
WiredHome | 29:422616aa04bd | 41 | #define INFO(x, ...) |
WiredHome | 29:422616aa04bd | 42 | #define WARN(x, ...) |
WiredHome | 29:422616aa04bd | 43 | #define ERR(x, ...) |
WiredHome | 32:0e4f2ae512e2 | 44 | #define HexDump(a, b, c) |
WiredHome | 29:422616aa04bd | 45 | #endif |
WiredHome | 29:422616aa04bd | 46 | |
WiredHome | 29:422616aa04bd | 47 | #ifdef LOCALFONT |
dreschpe | 0:de9d1462a835 | 48 | const unsigned char FONT8x8[97][8] = { |
WiredHome | 29:422616aa04bd | 49 | 0x08, 0x08, 0x08, 0X00, 0X00, 0X00, 0X00, 0X00, // columns, rows, num_bytes_per_char |
WiredHome | 29:422616aa04bd | 50 | 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, // space 0x20 |
WiredHome | 29:422616aa04bd | 51 | 0x30, 0x78, 0x78, 0x30, 0x30, 0X00, 0x30, 0X00, // ! |
WiredHome | 29:422616aa04bd | 52 | 0x6C, 0x6C, 0x6C, 0X00, 0X00, 0X00, 0X00, 0X00, // " |
WiredHome | 29:422616aa04bd | 53 | 0x6C, 0x6C, 0xFE, 0x6C, 0xFE, 0x6C, 0x6C, 0X00, // # |
WiredHome | 29:422616aa04bd | 54 | 0x18, 0x3E, 0x60, 0x3C, 0x06, 0x7C, 0x18, 0X00, // $ |
WiredHome | 29:422616aa04bd | 55 | 0X00, 0x63, 0x66, 0x0C, 0x18, 0x33, 0x63, 0X00, // % |
WiredHome | 29:422616aa04bd | 56 | 0x1C, 0x36, 0x1C, 0x3B, 0x6E, 0x66, 0x3B, 0X00, // & |
WiredHome | 29:422616aa04bd | 57 | 0x30, 0x30, 0x60, 0X00, 0X00, 0X00, 0X00, 0X00, // ' |
WiredHome | 29:422616aa04bd | 58 | 0x0C, 0x18, 0x30, 0x30, 0x30, 0x18, 0x0C, 0X00, // ( |
WiredHome | 29:422616aa04bd | 59 | 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x18, 0x30, 0X00, // ) |
WiredHome | 29:422616aa04bd | 60 | 0X00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0X00, 0X00, // * |
WiredHome | 29:422616aa04bd | 61 | 0X00, 0x30, 0x30, 0xFC, 0x30, 0x30, 0X00, 0X00, // + |
WiredHome | 29:422616aa04bd | 62 | 0X00, 0X00, 0X00, 0X00, 0X00, 0x18, 0x18, 0x30, // , |
WiredHome | 29:422616aa04bd | 63 | 0X00, 0X00, 0X00, 0x7E, 0X00, 0X00, 0X00, 0X00, // - |
WiredHome | 29:422616aa04bd | 64 | 0X00, 0X00, 0X00, 0X00, 0X00, 0x18, 0x18, 0X00, // . |
WiredHome | 29:422616aa04bd | 65 | 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0X00, // / (forward slash) |
WiredHome | 29:422616aa04bd | 66 | 0x3E, 0x63, 0x63, 0x6B, 0x63, 0x63, 0x3E, 0X00, // 0 0x30 |
WiredHome | 29:422616aa04bd | 67 | 0x18, 0x38, 0x58, 0x18, 0x18, 0x18, 0x7E, 0X00, // 1 |
WiredHome | 29:422616aa04bd | 68 | 0x3C, 0x66, 0x06, 0x1C, 0x30, 0x66, 0x7E, 0X00, // 2 |
WiredHome | 29:422616aa04bd | 69 | 0x3C, 0x66, 0x06, 0x1C, 0x06, 0x66, 0x3C, 0X00, // 3 |
WiredHome | 29:422616aa04bd | 70 | 0x0E, 0x1E, 0x36, 0x66, 0x7F, 0x06, 0x0F, 0X00, // 4 |
WiredHome | 29:422616aa04bd | 71 | 0x7E, 0x60, 0x7C, 0x06, 0x06, 0x66, 0x3C, 0X00, // 5 |
WiredHome | 29:422616aa04bd | 72 | 0x1C, 0x30, 0x60, 0x7C, 0x66, 0x66, 0x3C, 0X00, // 6 |
WiredHome | 29:422616aa04bd | 73 | 0x7E, 0x66, 0x06, 0x0C, 0x18, 0x18, 0x18, 0X00, // 7 |
WiredHome | 29:422616aa04bd | 74 | 0x3C, 0x66, 0x66, 0x3C, 0x66, 0x66, 0x3C, 0X00, // 8 |
WiredHome | 29:422616aa04bd | 75 | 0x3C, 0x66, 0x66, 0x3E, 0x06, 0x0C, 0x38, 0X00, // 9 |
WiredHome | 29:422616aa04bd | 76 | 0X00, 0x18, 0x18, 0X00, 0X00, 0x18, 0x18, 0X00, // : |
WiredHome | 29:422616aa04bd | 77 | 0X00, 0x18, 0x18, 0X00, 0X00, 0x18, 0x18, 0x30, // ; |
WiredHome | 29:422616aa04bd | 78 | 0x0C, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0C, 0X00, // < |
WiredHome | 29:422616aa04bd | 79 | 0X00, 0X00, 0x7E, 0X00, 0X00, 0x7E, 0X00, 0X00, // = |
WiredHome | 29:422616aa04bd | 80 | 0x30, 0x18, 0x0C, 0x06, 0x0C, 0x18, 0x30, 0X00, // > |
WiredHome | 29:422616aa04bd | 81 | 0x3C, 0x66, 0x06, 0x0C, 0x18, 0X00, 0x18, 0X00, // ? |
WiredHome | 29:422616aa04bd | 82 | 0x3E, 0x63, 0x6F, 0x69, 0x6F, 0x60, 0x3E, 0X00, // @ 0x40 |
WiredHome | 29:422616aa04bd | 83 | 0x18, 0x3C, 0x66, 0x66, 0x7E, 0x66, 0x66, 0X00, // A |
WiredHome | 29:422616aa04bd | 84 | 0x7E, 0x33, 0x33, 0x3E, 0x33, 0x33, 0x7E, 0X00, // B |
WiredHome | 29:422616aa04bd | 85 | 0x1E, 0x33, 0x60, 0x60, 0x60, 0x33, 0x1E, 0X00, // C |
WiredHome | 29:422616aa04bd | 86 | 0x7C, 0x36, 0x33, 0x33, 0x33, 0x36, 0x7C, 0X00, // D |
WiredHome | 29:422616aa04bd | 87 | 0x7F, 0x31, 0x34, 0x3C, 0x34, 0x31, 0x7F, 0X00, // E |
WiredHome | 29:422616aa04bd | 88 | 0x7F, 0x31, 0x34, 0x3C, 0x34, 0x30, 0x78, 0X00, // F |
WiredHome | 29:422616aa04bd | 89 | 0x1E, 0x33, 0x60, 0x60, 0x67, 0x33, 0x1F, 0X00, // G |
WiredHome | 29:422616aa04bd | 90 | 0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0X00, // H |
WiredHome | 29:422616aa04bd | 91 | 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0X00, // I |
WiredHome | 29:422616aa04bd | 92 | 0x0F, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3C, 0X00, // J |
WiredHome | 29:422616aa04bd | 93 | 0x73, 0x33, 0x36, 0x3C, 0x36, 0x33, 0x73, 0X00, // K |
WiredHome | 29:422616aa04bd | 94 | 0x78, 0x30, 0x30, 0x30, 0x31, 0x33, 0x7F, 0X00, // L |
WiredHome | 29:422616aa04bd | 95 | 0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0X00, // M |
WiredHome | 29:422616aa04bd | 96 | 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x63, 0x63, 0X00, // N |
WiredHome | 29:422616aa04bd | 97 | 0x3E, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3E, 0X00, // O |
WiredHome | 29:422616aa04bd | 98 | 0x7E, 0x33, 0x33, 0x3E, 0x30, 0x30, 0x78, 0X00, // P 0x50 |
WiredHome | 29:422616aa04bd | 99 | 0x3C, 0x66, 0x66, 0x66, 0x6E, 0x3C, 0x0E, 0X00, // Q |
WiredHome | 29:422616aa04bd | 100 | 0x7E, 0x33, 0x33, 0x3E, 0x36, 0x33, 0x73, 0X00, // R |
WiredHome | 29:422616aa04bd | 101 | 0x3C, 0x66, 0x30, 0x18, 0x0C, 0x66, 0x3C, 0X00, // S |
WiredHome | 29:422616aa04bd | 102 | 0x7E, 0x5A, 0x18, 0x18, 0x18, 0x18, 0x3C, 0X00, // T |
WiredHome | 29:422616aa04bd | 103 | 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0X00, // U |
WiredHome | 29:422616aa04bd | 104 | 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0X00, // V |
WiredHome | 29:422616aa04bd | 105 | 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0X00, // W |
WiredHome | 29:422616aa04bd | 106 | 0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0X00, // X |
WiredHome | 29:422616aa04bd | 107 | 0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x3C, 0X00, // Y |
WiredHome | 29:422616aa04bd | 108 | 0x7F, 0x63, 0x46, 0x0C, 0x19, 0x33, 0x7F, 0X00, // Z |
WiredHome | 29:422616aa04bd | 109 | 0x3C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, 0X00, // [ |
WiredHome | 29:422616aa04bd | 110 | 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0X00, // \ (back slash) |
WiredHome | 29:422616aa04bd | 111 | 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x3C, 0X00, // ] |
WiredHome | 29:422616aa04bd | 112 | 0x08, 0x1C, 0x36, 0x63, 0X00, 0X00, 0X00, 0X00, // ^ |
WiredHome | 29:422616aa04bd | 113 | 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0xFF, // _ |
WiredHome | 29:422616aa04bd | 114 | 0x18, 0x18, 0x0C, 0X00, 0X00, 0X00, 0X00, 0X00, // ` 0x60 |
WiredHome | 29:422616aa04bd | 115 | 0X00, 0X00, 0x3C, 0x06, 0x3E, 0x66, 0x3B, 0X00, // a |
WiredHome | 29:422616aa04bd | 116 | 0x70, 0x30, 0x3E, 0x33, 0x33, 0x33, 0x6E, 0X00, // b |
WiredHome | 29:422616aa04bd | 117 | 0X00, 0X00, 0x3C, 0x66, 0x60, 0x66, 0x3C, 0X00, // c |
WiredHome | 29:422616aa04bd | 118 | 0x0E, 0x06, 0x3E, 0x66, 0x66, 0x66, 0x3B, 0X00, // d |
WiredHome | 29:422616aa04bd | 119 | 0X00, 0X00, 0x3C, 0x66, 0x7E, 0x60, 0x3C, 0X00, // e |
WiredHome | 29:422616aa04bd | 120 | 0x1C, 0x36, 0x30, 0x78, 0x30, 0x30, 0x78, 0X00, // f |
WiredHome | 29:422616aa04bd | 121 | 0X00, 0X00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x7C, // g |
WiredHome | 29:422616aa04bd | 122 | 0x70, 0x30, 0x36, 0x3B, 0x33, 0x33, 0x73, 0X00, // h |
WiredHome | 29:422616aa04bd | 123 | 0x18, 0X00, 0x38, 0x18, 0x18, 0x18, 0x3C, 0X00, // i |
WiredHome | 29:422616aa04bd | 124 | 0x06, 0X00, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3C, // j |
WiredHome | 29:422616aa04bd | 125 | 0x70, 0x30, 0x33, 0x36, 0x3C, 0x36, 0x73, 0X00, // k |
WiredHome | 29:422616aa04bd | 126 | 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0X00, // l |
WiredHome | 29:422616aa04bd | 127 | 0X00, 0X00, 0x66, 0x7F, 0x7F, 0x6B, 0x63, 0X00, // m |
WiredHome | 29:422616aa04bd | 128 | 0X00, 0X00, 0x7C, 0x66, 0x66, 0x66, 0x66, 0X00, // n |
WiredHome | 29:422616aa04bd | 129 | 0X00, 0X00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0X00, // o |
WiredHome | 29:422616aa04bd | 130 | 0X00, 0X00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78, // p |
WiredHome | 29:422616aa04bd | 131 | 0X00, 0X00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F, // q |
WiredHome | 29:422616aa04bd | 132 | 0X00, 0X00, 0x6E, 0x3B, 0x33, 0x30, 0x78, 0X00, // r |
WiredHome | 29:422616aa04bd | 133 | 0X00, 0X00, 0x3E, 0x60, 0x3C, 0x06, 0x7C, 0X00, // s |
WiredHome | 29:422616aa04bd | 134 | 0x08, 0x18, 0x3E, 0x18, 0x18, 0x1A, 0x0C, 0X00, // t |
WiredHome | 29:422616aa04bd | 135 | 0X00, 0X00, 0x66, 0x66, 0x66, 0x66, 0x3B, 0X00, // u |
WiredHome | 29:422616aa04bd | 136 | 0X00, 0X00, 0x66, 0x66, 0x66, 0x3C, 0x18, 0X00, // v |
WiredHome | 29:422616aa04bd | 137 | 0X00, 0X00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0X00, // w |
WiredHome | 29:422616aa04bd | 138 | 0X00, 0X00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0X00, // x |
WiredHome | 29:422616aa04bd | 139 | 0X00, 0X00, 0x66, 0x66, 0x66, 0x3E, 0x06, 0x7C, // y |
WiredHome | 29:422616aa04bd | 140 | 0X00, 0X00, 0x7E, 0x4C, 0x18, 0x32, 0x7E, 0X00, // z |
WiredHome | 29:422616aa04bd | 141 | 0x0E, 0x18, 0x18, 0x70, 0x18, 0x18, 0x0E, 0X00, // { |
WiredHome | 29:422616aa04bd | 142 | 0x0C, 0x0C, 0x0C, 0X00, 0x0C, 0x0C, 0x0C, 0X00, // | |
WiredHome | 29:422616aa04bd | 143 | 0x70, 0x18, 0x18, 0x0E, 0x18, 0x18, 0x70, 0X00, // } |
WiredHome | 29:422616aa04bd | 144 | 0x3B, 0x6E, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, // ~ |
WiredHome | 29:422616aa04bd | 145 | 0x1C, 0x36, 0x36, 0x1C, 0X00, 0X00, 0X00, 0X00 // DEL |
WiredHome | 23:a50ded45dbaf | 146 | }; |
WiredHome | 29:422616aa04bd | 147 | #endif // LOCALFONT |
WiredHome | 19:3f82c1161fd2 | 148 | |
WiredHome | 42:7cbdfd2bbfc5 | 149 | char mytolower(char a) { |
WiredHome | 42:7cbdfd2bbfc5 | 150 | if (a >= 'A' && a <= 'Z') |
WiredHome | 42:7cbdfd2bbfc5 | 151 | return (a - 'A' + 'a'); |
WiredHome | 42:7cbdfd2bbfc5 | 152 | else |
WiredHome | 42:7cbdfd2bbfc5 | 153 | return a; |
WiredHome | 42:7cbdfd2bbfc5 | 154 | } |
WiredHome | 42:7cbdfd2bbfc5 | 155 | /// mystrnicmp exists because not all compiler libraries have this function. |
WiredHome | 42:7cbdfd2bbfc5 | 156 | /// |
WiredHome | 42:7cbdfd2bbfc5 | 157 | /// Some have strnicmp, others _strnicmp, and others have C++ methods, which |
WiredHome | 42:7cbdfd2bbfc5 | 158 | /// is outside the scope of this C-portable set of functions. |
WiredHome | 42:7cbdfd2bbfc5 | 159 | /// |
WiredHome | 42:7cbdfd2bbfc5 | 160 | /// @param l is a pointer to the string on the left |
WiredHome | 42:7cbdfd2bbfc5 | 161 | /// @param r is a pointer to the string on the right |
WiredHome | 42:7cbdfd2bbfc5 | 162 | /// @param n is the number of characters to compare |
WiredHome | 42:7cbdfd2bbfc5 | 163 | /// @returns -1 if l < r |
WiredHome | 42:7cbdfd2bbfc5 | 164 | /// @returns 0 if l == r |
WiredHome | 42:7cbdfd2bbfc5 | 165 | /// @returns +1 if l > r |
WiredHome | 42:7cbdfd2bbfc5 | 166 | /// |
WiredHome | 42:7cbdfd2bbfc5 | 167 | int mystrnicmp(const char *l, const char *r, size_t n) { |
WiredHome | 42:7cbdfd2bbfc5 | 168 | int result = 0; |
WiredHome | 42:7cbdfd2bbfc5 | 169 | |
WiredHome | 42:7cbdfd2bbfc5 | 170 | if (n != 0) { |
WiredHome | 42:7cbdfd2bbfc5 | 171 | do { |
WiredHome | 42:7cbdfd2bbfc5 | 172 | result = mytolower(*l++) - mytolower(*r++); |
WiredHome | 42:7cbdfd2bbfc5 | 173 | } while ((result == 0) && (*l != '\0') && (--n > 0)); |
WiredHome | 42:7cbdfd2bbfc5 | 174 | } |
WiredHome | 42:7cbdfd2bbfc5 | 175 | if (result < -1) |
WiredHome | 42:7cbdfd2bbfc5 | 176 | result = -1; |
WiredHome | 42:7cbdfd2bbfc5 | 177 | else if (result > 1) |
WiredHome | 42:7cbdfd2bbfc5 | 178 | result = 1; |
WiredHome | 42:7cbdfd2bbfc5 | 179 | return result; |
WiredHome | 42:7cbdfd2bbfc5 | 180 | } |
WiredHome | 42:7cbdfd2bbfc5 | 181 | |
WiredHome | 42:7cbdfd2bbfc5 | 182 | |
WiredHome | 29:422616aa04bd | 183 | GraphicsDisplay::GraphicsDisplay(const char *name) |
WiredHome | 29:422616aa04bd | 184 | : TextDisplay(name) |
WiredHome | 19:3f82c1161fd2 | 185 | { |
WiredHome | 29:422616aa04bd | 186 | font = NULL; |
dreschpe | 0:de9d1462a835 | 187 | } |
WiredHome | 19:3f82c1161fd2 | 188 | |
WiredHome | 29:422616aa04bd | 189 | RetCode_t GraphicsDisplay::set_font(const unsigned char * _font) |
WiredHome | 19:3f82c1161fd2 | 190 | { |
WiredHome | 37:f19b7e7449dc | 191 | font = _font; // trusting them, but it might be good to put some checks in here... |
WiredHome | 37:f19b7e7449dc | 192 | return noerror; |
dreschpe | 0:de9d1462a835 | 193 | } |
dreschpe | 0:de9d1462a835 | 194 | |
WiredHome | 29:422616aa04bd | 195 | #ifdef LOCALFONT |
WiredHome | 29:422616aa04bd | 196 | int GraphicsDisplay::character(int x, int y, int value) |
WiredHome | 29:422616aa04bd | 197 | { |
WiredHome | 29:422616aa04bd | 198 | if (value <= 0x1F && value >= 7F) |
WiredHome | 29:422616aa04bd | 199 | return 0; |
WiredHome | 29:422616aa04bd | 200 | |
WiredHome | 29:422616aa04bd | 201 | return blitbit(x, y, FONT8X8[0][0], FONT8X8[0][1], |
WiredHome | 29:422616aa04bd | 202 | (char *)&(FONT8x8[value - 0x1F][0])); |
WiredHome | 29:422616aa04bd | 203 | } |
WiredHome | 29:422616aa04bd | 204 | #else |
WiredHome | 29:422616aa04bd | 205 | int GraphicsDisplay::character(int x, int y, int c) |
WiredHome | 29:422616aa04bd | 206 | { |
WiredHome | 29:422616aa04bd | 207 | unsigned int offset; |
WiredHome | 29:422616aa04bd | 208 | const unsigned char * charRecord; |
WiredHome | 29:422616aa04bd | 209 | |
WiredHome | 29:422616aa04bd | 210 | if (c <= 0x1F || c >= 0x7F) |
WiredHome | 29:422616aa04bd | 211 | return 0; |
WiredHome | 29:422616aa04bd | 212 | offset = font[0]; // bytes / char |
WiredHome | 29:422616aa04bd | 213 | charRecord = &font[((c - ' ') * offset) + 4]; // start of char bitmap |
WiredHome | 29:422616aa04bd | 214 | return fontblit(x, y, font, charRecord); |
WiredHome | 29:422616aa04bd | 215 | } |
WiredHome | 29:422616aa04bd | 216 | #endif |
WiredHome | 19:3f82c1161fd2 | 217 | |
WiredHome | 37:f19b7e7449dc | 218 | RetCode_t GraphicsDisplay::window(loc_t x, loc_t y, dim_t w, dim_t h) |
WiredHome | 19:3f82c1161fd2 | 219 | { |
dreschpe | 0:de9d1462a835 | 220 | // current pixel location |
dreschpe | 0:de9d1462a835 | 221 | _x = x; |
dreschpe | 0:de9d1462a835 | 222 | _y = y; |
dreschpe | 0:de9d1462a835 | 223 | // window settings |
dreschpe | 0:de9d1462a835 | 224 | _x1 = x; |
dreschpe | 0:de9d1462a835 | 225 | _x2 = x + w - 1; |
dreschpe | 0:de9d1462a835 | 226 | _y1 = y; |
dreschpe | 0:de9d1462a835 | 227 | _y2 = y + h - 1; |
WiredHome | 32:0e4f2ae512e2 | 228 | return noerror; |
dreschpe | 0:de9d1462a835 | 229 | } |
WiredHome | 19:3f82c1161fd2 | 230 | |
WiredHome | 31:c72e12cd5c67 | 231 | void GraphicsDisplay::WindowMax(void) |
WiredHome | 31:c72e12cd5c67 | 232 | { |
WiredHome | 31:c72e12cd5c67 | 233 | window(0,0, width(),height()); |
WiredHome | 31:c72e12cd5c67 | 234 | } |
WiredHome | 31:c72e12cd5c67 | 235 | |
WiredHome | 55:dfbabef7003e | 236 | RetCode_t GraphicsDisplay::_putp(color_t color) |
WiredHome | 19:3f82c1161fd2 | 237 | { |
WiredHome | 33:b6b710758ab3 | 238 | pixel(_x, _y, color); |
dreschpe | 0:de9d1462a835 | 239 | // update pixel location based on window settings |
dreschpe | 0:de9d1462a835 | 240 | _x++; |
dreschpe | 0:de9d1462a835 | 241 | if(_x > _x2) { |
dreschpe | 0:de9d1462a835 | 242 | _x = _x1; |
dreschpe | 0:de9d1462a835 | 243 | _y++; |
dreschpe | 0:de9d1462a835 | 244 | if(_y > _y2) { |
dreschpe | 0:de9d1462a835 | 245 | _y = _y1; |
dreschpe | 0:de9d1462a835 | 246 | } |
dreschpe | 0:de9d1462a835 | 247 | } |
WiredHome | 32:0e4f2ae512e2 | 248 | return noerror; |
dreschpe | 0:de9d1462a835 | 249 | } |
dreschpe | 0:de9d1462a835 | 250 | |
WiredHome | 33:b6b710758ab3 | 251 | void GraphicsDisplay::fill(int x, int y, int w, int h, color_t color) |
WiredHome | 19:3f82c1161fd2 | 252 | { |
WiredHome | 33:b6b710758ab3 | 253 | fillrect(x,y, x+w, y+h, color); |
dreschpe | 0:de9d1462a835 | 254 | } |
WiredHome | 19:3f82c1161fd2 | 255 | |
WiredHome | 61:8f3153bf0baa | 256 | RetCode_t GraphicsDisplay::cls(uint16_t layers) |
WiredHome | 19:3f82c1161fd2 | 257 | { |
dreschpe | 0:de9d1462a835 | 258 | fill(0, 0, width(), height(), _background); |
WiredHome | 19:3f82c1161fd2 | 259 | return noerror; |
dreschpe | 0:de9d1462a835 | 260 | } |
WiredHome | 19:3f82c1161fd2 | 261 | |
WiredHome | 33:b6b710758ab3 | 262 | void GraphicsDisplay::blit(int x, int y, int w, int h, const int * color) |
WiredHome | 19:3f82c1161fd2 | 263 | { |
dreschpe | 0:de9d1462a835 | 264 | window(x, y, w, h); |
WiredHome | 37:f19b7e7449dc | 265 | _StartGraphicsStream(); |
WiredHome | 31:c72e12cd5c67 | 266 | for (int i=0; i<w*h; i++) { |
WiredHome | 55:dfbabef7003e | 267 | _putp(color[i]); |
dreschpe | 0:de9d1462a835 | 268 | } |
WiredHome | 37:f19b7e7449dc | 269 | _EndGraphicsStream(); |
WiredHome | 37:f19b7e7449dc | 270 | WindowMax(); |
dreschpe | 0:de9d1462a835 | 271 | } |
WiredHome | 19:3f82c1161fd2 | 272 | |
WiredHome | 37:f19b7e7449dc | 273 | #ifdef LOCALFONT |
WiredHome | 33:b6b710758ab3 | 274 | int GraphicsDisplay::blitbit(int x, int y, int w, int h, const char * color) |
WiredHome | 19:3f82c1161fd2 | 275 | { |
WiredHome | 29:422616aa04bd | 276 | _foreground = 0xFFFF; |
WiredHome | 33:b6b710758ab3 | 277 | INFO("blitbit(%d,%d, %d,%d, %02X) [%04X,%04X]", x,y, w,h, *color, _foreground, _background); |
WiredHome | 29:422616aa04bd | 278 | INFO("%lu %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X", |
WiredHome | 33:b6b710758ab3 | 279 | color, |
WiredHome | 33:b6b710758ab3 | 280 | color[0], color[1], color[2], color[3], color[4], color[5], color[6], color[7], |
WiredHome | 33:b6b710758ab3 | 281 | color[8], color[9], color[10], color[11], color[12], color[13], color[14], color[15]); |
dreschpe | 0:de9d1462a835 | 282 | window(x, y, w, h); |
WiredHome | 37:f19b7e7449dc | 283 | _StartGraphicsStream(); |
WiredHome | 29:422616aa04bd | 284 | for (int i = 0; i < w*h; i++) { |
WiredHome | 33:b6b710758ab3 | 285 | char byte = color[i >> 3]; |
dreschpe | 0:de9d1462a835 | 286 | int offset = i & 0x7; |
WiredHome | 29:422616aa04bd | 287 | if (offset == 0) |
WiredHome | 29:422616aa04bd | 288 | INFO(" %2d = %02X", i>>3, byte); |
dreschpe | 0:de9d1462a835 | 289 | int c = ((byte << offset) & 0x80) ? _foreground : _background; |
WiredHome | 55:dfbabef7003e | 290 | _putp(c); |
dreschpe | 0:de9d1462a835 | 291 | } |
WiredHome | 37:f19b7e7449dc | 292 | _EndGraphicsStream(); |
WiredHome | 37:f19b7e7449dc | 293 | WindowMax(); |
WiredHome | 29:422616aa04bd | 294 | return w; |
WiredHome | 29:422616aa04bd | 295 | } |
WiredHome | 37:f19b7e7449dc | 296 | #endif |
WiredHome | 29:422616aa04bd | 297 | |
WiredHome | 29:422616aa04bd | 298 | |
WiredHome | 29:422616aa04bd | 299 | int GraphicsDisplay::fontblit(int x, int y, const unsigned char * fontTable, const unsigned char * fontChar) |
WiredHome | 29:422616aa04bd | 300 | { |
WiredHome | 29:422616aa04bd | 301 | //int fontWidth = font[1]; // get hor size of font |
WiredHome | 29:422616aa04bd | 302 | int fontHeight = font[2]; // get vert size of font |
WiredHome | 29:422616aa04bd | 303 | int bytesPerLine = font[3]; // bytes per line |
WiredHome | 29:422616aa04bd | 304 | int charWidth = fontChar[0]; // width of this character |
WiredHome | 29:422616aa04bd | 305 | int px, py; |
WiredHome | 37:f19b7e7449dc | 306 | |
WiredHome | 37:f19b7e7449dc | 307 | //INFO("(%d,%d) %lu, %lu %X/%X", x,y, fontTable, fontChar, _foreground, _background); |
WiredHome | 37:f19b7e7449dc | 308 | //INFO("char size (%d,%d)", charWidth, fontHeight); |
WiredHome | 37:f19b7e7449dc | 309 | //HexDump("char", (uint8_t *)fontChar, 32); |
WiredHome | 37:f19b7e7449dc | 310 | //INFO("(f,b) = (%04X,%04X)", _foreground, _background) |
WiredHome | 29:422616aa04bd | 311 | window(x, y, charWidth, fontHeight); |
WiredHome | 37:f19b7e7449dc | 312 | _StartGraphicsStream(); |
WiredHome | 37:f19b7e7449dc | 313 | //INFO("(f,b) = (%04X,%04X)", _foreground, _background) |
WiredHome | 29:422616aa04bd | 314 | for (py = 0; py < fontHeight; py++) { |
WiredHome | 29:422616aa04bd | 315 | int bitmask = 1 << (py & 7); |
WiredHome | 29:422616aa04bd | 316 | |
WiredHome | 29:422616aa04bd | 317 | for (px = 0; px < charWidth; px++) { |
WiredHome | 29:422616aa04bd | 318 | int offset = (py / 8) + px * bytesPerLine; |
WiredHome | 29:422616aa04bd | 319 | unsigned char byte = fontChar[offset + 1]; // skip the char's # bits wide value |
WiredHome | 37:f19b7e7449dc | 320 | color_t c = (byte & bitmask) ? _foreground : _background; |
WiredHome | 37:f19b7e7449dc | 321 | //INFO("(%2d,%2d) %02X & %02X => %04X [%04X,%04X]", px, py, byte, bitmask, c, _foreground, _background); |
WiredHome | 37:f19b7e7449dc | 322 | //pixel(x+px, y+py, c); |
WiredHome | 55:dfbabef7003e | 323 | _putp(c); |
WiredHome | 29:422616aa04bd | 324 | } |
WiredHome | 29:422616aa04bd | 325 | } |
WiredHome | 37:f19b7e7449dc | 326 | _EndGraphicsStream(); |
WiredHome | 37:f19b7e7449dc | 327 | WindowMax(); |
WiredHome | 29:422616aa04bd | 328 | return charWidth; |
dreschpe | 0:de9d1462a835 | 329 | } |
dreschpe | 0:de9d1462a835 | 330 | |
WiredHome | 31:c72e12cd5c67 | 331 | // BMP Color Palette is BGRx |
WiredHome | 31:c72e12cd5c67 | 332 | // BBBB BBBB GGGG GGGG RRRR RRRR 0000 0000 |
WiredHome | 31:c72e12cd5c67 | 333 | // RGB16 is |
WiredHome | 31:c72e12cd5c67 | 334 | // RRRR RGGG GGGB BBBB |
WiredHome | 31:c72e12cd5c67 | 335 | // swap to little endian |
WiredHome | 31:c72e12cd5c67 | 336 | // GGGB BBBB RRRR RGGG |
WiredHome | 32:0e4f2ae512e2 | 337 | color_t GraphicsDisplay::RGBQuadToRGB16(RGBQUAD * colorPalette, uint16_t i) |
WiredHome | 31:c72e12cd5c67 | 338 | { |
WiredHome | 31:c72e12cd5c67 | 339 | color_t c; |
WiredHome | 31:c72e12cd5c67 | 340 | |
WiredHome | 31:c72e12cd5c67 | 341 | c = ((colorPalette[i].rgbBlue >> 3) << 0); |
WiredHome | 31:c72e12cd5c67 | 342 | c |= ((colorPalette[i].rgbGreen >> 2) << 5); |
WiredHome | 31:c72e12cd5c67 | 343 | c |= ((colorPalette[i].rgbRed >> 3) << 11); |
WiredHome | 31:c72e12cd5c67 | 344 | return c; |
WiredHome | 31:c72e12cd5c67 | 345 | } |
WiredHome | 29:422616aa04bd | 346 | |
WiredHome | 41:2956a0a221e5 | 347 | /// RRRR RGGG GGGB BBBB |
WiredHome | 41:2956a0a221e5 | 348 | RGBQUAD GraphicsDisplay::RGB16ToRGBQuad(color_t c) |
WiredHome | 41:2956a0a221e5 | 349 | { |
WiredHome | 41:2956a0a221e5 | 350 | RGBQUAD q; |
WiredHome | 41:2956a0a221e5 | 351 | |
WiredHome | 41:2956a0a221e5 | 352 | memset(&q, 0, sizeof(q)); |
WiredHome | 72:ecffe56af969 | 353 | q.rgbBlue = ((c & 0x001F) << 3) | (c & 0x07); /* Blue value */ |
WiredHome | 72:ecffe56af969 | 354 | q.rgbGreen = ((c & 0x07E0) >> 3) | ((c >> 7) & 0x03); /* Green value */ |
WiredHome | 72:ecffe56af969 | 355 | q.rgbRed = ((c & 0xF800) >> 8) | ((c >> 11) & 0x07); /* Red value */ |
WiredHome | 41:2956a0a221e5 | 356 | q.rgbReserved = 0; |
WiredHome | 41:2956a0a221e5 | 357 | return q; |
WiredHome | 41:2956a0a221e5 | 358 | } |
WiredHome | 41:2956a0a221e5 | 359 | |
WiredHome | 42:7cbdfd2bbfc5 | 360 | RetCode_t GraphicsDisplay::_RenderBitmap(loc_t x, loc_t y, uint32_t fileOffset, FILE * Image) |
WiredHome | 31:c72e12cd5c67 | 361 | { |
WiredHome | 31:c72e12cd5c67 | 362 | BITMAPINFOHEADER BMP_Info; |
WiredHome | 31:c72e12cd5c67 | 363 | RGBQUAD * colorPalette = NULL; |
WiredHome | 31:c72e12cd5c67 | 364 | int colorCount; |
WiredHome | 32:0e4f2ae512e2 | 365 | uint8_t * lineBuffer = NULL; |
WiredHome | 69:636867df24a1 | 366 | color_t * pixelBuffer = NULL; |
WiredHome | 31:c72e12cd5c67 | 367 | uint16_t BPP_t; |
WiredHome | 31:c72e12cd5c67 | 368 | uint32_t PixelWidth, PixelHeight; |
WiredHome | 31:c72e12cd5c67 | 369 | unsigned int i, offset; |
WiredHome | 31:c72e12cd5c67 | 370 | int padd,j; |
WiredHome | 59:fb40aad4efd4 | 371 | #ifdef DEBUG |
WiredHome | 59:fb40aad4efd4 | 372 | uint32_t start_data; |
WiredHome | 59:fb40aad4efd4 | 373 | #endif |
WiredHome | 31:c72e12cd5c67 | 374 | |
WiredHome | 42:7cbdfd2bbfc5 | 375 | // Now, Read the bitmap info header |
WiredHome | 31:c72e12cd5c67 | 376 | fread(&BMP_Info, 1, sizeof(BMP_Info), Image); |
WiredHome | 59:fb40aad4efd4 | 377 | HexDump("BMP_Info", (uint8_t *)&BMP_Info, sizeof(BMP_Info)); |
WiredHome | 31:c72e12cd5c67 | 378 | BPP_t = BMP_Info.biBitCount; |
WiredHome | 31:c72e12cd5c67 | 379 | INFO("biBitCount %04X", BPP_t); |
WiredHome | 32:0e4f2ae512e2 | 380 | if (BPP_t != 4 && BPP_t != 8 && BPP_t != 16 && BPP_t != 24) { // Support 4, 8, 16, 24-bits per pixel |
WiredHome | 31:c72e12cd5c67 | 381 | fclose(Image); |
WiredHome | 31:c72e12cd5c67 | 382 | return(not_supported_format); |
WiredHome | 31:c72e12cd5c67 | 383 | } |
WiredHome | 31:c72e12cd5c67 | 384 | |
WiredHome | 31:c72e12cd5c67 | 385 | PixelHeight = BMP_Info.biHeight; |
WiredHome | 31:c72e12cd5c67 | 386 | PixelWidth = BMP_Info.biWidth; |
WiredHome | 31:c72e12cd5c67 | 387 | if (PixelHeight > height() + y || PixelWidth > width() + x) { |
WiredHome | 31:c72e12cd5c67 | 388 | fclose(Image); |
WiredHome | 31:c72e12cd5c67 | 389 | return(image_too_big); |
WiredHome | 31:c72e12cd5c67 | 390 | } |
WiredHome | 31:c72e12cd5c67 | 391 | INFO("(%d,%d) (%d,%d)", x,y, PixelWidth,PixelHeight); |
WiredHome | 31:c72e12cd5c67 | 392 | if (BMP_Info.biBitCount <= 8) { |
WiredHome | 31:c72e12cd5c67 | 393 | int paletteSize; |
WiredHome | 31:c72e12cd5c67 | 394 | // Read the color palette |
WiredHome | 31:c72e12cd5c67 | 395 | colorCount = 1 << BMP_Info.biBitCount; |
WiredHome | 31:c72e12cd5c67 | 396 | paletteSize = sizeof(RGBQUAD) * colorCount; |
WiredHome | 31:c72e12cd5c67 | 397 | colorPalette = (RGBQUAD *)malloc(paletteSize); |
WiredHome | 31:c72e12cd5c67 | 398 | if (colorPalette == NULL) { |
WiredHome | 31:c72e12cd5c67 | 399 | fclose(Image); |
WiredHome | 31:c72e12cd5c67 | 400 | return(not_enough_ram); |
WiredHome | 31:c72e12cd5c67 | 401 | } |
WiredHome | 31:c72e12cd5c67 | 402 | fread(colorPalette, 1, paletteSize, Image); |
WiredHome | 59:fb40aad4efd4 | 403 | HexDump("Color Palette", (uint8_t *)colorPalette, paletteSize); |
WiredHome | 31:c72e12cd5c67 | 404 | } |
WiredHome | 31:c72e12cd5c67 | 405 | |
WiredHome | 32:0e4f2ae512e2 | 406 | int lineBufSize = ((BPP_t * PixelWidth + 7)/8); |
WiredHome | 59:fb40aad4efd4 | 407 | INFO("BPP_t %d, PixelWidth %d, lineBufSize %d", BPP_t, PixelWidth, lineBufSize); |
WiredHome | 32:0e4f2ae512e2 | 408 | lineBuffer = (uint8_t *)malloc(lineBufSize); |
WiredHome | 31:c72e12cd5c67 | 409 | if (lineBuffer == NULL) { |
WiredHome | 31:c72e12cd5c67 | 410 | free(colorPalette); |
WiredHome | 31:c72e12cd5c67 | 411 | fclose(Image); |
WiredHome | 31:c72e12cd5c67 | 412 | return(not_enough_ram); |
WiredHome | 31:c72e12cd5c67 | 413 | } |
WiredHome | 69:636867df24a1 | 414 | pixelBuffer = (color_t *)malloc(PixelWidth * sizeof(color_t)); |
WiredHome | 41:2956a0a221e5 | 415 | if (pixelBuffer == NULL) { |
WiredHome | 41:2956a0a221e5 | 416 | free(lineBuffer); |
WiredHome | 69:636867df24a1 | 417 | if (colorPalette) |
WiredHome | 69:636867df24a1 | 418 | free(colorPalette); |
WiredHome | 41:2956a0a221e5 | 419 | fclose(Image); |
WiredHome | 41:2956a0a221e5 | 420 | return(not_enough_ram); |
WiredHome | 41:2956a0a221e5 | 421 | } |
WiredHome | 31:c72e12cd5c67 | 422 | |
WiredHome | 32:0e4f2ae512e2 | 423 | // the Raw Data records are padded to a multiple of 4 bytes |
WiredHome | 32:0e4f2ae512e2 | 424 | int recordSize = 2; |
WiredHome | 32:0e4f2ae512e2 | 425 | if (BPP_t == 4) { |
WiredHome | 32:0e4f2ae512e2 | 426 | recordSize = 1; |
WiredHome | 32:0e4f2ae512e2 | 427 | } else if (BPP_t == 8) { |
WiredHome | 32:0e4f2ae512e2 | 428 | recordSize = 1; |
WiredHome | 32:0e4f2ae512e2 | 429 | } else if (BPP_t == 16) { |
WiredHome | 32:0e4f2ae512e2 | 430 | recordSize = 2; |
WiredHome | 32:0e4f2ae512e2 | 431 | } else if (BPP_t == 24) { |
WiredHome | 32:0e4f2ae512e2 | 432 | recordSize = 3; |
WiredHome | 32:0e4f2ae512e2 | 433 | } |
WiredHome | 31:c72e12cd5c67 | 434 | padd = -1; |
WiredHome | 31:c72e12cd5c67 | 435 | do { |
WiredHome | 31:c72e12cd5c67 | 436 | padd++; |
WiredHome | 32:0e4f2ae512e2 | 437 | } while ((PixelWidth * recordSize + padd) % 4 != 0); |
WiredHome | 31:c72e12cd5c67 | 438 | |
WiredHome | 32:0e4f2ae512e2 | 439 | // Define window for top to bottom and left to right so writing auto-wraps |
WiredHome | 31:c72e12cd5c67 | 440 | window(x,y, PixelWidth,PixelHeight); |
WiredHome | 32:0e4f2ae512e2 | 441 | SetGraphicsCursor(x, y); |
WiredHome | 32:0e4f2ae512e2 | 442 | _StartGraphicsStream(); |
WiredHome | 32:0e4f2ae512e2 | 443 | |
WiredHome | 42:7cbdfd2bbfc5 | 444 | //start_data = BMP_Header.bfOffBits; |
WiredHome | 59:fb40aad4efd4 | 445 | HexDump("Raw Data", (uint8_t *)&start_data, 32); |
WiredHome | 59:fb40aad4efd4 | 446 | INFO("(%d,%d) (%d,%d), [%d,%d]", x,y, PixelWidth,PixelHeight, lineBufSize, padd); |
WiredHome | 32:0e4f2ae512e2 | 447 | for (j = PixelHeight - 1; j >= 0; j--) { //Lines bottom up |
WiredHome | 42:7cbdfd2bbfc5 | 448 | offset = fileOffset + j * (lineBufSize + padd); // start of line |
WiredHome | 31:c72e12cd5c67 | 449 | fseek(Image, offset, SEEK_SET); |
WiredHome | 32:0e4f2ae512e2 | 450 | fread(lineBuffer, 1, lineBufSize, Image); // read a line - slow ! |
WiredHome | 59:fb40aad4efd4 | 451 | INFO("offset: %6X", offset); |
WiredHome | 32:0e4f2ae512e2 | 452 | for (i = 0; i < PixelWidth; i++) { // copy pixel data to TFT |
WiredHome | 31:c72e12cd5c67 | 453 | if (BPP_t == 4) { |
WiredHome | 31:c72e12cd5c67 | 454 | uint8_t dPix = lineBuffer[i/2]; |
WiredHome | 31:c72e12cd5c67 | 455 | if ((i & 1) == 0) |
WiredHome | 31:c72e12cd5c67 | 456 | dPix >>= 4; |
WiredHome | 31:c72e12cd5c67 | 457 | dPix &= 0x0F; |
WiredHome | 41:2956a0a221e5 | 458 | pixelBuffer[i] = RGBQuadToRGB16(colorPalette, dPix); |
WiredHome | 55:dfbabef7003e | 459 | //_putp(RGBQuadToRGB16(colorPalette, dPix)); |
WiredHome | 31:c72e12cd5c67 | 460 | } else if (BPP_t == 8) { |
WiredHome | 41:2956a0a221e5 | 461 | pixelBuffer[i] = RGBQuadToRGB16(colorPalette, lineBuffer[i]); |
WiredHome | 55:dfbabef7003e | 462 | //_putp(RGBQuadToRGB16(colorPalette, lineBuffer[i])); |
WiredHome | 32:0e4f2ae512e2 | 463 | } else if (BPP_t == 16) { |
WiredHome | 41:2956a0a221e5 | 464 | pixelBuffer[i] = lineBuffer[i]; |
WiredHome | 55:dfbabef7003e | 465 | //_putp(lineBuffer[i]); |
WiredHome | 32:0e4f2ae512e2 | 466 | } else if (BPP_t == 24) { |
WiredHome | 37:f19b7e7449dc | 467 | color_t color; |
WiredHome | 32:0e4f2ae512e2 | 468 | color = RGB(lineBuffer[i*3+2], lineBuffer[i*3+1], lineBuffer[i*3+0]); |
WiredHome | 41:2956a0a221e5 | 469 | pixelBuffer[i] = color; |
WiredHome | 41:2956a0a221e5 | 470 | //putp(color); |
WiredHome | 31:c72e12cd5c67 | 471 | } |
WiredHome | 31:c72e12cd5c67 | 472 | } |
WiredHome | 41:2956a0a221e5 | 473 | pixelStream(pixelBuffer, PixelWidth, x, y++); |
WiredHome | 31:c72e12cd5c67 | 474 | } |
WiredHome | 42:7cbdfd2bbfc5 | 475 | _EndGraphicsStream(); |
WiredHome | 42:7cbdfd2bbfc5 | 476 | WindowMax(); |
WiredHome | 69:636867df24a1 | 477 | free(pixelBuffer); // don't leak memory |
WiredHome | 31:c72e12cd5c67 | 478 | free(lineBuffer); |
WiredHome | 69:636867df24a1 | 479 | if (colorPalette) |
WiredHome | 69:636867df24a1 | 480 | free(colorPalette); |
WiredHome | 32:0e4f2ae512e2 | 481 | return (noerror); |
WiredHome | 31:c72e12cd5c67 | 482 | } |
WiredHome | 31:c72e12cd5c67 | 483 | |
WiredHome | 42:7cbdfd2bbfc5 | 484 | |
WiredHome | 42:7cbdfd2bbfc5 | 485 | RetCode_t GraphicsDisplay::RenderImageFile(loc_t x, loc_t y, const char *FileName) |
WiredHome | 42:7cbdfd2bbfc5 | 486 | { |
WiredHome | 42:7cbdfd2bbfc5 | 487 | if (mystrnicmp(FileName + strlen(FileName) - 4, ".bmp", 4) == 0) { |
WiredHome | 42:7cbdfd2bbfc5 | 488 | return RenderBitmapFile(x,y,FileName); |
WiredHome | 42:7cbdfd2bbfc5 | 489 | } else if (mystrnicmp(FileName + strlen(FileName) - 4, ".ico", 4) == 0) { |
WiredHome | 42:7cbdfd2bbfc5 | 490 | return RenderIconFile(x,y,FileName); |
WiredHome | 42:7cbdfd2bbfc5 | 491 | } else { |
WiredHome | 42:7cbdfd2bbfc5 | 492 | return not_supported_format; |
WiredHome | 42:7cbdfd2bbfc5 | 493 | } |
WiredHome | 42:7cbdfd2bbfc5 | 494 | } |
WiredHome | 42:7cbdfd2bbfc5 | 495 | |
WiredHome | 42:7cbdfd2bbfc5 | 496 | RetCode_t GraphicsDisplay::RenderBitmapFile(loc_t x, loc_t y, const char *Name_BMP) |
WiredHome | 42:7cbdfd2bbfc5 | 497 | { |
WiredHome | 42:7cbdfd2bbfc5 | 498 | BITMAPFILEHEADER BMP_Header; |
WiredHome | 42:7cbdfd2bbfc5 | 499 | |
WiredHome | 42:7cbdfd2bbfc5 | 500 | INFO("Opening {%s}", Name_BMP); |
WiredHome | 42:7cbdfd2bbfc5 | 501 | FILE *Image = fopen(Name_BMP, "rb"); |
WiredHome | 42:7cbdfd2bbfc5 | 502 | if (!Image) { |
WiredHome | 42:7cbdfd2bbfc5 | 503 | return(file_not_found); |
WiredHome | 42:7cbdfd2bbfc5 | 504 | } |
WiredHome | 42:7cbdfd2bbfc5 | 505 | |
WiredHome | 42:7cbdfd2bbfc5 | 506 | fread(&BMP_Header, 1, sizeof(BMP_Header), Image); // get the BMP Header |
WiredHome | 42:7cbdfd2bbfc5 | 507 | INFO("bfType %04X", BMP_Header.bfType); |
WiredHome | 59:fb40aad4efd4 | 508 | HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header)); |
WiredHome | 42:7cbdfd2bbfc5 | 509 | if (BMP_Header.bfType != BF_TYPE) { |
WiredHome | 42:7cbdfd2bbfc5 | 510 | fclose(Image); |
WiredHome | 42:7cbdfd2bbfc5 | 511 | return(not_bmp_format); |
WiredHome | 42:7cbdfd2bbfc5 | 512 | } |
WiredHome | 42:7cbdfd2bbfc5 | 513 | RetCode_t rt = _RenderBitmap(x, y, BMP_Header.bfOffBits, Image); |
WiredHome | 42:7cbdfd2bbfc5 | 514 | if (rt != noerror) { |
WiredHome | 42:7cbdfd2bbfc5 | 515 | return rt; |
WiredHome | 42:7cbdfd2bbfc5 | 516 | } else { |
WiredHome | 42:7cbdfd2bbfc5 | 517 | fclose(Image); |
WiredHome | 42:7cbdfd2bbfc5 | 518 | return (noerror); |
WiredHome | 42:7cbdfd2bbfc5 | 519 | } |
WiredHome | 42:7cbdfd2bbfc5 | 520 | } |
WiredHome | 42:7cbdfd2bbfc5 | 521 | |
WiredHome | 42:7cbdfd2bbfc5 | 522 | RetCode_t GraphicsDisplay::RenderIconFile(loc_t x, loc_t y, const char *Name_ICO) |
WiredHome | 42:7cbdfd2bbfc5 | 523 | { |
WiredHome | 42:7cbdfd2bbfc5 | 524 | ICOFILEHEADER ICO_Header; |
WiredHome | 42:7cbdfd2bbfc5 | 525 | ICODIRENTRY ICO_DirEntry; |
WiredHome | 42:7cbdfd2bbfc5 | 526 | |
WiredHome | 42:7cbdfd2bbfc5 | 527 | INFO("Opening {%s}", Name_ICO); |
WiredHome | 42:7cbdfd2bbfc5 | 528 | FILE *Image = fopen(Name_ICO, "rb"); |
WiredHome | 42:7cbdfd2bbfc5 | 529 | if (!Image) { |
WiredHome | 42:7cbdfd2bbfc5 | 530 | return(file_not_found); |
WiredHome | 42:7cbdfd2bbfc5 | 531 | } |
WiredHome | 42:7cbdfd2bbfc5 | 532 | |
WiredHome | 42:7cbdfd2bbfc5 | 533 | fread(&ICO_Header, 1, sizeof(ICO_Header), Image); // get the BMP Header |
WiredHome | 42:7cbdfd2bbfc5 | 534 | HexDump("ICO_Header", (uint8_t *)&ICO_Header, sizeof(ICO_Header)); |
WiredHome | 42:7cbdfd2bbfc5 | 535 | if (ICO_Header.Reserved_zero != 0 |
WiredHome | 42:7cbdfd2bbfc5 | 536 | || ICO_Header.icType != IC_TYPE |
WiredHome | 42:7cbdfd2bbfc5 | 537 | || ICO_Header.icImageCount == 0) { |
WiredHome | 42:7cbdfd2bbfc5 | 538 | fclose(Image); |
WiredHome | 42:7cbdfd2bbfc5 | 539 | return(not_ico_format); |
WiredHome | 42:7cbdfd2bbfc5 | 540 | } |
WiredHome | 42:7cbdfd2bbfc5 | 541 | |
WiredHome | 42:7cbdfd2bbfc5 | 542 | // Read ONLY the first of n possible directory entries. |
WiredHome | 42:7cbdfd2bbfc5 | 543 | fread(&ICO_DirEntry, 1, sizeof(ICO_DirEntry), Image); |
WiredHome | 42:7cbdfd2bbfc5 | 544 | HexDump("ICO_DirEntry", (uint8_t *)&ICO_DirEntry, sizeof(ICO_DirEntry)); |
WiredHome | 42:7cbdfd2bbfc5 | 545 | INFO("biBitCount %04X", ICO_DirEntry.biBitCount); |
WiredHome | 42:7cbdfd2bbfc5 | 546 | if (ICO_DirEntry.biBitCount != 0) { // Expecting this to be zero for ico |
WiredHome | 42:7cbdfd2bbfc5 | 547 | fclose(Image); |
WiredHome | 42:7cbdfd2bbfc5 | 548 | return(not_supported_format); |
WiredHome | 42:7cbdfd2bbfc5 | 549 | } |
WiredHome | 42:7cbdfd2bbfc5 | 550 | |
WiredHome | 42:7cbdfd2bbfc5 | 551 | RetCode_t rt = _RenderBitmap(x, y, ICO_DirEntry.bfOffBits, Image); |
WiredHome | 42:7cbdfd2bbfc5 | 552 | if (rt == noerror) { |
WiredHome | 42:7cbdfd2bbfc5 | 553 | fclose(Image); |
WiredHome | 42:7cbdfd2bbfc5 | 554 | return (noerror); |
WiredHome | 42:7cbdfd2bbfc5 | 555 | } else { |
WiredHome | 42:7cbdfd2bbfc5 | 556 | return rt; |
WiredHome | 42:7cbdfd2bbfc5 | 557 | } |
WiredHome | 42:7cbdfd2bbfc5 | 558 | } |
WiredHome | 42:7cbdfd2bbfc5 | 559 | |
WiredHome | 19:3f82c1161fd2 | 560 | int GraphicsDisplay::columns() |
WiredHome | 19:3f82c1161fd2 | 561 | { |
WiredHome | 19:3f82c1161fd2 | 562 | return width() / 8; |
dreschpe | 0:de9d1462a835 | 563 | } |
dreschpe | 0:de9d1462a835 | 564 | |
WiredHome | 19:3f82c1161fd2 | 565 | int GraphicsDisplay::rows() |
WiredHome | 19:3f82c1161fd2 | 566 | { |
WiredHome | 19:3f82c1161fd2 | 567 | return height() / 8; |
WiredHome | 19:3f82c1161fd2 | 568 | } |
WiredHome | 19:3f82c1161fd2 | 569 | |
WiredHome | 32:0e4f2ae512e2 | 570 |