MythTV master
mythbdoverlay.cpp
Go to the documentation of this file.
1#include <algorithm>
2
3// Qt
4#include <QPainter>
5
6// MythTV
8
9MythBDOverlay::MythBDOverlay(const bd_overlay_s* const Overlay)
10 : m_image(Overlay->w, Overlay->h, QImage::Format_Indexed8),
11 m_x(Overlay->x),
12 m_y(Overlay->y)
13{
14 Wipe();
15}
16
17MythBDOverlay::MythBDOverlay(const bd_argb_overlay_s* const Overlay)
18 : m_image(Overlay->w, Overlay->h, QImage::Format_ARGB32),
19 m_x(Overlay->x),
20 m_y(Overlay->y)
21{
22}
23
24void MythBDOverlay::SetPalette(const BD_PG_PALETTE_ENTRY *Palette)
25{
26 if (!Palette)
27 return;
28
29 QVector<QRgb> rgbpalette;
30 for (int i = 0; i < 256; i++)
31 {
32 int y = Palette[i].Y;
33 int cr = Palette[i].Cr;
34 int cb = Palette[i].Cb;
35 int a = Palette[i].T;
36 int r = std::clamp(int(y + (1.4022 * (cr - 128))), 0, 0xff);
37 int b = std::clamp(int(y + (1.7710 * (cb - 128))), 0, 0xff);
38 int g = std::clamp(int((1.7047 * y) - (0.1952 * b) - (0.5647 * r)), 0, 0xff);
39 rgbpalette.push_back(static_cast<uint>((a << 24) | (r << 16) | (g << 8) | b));
40 }
41 m_image.setColorTable(rgbpalette);
42}
43
45{
46 Wipe(0, 0, m_image.width(), m_image.height());
47}
48
49void MythBDOverlay::Wipe(int Left, int Top, int Width, int Height)
50{
51 if (m_image.format() == QImage::Format_Indexed8)
52 {
53 uint8_t *data = m_image.bits();
54 int32_t offset = (Top * m_image.bytesPerLine()) + Left;
55 for (int i = 0; i < Height; i++ )
56 {
57 memset(&data[offset], 0xff, static_cast<size_t>(Width));
58 offset += m_image.bytesPerLine();
59 }
60 }
61 else
62 {
63 QColor transparent(0, 0, 0, 255);
64 QPainter painter(&m_image);
65 painter.setCompositionMode(QPainter::CompositionMode_Source);
66 painter.fillRect(Left, Top, Width, Height, transparent);
67 }
68}
69
void SetPalette(const BD_PG_PALETTE_ENTRY *Palette)
MythBDOverlay()=default
void Wipe(void)
unsigned int uint
Definition: freesurround.h:24
static eu8 clamp(eu8 value, eu8 low, eu8 high)
Definition: pxsup2dast.c:206