Refactoring and proper handling of quantization.
Moving color and dithering related helpers into dedicated file. In case of 2bpp (i.e. file generated from JPG), we don't apply any color adjustments. In other cases, they are applied based on selected algorithm.
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "BitmapHelpers.h"
|
||||
|
||||
enum class BmpReaderError : uint8_t {
|
||||
Ok = 0,
|
||||
FileInvalid,
|
||||
@@ -30,7 +32,7 @@ class Bitmap {
|
||||
public:
|
||||
static const char* errorToString(BmpReaderError err);
|
||||
|
||||
explicit Bitmap(FsFile& file, bool useFloydSteinberg = false) : file(file), useFloydSteinberg(useFloydSteinberg) {}
|
||||
explicit Bitmap(FsFile& file, bool dithering = false) : file(file), dithering(dithering) {}
|
||||
~Bitmap();
|
||||
BmpReaderError parseHeaders();
|
||||
BmpReaderError readNextRow(uint8_t* data, uint8_t* rowBuffer) const;
|
||||
@@ -46,7 +48,7 @@ class Bitmap {
|
||||
static uint32_t readLE32(FsFile& f);
|
||||
|
||||
FsFile& file;
|
||||
bool useFloydSteinberg = false;
|
||||
bool dithering = false;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
bool topDown = false;
|
||||
@@ -59,9 +61,7 @@ class Bitmap {
|
||||
mutable int16_t* errorCurRow = nullptr;
|
||||
mutable int16_t* errorNextRow = nullptr;
|
||||
mutable int prevRowY = -1; // Track row progression for error propagation
|
||||
};
|
||||
|
||||
// Helper functions
|
||||
uint8_t quantize(int gray, int x, int y);
|
||||
uint8_t quantizeSimple(int gray);
|
||||
int adjustPixel(int gray);
|
||||
mutable AtkinsonDitherer* atkinsonDitherer = nullptr;
|
||||
mutable FloydSteinbergDitherer* fsDitherer = nullptr;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user