Some fixes for cover generation

This commit is contained in:
jpirnay
2026-05-08 18:04:41 +02:00
parent 13e87ff470
commit 79ef2eea91
5 changed files with 29 additions and 15 deletions
+12 -9
View File
@@ -1550,8 +1550,6 @@ void GfxRenderer::drawBitmap(const Bitmap& bitmap, const int x, const int y, con
bool isScaled = false;
int cropPixX = std::floor(bitmap.getWidth() * cropX / 2.0f);
int cropPixY = std::floor(bitmap.getHeight() * cropY / 2.0f);
LOG_DBG("GFX", "Cropping %dx%d by %dx%d pix, is %s", bitmap.getWidth(), bitmap.getHeight(), cropPixX, cropPixY,
bitmap.isTopDown() ? "top-down" : "bottom-up");
const float croppedWidth = (1.0f - cropX) * static_cast<float>(bitmap.getWidth());
const float croppedHeight = (1.0f - cropY) * static_cast<float>(bitmap.getHeight());
@@ -1573,7 +1571,6 @@ void GfxRenderer::drawBitmap(const Bitmap& bitmap, const int x, const int y, con
scale = fitScale;
isScaled = true;
}
LOG_DBG("GFX", "Scaling by %f - %s", scale, isScaled ? "scaled" : "not scaled");
// Calculate output row size (2 bits per pixel, packed into bytes)
// IMPORTANT: Use int, not uint8_t, to avoid overflow for images > 1020 pixels wide
@@ -1650,13 +1647,19 @@ void GfxRenderer::drawBitmap1Bit(const Bitmap& bitmap, const int x, const int y,
const int maxHeight) const {
float scale = 1.0f;
bool isScaled = false;
if (maxWidth > 0 && bitmap.getWidth() > maxWidth) {
scale = static_cast<float>(maxWidth) / static_cast<float>(bitmap.getWidth());
isScaled = true;
if (maxWidth > 0) {
const float s = static_cast<float>(maxWidth) / static_cast<float>(bitmap.getWidth());
if (s != 1.0f) {
scale = s;
isScaled = true;
}
}
if (maxHeight > 0 && bitmap.getHeight() > maxHeight) {
scale = std::min(scale, static_cast<float>(maxHeight) / static_cast<float>(bitmap.getHeight()));
isScaled = true;
if (maxHeight > 0) {
const float s = static_cast<float>(maxHeight) / static_cast<float>(bitmap.getHeight());
if (s < scale) {
scale = s;
isScaled = (scale != 1.0f);
}
}
// For 1-bit BMP, output is still 2-bit packed (for consistency with readNextRow)