fix cover art sizing options
This commit is contained in:
@@ -141,58 +141,79 @@ void SleepActivity::renderBitmapSleepScreen(const Bitmap& bitmap) const {
|
||||
const auto pageWidth = renderer.getScreenWidth();
|
||||
const auto pageHeight = renderer.getScreenHeight();
|
||||
float cropX = 0, cropY = 0;
|
||||
int drawWidth = pageWidth;
|
||||
int drawHeight = pageHeight;
|
||||
|
||||
Serial.printf("[%lu] [SLP] bitmap %d x %d, screen %d x %d\n", millis(), bitmap.getWidth(), bitmap.getHeight(),
|
||||
pageWidth, pageHeight);
|
||||
if (bitmap.getWidth() > pageWidth || bitmap.getHeight() > pageHeight) {
|
||||
// image will scale, make sure placement is right
|
||||
float ratio = static_cast<float>(bitmap.getWidth()) / static_cast<float>(bitmap.getHeight());
|
||||
const float screenRatio = static_cast<float>(pageWidth) / static_cast<float>(pageHeight);
|
||||
|
||||
Serial.printf("[%lu] [SLP] bitmap ratio: %f, screen ratio: %f\n", millis(), ratio, screenRatio);
|
||||
if (ratio > screenRatio) {
|
||||
// image wider than viewport ratio, scaled down image needs to be centered vertically
|
||||
if (SETTINGS.sleepScreenCoverMode == CrossPointSettings::SLEEP_SCREEN_COVER_MODE::CROP) {
|
||||
cropX = 1.0f - (screenRatio / ratio);
|
||||
Serial.printf("[%lu] [SLP] Cropping bitmap x: %f\n", millis(), cropX);
|
||||
ratio = (1.0f - cropX) * static_cast<float>(bitmap.getWidth()) / static_cast<float>(bitmap.getHeight());
|
||||
}
|
||||
x = 0;
|
||||
y = std::round((static_cast<float>(pageHeight) - static_cast<float>(pageWidth) / ratio) / 2);
|
||||
Serial.printf("[%lu] [SLP] Centering with ratio %f to y=%d\n", millis(), ratio, y);
|
||||
} else {
|
||||
// image taller than viewport ratio, scaled down image needs to be centered horizontally
|
||||
if (SETTINGS.sleepScreenCoverMode == CrossPointSettings::SLEEP_SCREEN_COVER_MODE::CROP) {
|
||||
cropY = 1.0f - (ratio / screenRatio);
|
||||
Serial.printf("[%lu] [SLP] Cropping bitmap y: %f\n", millis(), cropY);
|
||||
ratio = static_cast<float>(bitmap.getWidth()) / ((1.0f - cropY) * static_cast<float>(bitmap.getHeight()));
|
||||
}
|
||||
x = std::round((static_cast<float>(pageWidth) - static_cast<float>(pageHeight) * ratio) / 2);
|
||||
y = 0;
|
||||
Serial.printf("[%lu] [SLP] Centering with ratio %f to x=%d\n", millis(), ratio, x);
|
||||
}
|
||||
} else {
|
||||
// center the image
|
||||
const float bitmapRatio = static_cast<float>(bitmap.getWidth()) / static_cast<float>(bitmap.getHeight());
|
||||
const float screenRatio = static_cast<float>(pageWidth) / static_cast<float>(pageHeight);
|
||||
Serial.printf("[%lu] [SLP] bitmap ratio: %f, screen ratio: %f\n", millis(), bitmapRatio, screenRatio);
|
||||
|
||||
const auto coverMode = SETTINGS.sleepScreenCoverMode;
|
||||
|
||||
if (coverMode == CrossPointSettings::SLEEP_SCREEN_COVER_MODE::ACTUAL) {
|
||||
// ACTUAL mode: Show image at actual size, centered (no scaling)
|
||||
x = (pageWidth - bitmap.getWidth()) / 2;
|
||||
y = (pageHeight - bitmap.getHeight()) / 2;
|
||||
// Don't constrain to screen dimensions - drawBitmap will clip
|
||||
drawWidth = 0;
|
||||
drawHeight = 0;
|
||||
Serial.printf("[%lu] [SLP] ACTUAL mode: centering at %d, %d\n", millis(), x, y);
|
||||
} else if (coverMode == CrossPointSettings::SLEEP_SCREEN_COVER_MODE::CROP) {
|
||||
// CROP mode: Scale to fill screen completely (may crop edges)
|
||||
// Calculate crop values to fill the screen while maintaining aspect ratio
|
||||
if (bitmapRatio > screenRatio) {
|
||||
// Image is wider than screen ratio - crop horizontally
|
||||
cropX = 1.0f - (screenRatio / bitmapRatio);
|
||||
Serial.printf("[%lu] [SLP] CROP mode: cropping x by %f\n", millis(), cropX);
|
||||
} else if (bitmapRatio < screenRatio) {
|
||||
// Image is taller than screen ratio - crop vertically
|
||||
cropY = 1.0f - (bitmapRatio / screenRatio);
|
||||
Serial.printf("[%lu] [SLP] CROP mode: cropping y by %f\n", millis(), cropY);
|
||||
}
|
||||
// After cropping, the image should fill the screen exactly
|
||||
x = 0;
|
||||
y = 0;
|
||||
Serial.printf("[%lu] [SLP] CROP mode: drawing at 0, 0 with crop %f, %f\n", millis(), cropX, cropY);
|
||||
} else {
|
||||
// FIT mode (default): Scale to fit entire image within screen (may have letterboxing)
|
||||
// Calculate the scaled dimensions
|
||||
float scale;
|
||||
if (bitmapRatio > screenRatio) {
|
||||
// Image is wider than screen ratio - fit to width
|
||||
scale = static_cast<float>(pageWidth) / static_cast<float>(bitmap.getWidth());
|
||||
} else {
|
||||
// Image is taller than screen ratio - fit to height
|
||||
scale = static_cast<float>(pageHeight) / static_cast<float>(bitmap.getHeight());
|
||||
}
|
||||
const int scaledWidth = static_cast<int>(bitmap.getWidth() * scale);
|
||||
const int scaledHeight = static_cast<int>(bitmap.getHeight() * scale);
|
||||
|
||||
// Center the scaled image
|
||||
x = (pageWidth - scaledWidth) / 2;
|
||||
y = (pageHeight - scaledHeight) / 2;
|
||||
Serial.printf("[%lu] [SLP] FIT mode: scale %f, scaled size %d x %d, position %d, %d\n", millis(), scale,
|
||||
scaledWidth, scaledHeight, x, y);
|
||||
}
|
||||
|
||||
Serial.printf("[%lu] [SLP] drawing to %d x %d\n", millis(), x, y);
|
||||
renderer.clearScreen();
|
||||
renderer.drawBitmap(bitmap, x, y, pageWidth, pageHeight, cropX, cropY);
|
||||
renderer.drawBitmap(bitmap, x, y, drawWidth, drawHeight, cropX, cropY);
|
||||
renderer.displayBuffer(EInkDisplay::HALF_REFRESH);
|
||||
|
||||
if (bitmap.hasGreyscale()) {
|
||||
bitmap.rewindToData();
|
||||
renderer.clearScreen(0x00);
|
||||
renderer.setRenderMode(GfxRenderer::GRAYSCALE_LSB);
|
||||
renderer.drawBitmap(bitmap, x, y, pageWidth, pageHeight, cropX, cropY);
|
||||
renderer.drawBitmap(bitmap, x, y, drawWidth, drawHeight, cropX, cropY);
|
||||
renderer.copyGrayscaleLsbBuffers();
|
||||
|
||||
bitmap.rewindToData();
|
||||
renderer.clearScreen(0x00);
|
||||
renderer.setRenderMode(GfxRenderer::GRAYSCALE_MSB);
|
||||
renderer.drawBitmap(bitmap, x, y, pageWidth, pageHeight, cropX, cropY);
|
||||
renderer.drawBitmap(bitmap, x, y, drawWidth, drawHeight, cropX, cropY);
|
||||
renderer.copyGrayscaleMsbBuffers();
|
||||
|
||||
renderer.displayGrayBuffer();
|
||||
|
||||
Reference in New Issue
Block a user