feat: Take screenshots (#759)

## Summary

* **What is the goal of this PR?** Implements a take-screenshot feature
* **What changes are included?**

- Quick press Power button and Down button at the same time to take a
screenshot
- Screenshots are saved in `screenshots` folder

## Additional Context

- Currently it does not use the device orientation.

---

Example screenshots:


![screenshot-6771.bmp](https://github.com/user-attachments/files/25157071/screenshot-6771.bmp)

[screenshot-6771.bmp](https://github.com/user-attachments/files/25157071/screenshot-6771.bmp)


![screenshot-14158.bmp](https://github.com/user-attachments/files/25157073/screenshot-14158.bmp)

[screenshot-14158.bmp](https://github.com/user-attachments/files/25157073/screenshot-14158.bmp)


### AI Usage

Did you use AI tools to help write this code? _** YES

---------

Co-authored-by: Eliz Kilic <elizk@google.com>
Co-authored-by: Xuan Son Nguyen <son@huggingface.co>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Arthur Tazhitdinov <lisnake@gmail.com>
This commit is contained in:
Eliz
2026-02-22 04:22:32 +00:00
committed by GitHub
parent 5f5561b684
commit c1fad16e10
19 changed files with 264 additions and 10 deletions

View File

@@ -1,6 +1,9 @@
#include "BitmapHelpers.h"
#include <cstdint>
#include <cstring> // Added for memset
#include "Bitmap.h"
// Brightness/Contrast adjustments:
constexpr bool USE_BRIGHTNESS = false; // true: apply brightness/gamma adjustments
@@ -104,3 +107,44 @@ uint8_t quantize1bit(int gray, int x, int y) {
const int adjustedThreshold = 128 + ((threshold - 128) / 2); // Range: 64-192
return (gray >= adjustedThreshold) ? 1 : 0;
}
void createBmpHeader(BmpHeader* bmpHeader, int width, int height) {
if (!bmpHeader) return;
// Zero out the memory to ensure no garbage data if called on uninitialized stack memory
std::memset(bmpHeader, 0, sizeof(BmpHeader));
uint32_t rowSize = (width + 31) / 32 * 4;
uint32_t imageSize = rowSize * height;
uint32_t fileSize = sizeof(BmpHeader) + imageSize;
bmpHeader->fileHeader.bfType = 0x4D42;
bmpHeader->fileHeader.bfSize = fileSize;
bmpHeader->fileHeader.bfReserved1 = 0;
bmpHeader->fileHeader.bfReserved2 = 0;
bmpHeader->fileHeader.bfOffBits = sizeof(BmpHeader);
bmpHeader->infoHeader.biSize = sizeof(bmpHeader->infoHeader);
bmpHeader->infoHeader.biWidth = width;
bmpHeader->infoHeader.biHeight = height;
bmpHeader->infoHeader.biPlanes = 1;
bmpHeader->infoHeader.biBitCount = 1;
bmpHeader->infoHeader.biCompression = 0;
bmpHeader->infoHeader.biSizeImage = imageSize;
bmpHeader->infoHeader.biXPelsPerMeter = 0;
bmpHeader->infoHeader.biYPelsPerMeter = 0;
bmpHeader->infoHeader.biClrUsed = 0;
bmpHeader->infoHeader.biClrImportant = 0;
// Color 0 (black)
bmpHeader->colors[0].rgbBlue = 0;
bmpHeader->colors[0].rgbGreen = 0;
bmpHeader->colors[0].rgbRed = 0;
bmpHeader->colors[0].rgbReserved = 0;
// Color 1 (white)
bmpHeader->colors[1].rgbBlue = 255;
bmpHeader->colors[1].rgbGreen = 255;
bmpHeader->colors[1].rgbRed = 255;
bmpHeader->colors[1].rgbReserved = 0;
}