Add some linter comments
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
#include <Logging.h>
|
#include <Logging.h>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <memory>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#include "DirectPixelWriter.h"
|
#include "DirectPixelWriter.h"
|
||||||
@@ -43,21 +44,13 @@ struct JpegContext {
|
|||||||
// See PngContext for the rationale: monochromeOutput requests a 1-bit Atkinson dither
|
// See PngContext for the rationale: monochromeOutput requests a 1-bit Atkinson dither
|
||||||
// emitting only 0/3 so the BW DirectPixelWriter (`pixelValue < 3` rule) maps cleanly.
|
// emitting only 0/3 so the BW DirectPixelWriter (`pixelValue < 3` rule) maps cleanly.
|
||||||
int oneBitDitherRow{-1};
|
int oneBitDitherRow{-1};
|
||||||
Atkinson1BitDitherer* atkinson1BitDitherer{nullptr};
|
std::unique_ptr<Atkinson1BitDitherer> atkinson1BitDitherer;
|
||||||
|
|
||||||
#ifdef ENABLE_IMAGE_DITHERING_EXTENSION
|
#ifdef ENABLE_IMAGE_DITHERING_EXTENSION
|
||||||
int currentDitherRow{-1};
|
int currentDitherRow{-1};
|
||||||
AtkinsonDitherer* atkinsonDitherer{nullptr};
|
std::unique_ptr<AtkinsonDitherer> atkinsonDitherer;
|
||||||
DiffusedBayerDitherer* diffusedBayerDitherer{nullptr};
|
std::unique_ptr<DiffusedBayerDitherer> diffusedBayerDitherer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
~JpegContext() {
|
|
||||||
delete atkinson1BitDitherer;
|
|
||||||
#ifdef ENABLE_IMAGE_DITHERING_EXTENSION
|
|
||||||
delete atkinsonDitherer;
|
|
||||||
delete diffusedBayerDitherer;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Advance the 1-bit Atkinson ditherer to the requested destination row.
|
// Advance the 1-bit Atkinson ditherer to the requested destination row.
|
||||||
@@ -136,9 +129,9 @@ uint8_t ditherGray(JpegContext& ctx, uint8_t gray, int localX, int outX, int out
|
|||||||
// File I/O callbacks use pFile->fHandle to access the FsFile*,
|
// File I/O callbacks use pFile->fHandle to access the FsFile*,
|
||||||
// avoiding the need for global file state.
|
// avoiding the need for global file state.
|
||||||
void* jpegOpen(const char* filename, int32_t* size) {
|
void* jpegOpen(const char* filename, int32_t* size) {
|
||||||
FsFile* f = new FsFile();
|
FsFile* f = new FsFile(); // NOLINT(cppcoreguidelines-owning-memory) — ownership transferred via void* to JPEGDEC callbacks
|
||||||
if (!Storage.openFileForRead("JPG", std::string(filename), *f)) {
|
if (!Storage.openFileForRead("JPG", std::string(filename), *f)) {
|
||||||
delete f;
|
delete f; // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
*size = f->size();
|
*size = f->size();
|
||||||
@@ -149,7 +142,7 @@ void jpegClose(void* handle) {
|
|||||||
FsFile* f = reinterpret_cast<FsFile*>(handle);
|
FsFile* f = reinterpret_cast<FsFile*>(handle);
|
||||||
if (f) {
|
if (f) {
|
||||||
f->close();
|
f->close();
|
||||||
delete f;
|
delete f; // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,7 +406,7 @@ bool JpegToFramebufferConverter::getDimensionsStatic(const std::string& imagePat
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
JPEGDEC* jpeg = new (std::nothrow) JPEGDEC();
|
std::unique_ptr<JPEGDEC> jpeg(new (std::nothrow) JPEGDEC());
|
||||||
if (!jpeg) {
|
if (!jpeg) {
|
||||||
LOG_ERR("JPG", "Failed to allocate JPEG decoder for dimensions");
|
LOG_ERR("JPG", "Failed to allocate JPEG decoder for dimensions");
|
||||||
return false;
|
return false;
|
||||||
@@ -422,7 +415,6 @@ bool JpegToFramebufferConverter::getDimensionsStatic(const std::string& imagePat
|
|||||||
int rc = jpeg->open(imagePath.c_str(), jpegOpen, jpegClose, jpegRead, jpegSeek, nullptr);
|
int rc = jpeg->open(imagePath.c_str(), jpegOpen, jpegClose, jpegRead, jpegSeek, nullptr);
|
||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
LOG_ERR("JPG", "Failed to open JPEG for dimensions (err=%d): %s", jpeg->getLastError(), imagePath.c_str());
|
LOG_ERR("JPG", "Failed to open JPEG for dimensions (err=%d): %s", jpeg->getLastError(), imagePath.c_str());
|
||||||
delete jpeg;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -431,7 +423,6 @@ bool JpegToFramebufferConverter::getDimensionsStatic(const std::string& imagePat
|
|||||||
LOG_DBG("JPG", "Image dimensions: %dx%d", out.width, out.height);
|
LOG_DBG("JPG", "Image dimensions: %dx%d", out.width, out.height);
|
||||||
|
|
||||||
jpeg->close();
|
jpeg->close();
|
||||||
delete jpeg;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,7 +436,7 @@ bool JpegToFramebufferConverter::decodeToFramebuffer(const std::string& imagePat
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
JPEGDEC* jpeg = new (std::nothrow) JPEGDEC();
|
std::unique_ptr<JPEGDEC> jpeg(new (std::nothrow) JPEGDEC());
|
||||||
if (!jpeg) {
|
if (!jpeg) {
|
||||||
LOG_ERR("JPG", "Failed to allocate JPEG decoder");
|
LOG_ERR("JPG", "Failed to allocate JPEG decoder");
|
||||||
return false;
|
return false;
|
||||||
@@ -460,7 +451,6 @@ bool JpegToFramebufferConverter::decodeToFramebuffer(const std::string& imagePat
|
|||||||
int rc = jpeg->open(imagePath.c_str(), jpegOpen, jpegClose, jpegRead, jpegSeek, jpegDrawCallback);
|
int rc = jpeg->open(imagePath.c_str(), jpegOpen, jpegClose, jpegRead, jpegSeek, jpegDrawCallback);
|
||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
LOG_ERR("JPG", "Failed to open JPEG (err=%d): %s", jpeg->getLastError(), imagePath.c_str());
|
LOG_ERR("JPG", "Failed to open JPEG (err=%d): %s", jpeg->getLastError(), imagePath.c_str());
|
||||||
delete jpeg;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,13 +460,11 @@ bool JpegToFramebufferConverter::decodeToFramebuffer(const std::string& imagePat
|
|||||||
if (srcWidth <= 0 || srcHeight <= 0) {
|
if (srcWidth <= 0 || srcHeight <= 0) {
|
||||||
LOG_ERR("JPG", "Invalid JPEG dimensions: %dx%d", srcWidth, srcHeight);
|
LOG_ERR("JPG", "Invalid JPEG dimensions: %dx%d", srcWidth, srcHeight);
|
||||||
jpeg->close();
|
jpeg->close();
|
||||||
delete jpeg;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validateImageDimensions(srcWidth, srcHeight, "JPEG")) {
|
if (!validateImageDimensions(srcWidth, srcHeight, "JPEG")) {
|
||||||
jpeg->close();
|
jpeg->close();
|
||||||
delete jpeg;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -543,7 +531,7 @@ bool JpegToFramebufferConverter::decodeToFramebuffer(const std::string& imagePat
|
|||||||
// See PngToFramebufferConverter for rationale: BW-only display needs a 1-bit
|
// See PngToFramebufferConverter for rationale: BW-only display needs a 1-bit
|
||||||
// dither so mid-grays don't collapse to black under DirectPixelWriter's `< 3` rule.
|
// dither so mid-grays don't collapse to black under DirectPixelWriter's `< 3` rule.
|
||||||
if (config.monochromeOutput) {
|
if (config.monochromeOutput) {
|
||||||
ctx.atkinson1BitDitherer = new (std::nothrow) Atkinson1BitDitherer(destWidth);
|
ctx.atkinson1BitDitherer.reset(new (std::nothrow) Atkinson1BitDitherer(destWidth));
|
||||||
if (!ctx.atkinson1BitDitherer) {
|
if (!ctx.atkinson1BitDitherer) {
|
||||||
LOG_ERR("JPG", "Failed to allocate 1-bit Atkinson ditherer, falling back to 4-level dither");
|
LOG_ERR("JPG", "Failed to allocate 1-bit Atkinson ditherer, falling back to 4-level dither");
|
||||||
}
|
}
|
||||||
@@ -553,13 +541,13 @@ bool JpegToFramebufferConverter::decodeToFramebuffer(const std::string& imagePat
|
|||||||
#ifdef ENABLE_IMAGE_DITHERING_EXTENSION
|
#ifdef ENABLE_IMAGE_DITHERING_EXTENSION
|
||||||
switch (config.ditherMode) {
|
switch (config.ditherMode) {
|
||||||
case ImageDitherMode::Atkinson:
|
case ImageDitherMode::Atkinson:
|
||||||
ctx.atkinsonDitherer = new (std::nothrow) AtkinsonDitherer(destWidth);
|
ctx.atkinsonDitherer.reset(new (std::nothrow) AtkinsonDitherer(destWidth));
|
||||||
if (!ctx.atkinsonDitherer) {
|
if (!ctx.atkinsonDitherer) {
|
||||||
LOG_ERR("JPG", "Failed to allocate Atkinson ditherer, falling back to Bayer");
|
LOG_ERR("JPG", "Failed to allocate Atkinson ditherer, falling back to Bayer");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ImageDitherMode::DiffusedBayer:
|
case ImageDitherMode::DiffusedBayer:
|
||||||
ctx.diffusedBayerDitherer = new (std::nothrow) DiffusedBayerDitherer(destWidth);
|
ctx.diffusedBayerDitherer.reset(new (std::nothrow) DiffusedBayerDitherer(destWidth));
|
||||||
if (!ctx.diffusedBayerDitherer) {
|
if (!ctx.diffusedBayerDitherer) {
|
||||||
LOG_ERR("JPG", "Failed to allocate diffused Bayer ditherer, falling back to Bayer");
|
LOG_ERR("JPG", "Failed to allocate diffused Bayer ditherer, falling back to Bayer");
|
||||||
}
|
}
|
||||||
@@ -579,12 +567,10 @@ bool JpegToFramebufferConverter::decodeToFramebuffer(const std::string& imagePat
|
|||||||
if (rc != 1) {
|
if (rc != 1) {
|
||||||
LOG_ERR("JPG", "Decode failed (rc=%d, lastError=%d)", rc, jpeg->getLastError());
|
LOG_ERR("JPG", "Decode failed (rc=%d, lastError=%d)", rc, jpeg->getLastError());
|
||||||
jpeg->close();
|
jpeg->close();
|
||||||
delete jpeg;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
jpeg->close();
|
jpeg->close();
|
||||||
delete jpeg;
|
|
||||||
LOG_DBG("JPG", "JPEG decoding complete - render time: %lu ms", decodeTime);
|
LOG_DBG("JPG", "JPEG decoding complete - render time: %lu ms", decodeTime);
|
||||||
|
|
||||||
// Write cache file if caching was enabled
|
// Write cache file if caching was enabled
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <PNGdec.h>
|
#include <PNGdec.h>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <memory>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#include "DirectPixelWriter.h"
|
#include "DirectPixelWriter.h"
|
||||||
@@ -44,21 +45,13 @@ struct PngContext {
|
|||||||
// `pixelValue < 3` rule. The 4-level dither path collapses mid-grays to solid
|
// `pixelValue < 3` rule. The 4-level dither path collapses mid-grays to solid
|
||||||
// black under that rule.
|
// black under that rule.
|
||||||
int oneBitDitherRow{-1};
|
int oneBitDitherRow{-1};
|
||||||
Atkinson1BitDitherer* atkinson1BitDitherer{nullptr};
|
std::unique_ptr<Atkinson1BitDitherer> atkinson1BitDitherer;
|
||||||
|
|
||||||
#ifdef ENABLE_IMAGE_DITHERING_EXTENSION
|
#ifdef ENABLE_IMAGE_DITHERING_EXTENSION
|
||||||
int currentDitherRow{-1};
|
int currentDitherRow{-1};
|
||||||
AtkinsonDitherer* atkinsonDitherer{nullptr};
|
std::unique_ptr<AtkinsonDitherer> atkinsonDitherer;
|
||||||
DiffusedBayerDitherer* diffusedBayerDitherer{nullptr};
|
std::unique_ptr<DiffusedBayerDitherer> diffusedBayerDitherer;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
~PngContext() {
|
|
||||||
delete atkinson1BitDitherer;
|
|
||||||
#ifdef ENABLE_IMAGE_DITHERING_EXTENSION
|
|
||||||
delete atkinsonDitherer;
|
|
||||||
delete diffusedBayerDitherer;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Advance the 1-bit Atkinson ditherer to the requested destination row.
|
// Advance the 1-bit Atkinson ditherer to the requested destination row.
|
||||||
@@ -140,9 +133,9 @@ uint8_t ditherGray(PngContext& ctx, uint8_t gray, int localX, int outX, int outY
|
|||||||
// File I/O callbacks use pFile->fHandle to access the FsFile*,
|
// File I/O callbacks use pFile->fHandle to access the FsFile*,
|
||||||
// avoiding the need for global file state.
|
// avoiding the need for global file state.
|
||||||
void* pngOpenWithHandle(const char* filename, int32_t* size) {
|
void* pngOpenWithHandle(const char* filename, int32_t* size) {
|
||||||
FsFile* f = new FsFile();
|
FsFile* f = new FsFile(); // NOLINT(cppcoreguidelines-owning-memory) — ownership transferred via void* to PNGdec callbacks
|
||||||
if (!Storage.openFileForRead("PNG", std::string(filename), *f)) {
|
if (!Storage.openFileForRead("PNG", std::string(filename), *f)) {
|
||||||
delete f;
|
delete f; // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
*size = f->size();
|
*size = f->size();
|
||||||
@@ -153,7 +146,7 @@ void pngCloseWithHandle(void* handle) {
|
|||||||
FsFile* f = reinterpret_cast<FsFile*>(handle);
|
FsFile* f = reinterpret_cast<FsFile*>(handle);
|
||||||
if (f) {
|
if (f) {
|
||||||
f->close();
|
f->close();
|
||||||
delete f;
|
delete f; // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -341,7 +334,7 @@ bool PngToFramebufferConverter::getDimensionsStatic(const std::string& imagePath
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
PNG* png = new (std::nothrow) PNG();
|
std::unique_ptr<PNG> png(new (std::nothrow) PNG());
|
||||||
if (!png) {
|
if (!png) {
|
||||||
LOG_ERR("PNG", "Failed to allocate PNG decoder for dimensions");
|
LOG_ERR("PNG", "Failed to allocate PNG decoder for dimensions");
|
||||||
return false;
|
return false;
|
||||||
@@ -352,7 +345,6 @@ bool PngToFramebufferConverter::getDimensionsStatic(const std::string& imagePath
|
|||||||
|
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
LOG_ERR("PNG", "Failed to open PNG for dimensions: %d", rc);
|
LOG_ERR("PNG", "Failed to open PNG for dimensions: %d", rc);
|
||||||
delete png;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,7 +352,6 @@ bool PngToFramebufferConverter::getDimensionsStatic(const std::string& imagePath
|
|||||||
out.height = png->getHeight();
|
out.height = png->getHeight();
|
||||||
|
|
||||||
png->close();
|
png->close();
|
||||||
delete png;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,7 +366,7 @@ bool PngToFramebufferConverter::decodeToFramebuffer(const std::string& imagePath
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Heap-allocate PNG decoder (~42 KB) - freed at end of function
|
// Heap-allocate PNG decoder (~42 KB) - freed at end of function
|
||||||
PNG* png = new (std::nothrow) PNG();
|
std::unique_ptr<PNG> png(new (std::nothrow) PNG());
|
||||||
if (!png) {
|
if (!png) {
|
||||||
LOG_ERR("PNG", "Failed to allocate PNG decoder");
|
LOG_ERR("PNG", "Failed to allocate PNG decoder");
|
||||||
return false;
|
return false;
|
||||||
@@ -391,13 +382,11 @@ bool PngToFramebufferConverter::decodeToFramebuffer(const std::string& imagePath
|
|||||||
pngDrawCallback);
|
pngDrawCallback);
|
||||||
if (rc != PNG_SUCCESS) {
|
if (rc != PNG_SUCCESS) {
|
||||||
LOG_ERR("PNG", "Failed to open PNG: %d", rc);
|
LOG_ERR("PNG", "Failed to open PNG: %d", rc);
|
||||||
delete png;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!validateImageDimensions(png->getWidth(), png->getHeight(), "PNG")) {
|
if (!validateImageDimensions(png->getWidth(), png->getHeight(), "PNG")) {
|
||||||
png->close();
|
png->close();
|
||||||
delete png;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -433,7 +422,6 @@ bool PngToFramebufferConverter::decodeToFramebuffer(const std::string& imagePath
|
|||||||
requiredInternal, ctx.srcWidth, pixelType, PNG_MAX_BUFFERED_PIXELS);
|
requiredInternal, ctx.srcWidth, pixelType, PNG_MAX_BUFFERED_PIXELS);
|
||||||
LOG_ERR("PNG", "Aborting decode to avoid PNGdec internal buffer overflow");
|
LOG_ERR("PNG", "Aborting decode to avoid PNGdec internal buffer overflow");
|
||||||
png->close();
|
png->close();
|
||||||
delete png;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,7 +435,6 @@ bool PngToFramebufferConverter::decodeToFramebuffer(const std::string& imagePath
|
|||||||
if (!ctx.grayLineBuffer) {
|
if (!ctx.grayLineBuffer) {
|
||||||
LOG_ERR("PNG", "Failed to allocate gray line buffer");
|
LOG_ERR("PNG", "Failed to allocate gray line buffer");
|
||||||
png->close();
|
png->close();
|
||||||
delete png;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -475,7 +462,7 @@ bool PngToFramebufferConverter::decodeToFramebuffer(const std::string& imagePath
|
|||||||
// The 1-bit ditherer emits only 0 or 3 so the BW writer maps cleanly to
|
// The 1-bit ditherer emits only 0 or 3 so the BW writer maps cleanly to
|
||||||
// black/white.
|
// black/white.
|
||||||
if (config.monochromeOutput) {
|
if (config.monochromeOutput) {
|
||||||
ctx.atkinson1BitDitherer = new (std::nothrow) Atkinson1BitDitherer(ctx.dstWidth);
|
ctx.atkinson1BitDitherer.reset(new (std::nothrow) Atkinson1BitDitherer(ctx.dstWidth));
|
||||||
if (!ctx.atkinson1BitDitherer) {
|
if (!ctx.atkinson1BitDitherer) {
|
||||||
LOG_ERR("PNG", "Failed to allocate 1-bit Atkinson ditherer, falling back to 4-level dither");
|
LOG_ERR("PNG", "Failed to allocate 1-bit Atkinson ditherer, falling back to 4-level dither");
|
||||||
}
|
}
|
||||||
@@ -485,13 +472,13 @@ bool PngToFramebufferConverter::decodeToFramebuffer(const std::string& imagePath
|
|||||||
#ifdef ENABLE_IMAGE_DITHERING_EXTENSION
|
#ifdef ENABLE_IMAGE_DITHERING_EXTENSION
|
||||||
switch (config.ditherMode) {
|
switch (config.ditherMode) {
|
||||||
case ImageDitherMode::Atkinson:
|
case ImageDitherMode::Atkinson:
|
||||||
ctx.atkinsonDitherer = new (std::nothrow) AtkinsonDitherer(ctx.dstWidth);
|
ctx.atkinsonDitherer.reset(new (std::nothrow) AtkinsonDitherer(ctx.dstWidth));
|
||||||
if (!ctx.atkinsonDitherer) {
|
if (!ctx.atkinsonDitherer) {
|
||||||
LOG_ERR("PNG", "Failed to allocate Atkinson ditherer, falling back to Bayer");
|
LOG_ERR("PNG", "Failed to allocate Atkinson ditherer, falling back to Bayer");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ImageDitherMode::DiffusedBayer:
|
case ImageDitherMode::DiffusedBayer:
|
||||||
ctx.diffusedBayerDitherer = new (std::nothrow) DiffusedBayerDitherer(ctx.dstWidth);
|
ctx.diffusedBayerDitherer.reset(new (std::nothrow) DiffusedBayerDitherer(ctx.dstWidth));
|
||||||
if (!ctx.diffusedBayerDitherer) {
|
if (!ctx.diffusedBayerDitherer) {
|
||||||
LOG_ERR("PNG", "Failed to allocate diffused Bayer ditherer, falling back to Bayer");
|
LOG_ERR("PNG", "Failed to allocate diffused Bayer ditherer, falling back to Bayer");
|
||||||
}
|
}
|
||||||
@@ -514,12 +501,10 @@ bool PngToFramebufferConverter::decodeToFramebuffer(const std::string& imagePath
|
|||||||
if (rc != PNG_SUCCESS) {
|
if (rc != PNG_SUCCESS) {
|
||||||
LOG_ERR("PNG", "Decode failed: %d", rc);
|
LOG_ERR("PNG", "Decode failed: %d", rc);
|
||||||
png->close();
|
png->close();
|
||||||
delete png;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
png->close();
|
png->close();
|
||||||
delete png;
|
|
||||||
LOG_DBG("PNG", "PNG decoding complete - render time: %lu ms", decodeTime);
|
LOG_DBG("PNG", "PNG decoding complete - render time: %lu ms", decodeTime);
|
||||||
|
|
||||||
// Write cache file if caching was enabled and buffer was allocated
|
// Write cache file if caching was enabled and buffer was allocated
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#include <esp_system.h>
|
#include <esp_system.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <memory>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
|
||||||
#include "../reader/EpubReaderActivity.h"
|
#include "../reader/EpubReaderActivity.h"
|
||||||
@@ -47,9 +48,9 @@ struct PngOverlayCtx {
|
|||||||
|
|
||||||
// PNGdec file I/O callbacks — mirror the pattern in PngToFramebufferConverter.cpp.
|
// PNGdec file I/O callbacks — mirror the pattern in PngToFramebufferConverter.cpp.
|
||||||
void* pngSleepOpen(const char* filename, int32_t* size) {
|
void* pngSleepOpen(const char* filename, int32_t* size) {
|
||||||
FsFile* f = new FsFile();
|
FsFile* f = new FsFile(); // NOLINT(cppcoreguidelines-owning-memory) — ownership transferred via void* to PNGdec callbacks
|
||||||
if (!Storage.openFileForRead("SLP", std::string(filename), *f)) {
|
if (!Storage.openFileForRead("SLP", std::string(filename), *f)) {
|
||||||
delete f;
|
delete f; // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
*size = f->size();
|
*size = f->size();
|
||||||
@@ -59,7 +60,7 @@ void pngSleepClose(void* handle) {
|
|||||||
FsFile* f = reinterpret_cast<FsFile*>(handle);
|
FsFile* f = reinterpret_cast<FsFile*>(handle);
|
||||||
if (f) {
|
if (f) {
|
||||||
f->close();
|
f->close();
|
||||||
delete f;
|
delete f; // NOLINT(cppcoreguidelines-owning-memory)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int32_t pngSleepRead(PNGFILE* pFile, uint8_t* pBuf, int32_t len) {
|
int32_t pngSleepRead(PNGFILE* pFile, uint8_t* pBuf, int32_t len) {
|
||||||
@@ -869,13 +870,12 @@ void SleepActivity::renderOverlaySleepScreen() const {
|
|||||||
LOG_ERR("SLP", "Not enough heap for PNG overlay decoder");
|
LOG_ERR("SLP", "Not enough heap for PNG overlay decoder");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
PNG* png = new (std::nothrow) PNG();
|
std::unique_ptr<PNG> png(new (std::nothrow) PNG());
|
||||||
if (!png) return false;
|
if (!png) return false;
|
||||||
|
|
||||||
int rc = png->open(filename.c_str(), pngSleepOpen, pngSleepClose, pngSleepRead, pngSleepSeek, pngOverlayDraw);
|
int rc = png->open(filename.c_str(), pngSleepOpen, pngSleepClose, pngSleepRead, pngSleepSeek, pngOverlayDraw);
|
||||||
if (rc != PNG_SUCCESS) {
|
if (rc != PNG_SUCCESS) {
|
||||||
LOG_DBG("SLP", "PNG open failed: %s (%d)", filename.c_str(), rc);
|
LOG_DBG("SLP", "PNG open failed: %s (%d)", filename.c_str(), rc);
|
||||||
delete png;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -905,7 +905,6 @@ void SleepActivity::renderOverlaySleepScreen() const {
|
|||||||
|
|
||||||
rc = png->decode(&ctx, 0);
|
rc = png->decode(&ctx, 0);
|
||||||
png->close();
|
png->close();
|
||||||
delete png;
|
|
||||||
return rc == PNG_SUCCESS;
|
return rc == PNG_SUCCESS;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user