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