diff options
author | David Crocker <dcrocker@eschertech.com> | 2022-02-11 20:07:20 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2022-02-11 20:07:20 +0300 |
commit | 825ae994c240dd20c6be15351ed57f9feda656fb (patch) | |
tree | 51375591e8f7c5f88d723ec94d6d78ff6b2bd897 /src | |
parent | aa5c62260d29c150c17c7400ad8b567d51dc2bac (diff) |
Suppot JPEG thumbnail images
Diffstat (limited to 'src')
-rw-r--r-- | src/GCodes/GCodeFileInfo.h | 2 | ||||
-rw-r--r-- | src/Platform/RepRap.cpp | 4 | ||||
-rw-r--r-- | src/Storage/FileInfoParser.cpp | 13 |
3 files changed, 13 insertions, 6 deletions
diff --git a/src/GCodes/GCodeFileInfo.h b/src/GCodes/GCodeFileInfo.h index df527c8f..d925e547 100644 --- a/src/GCodes/GCodeFileInfo.h +++ b/src/GCodes/GCodeFileInfo.h @@ -15,7 +15,7 @@ struct GCodeFileInfo { struct ThumbnailInfo { - NamedEnum(Format, uint8_t, png, qoi); + NamedEnum(Format, uint8_t, png, qoi, jpeg); FilePosition offset; uint32_t size; uint16_t width, height; diff --git a/src/Platform/RepRap.cpp b/src/Platform/RepRap.cpp index 5a69dd18..e393f08e 100644 --- a/src/Platform/RepRap.cpp +++ b/src/Platform/RepRap.cpp @@ -2326,8 +2326,8 @@ OutputBuffer *RepRap::GetThumbnailResponse(const char *filename, FilePosition of continue; } - // Check for end of thumbnail - if (StringStartsWith(p, "thumbnail end") || StringStartsWith(p, "thumbnail_QOI end")) + // Check for end of thumbnail. We'd like to use a regex here but we can't afford the flash space of a regex parser in some build configurations. + if (StringStartsWith(p, "thumbnail end") || StringStartsWith(p, "thumbnail_QOI end")|| StringStartsWith(p, "thumbnail_JPG end")) { offset = 0; break; diff --git a/src/Storage/FileInfoParser.cpp b/src/Storage/FileInfoParser.cpp index f7ddf326..28deb67d 100644 --- a/src/Storage/FileInfoParser.cpp +++ b/src/Storage/FileInfoParser.cpp @@ -974,24 +974,31 @@ bool FileInfoParser::FindThumbnails(const char *_ecv_array bufp, FilePosition bu constexpr const char * PngThumbnailBegin = "; thumbnail begin "; constexpr const char * QoiThumbnailBegin = "; thumbnail_QOI begin "; + constexpr const char * JpegThumbnailBegin = "; thumbnail_JPG begin "; const char *_ecv_array pos = bufp; while (true) { const char *_ecv_array qoiPos = strstr(pos, QoiThumbnailBegin); const char *_ecv_array pngPos = strstr(pos, PngThumbnailBegin); + const char *_ecv_array jpegPos = strstr(pos, JpegThumbnailBegin); GCodeFileInfo::ThumbnailInfo::Format fmt(GCodeFileInfo::ThumbnailInfo::Format::qoi); - if (qoiPos != nullptr && (pngPos == nullptr || qoiPos < pngPos)) + if (qoiPos != nullptr && (pngPos == nullptr || qoiPos < pngPos) && (jpegPos == nullptr || qoiPos < jpegPos)) { // found a QOI thumbnail pos = qoiPos + strlen(QoiThumbnailBegin); - fmt = GCodeFileInfo::ThumbnailInfo::Format::qoi; } - else if (pngPos != nullptr) + else if (pngPos != nullptr && (jpegPos == nullptr || pngPos < jpegPos)) { // found a PNG thumbnail pos = pngPos + strlen(PngThumbnailBegin); fmt = GCodeFileInfo::ThumbnailInfo::Format::png; } + else if (jpegPos != nullptr) + { + // found a JPEG thumbnail + pos = jpegPos + strlen(JpegThumbnailBegin); + fmt = GCodeFileInfo::ThumbnailInfo::Format::jpeg; + } else { return false; // no more thumbnails in this buffer, but we have room to save more thumbnail details |