1#ifndef NNGN_GRAPHICS_TERMINAL_FRAME_BUFFER_H
2#define NNGN_GRAPHICS_TERMINAL_FRAME_BUFFER_H
21 std::span<char>
span(
void) {
return this->
v; }
22 std::span<char>
prefix(
void);
23 std::span<char>
pixels(
void);
24 std::span<char>
suffix(
void);
37 std::size_t
dedup(
void);
55 static_assert(std::has_unique_object_representations_v<ColoredPixel>);
66 constexpr auto f = [](std::span<char>
s,
u8 x) {
67 using namespace std::string_view_literals;
69 constexpr auto z =
static_cast<unsigned>(
'0');
70 const auto i =
static_cast<unsigned>(x);
71 s[2] =
static_cast<char>(z +
i % 10);
72 s[1] =
static_cast<char>(z +
i / 10 % 10);
73 s[0] =
static_cast<char>(z +
i / 100 % 10);
85 static_assert(off0 < off1);
86 constexpr auto n = off1 - off0;
87 return std::memcmp(lhs.
r.data(), rhs.
r.data(),
n) == 0;
121 return std::span{this->
v}.subspan(0, this->
prefix_size);
129 return std::span{this->
v}.subspan(this->
v.size() - this->suffix_size);
135 using namespace std::string_view_literals;
137 " `^\",:;Il!i~+_-?][}{1)(|\\/"
138 "tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$"sv;
139 constexpr auto max =
static_cast<float>(lum.size() - 1);
140 const auto fc =
static_cast<vec4>(color) / 255.0f;
143 const auto ci =
static_cast<std::size_t
>(
c * max);
146 const auto w =
static_cast<std::size_t
>(this->
m_size.
x);
147 const auto i =
w * y + x;
158 const auto fc =
static_cast<vec4>(color);
159 const auto rgb =
static_cast<Texture::texel3>(fc.xyz() * (fc[3] / 255.0f));
160 const auto w =
static_cast<std::size_t
>(this->
m_size.
x);
161 const auto i =
w * y + x;
165 std::memcpy(&
ps[
i], &px,
sizeof(px));
static constexpr vector_type< T > avg(T v)
Definition math.h:285
Definition frame_buffer.h:12
void resize_and_clear(uvec2 s)
Changes the size and clears the content according to the mode.
Definition frame_buffer.cpp:52
std::size_t prefix_size
Definition frame_buffer.h:61
std::span< char > prefix(void)
Definition frame_buffer.h:120
void flip(void)
Inverts the Y coord.
Definition frame_buffer.cpp:74
static constexpr std::size_t prefix_size_from_flags(Flag f)
Definition frame_buffer.h:100
std::size_t suffix_size
Definition frame_buffer.h:61
Mode mode
Definition frame_buffer.h:59
Flags< Flag > flags
Definition frame_buffer.h:58
std::vector< char > flip_tmp
Definition frame_buffer.h:60
std::span< char > pixels(void)
Definition frame_buffer.h:124
std::size_t pixel_size(void) const
Definition frame_buffer.h:110
std::vector< char > v
Definition frame_buffer.h:60
uvec2 size(void) const
Size of the frame buffer in pixels.
Definition frame_buffer.h:19
std::span< char > span(void)
Pointer to the content.
Definition frame_buffer.h:21
std::span< char > suffix(void)
Definition frame_buffer.h:128
FrameBuffer(Flag f, Mode m)
Definition frame_buffer.h:90
void write_ascii(std::size_t x, std::size_t y, Texture::texel4 color)
Write pixel at {x, y} with color, ASCII output.
Definition frame_buffer.h:132
uvec2 m_size
Definition frame_buffer.h:62
void write_colored(std::size_t x, std::size_t y, Texture::texel4 color)
Write pixel at {x, y} with color, colored output.
Definition frame_buffer.h:152
std::size_t dedup(void)
Eliminates redundant information, possibly reducing the size.
Definition frame_buffer.cpp:88
vec4_base< u8 > texel4
Definition texture.h:21
assert
Definition debug.lua:3
function DEMO text end
Definition demo0.lua:6
for i
Definition font.lua:5
local n
Definition dump_lights.lua:5
local c
Definition gamma.lua:11
local r
Definition gamma.lua:7
constexpr const R * begin(const T< R > &v)
Definition vec.h:207
constexpr To byte_cast(From p)
reinterpret_cast restricted to conversions from/to char/uchar.
Definition utils.h:121
constexpr auto to_underlying(T t)
Definition utils.h:138
consteval auto to_array(const char *s)
Definition ranges.h:80
std::uint8_t u8
Definition def.h:12
constexpr bool is_sequence(R &&r, Proj proj={})
Definition ranges.h:119
local w
Definition strict.lua:12
Wrapper for a small unsigned integral representing flags.
Definition flags.h:18
constexpr bool is_set(AT a) const
Definition flags.h:45
TerminalMode
Definition graphics.h:163
TerminalFlag
Definition graphics.h:156
static constexpr auto bg_color_24bit
Definition const.h:25
static constexpr auto reset_color
Definition const.h:24
Definition frame_buffer.h:39
std::array< char, 3 > r
Definition frame_buffer.h:48
char m
Definition frame_buffer.h:53
std::array< char, 3 > g
Definition frame_buffer.h:50
char semicolon0
Definition frame_buffer.h:49
std::array< char, CMD.size()> cmd
Definition frame_buffer.h:47
static bool cmp_rgb(const ColoredPixel &lhs, const ColoredPixel &rhs)
Equality comparison for the RGB portion of the data.
Definition frame_buffer.h:80
char space
Definition frame_buffer.h:53
ColoredPixel(void)=default
Constructs a black pixel.
std::array< char, 3 > b
Definition frame_buffer.h:52
static constexpr auto CMD
Definition frame_buffer.h:46
char semicolon1
Definition frame_buffer.h:51
static constexpr auto clear
Definition const.h:12
static constexpr auto pos
Definition const.h:13
std::chrono::seconds s
Definition timing.cpp:6