LCD LIB

Dependents:   HagridOS5

Fork of RA8875 by David Smart

Committer:
WiredHome
Date:
Sat Feb 08 17:35:45 2014 +0000
Revision:
41:2956a0a221e5
Parent:
40:04aa280dfa39
Child:
42:7cbdfd2bbfc5
Added PrintScreen method, to capture the current image to a file system.; Improved performance of pixel streaming (rendering a bitmap and capturing a bitmap).; Ran performance checks, then disabled debug and the performance information.

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