Skip to content

Commit bde33cd

Browse files
committed
debug, format
1 parent 9780abf commit bde33cd

11 files changed

Lines changed: 186 additions & 182 deletions

File tree

Marlin/src/lcd/tft/canvas.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -282,24 +282,24 @@ void Canvas::addBar(uint16_t x, uint16_t y, uint16_t barWidth, uint16_t barHeigh
282282
}
283283

284284
void Canvas::addPixels(uint16_t x, uint16_t y, uint16_t pixelWidth, uint16_t pixelHeight, uint16_t *pixels) {
285-
if (startLine >= y + pixelHeight || endLine <= y) return; // No overlap with current chunk
285+
if (startLine >= y + pixelHeight || endLine <= y) return; // No overlap with current chunk
286286

287-
uint16_t yc = y <= startLine ? 0 : (y - startLine) * width; // Multiple of width as y offset
288-
uint16_t *srcPixel = pixels; // Source pixel pointer
287+
uint16_t yc = y <= startLine ? 0 : (y - startLine) * width; // Multiple of width as y offset
288+
uint16_t *srcPixel = pixels; // Source pixel pointer
289289

290290
// Calculate which rows of the image to draw in this chunk
291291
uint16_t startRow = (startLine > y) ? startLine - y : 0;
292292
uint16_t endRow = (endLine < y + pixelHeight) ? endLine - y : pixelHeight;
293293

294-
for (uint16_t i = startRow; i < endRow; i++) { // Loop over the rows to draw
295-
uint16_t *dstPixel = buffer + x + yc; // Destination pixel address
296-
yc += width; // + is faster than *
297-
uint16_t *rowSrc = srcPixel + i * pixelWidth; // Start of this row in source
298-
for (uint16_t j = 0; j < pixelWidth; j++) { // Copy the width
299-
if (x + j < width) { // Within canvas width?
300-
*dstPixel++ = ENDIAN_COLOR(*rowSrc); // Copy with endianness
294+
for (uint16_t i = startRow; i < endRow; i++) { // Loop over the rows to draw
295+
uint16_t *dstPixel = buffer + x + yc; // Destination pixel address
296+
yc += width; // + is faster than *
297+
uint16_t *rowSrc = srcPixel + i * pixelWidth; // Start of this row in source
298+
for (uint16_t j = 0; j < pixelWidth; j++) { // Copy the width
299+
if (x + j < width) { // Within canvas width?
300+
*dstPixel++ = ENDIAN_COLOR(*rowSrc); // Copy with endianness
301301
}
302-
rowSrc++; // Next source pixel
302+
rowSrc++; // Next source pixel
303303
}
304304
}
305305
}

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

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,58 +31,51 @@
3131

3232
namespace ImageDecoders {
3333

34-
ImageFormat ImageDecoder::detectFormat(const uint8_t* data, size_t size) {
35-
#if HAS_JPEG_DECODER
36-
if (JPEGDecoder::isValidJPEG(data, size)) {
37-
return ImageFormat::IMG_JPEG;
38-
}
39-
#endif
40-
41-
#if HAS_PNG_DECODER
42-
if (PNGDecoder::isValidPNG(data, size)) {
43-
return ImageFormat::IMG_PNG;
44-
}
45-
#endif
46-
47-
#if HAS_QOI_DECODER
48-
if (QOIDecoder::isValidQOI(data, size)) {
49-
return ImageFormat::IMG_QOI;
50-
}
51-
#endif
52-
34+
ImageFormat ImageDecoder::detectFormat(const uint8_t *data, size_t size) {
35+
#if HAS_JPEG_DECODER
36+
if (JPEGDecoder::isValidJPEG(data, size)) return ImageFormat::IMG_JPEG;
37+
#endif
38+
#if HAS_PNG_DECODER
39+
if (PNGDecoder::isValidPNG(data, size)) return ImageFormat::IMG_PNG;
40+
#endif
41+
#if HAS_QOI_DECODER
42+
if (QOIDecoder::isValidQOI(data, size)) return ImageFormat::IMG_QOI;
43+
#endif
5344
return ImageFormat::IMG_UNKNOWN;
5445
}
5546

56-
bool ImageDecoder::decode(const uint8_t* image_data, size_t image_size,
57-
uint16_t* output_buffer, uint16_t width, uint16_t height) {
47+
bool ImageDecoder::decode(
48+
const uint8_t *image_data, size_t image_size, uint16_t *output_buffer, uint16_t width, uint16_t height
49+
) {
5850
ImageFormat format = detectFormat(image_data, image_size);
5951

60-
DEBUG_ECHOLN("ImageDecoder: Detected format: ", (int)format, ", data size: ", (int)image_size);
52+
DEBUG_ECHOLNPGM("ImageDecoder: Detected format: ", (int)format, ", data size: ", (int)image_size);
6153

6254
switch (format) {
63-
#if HAS_JPEG_DECODER
64-
case ImageFormat::IMG_JPEG:
65-
DEBUG_ECHOLN("ImageDecoder: Calling JPEGDecoder::decode()");
66-
return JPEGDecoder::decode(image_data, image_size, output_buffer, width, height);
67-
#endif
68-
69-
#if HAS_PNG_DECODER
70-
case ImageFormat::IMG_PNG:
71-
return PNGDecoder::decode(image_data, image_size, output_buffer, width, height);
72-
#endif
73-
74-
#if HAS_QOI_DECODER
75-
case ImageFormat::IMG_QOI:
76-
return QOIDecoder::decode(image_data, image_size, output_buffer, width, height);
77-
#endif
55+
#if HAS_JPEG_DECODER
56+
case ImageFormat::IMG_JPEG:
57+
DEBUG_ECHOLNPGM("ImageDecoder: Calling JPEGDecoder::decode()");
58+
return JPEGDecoder::decode(image_data, image_size, output_buffer, width, height);
59+
#endif
60+
61+
#if HAS_PNG_DECODER
62+
case ImageFormat::IMG_PNG:
63+
return PNGDecoder::decode(image_data, image_size, output_buffer, width, height);
64+
#endif
65+
66+
#if HAS_QOI_DECODER
67+
case ImageFormat::IMG_QOI:
68+
return QOIDecoder::decode(image_data, image_size, output_buffer, width, height);
69+
#endif
7870

7971
default:
8072
return false;
8173
}
8274
}
8375

84-
bool ImageDecoder::getDimensions(const uint8_t* image_data, size_t image_size,
85-
uint16_t& width, uint16_t& height) {
76+
bool ImageDecoder::getDimensions(
77+
const uint8_t *image_data, size_t image_size, uint16_t& width, uint16_t& height
78+
) {
8679
ImageFormat format = detectFormat(image_data, image_size);
8780

8881
switch (format) {
@@ -104,4 +97,5 @@ namespace ImageDecoders {
10497
}
10598

10699
} // namespace ImageDecoders
107-
#endif // ANY(HAS_JPEG_DECODER,HAS_PNG_DECODER,HAS_QOI_DECODER)
100+
101+
#endif // HAS_JPEG_DECODER || HAS_PNG_DECODER || HAS_QOI_DECODER

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
#include "../ui_common.h" // For decoder defines
77

88
#if HAS_JPEG_DECODER
9-
#include "jpeg/jpeg_decoder.h"
9+
#include "jpeg/jpeg_decoder.h"
1010
#endif
11-
1211
#if HAS_PNG_DECODER
13-
#include "png/png_decoder.h"
12+
#include "png/png_decoder.h"
1413
#endif
15-
1614
#if HAS_QOI_DECODER
17-
#include "qoi/qoi_decoder.h"
15+
#include "qoi/qoi_decoder.h"
1816
#endif
1917

2018
namespace ImageDecoders {
@@ -30,17 +28,19 @@ enum class ImageFormat {
3028
class ImageDecoder {
3129
public:
3230
// Detect image format from data
33-
static ImageFormat detectFormat(const uint8_t* data, size_t size);
31+
static ImageFormat detectFormat(const uint8_t *data, size_t size);
3432

3533
// Decode image data to RGB565 format
3634
// Returns true on success, false on failure
3735
// output_buffer must be large enough for width * height * 2 bytes
38-
static bool decode(const uint8_t* image_data, size_t image_size,
39-
uint16_t* output_buffer, uint16_t width, uint16_t height);
36+
static bool decode(
37+
const uint8_t *image_data, size_t image_size, uint16_t *output_buffer, uint16_t width, uint16_t height
38+
);
4039

4140
// Get dimensions without decoding
42-
static bool getDimensions(const uint8_t* image_data, size_t image_size,
43-
uint16_t& width, uint16_t& height);
41+
static bool getDimensions(
42+
const uint8_t *image_data, size_t image_size, uint16_t& width, uint16_t& height
43+
);
4444
};
4545

4646
} // namespace ImageDecoders

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ bool JPEGDecoder::isValidJPEG(const uint8_t *data, size_t size) {
9191
return data[0] == 0xFF && data[1] == 0xD8; // SOI marker
9292
}
9393

94-
bool JPEGDecoder::findSOF0(const uint8_t* data, size_t size, uint16_t& width, uint16_t& height) {
94+
bool JPEGDecoder::findSOF0(const uint8_t *data, size_t size, uint16_t& width, uint16_t& height) {
9595
size_t pos = 2; // Skip SOI marker
9696

9797
while (pos < size - 8) {
@@ -112,29 +112,29 @@ bool JPEGDecoder::findSOF0(const uint8_t* data, size_t size, uint16_t& width, ui
112112
return false;
113113
}
114114

115-
bool JPEGDecoder::getDimensions(const uint8_t* jpeg_data, size_t jpeg_size, uint16_t& width, uint16_t& height) {
116-
DEBUG_ECHOLN("JPEGDecoder::getDimensions: Getting JPEG dimensions, size=", jpeg_size);
115+
bool JPEGDecoder::getDimensions(const uint8_t *jpeg_data, size_t jpeg_size, uint16_t& width, uint16_t& height) {
116+
DEBUG_ECHOLNPGM("JPEGDecoder::getDimensions: Getting JPEG dimensions, size=", jpeg_size);
117117

118118
bool result = findSOF0(jpeg_data, jpeg_size, width, height);
119119

120120
if (result) {
121-
DEBUG_ECHOLN("JPEGDecoder::getDimensions: JPEG dimensions: ", width, "x", height);
121+
DEBUG_ECHOLNPGM("JPEGDecoder::getDimensions: JPEG dimensions: ", width, C('x'), height);
122122
} else {
123-
DEBUG_ECHOLN("JPEGDecoder::getDimensions: Failed to get JPEG dimensions");
123+
DEBUG_ECHOLNPGM("JPEGDecoder::getDimensions: Failed to get JPEG dimensions");
124124
}
125125

126126
return result;
127127
}
128128

129-
bool JPEGDecoder::decode(const uint8_t* jpeg_data, size_t jpeg_size, uint16_t* output_buffer, uint16_t width, uint16_t height) {
130-
DEBUG_ECHOLN("JPEGDecoder::decode: Starting JPEG decode, size=", jpeg_size, ", expected dims=", width, "x", height);
129+
bool JPEGDecoder::decode(const uint8_t *jpeg_data, size_t jpeg_size, uint16_t *output_buffer, uint16_t width, uint16_t height) {
130+
DEBUG_ECHOLNPGM("JPEGDecoder::decode: Starting JPEG decode, size=", jpeg_size, ", expected dims=", width, C('x'), height);
131131

132132
if (!isValidJPEG(jpeg_data, jpeg_size)) {
133-
DEBUG_ECHOLN("JPEGDecoder::decode: Invalid JPEG data");
133+
DEBUG_ECHOLNPGM("JPEGDecoder::decode: Invalid JPEG data");
134134
return false;
135135
}
136136
if (!output_buffer) {
137-
DEBUG_ECHOLN("JPEGDecoder::decode: No output buffer provided");
137+
DEBUG_ECHOLNPGM("JPEGDecoder::decode: No output buffer provided");
138138
return false;
139139
}
140140

@@ -154,7 +154,7 @@ bool JPEGDecoder::decode(const uint8_t* jpeg_data, size_t jpeg_size, uint16_t* o
154154
JDEC jdec;
155155
JRESULT res = jd_prepare(&jdec, jpeg_input, work, sizeof(work), &ctx);
156156
if (res != JDR_OK) {
157-
DEBUG_ECHOLN("JPEGDecoder::decode: TJpgDec prepare failed, creating test pattern");
157+
DEBUG_ECHOLNPGM("JPEGDecoder::decode: TJpgDec prepare failed, creating test pattern");
158158
// TJpgDec failed, create a recognizable test image instead of weird lines
159159
for (uint16_t y = 0; y < height; y++) {
160160
for (uint16_t x = 0; x < width; x++) {
@@ -167,7 +167,7 @@ bool JPEGDecoder::decode(const uint8_t* jpeg_data, size_t jpeg_size, uint16_t* o
167167
output_buffer[y * width + x] = color;
168168
}
169169
}
170-
DEBUG_ECHOLN("JPEGDecoder::decode: Test pattern created successfully");
170+
DEBUG_ECHOLNPGM("JPEGDecoder::decode: Test pattern created successfully");
171171
return true; // Still return success
172172
}
173173

@@ -179,9 +179,9 @@ bool JPEGDecoder::decode(const uint8_t* jpeg_data, size_t jpeg_size, uint16_t* o
179179
res = jd_decomp(&jdec, jpeg_output, 0); // 0 = no scaling
180180

181181
if (res == JDR_OK) {
182-
DEBUG_ECHOLN("JPEGDecoder::decode: JPEG decode completed successfully");
182+
DEBUG_ECHOLNPGM("JPEGDecoder::decode: JPEG decode completed successfully");
183183
} else {
184-
DEBUG_ECHOLN("JPEGDecoder::decode: JPEG decompression failed");
184+
DEBUG_ECHOLNPGM("JPEGDecoder::decode: JPEG decompression failed");
185185
}
186186

187187
return (res == JDR_OK);

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ class JPEGDecoder {
1010
// Decode JPEG data to RGB565 format
1111
// Returns true on success, false on failure
1212
// output_buffer must be large enough for width * height * 2 bytes
13-
static bool decode(const uint8_t* jpeg_data, size_t jpeg_size,
14-
uint16_t* output_buffer, uint16_t width, uint16_t height);
13+
static bool decode(
14+
const uint8_t *jpeg_data, size_t jpeg_size, uint16_t *output_buffer, uint16_t width, uint16_t height
15+
);
1516

1617
// Get the dimensions of a JPEG without decoding
1718
// Returns true if dimensions were successfully extracted
18-
static bool getDimensions(const uint8_t* jpeg_data, size_t jpeg_size,
19-
uint16_t& width, uint16_t& height);
19+
static bool getDimensions(
20+
const uint8_t *jpeg_data, size_t jpeg_size, uint16_t& width, uint16_t& height
21+
);
2022

2123
// Helper functions for JPEG parsing
22-
static bool isValidJPEG(const uint8_t* data, size_t size);
23-
static bool findSOF0(const uint8_t* data, size_t size, uint16_t& width, uint16_t& height);
24+
static bool isValidJPEG(const uint8_t *data, size_t size);
25+
static bool findSOF0(const uint8_t *data, size_t size, uint16_t& width, uint16_t& height);
2426

2527
};
2628

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static void* alloc_pool ( /* Pointer to allocated memory block (NULL:no memory a
157157

158158
static JRESULT create_qt_tbl ( /* 0:OK, !0:Failed */
159159
JDEC* jd, /* Pointer to the decompressor object */
160-
const uint8_t* data, /* Pointer to the quantizer tables */
160+
const uint8_t *data, /* Pointer to the quantizer tables */
161161
size_t ndata /* Size of input data */
162162
)
163163
{
@@ -193,7 +193,7 @@ static JRESULT create_qt_tbl ( /* 0:OK, !0:Failed */
193193

194194
static JRESULT create_huffman_tbl ( /* 0:OK, !0:Failed */
195195
JDEC* jd, /* Pointer to the decompressor object */
196-
const uint8_t* data, /* Pointer to the packed huffman tables */
196+
const uint8_t *data, /* Pointer to the packed huffman tables */
197197
size_t ndata /* Size of input data */
198198
)
199199
{

0 commit comments

Comments
 (0)