parent
9237b2b1ac
commit
b9ff412df5
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,15 @@ |
|||||||
|
#ifndef MONOFORMAT_PARSEONLY_HPP |
||||||
|
#define MONOFORMAT_PARSEONLY_HPP |
||||||
|
|
||||||
|
#include "monoformat_parsehelpers.hpp" |
||||||
|
#include "monoformat_schema.hpp" |
||||||
|
|
||||||
|
namespace monoformat { |
||||||
|
|
||||||
|
std::expected<void, ParseError> parseAndApply(std::span<std::byte const> data, OneBitBufferInterface* buffer, |
||||||
|
std::uint16_t screenWidth, std::uint16_t screenHeight, |
||||||
|
bool isFront, std::size_t animationTick, std::int64_t currentTimestamp); |
||||||
|
|
||||||
|
} // namespace monoformat
|
||||||
|
|
||||||
|
#endif // MONOFORMAT_PARSEONLY_HPP
|
||||||
@ -0,0 +1,103 @@ |
|||||||
|
#include "monoformat_schema.hpp" |
||||||
|
|
||||||
|
#include <tuple> |
||||||
|
|
||||||
|
namespace monoformat { |
||||||
|
|
||||||
|
MemoryOneBitBuffer::MemoryOneBitBuffer(std::span<std::byte> buffer, std::uint16_t width, std::uint16_t height) |
||||||
|
: m_width{width} |
||||||
|
, m_height{height} |
||||||
|
, m_buffer{buffer} |
||||||
|
{ |
||||||
|
std::size_t expectedSize = (m_width * m_height + 8 - 1) / 8; |
||||||
|
if (m_buffer.size() < expectedSize) { |
||||||
|
m_width = 0; |
||||||
|
m_height = 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
MemoryOneBitBuffer::~MemoryOneBitBuffer() { |
||||||
|
} |
||||||
|
|
||||||
|
bool MemoryOneBitBuffer::isPixelSet(std::uint16_t x, std::uint16_t y) const { |
||||||
|
if (x >= m_width || y >= m_height) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
std::size_t pxIndex = static_cast<std::size_t>(y) * m_width + x; |
||||||
|
std::size_t byteIndex = pxIndex / 8; |
||||||
|
std::size_t bitIndex = pxIndex % 8; |
||||||
|
return ((static_cast<std::uint8_t>(m_buffer[byteIndex]) >> bitIndex) & 0x01) == 0x01; |
||||||
|
} |
||||||
|
|
||||||
|
void MemoryOneBitBuffer::setPixel(std::uint16_t x, std::uint16_t y, bool value) { |
||||||
|
if (x >= m_width || y >= m_height) { |
||||||
|
return; |
||||||
|
} |
||||||
|
std::size_t pxIndex = static_cast<std::size_t>(y) * m_width + x; |
||||||
|
std::size_t byteIndex = pxIndex / 8; |
||||||
|
std::size_t bitIndex = pxIndex % 8; |
||||||
|
if (value) { |
||||||
|
m_buffer[byteIndex] = static_cast<std::byte>(static_cast<std::uint8_t>(m_buffer[byteIndex]) | (1u << bitIndex)); |
||||||
|
} else { |
||||||
|
m_buffer[byteIndex] = static_cast<std::byte>(static_cast<std::uint8_t>(m_buffer[byteIndex]) & ~(1u << bitIndex)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
ConstMemoryOneBitBuffer::ConstMemoryOneBitBuffer(std::span<std::byte const> buffer, std::uint16_t width, std::uint16_t height) |
||||||
|
: m_width{width} |
||||||
|
, m_height{height} |
||||||
|
, m_buffer{buffer} |
||||||
|
{ |
||||||
|
std::size_t expectedSize = (m_width * m_height + 8 - 1) / 8; |
||||||
|
if (m_buffer.size() < expectedSize) { |
||||||
|
m_width = 0; |
||||||
|
m_height = 0; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
ConstMemoryOneBitBuffer::~ConstMemoryOneBitBuffer() { |
||||||
|
} |
||||||
|
|
||||||
|
bool ConstMemoryOneBitBuffer::isPixelSet(std::uint16_t x, std::uint16_t y) const { |
||||||
|
if (x >= m_width || y >= m_height) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
std::size_t pxIndex = static_cast<std::size_t>(y) * m_width + x; |
||||||
|
std::size_t byteIndex = pxIndex / 8; |
||||||
|
std::size_t bitIndex = pxIndex % 8; |
||||||
|
return ((static_cast<std::uint8_t>(m_buffer[byteIndex]) >> bitIndex) & 0x01) == 0x01; |
||||||
|
} |
||||||
|
|
||||||
|
void ConstMemoryOneBitBuffer::setPixel(std::uint16_t x, std::uint16_t y, bool value) { |
||||||
|
std::ignore = x; |
||||||
|
std::ignore = y; |
||||||
|
std::ignore = value; |
||||||
|
} |
||||||
|
|
||||||
|
ClippedImage::ClippedImage(OneBitBufferInterface* underlying, std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height) |
||||||
|
: m_underlying{underlying} |
||||||
|
, m_x{x} |
||||||
|
, m_y{y} |
||||||
|
, m_width{width} |
||||||
|
, m_height{height} |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
ClippedImage::~ClippedImage() { |
||||||
|
} |
||||||
|
|
||||||
|
bool ClippedImage::isPixelSet(std::uint16_t x, std::uint16_t y) const { |
||||||
|
if (x >= m_width || y >= m_height) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
return m_underlying->isPixelSet(x + m_x, y + m_y); |
||||||
|
} |
||||||
|
|
||||||
|
void ClippedImage::setPixel(std::uint16_t x, std::uint16_t y, bool value) { |
||||||
|
if (x >= m_width || y >= m_height) { |
||||||
|
return; |
||||||
|
} |
||||||
|
m_underlying->setPixel(x + m_x, y + m_y, value); |
||||||
|
} |
||||||
|
|
||||||
|
} // namespace monoformat
|
||||||
@ -0,0 +1,77 @@ |
|||||||
|
#ifndef MONOFORMAT_SCHEMA_HPP |
||||||
|
#define MONOFORMAT_SCHEMA_HPP |
||||||
|
|
||||||
|
#include <cstddef> |
||||||
|
#include <cstdint> |
||||||
|
#include <span> |
||||||
|
|
||||||
|
namespace monoformat { |
||||||
|
|
||||||
|
enum class SectionType { |
||||||
|
AlwaysDrawn = 1, |
||||||
|
TimeBasedDrawn = 2, |
||||||
|
CustomFont = 32, |
||||||
|
}; |
||||||
|
|
||||||
|
enum class ElementType { |
||||||
|
Image = 1, |
||||||
|
Animation = 2, |
||||||
|
HScrollImage = 3, |
||||||
|
VScrollImage = 4, |
||||||
|
Line = 5, |
||||||
|
ClippedText = 16, |
||||||
|
HScrollText = 17, |
||||||
|
//VScrollText = 18,
|
||||||
|
CurrentTime = 32, |
||||||
|
}; |
||||||
|
|
||||||
|
enum class LineStyle : std::uint8_t { |
||||||
|
Solid = 0, |
||||||
|
}; |
||||||
|
|
||||||
|
struct OneBitBufferInterface { |
||||||
|
using Color = bool; |
||||||
|
|
||||||
|
virtual ~OneBitBufferInterface() = default; |
||||||
|
virtual bool isPixelSet(std::uint16_t x, std::uint16_t y) const = 0; |
||||||
|
virtual void setPixel(std::uint16_t x, std::uint16_t y, bool value) = 0; |
||||||
|
}; |
||||||
|
|
||||||
|
struct MemoryOneBitBuffer : public OneBitBufferInterface { |
||||||
|
MemoryOneBitBuffer(std::span<std::byte> buffer, std::uint16_t width, std::uint16_t height); |
||||||
|
virtual ~MemoryOneBitBuffer() override; |
||||||
|
virtual bool isPixelSet(std::uint16_t x, std::uint16_t y) const override; |
||||||
|
virtual void setPixel(std::uint16_t x, std::uint16_t y, bool value) override; |
||||||
|
private: |
||||||
|
std::uint16_t m_width{}; |
||||||
|
std::uint16_t m_height{}; |
||||||
|
std::span<std::byte> m_buffer; |
||||||
|
}; |
||||||
|
|
||||||
|
struct ConstMemoryOneBitBuffer : public OneBitBufferInterface { |
||||||
|
ConstMemoryOneBitBuffer(std::span<std::byte const> buffer, std::uint16_t width, std::uint16_t height); |
||||||
|
virtual ~ConstMemoryOneBitBuffer() override; |
||||||
|
virtual bool isPixelSet(std::uint16_t x, std::uint16_t y) const override; |
||||||
|
virtual void setPixel(std::uint16_t x, std::uint16_t y, bool value) override; |
||||||
|
private: |
||||||
|
std::uint16_t m_width{}; |
||||||
|
std::uint16_t m_height{}; |
||||||
|
std::span<std::byte const> m_buffer; |
||||||
|
}; |
||||||
|
|
||||||
|
struct ClippedImage : public OneBitBufferInterface { |
||||||
|
ClippedImage(OneBitBufferInterface* underlying, std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height); |
||||||
|
virtual ~ClippedImage() override; |
||||||
|
virtual bool isPixelSet(std::uint16_t x, std::uint16_t y) const override; |
||||||
|
virtual void setPixel(std::uint16_t x, std::uint16_t y, bool value) override; |
||||||
|
private: |
||||||
|
OneBitBufferInterface* m_underlying{}; |
||||||
|
std::uint16_t m_x{}; |
||||||
|
std::uint16_t m_y{}; |
||||||
|
std::uint16_t m_width{}; |
||||||
|
std::uint16_t m_height{}; |
||||||
|
}; |
||||||
|
|
||||||
|
} // namespace monoformat
|
||||||
|
|
||||||
|
#endif // MONOFORMAT_SCHEMA_HPP
|
||||||
Loading…
Reference in new issue