displayign images works with some dim
This commit is contained in:
+22
-13
@@ -13,6 +13,7 @@ WebServer server(80);
|
||||
Pixel new_image[16][16];
|
||||
char* fileContent = nullptr;
|
||||
size_t fileContent_len = 0;
|
||||
String upload_error_message = "";
|
||||
|
||||
|
||||
void handleRoot()
|
||||
@@ -29,6 +30,7 @@ void handleUploadPage()
|
||||
void handleBmpUpload() {
|
||||
HTTPUpload& upload = server.upload();
|
||||
if (upload.status == UPLOAD_FILE_START) {
|
||||
upload_error_message = "";
|
||||
if (fileContent) {
|
||||
free(fileContent);
|
||||
fileContent = nullptr;
|
||||
@@ -46,11 +48,18 @@ void handleBmpUpload() {
|
||||
char header[54];
|
||||
memcpy(header, fileContent, 54);
|
||||
|
||||
int dataOffset = *(int*)&header[10];
|
||||
int width = *(int*)&header[18];
|
||||
int height = *(int*)&header[22];
|
||||
short bitsPerPixel = *(short*)&header[28];
|
||||
|
||||
if (bitsPerPixel != 24) {
|
||||
upload_error_message = "Unsupported BMP format: Only 24-bit BMPs are supported";
|
||||
return;
|
||||
}
|
||||
|
||||
if (width < 1 || width > 48 || height < 1 || height > 16) {
|
||||
server.send(400, "text/plain", "Invalid image dimensions");
|
||||
upload_error_message = "Invalid image dimensions";
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,20 +68,16 @@ void handleBmpUpload() {
|
||||
|
||||
// Read pixel data
|
||||
int row_padded = (width*3 + 3) & (~3);
|
||||
char* pixel_data = fileContent + 54;
|
||||
char* pixel_data = fileContent + dataOffset;
|
||||
|
||||
for (int y = height - 1; y >= 0; y--) {
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
saved_images[0].pixels[y][x].b = pixel_data[y*row_padded + x*3 + 0];
|
||||
saved_images[0].pixels[y][x].g = pixel_data[y*row_padded + x*3 + 1];
|
||||
saved_images[0].pixels[y][x].r = pixel_data[y*row_padded + x*3 + 2];
|
||||
int bmp_row = height - 1 - y;
|
||||
saved_images[0].pixels[y][x].b = pixel_data[bmp_row*row_padded + x*3 + 0];
|
||||
saved_images[0].pixels[y][x].g = pixel_data[bmp_row*row_padded + x*3 + 1];
|
||||
saved_images[0].pixels[y][x].r = pixel_data[bmp_row*row_padded + x*3 + 2];
|
||||
}
|
||||
}
|
||||
|
||||
pixels.clear();
|
||||
drawImageFromMemoryByIndex(0, 0, 0);
|
||||
pixels.show();
|
||||
server.send(200, "text/plain", "OK");
|
||||
|
||||
free(fileContent);
|
||||
fileContent = nullptr;
|
||||
@@ -86,7 +91,7 @@ void handleBmpUpload() {
|
||||
void handleShowSaved()
|
||||
{
|
||||
pixels.clear();
|
||||
drawImageFromMemoryByIndex(0, 0, 0);
|
||||
drawImageFromMemoryByIndex(0, 0, 0, 100);
|
||||
pixels.show();
|
||||
server.send(200, "text/plain", "OK");
|
||||
}
|
||||
@@ -106,7 +111,11 @@ void start_server()
|
||||
server.on("/show-saved", handleShowSaved);
|
||||
server.on("/upload-page", HTTP_GET, handleUploadPage);
|
||||
server.on("/upload-bmp", HTTP_POST, []() {
|
||||
server.send(200, "text/plain", "");
|
||||
if (upload_error_message.length() > 0) {
|
||||
server.send(400, "text/plain", upload_error_message);
|
||||
} else {
|
||||
server.send(200, "text/plain", "Upload OK");
|
||||
}
|
||||
}, handleBmpUpload);
|
||||
server.begin();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user