initial commit
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
#include "SmpteBarsFeed.hpp"
|
||||
#include "PixelFormat.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace
|
||||
{
|
||||
RgbColor smpteColorAt(
|
||||
uint32_t x,
|
||||
uint32_t y,
|
||||
uint32_t width,
|
||||
uint32_t height)
|
||||
{
|
||||
// 75% SMPTE color bars: 0.75 * 255 = 191
|
||||
static constexpr std::array<RgbColor, 8> TopBars =
|
||||
{
|
||||
RgbColor{191, 191, 191}, // 75% white
|
||||
RgbColor{191, 191, 0}, // yellow
|
||||
RgbColor{0, 191, 191}, // cyan
|
||||
RgbColor{0, 191, 0}, // green
|
||||
RgbColor{191, 0, 191}, // magenta
|
||||
RgbColor{191, 0, 0}, // red
|
||||
RgbColor{0, 0, 191}, // blue
|
||||
RgbColor{16, 16, 16} // black (reference)
|
||||
};
|
||||
|
||||
static constexpr std::array<RgbColor, 8> MiddleBars =
|
||||
{
|
||||
RgbColor{16, 16, 130}, // blue -I
|
||||
RgbColor{16, 16, 16}, // black
|
||||
RgbColor{130, 16, 130}, // magenta +Q
|
||||
RgbColor{16, 16, 16}, // black
|
||||
RgbColor{16, 130, 130}, // cyan +I
|
||||
RgbColor{16, 16, 16}, // black
|
||||
RgbColor{191, 191, 191}, // 75% white
|
||||
RgbColor{191, 191, 191} // 75% white
|
||||
};
|
||||
|
||||
const uint32_t topHeight = (height * 2) / 3;
|
||||
const uint32_t middleHeight = (height * 3) / 4;
|
||||
const size_t bar = (x * TopBars.size()) / width;
|
||||
|
||||
if (y < topHeight)
|
||||
{
|
||||
return TopBars[bar];
|
||||
}
|
||||
|
||||
if (y < middleHeight)
|
||||
{
|
||||
return MiddleBars[bar];
|
||||
}
|
||||
|
||||
const uint32_t segment = (x * 4) / width;
|
||||
|
||||
if (segment == 0)
|
||||
{
|
||||
return {0, 33, 76}; // -I (narrow cyan)
|
||||
}
|
||||
|
||||
if (segment == 1)
|
||||
{
|
||||
return {33, 0, 51}; // +Q (purple)
|
||||
}
|
||||
|
||||
if (segment == 2)
|
||||
{
|
||||
return {16, 16, 16}; // black
|
||||
}
|
||||
|
||||
return {26, 26, 26}; // 10% gray (pluge reference)
|
||||
}
|
||||
}
|
||||
|
||||
SmpteBarsFeed::SmpteBarsFeed(
|
||||
uint32_t frameWidth,
|
||||
uint32_t frameHeight)
|
||||
{
|
||||
frame.width = frameWidth;
|
||||
frame.height = frameHeight;
|
||||
frame.pixels.resize(frame.width * frame.height);
|
||||
|
||||
for (uint32_t y = 0; y < frame.height; ++y)
|
||||
{
|
||||
for (uint32_t x = 0; x < frame.width; ++x)
|
||||
{
|
||||
frame.pixels[y * frame.width + x] =
|
||||
packRgba8(
|
||||
smpteColorAt(
|
||||
x,
|
||||
y,
|
||||
frame.width,
|
||||
frame.height
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const VideoFrame& SmpteBarsFeed::getFrame(uint32_t frameCounter)
|
||||
{
|
||||
(void)frameCounter;
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
FeedRuntimeStatus SmpteBarsFeed::status() const
|
||||
{
|
||||
return FeedRuntimeStatus::Bars;
|
||||
}
|
||||
|
||||
std::string SmpteBarsFeed::displayName() const
|
||||
{
|
||||
return "BARS";
|
||||
}
|
||||
Reference in New Issue
Block a user