LCD LIB

Dependents:   HagridOS5

Fork of RA8875 by David Smart

Committer:
WiredHome
Date:
Wed Jan 22 03:50:55 2014 +0000
Revision:
33:b6b710758ab3
Parent:
32:0e4f2ae512e2
Child:
34:c99ec28fac66
Documentation fixes after running doxygen externally.
; And migrated colour to color.

Who changed what in which revision?

UserRevisionLine numberNew 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 32:0e4f2ae512e2 5 * Software Rendering of a Bitmap from the localfilesystem
WiredHome 32:0e4f2ae512e2 6 * 34 sec: 352x272 pixels, 8-bit color, 94.5kbytes
WiredHome 32:0e4f2ae512e2 7 * Hardware Rendering
WiredHome 32:0e4f2ae512e2 8 * 9 sec: same file.
dreschpe 0:de9d1462a835 9 */
WiredHome 19:3f82c1161fd2 10
dreschpe 0:de9d1462a835 11 #include "GraphicsDisplay.h"
WiredHome 31:c72e12cd5c67 12 #include "Bitmap.h"
dreschpe 0:de9d1462a835 13
WiredHome 32:0e4f2ae512e2 14 // Defining USE_HW causes compilation of code that uses hardware drawing
WiredHome 32:0e4f2ae512e2 15 // provided by the super-class.
WiredHome 32:0e4f2ae512e2 16 #define USE_HW
WiredHome 32:0e4f2ae512e2 17
WiredHome 32:0e4f2ae512e2 18 //#define DEBUG "GD"
WiredHome 29:422616aa04bd 19 // ...
WiredHome 29:422616aa04bd 20 // INFO("Stuff to show %d", var); // new-line is automatically appended
WiredHome 29:422616aa04bd 21 //
WiredHome 29:422616aa04bd 22 #if (defined(DEBUG) && !defined(TARGET_LPC11U24))
WiredHome 29:422616aa04bd 23 #define INFO(x, ...) std::printf("[INF %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 29:422616aa04bd 24 #define WARN(x, ...) std::printf("[WRN %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 29:422616aa04bd 25 #define ERR(x, ...) std::printf("[ERR %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__);
WiredHome 31:c72e12cd5c67 26 void HexDump(char * title, uint8_t * p, int count)
WiredHome 31:c72e12cd5c67 27 {
WiredHome 31:c72e12cd5c67 28 int i;
WiredHome 31:c72e12cd5c67 29 char buf[100] = "0000: ";
WiredHome 31:c72e12cd5c67 30
WiredHome 31:c72e12cd5c67 31 if (*title)
WiredHome 31:c72e12cd5c67 32 INFO("%s", title);
WiredHome 31:c72e12cd5c67 33 for (i=0; i<count; ) {
WiredHome 31:c72e12cd5c67 34 sprintf(buf + strlen(buf), "%02X ", *(p+i));
WiredHome 31:c72e12cd5c67 35 if ((++i & 0x0F) == 0x00) {
WiredHome 31:c72e12cd5c67 36 INFO("%s", buf);
WiredHome 31:c72e12cd5c67 37 if (i < count)
WiredHome 31:c72e12cd5c67 38 sprintf(buf, "%04X: ", i);
WiredHome 31:c72e12cd5c67 39 else
WiredHome 31:c72e12cd5c67 40 buf[0] = '\0';
WiredHome 31:c72e12cd5c67 41 }
WiredHome 31:c72e12cd5c67 42 }
WiredHome 31:c72e12cd5c67 43 if (strlen(buf))
WiredHome 31:c72e12cd5c67 44 INFO("%s", buf);
WiredHome 31:c72e12cd5c67 45 }
WiredHome 29:422616aa04bd 46 #else
WiredHome 29:422616aa04bd 47 #define INFO(x, ...)
WiredHome 29:422616aa04bd 48 #define WARN(x, ...)
WiredHome 29:422616aa04bd 49 #define ERR(x, ...)
WiredHome 32:0e4f2ae512e2 50 #define HexDump(a, b, c)
WiredHome 29:422616aa04bd 51 #endif
WiredHome 29:422616aa04bd 52
WiredHome 29:422616aa04bd 53 // #define LOCALFONT
WiredHome 29:422616aa04bd 54
WiredHome 29:422616aa04bd 55 #ifdef LOCALFONT
dreschpe 0:de9d1462a835 56 const unsigned char FONT8x8[97][8] = {
WiredHome 29:422616aa04bd 57 0x08, 0x08, 0x08, 0X00, 0X00, 0X00, 0X00, 0X00, // columns, rows, num_bytes_per_char
WiredHome 29:422616aa04bd 58 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, // space 0x20
WiredHome 29:422616aa04bd 59 0x30, 0x78, 0x78, 0x30, 0x30, 0X00, 0x30, 0X00, // !
WiredHome 29:422616aa04bd 60 0x6C, 0x6C, 0x6C, 0X00, 0X00, 0X00, 0X00, 0X00, // "
WiredHome 29:422616aa04bd 61 0x6C, 0x6C, 0xFE, 0x6C, 0xFE, 0x6C, 0x6C, 0X00, // #
WiredHome 29:422616aa04bd 62 0x18, 0x3E, 0x60, 0x3C, 0x06, 0x7C, 0x18, 0X00, // $
WiredHome 29:422616aa04bd 63 0X00, 0x63, 0x66, 0x0C, 0x18, 0x33, 0x63, 0X00, // %
WiredHome 29:422616aa04bd 64 0x1C, 0x36, 0x1C, 0x3B, 0x6E, 0x66, 0x3B, 0X00, // &
WiredHome 29:422616aa04bd 65 0x30, 0x30, 0x60, 0X00, 0X00, 0X00, 0X00, 0X00, // '
WiredHome 29:422616aa04bd 66 0x0C, 0x18, 0x30, 0x30, 0x30, 0x18, 0x0C, 0X00, // (
WiredHome 29:422616aa04bd 67 0x30, 0x18, 0x0C, 0x0C, 0x0C, 0x18, 0x30, 0X00, // )
WiredHome 29:422616aa04bd 68 0X00, 0x66, 0x3C, 0xFF, 0x3C, 0x66, 0X00, 0X00, // *
WiredHome 29:422616aa04bd 69 0X00, 0x30, 0x30, 0xFC, 0x30, 0x30, 0X00, 0X00, // +
WiredHome 29:422616aa04bd 70 0X00, 0X00, 0X00, 0X00, 0X00, 0x18, 0x18, 0x30, // ,
WiredHome 29:422616aa04bd 71 0X00, 0X00, 0X00, 0x7E, 0X00, 0X00, 0X00, 0X00, // -
WiredHome 29:422616aa04bd 72 0X00, 0X00, 0X00, 0X00, 0X00, 0x18, 0x18, 0X00, // .
WiredHome 29:422616aa04bd 73 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x40, 0X00, // / (forward slash)
WiredHome 29:422616aa04bd 74 0x3E, 0x63, 0x63, 0x6B, 0x63, 0x63, 0x3E, 0X00, // 0 0x30
WiredHome 29:422616aa04bd 75 0x18, 0x38, 0x58, 0x18, 0x18, 0x18, 0x7E, 0X00, // 1
WiredHome 29:422616aa04bd 76 0x3C, 0x66, 0x06, 0x1C, 0x30, 0x66, 0x7E, 0X00, // 2
WiredHome 29:422616aa04bd 77 0x3C, 0x66, 0x06, 0x1C, 0x06, 0x66, 0x3C, 0X00, // 3
WiredHome 29:422616aa04bd 78 0x0E, 0x1E, 0x36, 0x66, 0x7F, 0x06, 0x0F, 0X00, // 4
WiredHome 29:422616aa04bd 79 0x7E, 0x60, 0x7C, 0x06, 0x06, 0x66, 0x3C, 0X00, // 5
WiredHome 29:422616aa04bd 80 0x1C, 0x30, 0x60, 0x7C, 0x66, 0x66, 0x3C, 0X00, // 6
WiredHome 29:422616aa04bd 81 0x7E, 0x66, 0x06, 0x0C, 0x18, 0x18, 0x18, 0X00, // 7
WiredHome 29:422616aa04bd 82 0x3C, 0x66, 0x66, 0x3C, 0x66, 0x66, 0x3C, 0X00, // 8
WiredHome 29:422616aa04bd 83 0x3C, 0x66, 0x66, 0x3E, 0x06, 0x0C, 0x38, 0X00, // 9
WiredHome 29:422616aa04bd 84 0X00, 0x18, 0x18, 0X00, 0X00, 0x18, 0x18, 0X00, // :
WiredHome 29:422616aa04bd 85 0X00, 0x18, 0x18, 0X00, 0X00, 0x18, 0x18, 0x30, // ;
WiredHome 29:422616aa04bd 86 0x0C, 0x18, 0x30, 0x60, 0x30, 0x18, 0x0C, 0X00, // <
WiredHome 29:422616aa04bd 87 0X00, 0X00, 0x7E, 0X00, 0X00, 0x7E, 0X00, 0X00, // =
WiredHome 29:422616aa04bd 88 0x30, 0x18, 0x0C, 0x06, 0x0C, 0x18, 0x30, 0X00, // >
WiredHome 29:422616aa04bd 89 0x3C, 0x66, 0x06, 0x0C, 0x18, 0X00, 0x18, 0X00, // ?
WiredHome 29:422616aa04bd 90 0x3E, 0x63, 0x6F, 0x69, 0x6F, 0x60, 0x3E, 0X00, // @ 0x40
WiredHome 29:422616aa04bd 91 0x18, 0x3C, 0x66, 0x66, 0x7E, 0x66, 0x66, 0X00, // A
WiredHome 29:422616aa04bd 92 0x7E, 0x33, 0x33, 0x3E, 0x33, 0x33, 0x7E, 0X00, // B
WiredHome 29:422616aa04bd 93 0x1E, 0x33, 0x60, 0x60, 0x60, 0x33, 0x1E, 0X00, // C
WiredHome 29:422616aa04bd 94 0x7C, 0x36, 0x33, 0x33, 0x33, 0x36, 0x7C, 0X00, // D
WiredHome 29:422616aa04bd 95 0x7F, 0x31, 0x34, 0x3C, 0x34, 0x31, 0x7F, 0X00, // E
WiredHome 29:422616aa04bd 96 0x7F, 0x31, 0x34, 0x3C, 0x34, 0x30, 0x78, 0X00, // F
WiredHome 29:422616aa04bd 97 0x1E, 0x33, 0x60, 0x60, 0x67, 0x33, 0x1F, 0X00, // G
WiredHome 29:422616aa04bd 98 0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0X00, // H
WiredHome 29:422616aa04bd 99 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0X00, // I
WiredHome 29:422616aa04bd 100 0x0F, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3C, 0X00, // J
WiredHome 29:422616aa04bd 101 0x73, 0x33, 0x36, 0x3C, 0x36, 0x33, 0x73, 0X00, // K
WiredHome 29:422616aa04bd 102 0x78, 0x30, 0x30, 0x30, 0x31, 0x33, 0x7F, 0X00, // L
WiredHome 29:422616aa04bd 103 0x63, 0x77, 0x7F, 0x7F, 0x6B, 0x63, 0x63, 0X00, // M
WiredHome 29:422616aa04bd 104 0x63, 0x73, 0x7B, 0x6F, 0x67, 0x63, 0x63, 0X00, // N
WiredHome 29:422616aa04bd 105 0x3E, 0x63, 0x63, 0x63, 0x63, 0x63, 0x3E, 0X00, // O
WiredHome 29:422616aa04bd 106 0x7E, 0x33, 0x33, 0x3E, 0x30, 0x30, 0x78, 0X00, // P 0x50
WiredHome 29:422616aa04bd 107 0x3C, 0x66, 0x66, 0x66, 0x6E, 0x3C, 0x0E, 0X00, // Q
WiredHome 29:422616aa04bd 108 0x7E, 0x33, 0x33, 0x3E, 0x36, 0x33, 0x73, 0X00, // R
WiredHome 29:422616aa04bd 109 0x3C, 0x66, 0x30, 0x18, 0x0C, 0x66, 0x3C, 0X00, // S
WiredHome 29:422616aa04bd 110 0x7E, 0x5A, 0x18, 0x18, 0x18, 0x18, 0x3C, 0X00, // T
WiredHome 29:422616aa04bd 111 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0X00, // U
WiredHome 29:422616aa04bd 112 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0X00, // V
WiredHome 29:422616aa04bd 113 0x63, 0x63, 0x63, 0x6B, 0x7F, 0x77, 0x63, 0X00, // W
WiredHome 29:422616aa04bd 114 0x63, 0x63, 0x36, 0x1C, 0x1C, 0x36, 0x63, 0X00, // X
WiredHome 29:422616aa04bd 115 0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x3C, 0X00, // Y
WiredHome 29:422616aa04bd 116 0x7F, 0x63, 0x46, 0x0C, 0x19, 0x33, 0x7F, 0X00, // Z
WiredHome 29:422616aa04bd 117 0x3C, 0x30, 0x30, 0x30, 0x30, 0x30, 0x3C, 0X00, // [
WiredHome 29:422616aa04bd 118 0x60, 0x30, 0x18, 0x0C, 0x06, 0x03, 0x01, 0X00, // \ (back slash)
WiredHome 29:422616aa04bd 119 0x3C, 0x0C, 0x0C, 0x0C, 0x0C, 0x0C, 0x3C, 0X00, // ]
WiredHome 29:422616aa04bd 120 0x08, 0x1C, 0x36, 0x63, 0X00, 0X00, 0X00, 0X00, // ^
WiredHome 29:422616aa04bd 121 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0xFF, // _
WiredHome 29:422616aa04bd 122 0x18, 0x18, 0x0C, 0X00, 0X00, 0X00, 0X00, 0X00, // ` 0x60
WiredHome 29:422616aa04bd 123 0X00, 0X00, 0x3C, 0x06, 0x3E, 0x66, 0x3B, 0X00, // a
WiredHome 29:422616aa04bd 124 0x70, 0x30, 0x3E, 0x33, 0x33, 0x33, 0x6E, 0X00, // b
WiredHome 29:422616aa04bd 125 0X00, 0X00, 0x3C, 0x66, 0x60, 0x66, 0x3C, 0X00, // c
WiredHome 29:422616aa04bd 126 0x0E, 0x06, 0x3E, 0x66, 0x66, 0x66, 0x3B, 0X00, // d
WiredHome 29:422616aa04bd 127 0X00, 0X00, 0x3C, 0x66, 0x7E, 0x60, 0x3C, 0X00, // e
WiredHome 29:422616aa04bd 128 0x1C, 0x36, 0x30, 0x78, 0x30, 0x30, 0x78, 0X00, // f
WiredHome 29:422616aa04bd 129 0X00, 0X00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x7C, // g
WiredHome 29:422616aa04bd 130 0x70, 0x30, 0x36, 0x3B, 0x33, 0x33, 0x73, 0X00, // h
WiredHome 29:422616aa04bd 131 0x18, 0X00, 0x38, 0x18, 0x18, 0x18, 0x3C, 0X00, // i
WiredHome 29:422616aa04bd 132 0x06, 0X00, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3C, // j
WiredHome 29:422616aa04bd 133 0x70, 0x30, 0x33, 0x36, 0x3C, 0x36, 0x73, 0X00, // k
WiredHome 29:422616aa04bd 134 0x38, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, 0X00, // l
WiredHome 29:422616aa04bd 135 0X00, 0X00, 0x66, 0x7F, 0x7F, 0x6B, 0x63, 0X00, // m
WiredHome 29:422616aa04bd 136 0X00, 0X00, 0x7C, 0x66, 0x66, 0x66, 0x66, 0X00, // n
WiredHome 29:422616aa04bd 137 0X00, 0X00, 0x3C, 0x66, 0x66, 0x66, 0x3C, 0X00, // o
WiredHome 29:422616aa04bd 138 0X00, 0X00, 0x6E, 0x33, 0x33, 0x3E, 0x30, 0x78, // p
WiredHome 29:422616aa04bd 139 0X00, 0X00, 0x3B, 0x66, 0x66, 0x3E, 0x06, 0x0F, // q
WiredHome 29:422616aa04bd 140 0X00, 0X00, 0x6E, 0x3B, 0x33, 0x30, 0x78, 0X00, // r
WiredHome 29:422616aa04bd 141 0X00, 0X00, 0x3E, 0x60, 0x3C, 0x06, 0x7C, 0X00, // s
WiredHome 29:422616aa04bd 142 0x08, 0x18, 0x3E, 0x18, 0x18, 0x1A, 0x0C, 0X00, // t
WiredHome 29:422616aa04bd 143 0X00, 0X00, 0x66, 0x66, 0x66, 0x66, 0x3B, 0X00, // u
WiredHome 29:422616aa04bd 144 0X00, 0X00, 0x66, 0x66, 0x66, 0x3C, 0x18, 0X00, // v
WiredHome 29:422616aa04bd 145 0X00, 0X00, 0x63, 0x6B, 0x7F, 0x7F, 0x36, 0X00, // w
WiredHome 29:422616aa04bd 146 0X00, 0X00, 0x63, 0x36, 0x1C, 0x36, 0x63, 0X00, // x
WiredHome 29:422616aa04bd 147 0X00, 0X00, 0x66, 0x66, 0x66, 0x3E, 0x06, 0x7C, // y
WiredHome 29:422616aa04bd 148 0X00, 0X00, 0x7E, 0x4C, 0x18, 0x32, 0x7E, 0X00, // z
WiredHome 29:422616aa04bd 149 0x0E, 0x18, 0x18, 0x70, 0x18, 0x18, 0x0E, 0X00, // {
WiredHome 29:422616aa04bd 150 0x0C, 0x0C, 0x0C, 0X00, 0x0C, 0x0C, 0x0C, 0X00, // |
WiredHome 29:422616aa04bd 151 0x70, 0x18, 0x18, 0x0E, 0x18, 0x18, 0x70, 0X00, // }
WiredHome 29:422616aa04bd 152 0x3B, 0x6E, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, // ~
WiredHome 29:422616aa04bd 153 0x1C, 0x36, 0x36, 0x1C, 0X00, 0X00, 0X00, 0X00 // DEL
WiredHome 23:a50ded45dbaf 154 };
WiredHome 29:422616aa04bd 155 #endif // LOCALFONT
WiredHome 19:3f82c1161fd2 156
WiredHome 29:422616aa04bd 157 GraphicsDisplay::GraphicsDisplay(const char *name)
WiredHome 29:422616aa04bd 158 : TextDisplay(name)
WiredHome 19:3f82c1161fd2 159 {
WiredHome 29:422616aa04bd 160 font = NULL;
WiredHome 19:3f82c1161fd2 161 //foreground(0xFFFF);
WiredHome 19:3f82c1161fd2 162 //background(0x0000);
dreschpe 0:de9d1462a835 163 }
WiredHome 19:3f82c1161fd2 164
WiredHome 29:422616aa04bd 165 RetCode_t GraphicsDisplay::set_font(const unsigned char * _font)
WiredHome 19:3f82c1161fd2 166 {
WiredHome 29:422616aa04bd 167 font = _font;
WiredHome 29:422616aa04bd 168 INFO("set_font(%lu) %lu", _font, font);
WiredHome 29:422616aa04bd 169 return noerror; // trusting them, but it might be good to put some checks in here...
dreschpe 0:de9d1462a835 170 }
dreschpe 0:de9d1462a835 171
WiredHome 29:422616aa04bd 172 #ifdef LOCALFONT
WiredHome 29:422616aa04bd 173 int GraphicsDisplay::character(int x, int y, int value)
WiredHome 29:422616aa04bd 174 {
WiredHome 29:422616aa04bd 175 INFO("character(%d,%d,%c)", x, t, value);
WiredHome 29:422616aa04bd 176 if (value <= 0x1F && value >= 7F)
WiredHome 29:422616aa04bd 177 return 0;
WiredHome 29:422616aa04bd 178
WiredHome 29:422616aa04bd 179 return blitbit(x, y, FONT8X8[0][0], FONT8X8[0][1],
WiredHome 29:422616aa04bd 180 (char *)&(FONT8x8[value - 0x1F][0]));
WiredHome 29:422616aa04bd 181 }
WiredHome 29:422616aa04bd 182 #else
WiredHome 29:422616aa04bd 183 int GraphicsDisplay::character(int x, int y, int c)
WiredHome 29:422616aa04bd 184 {
WiredHome 29:422616aa04bd 185 unsigned int offset;
WiredHome 29:422616aa04bd 186 const unsigned char * charRecord;
WiredHome 29:422616aa04bd 187
WiredHome 29:422616aa04bd 188 if (c <= 0x1F || c >= 0x7F)
WiredHome 29:422616aa04bd 189 return 0;
WiredHome 29:422616aa04bd 190 offset = font[0]; // bytes / char
WiredHome 29:422616aa04bd 191 charRecord = &font[((c - ' ') * offset) + 4]; // start of char bitmap
WiredHome 29:422616aa04bd 192 return fontblit(x, y, font, charRecord);
WiredHome 29:422616aa04bd 193 }
WiredHome 29:422616aa04bd 194 #endif
WiredHome 19:3f82c1161fd2 195
WiredHome 32:0e4f2ae512e2 196 RetCode_t GraphicsDisplay::window(unsigned int x, unsigned int y, unsigned int w, unsigned int h)
WiredHome 19:3f82c1161fd2 197 {
dreschpe 0:de9d1462a835 198 // current pixel location
dreschpe 0:de9d1462a835 199 _x = x;
dreschpe 0:de9d1462a835 200 _y = y;
dreschpe 0:de9d1462a835 201 // window settings
dreschpe 0:de9d1462a835 202 _x1 = x;
dreschpe 0:de9d1462a835 203 _x2 = x + w - 1;
dreschpe 0:de9d1462a835 204 _y1 = y;
dreschpe 0:de9d1462a835 205 _y2 = y + h - 1;
WiredHome 32:0e4f2ae512e2 206 return noerror;
dreschpe 0:de9d1462a835 207 }
WiredHome 19:3f82c1161fd2 208
WiredHome 31:c72e12cd5c67 209 void GraphicsDisplay::WindowMax(void)
WiredHome 31:c72e12cd5c67 210 {
WiredHome 31:c72e12cd5c67 211 window(0,0, width(),height());
WiredHome 31:c72e12cd5c67 212 }
WiredHome 31:c72e12cd5c67 213
WiredHome 33:b6b710758ab3 214 RetCode_t GraphicsDisplay::putp(color_t color)
WiredHome 19:3f82c1161fd2 215 {
dreschpe 0:de9d1462a835 216 // put pixel at current pixel location
WiredHome 33:b6b710758ab3 217 pixel(_x, _y, color);
dreschpe 0:de9d1462a835 218 // update pixel location based on window settings
dreschpe 0:de9d1462a835 219 _x++;
dreschpe 0:de9d1462a835 220 if(_x > _x2) {
dreschpe 0:de9d1462a835 221 _x = _x1;
dreschpe 0:de9d1462a835 222 _y++;
dreschpe 0:de9d1462a835 223 if(_y > _y2) {
dreschpe 0:de9d1462a835 224 _y = _y1;
dreschpe 0:de9d1462a835 225 }
dreschpe 0:de9d1462a835 226 }
WiredHome 32:0e4f2ae512e2 227 return noerror;
dreschpe 0:de9d1462a835 228 }
dreschpe 0:de9d1462a835 229
WiredHome 33:b6b710758ab3 230 void GraphicsDisplay::fill(int x, int y, int w, int h, color_t color)
WiredHome 19:3f82c1161fd2 231 {
WiredHome 32:0e4f2ae512e2 232 #ifdef USE_HW
WiredHome 33:b6b710758ab3 233 fillrect(x,y, x+w, y+h, color);
WiredHome 32:0e4f2ae512e2 234 #else
dreschpe 0:de9d1462a835 235 window(x, y, w, h);
dreschpe 0:de9d1462a835 236 for(int i=0; i<w*h; i++) {
WiredHome 33:b6b710758ab3 237 putp(color);
dreschpe 0:de9d1462a835 238 }
WiredHome 32:0e4f2ae512e2 239 #endif
dreschpe 0:de9d1462a835 240 }
WiredHome 19:3f82c1161fd2 241
WiredHome 19:3f82c1161fd2 242 RetCode_t GraphicsDisplay::cls()
WiredHome 19:3f82c1161fd2 243 {
dreschpe 0:de9d1462a835 244 fill(0, 0, width(), height(), _background);
WiredHome 19:3f82c1161fd2 245 return noerror;
dreschpe 0:de9d1462a835 246 }
WiredHome 19:3f82c1161fd2 247
WiredHome 33:b6b710758ab3 248 void GraphicsDisplay::blit(int x, int y, int w, int h, const int * color)
WiredHome 19:3f82c1161fd2 249 {
dreschpe 0:de9d1462a835 250 window(x, y, w, h);
WiredHome 31:c72e12cd5c67 251 for (int i=0; i<w*h; i++) {
WiredHome 33:b6b710758ab3 252 putp(color[i]);
dreschpe 0:de9d1462a835 253 }
dreschpe 0:de9d1462a835 254 }
WiredHome 19:3f82c1161fd2 255
WiredHome 33:b6b710758ab3 256 int GraphicsDisplay::blitbit(int x, int y, int w, int h, const char * color)
WiredHome 19:3f82c1161fd2 257 {
WiredHome 29:422616aa04bd 258 _foreground = 0xFFFF;
WiredHome 33:b6b710758ab3 259 INFO("blitbit(%d,%d, %d,%d, %02X) [%04X,%04X]", x,y, w,h, *color, _foreground, _background);
WiredHome 29:422616aa04bd 260 INFO("%lu %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X",
WiredHome 33:b6b710758ab3 261 color,
WiredHome 33:b6b710758ab3 262 color[0], color[1], color[2], color[3], color[4], color[5], color[6], color[7],
WiredHome 33:b6b710758ab3 263 color[8], color[9], color[10], color[11], color[12], color[13], color[14], color[15]);
dreschpe 0:de9d1462a835 264 window(x, y, w, h);
WiredHome 29:422616aa04bd 265 for (int i = 0; i < w*h; i++) {
WiredHome 33:b6b710758ab3 266 char byte = color[i >> 3];
dreschpe 0:de9d1462a835 267 int offset = i & 0x7;
WiredHome 29:422616aa04bd 268 if (offset == 0)
WiredHome 29:422616aa04bd 269 INFO(" %2d = %02X", i>>3, byte);
dreschpe 0:de9d1462a835 270 int c = ((byte << offset) & 0x80) ? _foreground : _background;
dreschpe 0:de9d1462a835 271 putp(c);
dreschpe 0:de9d1462a835 272 }
WiredHome 29:422616aa04bd 273 return w;
WiredHome 29:422616aa04bd 274 }
WiredHome 29:422616aa04bd 275
WiredHome 29:422616aa04bd 276
WiredHome 29:422616aa04bd 277 int GraphicsDisplay::fontblit(int x, int y, const unsigned char * fontTable, const unsigned char * fontChar)
WiredHome 29:422616aa04bd 278 {
WiredHome 19:3f82c1161fd2 279 _foreground = 0xFFFF;
WiredHome 29:422616aa04bd 280 //int fontWidth = font[1]; // get hor size of font
WiredHome 29:422616aa04bd 281 int fontHeight = font[2]; // get vert size of font
WiredHome 29:422616aa04bd 282 int bytesPerLine = font[3]; // bytes per line
WiredHome 29:422616aa04bd 283 int charWidth = fontChar[0]; // width of this character
WiredHome 29:422616aa04bd 284 int px, py;
WiredHome 29:422616aa04bd 285 window(x, y, charWidth, fontHeight);
WiredHome 29:422616aa04bd 286
WiredHome 29:422616aa04bd 287 for (py = 0; py < fontHeight; py++) {
WiredHome 29:422616aa04bd 288 int bitmask = 1 << (py & 7);
WiredHome 29:422616aa04bd 289
WiredHome 29:422616aa04bd 290 for (px = 0; px < charWidth; px++) {
WiredHome 29:422616aa04bd 291 int offset = (py / 8) + px * bytesPerLine;
WiredHome 29:422616aa04bd 292 unsigned char byte = fontChar[offset + 1]; // skip the char's # bits wide value
WiredHome 29:422616aa04bd 293 int c = (byte & bitmask) ? _foreground : _background;
WiredHome 29:422616aa04bd 294 putp(c);
WiredHome 29:422616aa04bd 295 }
WiredHome 29:422616aa04bd 296 }
WiredHome 29:422616aa04bd 297 return charWidth;
dreschpe 0:de9d1462a835 298 }
dreschpe 0:de9d1462a835 299
WiredHome 31:c72e12cd5c67 300 // BMP Color Palette is BGRx
WiredHome 31:c72e12cd5c67 301 // BBBB BBBB GGGG GGGG RRRR RRRR 0000 0000
WiredHome 31:c72e12cd5c67 302 // RGB16 is
WiredHome 31:c72e12cd5c67 303 // RRRR RGGG GGGB BBBB
WiredHome 31:c72e12cd5c67 304 // swap to little endian
WiredHome 31:c72e12cd5c67 305 // GGGB BBBB RRRR RGGG
WiredHome 32:0e4f2ae512e2 306 color_t GraphicsDisplay::RGBQuadToRGB16(RGBQUAD * colorPalette, uint16_t i)
WiredHome 31:c72e12cd5c67 307 {
WiredHome 31:c72e12cd5c67 308 color_t c;
WiredHome 31:c72e12cd5c67 309
WiredHome 31:c72e12cd5c67 310 c = ((colorPalette[i].rgbBlue >> 3) << 0);
WiredHome 31:c72e12cd5c67 311 c |= ((colorPalette[i].rgbGreen >> 2) << 5);
WiredHome 31:c72e12cd5c67 312 c |= ((colorPalette[i].rgbRed >> 3) << 11);
WiredHome 31:c72e12cd5c67 313 c = (c >> 8) | (c << 8);
WiredHome 31:c72e12cd5c67 314 //INFO("B %02X G %02X R %02X c %04X", colorPalette[i].rgbBlue, colorPalette[i].rgbGreen,
WiredHome 31:c72e12cd5c67 315 // colorPalette[i].rgbRed, c);
WiredHome 31:c72e12cd5c67 316 return c;
WiredHome 31:c72e12cd5c67 317 }
WiredHome 29:422616aa04bd 318
WiredHome 29:422616aa04bd 319
WiredHome 32:0e4f2ae512e2 320 RetCode_t GraphicsDisplay::RenderBitmapFile(unsigned int x, unsigned int y, const char *Name_BMP)
WiredHome 31:c72e12cd5c67 321 {
WiredHome 31:c72e12cd5c67 322 #define OffsetPixelWidth 18
WiredHome 31:c72e12cd5c67 323 #define OffsetPixelHeight 22
WiredHome 31:c72e12cd5c67 324 #define OffsetFileSize 34
WiredHome 31:c72e12cd5c67 325 #define OffsetPixData 10
WiredHome 31:c72e12cd5c67 326 #define OffsetBPP 28
WiredHome 31:c72e12cd5c67 327
WiredHome 31:c72e12cd5c67 328 BITMAPFILEHEADER BMP_Header;
WiredHome 31:c72e12cd5c67 329 BITMAPINFOHEADER BMP_Info;
WiredHome 31:c72e12cd5c67 330 RGBQUAD * colorPalette = NULL;
WiredHome 31:c72e12cd5c67 331 int colorCount;
WiredHome 32:0e4f2ae512e2 332 uint8_t * lineBuffer = NULL;
WiredHome 31:c72e12cd5c67 333
WiredHome 31:c72e12cd5c67 334 uint16_t BPP_t;
WiredHome 31:c72e12cd5c67 335 uint32_t PixelWidth, PixelHeight;
WiredHome 31:c72e12cd5c67 336 uint32_t start_data;
WiredHome 31:c72e12cd5c67 337 unsigned int i, offset;
WiredHome 31:c72e12cd5c67 338 int padd,j;
WiredHome 31:c72e12cd5c67 339
WiredHome 32:0e4f2ae512e2 340 INFO("Opening {%s}", Name_BMP);
WiredHome 32:0e4f2ae512e2 341 FILE *Image = fopen(Name_BMP, "rb");
WiredHome 31:c72e12cd5c67 342 if (!Image) {
WiredHome 31:c72e12cd5c67 343 return(file_not_found);
WiredHome 31:c72e12cd5c67 344 }
WiredHome 31:c72e12cd5c67 345
WiredHome 31:c72e12cd5c67 346 fread(&BMP_Header, 1, sizeof(BMP_Header), Image); // get the BMP Header
WiredHome 31:c72e12cd5c67 347 INFO("bfType %04X", BMP_Header.bfType);
WiredHome 31:c72e12cd5c67 348 //HexDump("BMP_Header", (uint8_t *)&BMP_Header, sizeof(BMP_Header));
WiredHome 32:0e4f2ae512e2 349 if (BMP_Header.bfType != BF_TYPE) {
WiredHome 31:c72e12cd5c67 350 fclose(Image);
WiredHome 32:0e4f2ae512e2 351 return(not_bmp_format);
WiredHome 31:c72e12cd5c67 352 }
WiredHome 31:c72e12cd5c67 353
WiredHome 31:c72e12cd5c67 354 fread(&BMP_Info, 1, sizeof(BMP_Info), Image);
WiredHome 31:c72e12cd5c67 355 //HexDump("BMP_Info", (uint8_t *)&BMP_Info, sizeof(BMP_Info));
WiredHome 31:c72e12cd5c67 356 BPP_t = BMP_Info.biBitCount;
WiredHome 31:c72e12cd5c67 357 INFO("biBitCount %04X", BPP_t);
WiredHome 32:0e4f2ae512e2 358 if (BPP_t != 4 && BPP_t != 8 && BPP_t != 16 && BPP_t != 24) { // Support 4, 8, 16, 24-bits per pixel
WiredHome 31:c72e12cd5c67 359 fclose(Image);
WiredHome 31:c72e12cd5c67 360 return(not_supported_format);
WiredHome 31:c72e12cd5c67 361 }
WiredHome 31:c72e12cd5c67 362
WiredHome 31:c72e12cd5c67 363 PixelHeight = BMP_Info.biHeight;
WiredHome 31:c72e12cd5c67 364 PixelWidth = BMP_Info.biWidth;
WiredHome 31:c72e12cd5c67 365 if (PixelHeight > height() + y || PixelWidth > width() + x) {
WiredHome 31:c72e12cd5c67 366 fclose(Image);
WiredHome 31:c72e12cd5c67 367 return(image_too_big);
WiredHome 31:c72e12cd5c67 368 }
WiredHome 31:c72e12cd5c67 369 INFO("(%d,%d) (%d,%d)", x,y, PixelWidth,PixelHeight);
WiredHome 31:c72e12cd5c67 370 if (BMP_Info.biBitCount <= 8) {
WiredHome 31:c72e12cd5c67 371 int paletteSize;
WiredHome 31:c72e12cd5c67 372 // Read the color palette
WiredHome 31:c72e12cd5c67 373 colorCount = 1 << BMP_Info.biBitCount;
WiredHome 31:c72e12cd5c67 374 paletteSize = sizeof(RGBQUAD) * colorCount;
WiredHome 31:c72e12cd5c67 375 colorPalette = (RGBQUAD *)malloc(paletteSize);
WiredHome 31:c72e12cd5c67 376 if (colorPalette == NULL) {
WiredHome 31:c72e12cd5c67 377 fclose(Image);
WiredHome 31:c72e12cd5c67 378 return(not_enough_ram);
WiredHome 31:c72e12cd5c67 379 }
WiredHome 31:c72e12cd5c67 380 fread(colorPalette, 1, paletteSize, Image);
WiredHome 32:0e4f2ae512e2 381 //HexDump("Color Palette", (uint8_t *)colorPalette, paletteSize);
WiredHome 31:c72e12cd5c67 382 }
WiredHome 31:c72e12cd5c67 383
WiredHome 32:0e4f2ae512e2 384 int lineBufSize = ((BPP_t * PixelWidth + 7)/8);
WiredHome 32:0e4f2ae512e2 385 //INFO("BPP_t %d, PixelWidth %d, lineBufSize %d", BPP_t, PixelWidth, lineBufSize);
WiredHome 32:0e4f2ae512e2 386 lineBuffer = (uint8_t *)malloc(lineBufSize);
WiredHome 31:c72e12cd5c67 387 if (lineBuffer == NULL) {
WiredHome 31:c72e12cd5c67 388 free(colorPalette);
WiredHome 31:c72e12cd5c67 389 fclose(Image);
WiredHome 31:c72e12cd5c67 390 return(not_enough_ram);
WiredHome 31:c72e12cd5c67 391 }
WiredHome 31:c72e12cd5c67 392
WiredHome 32:0e4f2ae512e2 393 // the Raw Data records are padded to a multiple of 4 bytes
WiredHome 32:0e4f2ae512e2 394 int recordSize = 2;
WiredHome 32:0e4f2ae512e2 395 if (BPP_t == 4) {
WiredHome 32:0e4f2ae512e2 396 recordSize = 1;
WiredHome 32:0e4f2ae512e2 397 } else if (BPP_t == 8) {
WiredHome 32:0e4f2ae512e2 398 recordSize = 1;
WiredHome 32:0e4f2ae512e2 399 } else if (BPP_t == 16) {
WiredHome 32:0e4f2ae512e2 400 recordSize = 2;
WiredHome 32:0e4f2ae512e2 401 } else if (BPP_t == 24) {
WiredHome 32:0e4f2ae512e2 402 recordSize = 3;
WiredHome 32:0e4f2ae512e2 403 }
WiredHome 31:c72e12cd5c67 404 padd = -1;
WiredHome 31:c72e12cd5c67 405 do {
WiredHome 31:c72e12cd5c67 406 padd++;
WiredHome 32:0e4f2ae512e2 407 } while ((PixelWidth * recordSize + padd) % 4 != 0);
WiredHome 31:c72e12cd5c67 408
WiredHome 32:0e4f2ae512e2 409 // Define window for top to bottom and left to right so writing auto-wraps
WiredHome 31:c72e12cd5c67 410 window(x,y, PixelWidth,PixelHeight);
WiredHome 32:0e4f2ae512e2 411 SetGraphicsCursor(x, y);
WiredHome 32:0e4f2ae512e2 412 _StartGraphicsStream();
WiredHome 32:0e4f2ae512e2 413
WiredHome 32:0e4f2ae512e2 414 start_data = BMP_Header.bfOffBits;
WiredHome 32:0e4f2ae512e2 415 HexDump("Raw Data", (uint8_t *)&start_data, 32);
WiredHome 32:0e4f2ae512e2 416 //bool tag = true;
WiredHome 32:0e4f2ae512e2 417 //INFO("(%d,%d) (%d,%d), [%d,%d]", x,y, PixelWidth,PixelHeight, lineBufSize, padd);
WiredHome 32:0e4f2ae512e2 418 for (j = PixelHeight - 1; j >= 0; j--) { //Lines bottom up
WiredHome 32:0e4f2ae512e2 419 offset = start_data + j * (lineBufSize + padd); // start of line
WiredHome 31:c72e12cd5c67 420 fseek(Image, offset, SEEK_SET);
WiredHome 32:0e4f2ae512e2 421 fread(lineBuffer, 1, lineBufSize, Image); // read a line - slow !
WiredHome 32:0e4f2ae512e2 422 //INFO("offset: %6X", offset);
WiredHome 32:0e4f2ae512e2 423 //if (tag)
WiredHome 32:0e4f2ae512e2 424 // HexDump("Line", (uint8_t *)lineBuffer, lineBufSize);
WiredHome 32:0e4f2ae512e2 425 for (i = 0; i < PixelWidth; i++) { // copy pixel data to TFT
WiredHome 31:c72e12cd5c67 426 if (BPP_t == 4) {
WiredHome 31:c72e12cd5c67 427 uint8_t dPix = lineBuffer[i/2];
WiredHome 31:c72e12cd5c67 428 if ((i & 1) == 0)
WiredHome 31:c72e12cd5c67 429 dPix >>= 4;
WiredHome 31:c72e12cd5c67 430 dPix &= 0x0F;
WiredHome 32:0e4f2ae512e2 431 putp(RGBQuadToRGB16(colorPalette, dPix));
WiredHome 31:c72e12cd5c67 432 } else if (BPP_t == 8) {
WiredHome 32:0e4f2ae512e2 433 putp(RGBQuadToRGB16(colorPalette, lineBuffer[i]));
WiredHome 32:0e4f2ae512e2 434 } else if (BPP_t == 16) {
WiredHome 32:0e4f2ae512e2 435 putp(lineBuffer[i]);
WiredHome 32:0e4f2ae512e2 436 } else if (BPP_t == 24) {
WiredHome 32:0e4f2ae512e2 437 color_t color; // BGR
WiredHome 32:0e4f2ae512e2 438 color = RGB(lineBuffer[i*3+2], lineBuffer[i*3+1], lineBuffer[i*3+0]);
WiredHome 32:0e4f2ae512e2 439 //if (tag)
WiredHome 32:0e4f2ae512e2 440 // INFO("color[%2d]: RGB(%02X,%02X,%02X) => %04X",
WiredHome 32:0e4f2ae512e2 441 // i, lineBuffer[i*2], lineBuffer[i*3+1], lineBuffer[i*3+0], color);
WiredHome 32:0e4f2ae512e2 442 color = (color >> 8) | (color << 8);
WiredHome 31:c72e12cd5c67 443 putp(color);
WiredHome 31:c72e12cd5c67 444 }
WiredHome 31:c72e12cd5c67 445 }
WiredHome 32:0e4f2ae512e2 446 //tag = false;
WiredHome 31:c72e12cd5c67 447 }
WiredHome 31:c72e12cd5c67 448 free(lineBuffer);
WiredHome 31:c72e12cd5c67 449 free(colorPalette);
WiredHome 31:c72e12cd5c67 450 fclose(Image);
WiredHome 32:0e4f2ae512e2 451 _EndGraphicsStream();
WiredHome 31:c72e12cd5c67 452 WindowMax();
WiredHome 32:0e4f2ae512e2 453 return (noerror);
WiredHome 31:c72e12cd5c67 454 }
WiredHome 31:c72e12cd5c67 455
WiredHome 19:3f82c1161fd2 456 int GraphicsDisplay::columns()
WiredHome 19:3f82c1161fd2 457 {
WiredHome 19:3f82c1161fd2 458 return width() / 8;
dreschpe 0:de9d1462a835 459 }
dreschpe 0:de9d1462a835 460
WiredHome 19:3f82c1161fd2 461 int GraphicsDisplay::rows()
WiredHome 19:3f82c1161fd2 462 {
WiredHome 19:3f82c1161fd2 463 return height() / 8;
WiredHome 19:3f82c1161fd2 464 }
WiredHome 19:3f82c1161fd2 465
WiredHome 32:0e4f2ae512e2 466