Skip to content

Commit 13bc612

Browse files
committed
fewer options
1 parent 5b783c2 commit 13bc612

File tree

10 files changed

+57
-61
lines changed

10 files changed

+57
-61
lines changed

Marlin/Configuration_adv.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,11 +2009,10 @@
20092009

20102010
// Color UI and G-code preview options
20112011
#if ENABLED(TFT_COLOR_UI)
2012-
//#define GCODE_PREVIEW // Preview G-code model thumbnail
20132012
// Image decoder options for G-code thumbnails
2014-
//#define HAS_JPEG_DECODER 1 // Enable JPEG thumbnail decoding
2015-
//#define HAS_PNG_DECODER 1 // Enable PNG thumbnail decoding
2016-
//#define HAS_QOI_DECODER 1 // Enable QOI thumbnail decoding
2013+
//#define GCODE_PREVIEW_JPEG // Enable JPEG thumbnail decoding
2014+
//#define GCODE_PREVIEW_PNG // Enable PNG thumbnail decoding
2015+
//#define GCODE_PREVIEW_QOI // Enable QOI thumbnail decoding
20172016
#endif
20182017

20192018
#endif // HAS_MEDIA

Marlin/src/inc/Conditionals-4-adv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,10 @@
10071007
#define HAS_EXTRA_PROGRESS 1
10081008
#endif
10091009

1010+
#if ANY(GCODE_PREVIEW_JPEG, GCODE_PREVIEW_PNG, GCODE_PREVIEW_QOI)
1011+
#define HAS_TFT_GCODE_PREVIEW 1
1012+
#endif
1013+
10101014
#if HAS_PRINT_PROGRESS && ANY(PRINT_PROGRESS_SHOW_DECIMALS, SHOW_REMAINING_TIME)
10111015
#define HAS_PRINT_PROGRESS_PERMYRIAD 1
10121016
#endif

Marlin/src/lcd/menu/menu_media.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "menu_item.h"
3232
#include "../../sd/cardreader.h"
3333

34-
#if ALL(TFT_COLOR_UI, GCODE_PREVIEW)
34+
#if HAS_TFT_GCODE_PREVIEW
3535
#include "../tft/ui_common.h"
3636
#include "../tft/ui_gcode_preview.h"
3737
#endif
@@ -69,7 +69,7 @@ class MenuItem_sdfile : public MenuItem_sdbase {
6969
MenuItem_sdbase::draw(sel, row, fstr, theCard, false);
7070
}
7171
static void action(FSTR_P const fstr, CardReader &) {
72-
#if ALL(TFT_COLOR_UI, GCODE_PREVIEW)
72+
#if HAS_TFT_GCODE_PREVIEW
7373
// Show preview for TFT_COLOR_UI
7474
// First process the preview data
7575
preview.invalidate(); // Clear any previous state

Marlin/src/lcd/tft/image_decoders/image_decoder.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "../../../inc/MarlinConfig.h"
2424

25-
#if ANY(HAS_JPEG_DECODER, HAS_PNG_DECODER, HAS_QOI_DECODER)
25+
#if HAS_TFT_GCODE_PREVIEW
2626

2727
//#define DEBUG_OUT 1
2828
#include "../../../core/debug_out.h"
@@ -32,13 +32,13 @@
3232
namespace ImageDecoders {
3333

3434
ImageFormat ImageDecoder::detectFormat(const uint8_t *data, size_t size) {
35-
#if HAS_JPEG_DECODER
35+
#if ENABLED(GCODE_PREVIEW_JPEG)
3636
if (JPEGDecoder::isValidJPEG(data, size)) return ImageFormat::IMG_JPEG;
3737
#endif
38-
#if HAS_PNG_DECODER
38+
#if ENABLED(GCODE_PREVIEW_PNG)
3939
if (PNGDecoder::isValidPNG(data, size)) return ImageFormat::IMG_PNG;
4040
#endif
41-
#if HAS_QOI_DECODER
41+
#if ENABLED(GCODE_PREVIEW_QOI)
4242
if (QOIDecoder::isValidQOI(data, size)) return ImageFormat::IMG_QOI;
4343
#endif
4444
return ImageFormat::IMG_UNKNOWN;
@@ -52,24 +52,21 @@ namespace ImageDecoders {
5252
DEBUG_ECHOLNPGM("ImageDecoder: Detected format: ", (int)format, ", data size: ", (int)image_size);
5353

5454
switch (format) {
55-
#if HAS_JPEG_DECODER
55+
#if ENABLED(GCODE_PREVIEW_JPEG)
5656
case ImageFormat::IMG_JPEG:
5757
DEBUG_ECHOLNPGM("ImageDecoder: Calling JPEGDecoder::decode()");
5858
return JPEGDecoder::decode(image_data, image_size, output_buffer, width, height);
5959
#endif
60-
61-
#if HAS_PNG_DECODER
60+
#if ENABLED(GCODE_PREVIEW_PNG)
6261
case ImageFormat::IMG_PNG:
6362
return PNGDecoder::decode(image_data, image_size, output_buffer, width, height);
6463
#endif
65-
66-
#if HAS_QOI_DECODER
64+
#if ENABLED(GCODE_PREVIEW_QOI)
6765
case ImageFormat::IMG_QOI:
6866
return QOIDecoder::decode(image_data, image_size, output_buffer, width, height);
6967
#endif
7068

71-
default:
72-
return false;
69+
default: return false;
7370
}
7471
}
7572

@@ -79,23 +76,23 @@ namespace ImageDecoders {
7976
ImageFormat format = detectFormat(image_data, image_size);
8077

8178
switch (format) {
82-
#if HAS_JPEG_DECODER
79+
#if ENABLED(GCODE_PREVIEW_JPEG)
8380
case ImageFormat::IMG_JPEG:
8481
return JPEGDecoder::getDimensions(image_data, image_size, width, height);
8582
#endif
86-
#if HAS_PNG_DECODER
83+
#if ENABLED(GCODE_PREVIEW_PNG)
8784
case ImageFormat::IMG_PNG:
8885
return PNGDecoder::getDimensions(image_data, image_size, width, height);
8986
#endif
90-
#if HAS_QOI_DECODER
87+
#if ENABLED(GCODE_PREVIEW_QOI)
9188
case ImageFormat::IMG_QOI:
9289
return QOIDecoder::getDimensions(image_data, image_size, width, height);
9390
#endif
94-
default:
95-
return false;
91+
92+
default: return false;
9693
}
9794
}
9895

9996
} // namespace ImageDecoders
10097

101-
#endif // HAS_JPEG_DECODER || HAS_PNG_DECODER || HAS_QOI_DECODER
98+
#endif // HAS_TFT_GCODE_PREVIEW

Marlin/src/lcd/tft/image_decoders/image_decoder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55

66
#include "../ui_common.h" // For decoder defines
77

8-
#if HAS_JPEG_DECODER
8+
#if ENABLED(GCODE_PREVIEW_JPEG)
99
#include "jpeg/jpeg_decoder.h"
1010
#endif
11-
#if HAS_PNG_DECODER
11+
#if ENABLED(GCODE_PREVIEW_PNG)
1212
#include "png/png_decoder.h"
1313
#endif
14-
#if HAS_QOI_DECODER
14+
#if ENABLED(GCODE_PREVIEW_QOI)
1515
#include "qoi/qoi_decoder.h"
1616
#endif
1717

Marlin/src/lcd/tft/image_decoders/jpeg/jpeg_decoder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "../../../../inc/MarlinConfig.h"
1818

19-
#if HAS_JPEG_DECODER
19+
#if ENABLED(GCODE_PREVIEW_JPEG)
2020

2121
//#define DEBUG_OUT 1
2222
#include "../../../../core/debug_out.h"
@@ -189,4 +189,4 @@ bool JPEGDecoder::decode(const uint8_t *jpeg_data, size_t jpeg_size, uint16_t *o
189189

190190
} // namespace ImageDecoders
191191

192-
#endif // HAS_JPEG_DECODER
192+
#endif // GCODE_PREVIEW_JPEG

Marlin/src/lcd/tft/image_decoders/png/png_decoder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "../../../../inc/MarlinConfig.h"
1818

19-
#if HAS_PNG_DECODER
19+
#if ENABLED(GCODE_PREVIEW_PNG)
2020

2121
//#define DEBUG_OUT 1
2222
#include "../../../../core/debug_out.h"
@@ -127,4 +127,4 @@ bool PNGDecoder::findIHDR(const uint8_t *data, size_t size, uint16_t& width, uin
127127

128128
} // namespace ImageDecoders
129129

130-
#endif // HAS_PNG_DECODER
130+
#endif // GCODE_PREVIEW_PNG

Marlin/src/lcd/tft/image_decoders/qoi/qoi_decoder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "../../../../inc/MarlinConfig.h"
1818

19-
#if HAS_QOI_DECODER
19+
#if ENABLED(GCODE_PREVIEW_QOI)
2020

2121
//#define DEBUG_OUT 1
2222
#include "../../../../core/debug_out.h"
@@ -111,4 +111,4 @@ bool QOIDecoder::isValidQOI(const uint8_t *data, size_t size) {
111111

112112
} // namespace ImageDecoders
113113

114-
#endif // HAS_QOI_DECODER
114+
#endif // GCODE_PREVIEW_QOI

Marlin/src/lcd/tft/ui_gcode_preview.cpp

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
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"
@@ -44,6 +44,8 @@
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

ini/features.ini

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ TOUCH_SCREEN = build_src_filter=+<src/lcd/tft/touch.cp
5858
HAS_UI_320X.+ = build_src_filter=+<src/lcd/tft/ui_move_axis_screen_320.cpp>
5959
HAS_UI_480X.+ = build_src_filter=+<src/lcd/tft/ui_move_axis_screen_480.cpp>
6060
HAS_UI_1024X.+ = build_src_filter=+<src/lcd/tft/ui_move_axis_screen_1024.cpp>
61-
GCODE_PREVIEW = build_src_filter=+<src/lcd/tft/ui_gcode_preview.cpp>
61+
HAS_TFT_GCODE_PREVIEW = build_src_filter=+<src/lcd/tft/ui_gcode_preview.cpp>
6262
HAS_(JPEG|PNG|QOI)_DECODER = build_src_filter=+<src/lcd/tft/image_decoders/image_decoder.cpp>
63-
HAS_JPEG_DECODER = build_src_filter=+<src/lcd/tft/image_decoders/jpeg>
64-
HAS_PNG_DECODER = build_src_filter=+<src/lcd/tft/image_decoders/png>
65-
HAS_QOI_DECODER = build_src_filter=+<src/lcd/tft/image_decoders/qoi>
63+
GCODE_PREVIEW_JPEG = build_src_filter=+<src/lcd/tft/image_decoders/jpeg>
64+
GCODE_PREVIEW_PNG = build_src_filter=+<src/lcd/tft/image_decoders/png>
65+
GCODE_PREVIEW_QOI = build_src_filter=+<src/lcd/tft/image_decoders/qoi>
6666
# Helvetica 14
6767
TFT_FONT_HELVETICA_14 = build_src_filter=+<src/lcd/tft/fontdata/Helvetica/Helvetica_14.cpp>
6868
# Helvetica 19

0 commit comments

Comments
 (0)