From 8da475901dc632b67c32003f4817145cd7b3e99f Mon Sep 17 00:00:00 2001 From: Jelmer Date: Tue, 27 Feb 2024 00:32:09 +0100 Subject: [PATCH] Support for rotating generated images based on tagtype profile --- ESP32_AP-Flasher/src/contentmanager.cpp | 4 ++-- ESP32_AP-Flasher/src/makeimage.cpp | 17 +++++++++++------ ESP32_AP-Flasher/wwwroot/edit.html | 3 ++- ESP32_AP-Flasher/wwwroot/main.js | 3 ++- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ESP32_AP-Flasher/src/contentmanager.cpp b/ESP32_AP-Flasher/src/contentmanager.cpp index 014a75ed..636f4a95 100644 --- a/ESP32_AP-Flasher/src/contentmanager.cpp +++ b/ESP32_AP-Flasher/src/contentmanager.cpp @@ -1186,7 +1186,7 @@ bool getCalFeed(String &filename, JsonObject &cfgobj, tagRecord *&taginfo, imgPa int temp = imageParams.height; imageParams.height = imageParams.width; imageParams.width = temp; - imageParams.rotatebuffer = 1 - imageParams.rotatebuffer; + imageParams.rotatebuffer = 1 - (imageParams.rotatebuffer%2); initSprite(spr, imageParams.width, imageParams.height, imageParams); } else { initSprite(spr, imageParams.width, imageParams.height, imageParams); @@ -2085,7 +2085,7 @@ void rotateBuffer(uint8_t rotation, uint8_t ¤tOrientation, TFT_eSprite &sp initSprite(spr, sprCpy.width(), sprCpy.height(), imageParams); sprCpy.pushToSprite(&spr, 0, 0); sprCpy.deleteSprite(); - imageParams.rotatebuffer = 1 - imageParams.rotatebuffer; + imageParams.rotatebuffer = 1 - (imageParams.rotatebuffer%2); } currentOrientation = rotation; } diff --git a/ESP32_AP-Flasher/src/makeimage.cpp b/ESP32_AP-Flasher/src/makeimage.cpp index d9ee0452..24d79f5a 100644 --- a/ESP32_AP-Flasher/src/makeimage.cpp +++ b/ESP32_AP-Flasher/src/makeimage.cpp @@ -88,10 +88,16 @@ uint32_t colorDistance(Color &c1, Color &c2, Error &e1) { void spr2color(TFT_eSprite &spr, imgParam &imageParams, uint8_t *buffer, size_t buffer_size, bool is_red) { uint8_t rotate = imageParams.rotate; long bufw = spr.width(), bufh = spr.height(); - if (imageParams.rotatebuffer) { + + if (imageParams.rotatebuffer % 2) { + //turn the image 90 or 270 rotate = (rotate + 3) % 4; + rotate = (rotate + (imageParams.rotatebuffer - 1)) % 4; bufw = spr.height(); bufh = spr.width(); + } else { + // rotate 180 + rotate = (rotate + (imageParams.rotatebuffer)) % 4; } memset(buffer, 0, buffer_size); @@ -234,8 +240,8 @@ size_t prepareHeader(uint8_t headerbuf[], uint16_t bufw, uint16_t bufh, imgParam uint8_t headersize = 6; headerbuf[0] = headersize; - memcpy(headerbuf + (imageParams.rotatebuffer == 1 ? 3 : 1), &bufw, sizeof(uint16_t)); - memcpy(headerbuf + (imageParams.rotatebuffer == 1 ? 1 : 3), &bufh, sizeof(uint16_t)); + memcpy(headerbuf + (imageParams.rotatebuffer % 2 == 1 ? 3 : 1), &bufw, sizeof(uint16_t)); + memcpy(headerbuf + (imageParams.rotatebuffer % 2 == 1 ? 1 : 3), &bufh, sizeof(uint16_t)); if (imageParams.hasRed && imageParams.bpp > 1) { totalbytes = buffer_size * 2 + headersize; @@ -258,7 +264,7 @@ size_t compressAndWrite(Miniz::tdefl_compressor *comp, const void *inbuf, size_t uint32_t t = millis(); Miniz::tdefl_compressOEPL(comp, inbuf, &inbytes_compressed, zlibbuf, &outbytes_compressed, flush); - Serial.printf("zlib: compressed %d into %d bytes in %d ms\n", inbytes_compressed, outbytes_compressed, millis()-t); + Serial.printf("zlib: compressed %d into %d bytes in %d ms\n", inbytes_compressed, outbytes_compressed, millis() - t); f_out.write((const uint8_t *)zlibbuf, outbytes_compressed); return outbytes_compressed; @@ -266,7 +272,7 @@ size_t compressAndWrite(Miniz::tdefl_compressor *comp, const void *inbuf, size_t void rewriteHeader(File &f_out) { // https://www.rfc-editor.org/rfc/rfc1950 - const uint8_t cmf = 0x48; // 4096 + const uint8_t cmf = 0x48; // 4096 // const uint8_t cmf = 0x58; // 8192 uint8_t flg, flevel = 3; uint16_t header = cmf << 8 | (flevel << 6); @@ -277,7 +283,6 @@ void rewriteHeader(File &f_out) { f_out.write(flg); } - void spr2buffer(TFT_eSprite &spr, String &fileout, imgParam &imageParams) { long t = millis(); diff --git a/ESP32_AP-Flasher/wwwroot/edit.html b/ESP32_AP-Flasher/wwwroot/edit.html index 8ec0e70e..bfeec7ea 100644 --- a/ESP32_AP-Flasher/wwwroot/edit.html +++ b/ESP32_AP-Flasher/wwwroot/edit.html @@ -435,7 +435,8 @@ } [canvas.width, canvas.height] = [tagTypes[hwtype].width, tagTypes[hwtype].height] || [0, 0]; - if (tagTypes[hwtype].rotatebuffer) [canvas.width, canvas.height] = [canvas.height, canvas.width]; + if (tagTypes[hwtype].rotatebuffer%2) [canvas.width, canvas.height] = [canvas.height, canvas.width]; + if (tagTypes[hwtype].rotatebuffer>=2) canvas.style.transform='rotate(180deg)'; const ctx = canvas.getContext('2d'); const imageData = ctx.createImageData(canvas.width, canvas.height); if (data.length == 0) canvas.style.display = 'none'; diff --git a/ESP32_AP-Flasher/wwwroot/main.js b/ESP32_AP-Flasher/wwwroot/main.js index 8b15c36a..e63b669c 100644 --- a/ESP32_AP-Flasher/wwwroot/main.js +++ b/ESP32_AP-Flasher/wwwroot/main.js @@ -1133,7 +1133,8 @@ function processQueue() { } [canvas.width, canvas.height] = [tagTypes[hwtype].width, tagTypes[hwtype].height] || [0, 0]; - if (tagTypes[hwtype].rotatebuffer) [canvas.width, canvas.height] = [canvas.height, canvas.width]; + if (tagTypes[hwtype].rotatebuffer%2) [canvas.width, canvas.height] = [canvas.height, canvas.width]; + if (tagTypes[hwtype].rotatebuffer>=2) canvas.style.transform='rotate(180deg)'; const ctx = canvas.getContext('2d'); const imageData = ctx.createImageData(canvas.width, canvas.height); if (data.length == 0) {