2727
2828#include " ../../inc/MarlinConfig.h"
2929
30- #if ALL(TFT_COLOR_UI, GCODE_PREVIEW)
30+ #if HAS_TFT_GCODE_PREVIEW
3131
3232#include " ui_common.h"
3333#include " ui_gcode_preview.h"
4444// #define DEBUG_OUT 1
4545#include " ../../core/debug_out.h"
4646
47+ Preview preview;
48+
4749/* *
4850 * Structure to hold file properties
4951 */
@@ -342,23 +344,13 @@ bool Preview::hasPreview() {
342344
343345 // Detect image format
344346 #if DEBUG_OUT
345- const char * format_name = " UNKNOWN" ;
346- #if HAS_JPEG_DECODER
347- if (ImageDecoders::JPEGDecoder::isValidJPEG (thumbdata, fileprop.thumbsize )) {
348- format_name = " JPEG" ;
349- } else
350- #endif
351- #if HAS_PNG_DECODER
352- if (ImageDecoders::PNGDecoder::isValidPNG (thumbdata, fileprop.thumbsize )) {
353- format_name = " PNG" ;
354- } else
355- #endif
356- #if HAS_QOI_DECODER
357- if (ImageDecoders::QOIDecoder::isValidQOI (thumbdata, fileprop.thumbsize )) {
358- format_name = " QOI" ;
359- } else
360- #endif
361- {} // Empty else for UNKNOWN case
347+ const char *format_name = " UNKNOWN" ;
348+ if (TERN0 (GCODE_PREVIEW_JPEG, ImageDecoders::JPEGDecoder::isValidJPEG (thumbdata, fileprop.thumbsize )))
349+ format_name = " JPEG" ;
350+ else if (TERN0 (GCODE_PREVIEW_PNG, ImageDecoders::PNGDecoder::isValidPNG (thumbdata, fileprop.thumbsize )))
351+ format_name = " PNG" ;
352+ else if (TERN0 (GCODE_PREVIEW_QOI, ImageDecoders::QOIDecoder::isValidQOI (thumbdata, fileprop.thumbsize )))
353+ format_name = " QOI" ;
362354 DEBUG_ECHOLNPGM (" G-code preview: Detected image format: " , format_name);
363355 #endif
364356
@@ -369,7 +361,8 @@ bool Preview::hasPreview() {
369361 // Use JPEG dimensions instead of G-code dimensions
370362 fileprop.thumbwidth = jpeg_width;
371363 fileprop.thumbheight = jpeg_height;
372- } else {
364+ }
365+ else {
373366 DEBUG_ECHOLNPGM (" G-code preview: Failed to get JPEG dimensions" );
374367 }
375368
@@ -381,7 +374,8 @@ bool Preview::hasPreview() {
381374 thumbdata, fileprop.thumbsize ,
382375 fileprop.decoded_thumb , fileprop.thumbwidth , fileprop.thumbheight
383376 );
384- } else {
377+ }
378+ else {
385379 DEBUG_ECHOLNPGM (" G-code preview: Image too large for buffer: " , fileprop.thumbwidth , C (' x' ), fileprop.thumbheight ,
386380 " needs " , required_bytes, " bytes, buffer has " , sizeof (fileprop.decoded_thumb ), " bytes" );
387381 }
@@ -393,7 +387,8 @@ bool Preview::hasPreview() {
393387 if (!fileprop.decode_success ) {
394388 DEBUG_ECHOLNPGM (" G-code preview: Failed to decode thumbnail image" );
395389 // Continue anyway - we can still show metadata
396- } else {
390+ }
391+ else {
397392 // Debug: Print first few decoded pixels
398393 DEBUG_ECHOPGM (" G-code preview: First 10 decoded pixels: " );
399394 for (int i = 0 ; i < 10 && i < fileprop.thumbwidth * fileprop.thumbheight ; i++) {
@@ -527,7 +522,10 @@ void Preview::drawFromSD() {
527522 tft.add_text (text_x, text_y + 25 , COLOR_RED, " Not available" );
528523 }
529524 #endif // TFT_COLOR_UI_LANDSCAPE
530- } else {
525+
526+ }
527+ else { // valid()
528+
531529 // Valid preview available
532530 char buf[100 ];
533531
@@ -712,6 +710,4 @@ void Preview::show(const int x, const int y) {
712710 // tft.add_rectangle(x, y, fileprop.thumbwidth, fileprop.thumbheight, COLOR_WHITE);
713711}
714712
715- Preview preview;
716-
717- #endif // TFT_COLOR_UI && GCODE_PREVIEW
713+ #endif // HAS_TFT_GCODE_PREVIEW
0 commit comments