Skip to content

Commit

Permalink
[DVB subtitles] (#3480)
Browse files Browse the repository at this point in the history
[DVB subtitles]
* add more colors

Cherry pick -> OpenPLi/enigma2@3c3adb1
  • Loading branch information
jbleyel authored Dec 24, 2024
1 parent 9dce992 commit e08c00c
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 34 deletions.
2 changes: 1 addition & 1 deletion data/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@
<item level="0" text="Subtitle black transparency" description="Configure the transparency of the black background of subtitles.">config.subtitles.subtitles_backtrans</item>
<item level="2" text="Subtitle font size" description="Configure the font size of the subtitles.">config.subtitles.subtitle_fontsize</item>
<item level="2" text="Subtitle delay when timing lacks" description="Configure the subtitle delay when timing information is not available.">config.subtitles.subtitle_noPTSrecordingdelay</item>
<item level="2" text="Yellow DVB subtitles" description="When enabled, graphical DVB subtitles will be displayed in yellow, instead of the original color.">config.subtitles.dvb_subtitles_yellow</item>
<item level="2" text="DVB subtitles color" description="A graphical DVB subtitles will be displayed in the selected color, instead of the original color.">config.subtitles.dvb_subtitles_color</item>
<item level="2" text="Use original DVB subtitle position" description="When enabled, graphical DVB subtitles will be displayed at their original position.">config.subtitles.dvb_subtitles_original_position</item>
<item level="2" text="Subtitle delay when timing is bad" description="Configure an additional delay to improve subtitle synchronization.">config.subtitles.subtitle_bad_timing_delay</item>
<item level="2" text="DVB subtitle black transparency" description="Configure the transparency of the black background of graphical DVB subtitles.">config.subtitles.dvb_subtitles_backtrans</item>
Expand Down
2 changes: 1 addition & 1 deletion lib/base/esettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int eSubtitleSettings::ttx_subtitle_colors = 1;
int eSubtitleSettings::subtitle_position = 50;
int eSubtitleSettings::dvb_subtitles_original_position = 0;
int eSubtitleSettings::dvb_subtitles_backtrans = 0;
bool eSubtitleSettings::dvb_subtitles_yellow = false;
int eSubtitleSettings::dvb_subtitles_color = 0;
bool eSubtitleSettings::dvb_subtitles_centered = false;
int eSubtitleSettings::subtitle_alignment_flag = gPainter::RT_HALIGN_CENTER;
bool eSubtitleSettings::colorise_dialogs = false;
Expand Down
4 changes: 2 additions & 2 deletions lib/base/esettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class eSubtitleSettings
static void setPangoSubtitleAutoRun(bool value) { pango_autoturnon = value; }
static void setDVBSubtitleOriginalPosition(int value) { dvb_subtitles_original_position = value; }
static void setDVBSubtitleBacktrans(int value) { dvb_subtitles_backtrans = value; }
static void setDVBSubtitleYellow(bool value) { dvb_subtitles_yellow = value; }
static void setDVBSubtitleColor(int value) { dvb_subtitles_color = value; }
static void setDVBSubtitleCentered(bool value) { dvb_subtitles_centered = value; }
static void setSubtitleReWrap(bool value) { subtitle_rewrap = value; }
static void setSubtitlePosition(int value) { subtitle_position = value; }
Expand Down Expand Up @@ -47,7 +47,7 @@ class eSubtitleSettings
static int subtitle_position;
static int dvb_subtitles_original_position;
static int dvb_subtitles_backtrans;
static bool dvb_subtitles_yellow;
static int dvb_subtitles_color;
static bool dvb_subtitles_centered;
static int subtitle_alignment_flag;
static int subtitle_borderwidth;
Expand Down
72 changes: 47 additions & 25 deletions lib/dvb/subtitle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1054,35 +1054,57 @@ void eDVBSubtitleParser::subtitle_redraw(int page_id)
break;
}

int bcktrans = eSubtitleSettings::dvb_subtitles_backtrans;
bool yellow = eSubtitleSettings::dvb_subtitles_yellow;

for (int i=0; i<clut_size; ++i)
int backgroundTransparency = eSubtitleSettings::dvb_subtitles_backtrans;
int subtitleColor = eSubtitleSettings::dvb_subtitles_color;
bool isYellow = subtitleColor == 1;
bool isGreen = subtitleColor == 2;
bool isCyan = subtitleColor == 4;
if (entries)
{
if (entries && entries[i].valid)
for (int i = 0; i < clut_size; ++i)
{
int y = entries[i].Y,
cr = entries[i].Cr,
cb = entries[i].Cb;
if (y > 0)
if (entries[i].valid)
{
y -= 16;
cr -= 128;
cb -= 128;
palette[i].r = MAX(MIN(((298 * y + 460 * cr) / 256), 255), 0);
palette[i].g = MAX(MIN(((298 * y - 55 * cb - 137 * cr) / 256), 255), 0);
palette[i].b = yellow?0:MAX(MIN(((298 * y + 543 * cb ) / 256), 255), 0);
if (palette[i].r || palette[i].g || palette[i].b)
palette[i].a = (entries[i].T) & 0xFF;
int y = entries[i].Y,
cr = entries[i].Cr,
cb = entries[i].Cb;
if (y > 0)
{
y -= 16;
cr -= 128;
cb -= 128;
palette[i].r = (isGreen || isCyan) ? 0 : std::max(std::min(((298 * y + 460 * cr) / 256), 255), 0);
palette[i].b = (isYellow || isGreen) ? 0 : std::max(std::min(((298 * y + 543 * cb) / 256), 255), 0);

if (isGreen)
{
palette[i].g = std::max(std::min(((298 * y) / 256), 255), 0);
}
else if (subtitleColor == 3) // magenta
{
palette[i].g = 0;
}
else if (isCyan)
{
palette[i].g = std::max(std::min(((298 * y + 543 * cb) / 256), 255), 0);
}
else // yellow , original
{
palette[i].g = std::max(std::min(((298 * y - 55 * cb - 137 * cr) / 256), 255), 0);
}

if (palette[i].r || palette[i].g || palette[i].b)
palette[i].a = (entries[i].T) & 0xFF;
else
palette[i].a = backgroundTransparency;
}
else
palette[i].a = bcktrans;
}
else
{
palette[i].r = 0;
palette[i].g = 0;
palette[i].b = 0;
palette[i].a = 0xFF;
{
palette[i].r = 0;
palette[i].g = 0;
palette[i].b = 0;
palette[i].a = 0xFF;
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions lib/python/Components/UsageConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -1702,11 +1702,11 @@ def setPangoSubtitleDelay(configElement):
config.subtitles.pango_subtitles_delay = ConfigSelection(default=0, choices=choiceList)
config.subtitles.pango_subtitles_delay.addNotifier(setPangoSubtitleDelay)

def setDVBSubtitleYellow(configElement):
eSubtitleSettings.setDVBSubtitleYellow(configElement.value)
def setDVBSubtitleColor(configElement):
eSubtitleSettings.setDVBSubtitleColor(configElement.value)

config.subtitles.dvb_subtitles_yellow = ConfigYesNo(default=False)
config.subtitles.dvb_subtitles_yellow.addNotifier(setDVBSubtitleYellow)
config.subtitles.dvb_subtitles_color = ConfigSelection(default=0, choices=[(0, _("Original")), (1, _("Yellow")), (2, _("Green")), (3, _("Magenta")), (4, _("Cyan"))])
config.subtitles.dvb_subtitles_color.addNotifier(setDVBSubtitleColor)

def setDVBSubtitleOriginalPosition(configElement):
eSubtitleSettings.setDVBSubtitleOriginalPosition(configElement.value)
Expand Down
2 changes: 1 addition & 1 deletion lib/python/Screens/AudioSelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def __init__(self, session, infobar):
])
if sub[0] == 0: # dvb
menu.extend([
getConfigMenuItem("dvb_subtitles_yellow"),
getConfigMenuItem("dvb_subtitles_color"),
getConfigMenuItem("dvb_subtitles_backtrans"),
getConfigMenuItem("dvb_subtitles_original_position"),
getConfigMenuItem("subtitle_position"),
Expand Down

0 comments on commit e08c00c

Please sign in to comment.