Some fixes for cover generation
This commit is contained in:
@@ -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)
|
||||
|
||||
+9
-1
@@ -266,7 +266,15 @@ std::string Xtc::getThumbBmpPath(int width, int height) const {
|
||||
return cachePath + "/thumb_" + std::to_string(width) + "x" + std::to_string(height) + ".bmp";
|
||||
}
|
||||
|
||||
bool Xtc::generateThumbBmp(int height) const { return generateThumbBmp(height * 0.6, height); }
|
||||
bool Xtc::generateThumbBmp(int height) const {
|
||||
const std::string destPath = getThumbBmpPath(height);
|
||||
if (Storage.exists(destPath.c_str())) return true;
|
||||
const int width = static_cast<int>(height * 0.6f);
|
||||
if (!generateThumbBmp(width, height)) return false;
|
||||
const std::string srcPath = getThumbBmpPath(width, height);
|
||||
Storage.rename(srcPath.c_str(), destPath.c_str());
|
||||
return Storage.exists(destPath.c_str());
|
||||
}
|
||||
|
||||
bool Xtc::generateThumbBmp(int width, int height) const {
|
||||
if (Storage.exists(getThumbBmpPath(width, height).c_str())) return true;
|
||||
|
||||
Reference in New Issue
Block a user