73 template<
typename T_COLOR_FEATURE,
typename T_FILE_METHOD>
class NeoBitmapFile
77 _fileAddressPixels(0),
98 if (!file || !file.seek(0))
109 result = _file.read((uint8_t*)(&bmpHeader),
sizeof(bmpHeader));
111 if (result !=
sizeof(bmpHeader) ||
118 result = _file.read((uint8_t*)(&bmpInfoHeader),
sizeof(bmpInfoHeader));
120 if (result !=
sizeof(bmpInfoHeader) ||
121 result != bmpInfoHeader.
Size ||
122 1 != bmpInfoHeader.
Planes ||
135 _width = abs(bmpInfoHeader.
Width);
136 _height = abs(bmpInfoHeader.
Height);
139 _bottomToTop = (bmpInfoHeader.
Height > 0);
141 _sizeRow = (bmpInfoHeader.
BitsPerPixel * _width + 31) / 32 * 4;
147 _fileAddressPixels = 0;
159 return T_COLOR_FEATURE::PixelSize;
164 return _width * _height;
179 if (x < 0 || x >= _width || y < 0 || y >= _height)
186 typename T_COLOR_FEATURE::ColorObject color;
187 if (!seek(x, y) || !readPixel(&color))
203 const uint16_t destPixelCount = destBuffer.
PixelCount();
204 typename T_COLOR_FEATURE::ColorObject color(0);
205 xSrc = constrainX(xSrc);
206 ySrc = constrainY(ySrc);
208 if (seek(xSrc, ySrc))
210 for (int16_t x = 0; x < wSrc && indexPixel < destPixelCount; x++, indexPixel++)
212 if (
static_cast<uint16_t
>(xSrc) < _width)
214 if (readPixel(&color))
216 color = shader.Apply(indexPixel, color);
221 T_COLOR_FEATURE::applyPixelColor(destBuffer.
Pixels, indexPixel, color);
234 Render<NeoShaderNop<typename T_COLOR_FEATURE::ColorObject>>(destBuffer, shaderNop, indexPixel, xSrc, ySrc, wSrc);
247 const uint16_t destPixelCount = destBuffer.
PixelCount();
248 typename T_COLOR_FEATURE::ColorObject color(0);
250 for (int16_t y = 0; y < hSrc; y++)
252 int16_t xFile = constrainX(xSrc);
253 int16_t yFile = constrainY(ySrc + y);
255 if (seek(xFile, yFile))
257 for (int16_t x = 0; x < wSrc; x++)
259 uint16_t indexDest = layoutMap(xDest + x, yDest + y);
261 if (
static_cast<uint16_t
>(xFile) < _width)
263 if (readPixel(&color))
265 color = shader.Apply(indexDest, color);
270 if (indexDest < destPixelCount)
272 T_COLOR_FEATURE::applyPixelColor(destBuffer.
Pixels, indexDest, color);
290 Render<NeoShaderNop<typename T_COLOR_FEATURE::ColorObject>>(destBuffer,
304 uint32_t _fileAddressPixels;
308 uint8_t _bytesPerPixel;
311 int16_t constrainX(int16_t x)
const
317 else if (
static_cast<uint16_t
>(x) >= _width)
324 int16_t constrainY(int16_t y)
const
330 else if (
static_cast<uint16_t
>(y) >= _height)
337 bool seek(int16_t x, int16_t y)
341 y = (_height - 1) - y;
344 uint32_t pos = y * _sizeRow + x * _bytesPerPixel;
345 pos += _fileAddressPixels;
347 return _file.seek(pos);
355 result = _file.read(bgr, _bytesPerPixel);
357 if (result != _bytesPerPixel)
376 result = _file.read(bgr, _bytesPerPixel);
378 if (result != _bytesPerPixel)
std::function< uint16_t(int16_t x, int16_t y)> LayoutMapCallback
Definition: LayoutMapCallback.h:39
BmpCompression
Definition: NeoBitmapFile.h:57
@ BI_Bitfields
Definition: NeoBitmapFile.h:61
@ BI_CmykRle4
Definition: NeoBitmapFile.h:67
@ BI_Jpeg
Definition: NeoBitmapFile.h:62
@ BI_CmykRle8
Definition: NeoBitmapFile.h:66
@ BI_Rle4
Definition: NeoBitmapFile.h:60
@ BI_AlphaBitfields
Definition: NeoBitmapFile.h:64
@ BI_Rle8
Definition: NeoBitmapFile.h:59
@ BI_Png
Definition: NeoBitmapFile.h:63
@ BI_Cmyk
Definition: NeoBitmapFile.h:65
@ BI_Rgb
Definition: NeoBitmapFile.h:58
const uint16_t c_BitmapFileId
Definition: NeoBitmapFile.h:28
Definition: NeoBitmapFile.h:74
uint16_t Height() const
Definition: NeoBitmapFile.h:172
size_t PixelSize() const
Definition: NeoBitmapFile.h:157
T_COLOR_FEATURE::ColorObject GetPixelColor(int16_t x, int16_t y)
Definition: NeoBitmapFile.h:177
~NeoBitmapFile()
Definition: NeoBitmapFile.h:86
uint16_t Width() const
Definition: NeoBitmapFile.h:167
uint16_t PixelCount() const
Definition: NeoBitmapFile.h:162
void Blt(NeoBufferContext< T_COLOR_FEATURE > destBuffer, int16_t xDest, int16_t yDest, int16_t xSrc, int16_t ySrc, int16_t wSrc, int16_t hSrc, LayoutMapCallback layoutMap)
Definition: NeoBitmapFile.h:279
void Render(NeoBufferContext< T_COLOR_FEATURE > destBuffer, T_SHADER &shader, uint16_t indexPixel, int16_t xSrc, int16_t ySrc, int16_t wSrc)
Definition: NeoBitmapFile.h:196
void Blt(NeoBufferContext< T_COLOR_FEATURE > destBuffer, uint16_t indexPixel, int16_t xSrc, int16_t ySrc, int16_t wSrc)
Definition: NeoBitmapFile.h:226
NeoBitmapFile()
Definition: NeoBitmapFile.h:76
bool Begin(T_FILE_METHOD file)
Definition: NeoBitmapFile.h:91
void Render(NeoBufferContext< T_COLOR_FEATURE > destBuffer, T_SHADER &shader, int16_t xDest, int16_t yDest, int16_t xSrc, int16_t ySrc, int16_t wSrc, int16_t hSrc, LayoutMapCallback layoutMap)
Definition: NeoBitmapFile.h:237
Definition: NeoShaderNop.h:29
Definition: NeoBufferContext.h:32
uint8_t * Pixels
Definition: NeoBufferContext.h:43
uint16_t PixelCount() const
Definition: NeoBufferContext.h:40
Definition: RgbColor.h:36
uint8_t G
Definition: RgbColor.h:247
uint8_t B
Definition: RgbColor.h:248
uint8_t R
Definition: RgbColor.h:246
Definition: RgbwColor.h:38
uint8_t R
Definition: RgbwColor.h:271
uint8_t W
Definition: RgbwColor.h:274
uint8_t B
Definition: RgbwColor.h:273
uint8_t G
Definition: RgbwColor.h:272