From 5fa58a002cc6170df75a38b4aa48274da9a15904 Mon Sep 17 00:00:00 2001 From: Eliz Date: Tue, 27 Jan 2026 13:21:59 +0000 Subject: [PATCH] feat: Add support to B&W filters to image covers (#476) ## Summary * **What is the goal of this PR?** (e.g., Implements the new feature for file uploading.) Implementation of a new feature in Display options as Image Filter * **What changes are included?** Black & White and Inverted Black & White options are added. ## Additional Context Here are some examples: | None | Contrast | Inverted | | --- | --- | --- | | image | image | image | | image | image | image | * Add any other information that might be helpful for the reviewer (e.g., performance implications, potential risks, specific areas to focus on). I have also tried adding Color inversion, but could not see much difference with that. It might be because my implementation was wrong. --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _** PARTIALLY **_ --------- Co-authored-by: Dave Allie --- USER_GUIDE.md | 4 ++++ src/CrossPointSettings.cpp | 9 ++++++--- src/CrossPointSettings.h | 8 ++++++++ src/activities/boot_sleep/SleepActivity.cpp | 11 ++++++++++- src/activities/settings/SettingsActivity.cpp | 4 +++- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/USER_GUIDE.md b/USER_GUIDE.md index bdc0f036..06973c92 100644 --- a/USER_GUIDE.md +++ b/USER_GUIDE.md @@ -105,6 +105,10 @@ The Settings screen allows you to configure the device's behavior. There are a f - **Sleep Screen Cover Mode**: How to display the book cover when "Cover" sleep screen is selected: - "Fit" (default) - Scale the image down to fit centered on the screen, padding with white borders as necessary - "Crop" - Scale the image down and crop as necessary to try to to fill the screen (Note: this is experimental and may not work as expected) +- **Sleep Screen Cover Filter**: What filter will be applied to the book cover when "Cover" sleep screen is selected + - "None" (default) - The cover image will be converted to a grayscale image and displayed as it is + - "Contrast" - The image will be displayed as a black & white image without grayscale conversion + - "Inverted" - The image will be inverted as in white&black and will be displayed without grayscale conversion - **Status Bar**: Configure the status bar displayed while reading: - "None" - No status bar - "No Progress" - Show status bar without reading progress diff --git a/src/CrossPointSettings.cpp b/src/CrossPointSettings.cpp index f3a7a524..232c7c57 100644 --- a/src/CrossPointSettings.cpp +++ b/src/CrossPointSettings.cpp @@ -22,7 +22,7 @@ void readAndValidate(FsFile& file, uint8_t& member, const uint8_t maxValue) { namespace { constexpr uint8_t SETTINGS_FILE_VERSION = 1; // Increment this when adding new persisted settings fields -constexpr uint8_t SETTINGS_COUNT = 22; +constexpr uint8_t SETTINGS_COUNT = 23; constexpr char SETTINGS_FILE[] = "/.crosspoint/settings.bin"; } // namespace @@ -57,9 +57,10 @@ bool CrossPointSettings::saveToFile() const { serialization::writePod(outputFile, hideBatteryPercentage); serialization::writePod(outputFile, longPressChapterSkip); serialization::writePod(outputFile, hyphenationEnabled); - // New fields added at end for backward compatibility serialization::writeString(outputFile, std::string(opdsUsername)); serialization::writeString(outputFile, std::string(opdsPassword)); + serialization::writePod(outputFile, sleepScreenCoverFilter); + // New fields added at end for backward compatibility outputFile.close(); Serial.printf("[%lu] [CPS] Settings saved to file\n", millis()); @@ -131,7 +132,6 @@ bool CrossPointSettings::loadFromFile() { if (++settingsRead >= fileSettingsCount) break; serialization::readPod(inputFile, hyphenationEnabled); if (++settingsRead >= fileSettingsCount) break; - // New fields added at end for backward compatibility { std::string usernameStr; serialization::readString(inputFile, usernameStr); @@ -146,6 +146,9 @@ bool CrossPointSettings::loadFromFile() { opdsPassword[sizeof(opdsPassword) - 1] = '\0'; } if (++settingsRead >= fileSettingsCount) break; + readAndValidate(inputFile, sleepScreenCoverFilter, SLEEP_SCREEN_COVER_FILTER_COUNT); + if (++settingsRead >= fileSettingsCount) break; + // New fields added at end for backward compatibility } while (false); inputFile.close(); diff --git a/src/CrossPointSettings.h b/src/CrossPointSettings.h index 6385f4f1..c450d348 100644 --- a/src/CrossPointSettings.h +++ b/src/CrossPointSettings.h @@ -17,6 +17,12 @@ class CrossPointSettings { enum SLEEP_SCREEN_MODE { DARK = 0, LIGHT = 1, CUSTOM = 2, COVER = 3, BLANK = 4, SLEEP_SCREEN_MODE_COUNT }; enum SLEEP_SCREEN_COVER_MODE { FIT = 0, CROP = 1, SLEEP_SCREEN_COVER_MODE_COUNT }; + enum SLEEP_SCREEN_COVER_FILTER { + NO_FILTER = 0, + BLACK_AND_WHITE = 1, + INVERTED_BLACK_AND_WHITE = 2, + SLEEP_SCREEN_COVER_FILTER_COUNT + }; // Status bar display type enum enum STATUS_BAR_MODE { @@ -95,6 +101,8 @@ class CrossPointSettings { uint8_t sleepScreen = DARK; // Sleep screen cover mode settings uint8_t sleepScreenCoverMode = FIT; + // Sleep screen cover filter + uint8_t sleepScreenCoverFilter = NO_FILTER; // Status bar settings uint8_t statusBar = FULL; // Text rendering settings diff --git a/src/activities/boot_sleep/SleepActivity.cpp b/src/activities/boot_sleep/SleepActivity.cpp index c4b98968..95fe742f 100644 --- a/src/activities/boot_sleep/SleepActivity.cpp +++ b/src/activities/boot_sleep/SleepActivity.cpp @@ -179,10 +179,19 @@ void SleepActivity::renderBitmapSleepScreen(const Bitmap& bitmap) const { Serial.printf("[%lu] [SLP] drawing to %d x %d\n", millis(), x, y); renderer.clearScreen(); + + const bool hasGreyscale = bitmap.hasGreyscale() && + SETTINGS.sleepScreenCoverFilter == CrossPointSettings::SLEEP_SCREEN_COVER_FILTER::NO_FILTER; + renderer.drawBitmap(bitmap, x, y, pageWidth, pageHeight, cropX, cropY); + + if (SETTINGS.sleepScreenCoverFilter == CrossPointSettings::SLEEP_SCREEN_COVER_FILTER::INVERTED_BLACK_AND_WHITE) { + renderer.invertScreen(); + } + renderer.displayBuffer(EInkDisplay::HALF_REFRESH); - if (bitmap.hasGreyscale()) { + if (hasGreyscale) { bitmap.rewindToData(); renderer.clearScreen(0x00); renderer.setRenderMode(GfxRenderer::GRAYSCALE_LSB); diff --git a/src/activities/settings/SettingsActivity.cpp b/src/activities/settings/SettingsActivity.cpp index a211e033..7316db05 100644 --- a/src/activities/settings/SettingsActivity.cpp +++ b/src/activities/settings/SettingsActivity.cpp @@ -11,11 +11,13 @@ const char* SettingsActivity::categoryNames[categoryCount] = {"Display", "Reader", "Controls", "System"}; namespace { -constexpr int displaySettingsCount = 5; +constexpr int displaySettingsCount = 6; const SettingInfo displaySettings[displaySettingsCount] = { // Should match with SLEEP_SCREEN_MODE SettingInfo::Enum("Sleep Screen", &CrossPointSettings::sleepScreen, {"Dark", "Light", "Custom", "Cover", "None"}), SettingInfo::Enum("Sleep Screen Cover Mode", &CrossPointSettings::sleepScreenCoverMode, {"Fit", "Crop"}), + SettingInfo::Enum("Sleep Screen Cover Filter", &CrossPointSettings::sleepScreenCoverFilter, + {"None", "Contrast", "Inverted"}), SettingInfo::Enum("Status Bar", &CrossPointSettings::statusBar, {"None", "No Progress", "Full w/ Percentage", "Full w/ Progress Bar", "Progress Bar"}), SettingInfo::Enum("Hide Battery %", &CrossPointSettings::hideBatteryPercentage, {"Never", "In Reader", "Always"}),