6 display.drawLine(display.width() * 0.5, 0, display.width() * 0.5, display.height(),
GxEPD_BLACK);
8 display.drawLine(display.width() * 0.25, 0, display.width() * 0.25, display.height(),
GxEPD_BLACK);
10 display.drawLine(display.width() * 0.75, 0, display.width() * 0.75, display.height(),
GxEPD_BLACK);
13 display.drawLine(0, display.height() * 0.5, display.width(), display.height() * 0.5,
GxEPD_BLACK);
15 display.drawLine(0, display.height() * 0.25, display.width(), display.height() * 0.25,
GxEPD_BLACK);
17 display.drawLine(0, display.height() * 0.75, display.width(), display.height() * 0.75,
GxEPD_BLACK);
24 uint16_t wt, ht, prev_height = y, prev_width = x;
26 display.setFont(
font);
27 display.setTextColor(color);
28 display.setTextSize(size);
30 display.getTextBounds(
string, 0, 0, &xt, &yt, &wt, &ht);
33 display.setCursor(prev_width, prev_height + ht);
35 display.setCursor(prev_width + ((w - wt) / 2), prev_height + ((h - ht) / 2));
37 display.print(
string);
75 uint32_t startTime = millis();
77 if ((x >= display.width()) || (y >= display.height()))
return;
80 DEBUG.print(
"Loading image '");
81 DEBUG.print(filename);
84 file = fs.open(String(
"/") + filename, FILE_READ);
86 DEBUG.print(
"File not found");
91 if (
read16(file) == 0x4D42) {
92 uint32_t fileSize =
read32(file);
93 uint32_t creatorBytes =
read32(file);
94 uint32_t imageOffset =
read32(file);
95 uint32_t headerSize =
read32(file);
96 uint32_t width =
read32(file);
97 uint32_t height =
read32(file);
98 uint16_t planes =
read16(file);
99 uint16_t depth =
read16(file);
100 uint32_t format =
read32(file);
101 if ((planes == 1) && ((format == 0) || (format == 3))) {
102 DEBUG.print(
"File size: ");
DEBUG.println(fileSize);
103 DEBUG.print(
"Image Offset: ");
DEBUG.println(imageOffset);
104 DEBUG.print(
"Header size: ");
DEBUG.println(headerSize);
105 DEBUG.print(
"Bit Depth: ");
DEBUG.println(depth);
106 DEBUG.print(
"Image size: ");
109 DEBUG.println(height);
111 uint32_t rowSize = (width * depth / 8 + 3) & ~3;
112 if (depth < 8) rowSize = ((width * depth + 8 - depth) / 8 + 3) & ~3;
119 if ((x + w - 1) >= display.width()) w = display.width() - x;
120 if ((y + h - 1) >= display.height()) h = display.height() - y;
122 uint8_t bitmask = 0xFF;
123 uint8_t bitshift = 8 - depth;
124 uint16_t red, green, blue;
125 bool whitish, colored;
126 if (depth == 1) with_color =
false;
128 if (depth < 8) bitmask >>= depth;
130 for (uint16_t pn = 0; pn < (1 << depth); pn++) {
135 whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80);
136 colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0));
137 if (0 == pn % 8) mono_palette_buffer[pn / 8] = 0;
138 mono_palette_buffer[pn / 8] |= whitish << pn % 8;
139 if (0 == pn % 8) color_palette_buffer[pn / 8] = 0;
140 color_palette_buffer[pn / 8] |= colored << pn % 8;
144 uint32_t rowPosition = flip ? imageOffset + (height - h) * rowSize : imageOffset;
145 for (uint16_t row = 0; row < h; row++, rowPosition += rowSize) {
146 uint32_t in_remain = rowSize;
148 uint32_t in_bytes = 0;
152 file.seekSet(rowPosition);
153 for (uint16_t col = 0; col < w; col++) {
155 if (in_idx >= in_bytes) {
156 in_bytes = file.read(input_buffer, in_remain >
sizeof(input_buffer) ?
sizeof(input_buffer) : in_remain);
157 in_remain -= in_bytes;
162 blue = input_buffer[in_idx++];
163 green = input_buffer[in_idx++];
164 red = input_buffer[in_idx++];
165 whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80);
166 colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0));
170 uint8_t lsb = input_buffer[in_idx++];
171 uint8_t msb = input_buffer[in_idx++];
173 blue = (lsb & 0x1F) << 3;
174 green = ((msb & 0x03) << 6) | ((lsb & 0xE0) >> 2);
175 red = (msb & 0x7C) << 1;
177 blue = (lsb & 0x1F) << 3;
178 green = ((msb & 0x07) << 5) | ((lsb & 0xE0) >> 3);
181 whitish = with_color ? ((red > 0x80) && (green > 0x80) && (blue > 0x80)) : ((red + green + blue) > 3 * 0x80);
182 colored = (red > 0xF0) || ((green > 0xF0) && (blue > 0xF0));
190 in_byte = input_buffer[in_idx++];
193 uint16_t pn = (in_byte >> bitshift) & bitmask;
194 whitish = mono_palette_buffer[pn / 8] & (0x1 << pn % 8);
195 colored = color_palette_buffer[pn / 8] & (0x1 << pn % 8);
203 else if (colored && with_color)
207 uint16_t yrow = y + (flip ? h - row - 1 : row);
208 display.drawPixel(x + col, yrow, color);
211 DEBUG.print(
"loaded in ");
DEBUG.print(millis() - startTime);
DEBUG.println(
" ms");
216 DEBUG.println(
"bitmap format not handled.");
void display_text_center(GxEPD2_GFX &display, int16_t x, int16_t y, const char *string, int16_t w=0, int16_t h=0, const GFXfont *font=&PAPERDINK_FONT_SML, uint16_t color=GxEPD_BLACK, uint8_t size=1)