| 30 | } |
| 31 | |
| 32 | void jpg2buffer(String filein, String fileout, imgParam &imageParams) { |
| 33 | TJpgDec.setSwapBytes(true); |
| 34 | TJpgDec.setJpgScale(1); |
| 35 | TJpgDec.setCallback(spr_output); |
| 36 | uint16_t w = 0, h = 0; |
| 37 | if (filein.c_str()[0] != '/') { |
| 38 | filein = "/" + filein; |
| 39 | } |
| 40 | TJpgDec.getFsJpgSize(&w, &h, filein, *contentFS); |
| 41 | if (w == 0 && h == 0) { |
| 42 | wsErr("invalid jpg"); |
| 43 | return; |
| 44 | } |
| 45 | Serial.println("jpeg conversion " + String(w) + "x" + String(h)); |
| 46 | |
| 47 | #ifdef BOARD_HAS_PSRAM |
| 48 | spr.setColorDepth(16); |
| 49 | #else |
| 50 | spr.setColorDepth(8); |
| 51 | #endif |
| 52 | spr.createSprite(w, h); |
| 53 | if (spr.getPointer() == nullptr) { |
| 54 | wsErr("low on memory. Fallback to 1bpp"); |
| 55 | util::printLargestFreeBlock(); |
| 56 | spr.setColorDepth(1); |
| 57 | spr.setBitmapColor(TFT_WHITE, TFT_BLACK); |
| 58 | imageParams.bufferbpp = 1; |
| 59 | spr.createSprite(w, h); |
| 60 | } |
| 61 | if (spr.getPointer() == nullptr) { |
| 62 | wsErr("Failed to create sprite in jpg2buffer"); |
| 63 | } else { |
| 64 | spr.fillSprite(TFT_WHITE); |
| 65 | TJpgDec.drawFsJpg(0, 0, filein, *contentFS); |
| 66 | |
| 67 | spr2buffer(spr, fileout, imageParams); |
| 68 | spr.deleteSprite(); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | struct Error { |
| 73 | int32_t r; |
no test coverage detected