Formatting.

This commit is contained in:
Jonas Diemer 2025-12-18 13:43:47 +01:00
parent 13fc5f7bbb
commit 5c22342dcc

View File

@ -9,8 +9,7 @@
#include "config.h" #include "config.h"
#include "images/CrossLarge.h" #include "images/CrossLarge.h"
void convertBmpToBWdisplayData(uint8_t* bmpData, void convertBmpToBWdisplayData(uint8_t* bmpData, int width, int height, uint8_t* displayImage) {
int width, int height, uint8_t* displayImage){
// Convert BMP data to 1bpp format for e-ink display // Convert BMP data to 1bpp format for e-ink display
// Implementation details depend on the specific BMP format and display requirements // Implementation details depend on the specific BMP format and display requirements
@ -26,7 +25,7 @@ void convertBmpToBWdisplayData(uint8_t* bmpData,
// Process each source row // Process each source row
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
// Calculate source row (BMPs are normally stored bottom-to-top) // Calculate source row (BMPs are normally stored bottom-to-top)
int srcRow = height-1-y; int srcRow = height - 1 - y;
// In 90-degree rotation, source Y becomes destination X // In 90-degree rotation, source Y becomes destination X
int destX = y; int destX = y;
@ -85,7 +84,7 @@ struct BMPHeader {
int32_t xPixelsPerMeter; // Horizontal resolution int32_t xPixelsPerMeter; // Horizontal resolution
int32_t yPixelsPerMeter; // Vertical resolution int32_t yPixelsPerMeter; // Vertical resolution
uint32_t totalColors; // Number of colors in palette uint32_t totalColors; // Number of colors in palette
uint32_t importantColors;// Number of important colors uint32_t importantColors; // Number of important colors
}; };
#pragma pack(pop) #pragma pack(pop)
@ -119,12 +118,12 @@ uint8_t* loadBMP(const char* filename, int& width, int& height) {
} }
// Check for supported bit depths // Check for supported bit depths
if (header.bitsPerPixel != 1){ //} && header.bitsPerPixel != 24) { if (header.bitsPerPixel != 1) { //} && header.bitsPerPixel != 24) {
Serial.printf("[%lu] [SleepScreen] Unsupported bit depth: %d\n", millis(), header.bitsPerPixel); Serial.printf("[%lu] [SleepScreen] Unsupported bit depth: %d\n", millis(), header.bitsPerPixel);
bmpFile.close(); bmpFile.close();
return nullptr; return nullptr;
} }
if (header.height < 0){ //} && header.bitsPerPixel != 24) { if (header.height < 0) { //} && header.bitsPerPixel != 24) {
Serial.printf("[%lu] [SleepScreen] Unsupported negative height\n", millis()); Serial.printf("[%lu] [SleepScreen] Unsupported negative height\n", millis());
bmpFile.close(); bmpFile.close();
return nullptr; return nullptr;
@ -134,7 +133,8 @@ uint8_t* loadBMP(const char* filename, int& width, int& height) {
width = header.width; width = header.width;
height = header.height; height = header.height;
Serial.printf("[%lu] [SleepScreen] BMP dimensions: %dx%d, %d bits/pixel\n", millis(), width, height, header.bitsPerPixel); Serial.printf("[%lu] [SleepScreen] BMP dimensions: %dx%d, %d bits/pixel\n", millis(), width, height,
header.bitsPerPixel);
// Calculate destination dimensions based on rotation type // Calculate destination dimensions based on rotation type
int destWidth, destHeight; int destWidth, destHeight;
@ -158,7 +158,6 @@ uint8_t* loadBMP(const char* filename, int& width, int& height) {
// Initialize to all white (0xFF = all bits set to 1) // Initialize to all white (0xFF = all bits set to 1)
memset(displayImage, 0xFF, bufferSize); memset(displayImage, 0xFF, bufferSize);
// With 4-byte divisibility assertion, no padding calculations are needed // With 4-byte divisibility assertion, no padding calculations are needed
// Add assertion that dimensions are divisible by 4 // Add assertion that dimensions are divisible by 4
@ -180,8 +179,7 @@ uint8_t* loadBMP(const char* filename, int& width, int& height) {
// Allocate a buffer for the entire bitmap // Allocate a buffer for the entire bitmap
uint8_t* bmpData = (uint8_t*)malloc(totalBitmapSize); uint8_t* bmpData = (uint8_t*)malloc(totalBitmapSize);
if (!bmpData) { if (!bmpData) {
Serial.printf("[%lu] [SleepScreen] Failed to allocate bitmap buffer (%d bytes)\n", Serial.printf("[%lu] [SleepScreen] Failed to allocate bitmap buffer (%d bytes)\n", millis(), totalBitmapSize);
millis(), totalBitmapSize);
free(displayImage); free(displayImage);
bmpFile.close(); bmpFile.close();
return nullptr; return nullptr;
@ -191,15 +189,15 @@ uint8_t* loadBMP(const char* filename, int& width, int& height) {
bmpFile.seek(header.dataOffset); bmpFile.seek(header.dataOffset);
bmpFile.read(bmpData, totalBitmapSize); bmpFile.read(bmpData, totalBitmapSize);
convertBmpToBWdisplayData(bmpData, width, height,displayImage); convertBmpToBWdisplayData(bmpData, width, height, displayImage);
// Clean up // Clean up
free(bmpData); free(bmpData);
} }
bmpFile.close(); bmpFile.close();
const unsigned long elapsedTime = millis() - startTime; const unsigned long elapsedTime = millis() - startTime;
Serial.printf("[%lu] [SleepScreen] Successfully loaded BMP: %dx%d in %lu ms\n", Serial.printf("[%lu] [SleepScreen] Successfully loaded BMP: %dx%d in %lu ms\n", millis(), destWidth, destHeight,
millis(), destWidth, destHeight, elapsedTime); elapsedTime);
return displayImage; return displayImage;
} }
@ -240,8 +238,8 @@ void SleepActivity::onEnter() {
// Note: We've applied 90-degree clockwise rotation to compensate for // Note: We've applied 90-degree clockwise rotation to compensate for
// the renderer's behavior and ensure the image appears correctly // the renderer's behavior and ensure the image appears correctly
// on the e-ink display. // on the e-ink display.
Serial.printf("[%lu] [SleepScreen] Drawing at position: %d,%d (dimensions: %dx%d)\n", millis(), Serial.printf("[%lu] [SleepScreen] Drawing at position: %d,%d (dimensions: %dx%d)\n", millis(), xPos, yPos,
xPos, yPos, imageWidth, imageHeight); imageWidth, imageHeight);
renderer.drawImage(imageData, xPos, yPos, imageWidth, imageHeight); renderer.drawImage(imageData, xPos, yPos, imageWidth, imageHeight);
// Free the image data // Free the image data