Custom sleep screen support with BMP reading (#57)
## Summary * Builds on top of https://github.com/daveallie/crosspoint-reader/pull/16 - adresses https://github.com/daveallie/crosspoint-reader/discussions/14 * This PR adds the ability for the user to supply a custom `sleep.bmp` image at the root of the SD card that will be shown instead of the default sleep screen if present. * Supports: * Different BPPs: * 1bit * 2bit * 8bit * 24bit * 32bit (with alpha-channel ignored) * Grayscale rendering --------- Co-authored-by: Sam Davis <sam@sjd.co>
This commit is contained in:
52
lib/GfxRenderer/Bitmap.h
Normal file
52
lib/GfxRenderer/Bitmap.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <FS.h>
|
||||
|
||||
enum class BmpReaderError : uint8_t {
|
||||
Ok = 0,
|
||||
FileInvalid,
|
||||
SeekStartFailed,
|
||||
|
||||
NotBMP,
|
||||
DIBTooSmall,
|
||||
|
||||
BadPlanes,
|
||||
UnsupportedBpp,
|
||||
UnsupportedCompression,
|
||||
|
||||
BadDimensions,
|
||||
PaletteTooLarge,
|
||||
|
||||
SeekPixelDataFailed,
|
||||
BufferTooSmall,
|
||||
OomRowBuffer,
|
||||
ShortReadRow,
|
||||
};
|
||||
|
||||
class Bitmap {
|
||||
public:
|
||||
static const char* errorToString(BmpReaderError err);
|
||||
|
||||
explicit Bitmap(File& file) : file(file) {}
|
||||
BmpReaderError parseHeaders();
|
||||
BmpReaderError readRow(uint8_t* data, uint8_t* rowBuffer) const;
|
||||
BmpReaderError rewindToData() const;
|
||||
int getWidth() const { return width; }
|
||||
int getHeight() const { return height; }
|
||||
bool isTopDown() const { return topDown; }
|
||||
bool hasGreyscale() const { return bpp > 1; }
|
||||
int getRowBytes() const { return rowBytes; }
|
||||
|
||||
private:
|
||||
static uint16_t readLE16(File& f);
|
||||
static uint32_t readLE32(File& f);
|
||||
|
||||
File& file;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
bool topDown = false;
|
||||
uint32_t bfOffBits = 0;
|
||||
uint16_t bpp = 0;
|
||||
int rowBytes = 0;
|
||||
uint8_t paletteLum[256] = {};
|
||||
};
|
||||
Reference in New Issue
Block a user