diff options
author | Underground78 <underground78@users.sourceforge.net> | 2013-08-04 16:37:34 +0400 |
---|---|---|
committer | Underground78 <underground78@users.sourceforge.net> | 2014-07-13 20:08:34 +0400 |
commit | 0ef048aabb69881036163e5b4e0a03d466b8a0ac (patch) | |
tree | 0f9bd63506dad5d14d0d48cbebdc605128ad2139 /src/Subtitles | |
parent | 7ab32f0d182a0d9550ba366779e4f9cc876b0946 (diff) |
ISR: Add a mode that automatically chooses the rendering target for text subtitles.
When using this mode, SSA/ASS subtitles will be rendered on the video frame while other text subtitles will be rendered on the full window.
Fixes #4345.
Diffstat (limited to 'src/Subtitles')
-rw-r--r-- | src/Subtitles/RTS.cpp | 35 | ||||
-rw-r--r-- | src/Subtitles/RTS.h | 2 | ||||
-rw-r--r-- | src/Subtitles/STS.cpp | 26 | ||||
-rw-r--r-- | src/Subtitles/STS.h | 46 | ||||
-rw-r--r-- | src/Subtitles/USFSubtitles.cpp | 8 |
5 files changed, 70 insertions, 47 deletions
diff --git a/src/Subtitles/RTS.cpp b/src/Subtitles/RTS.cpp index a55eb2751..f42a2fcef 100644 --- a/src/Subtitles/RTS.cpp +++ b/src/Subtitles/RTS.cpp @@ -1099,7 +1099,7 @@ CSubtitle::CSubtitle(COutlineCache& outlineCache, COverlayCache& overlayCache) , m_scrAlignment(0)
, m_wrapStyle(0)
, m_fAnimated(false)
- , m_relativeTo(1)
+ , m_relativeTo(STSStyle::AUTO)
, m_topborder(0)
, m_bottomborder(0)
, m_overlayCache(overlayCache)
@@ -2157,7 +2157,7 @@ bool CRenderedTextSubtitle::CreateSubFromSSATag(CSubtitle* sub, const SSATagsLis if (nParams == 1 && nParamsInt == 0 && !sub->m_pClipper) {
sub->m_pClipper = DEBUG_NEW CClipper(tag.params[0], CSize(m_size.cx >> 3, m_size.cy >> 3), sub->m_scalex, sub->m_scaley,
- invert, (sub->m_relativeTo == 1) ? CPoint(m_vidrect.left, m_vidrect.top) : CPoint(0, 0),
+ invert, (sub->m_relativeTo == STSStyle::VIDEO) ? CPoint(m_vidrect.left, m_vidrect.top) : CPoint(0, 0),
m_outlineCache, m_overlayCache);
} else if (nParams == 1 && nParamsInt == 1 && !sub->m_pClipper) {
long scale = tag.paramsInt[0];
@@ -2166,7 +2166,7 @@ bool CRenderedTextSubtitle::CreateSubFromSSATag(CSubtitle* sub, const SSATagsLis }
sub->m_pClipper = DEBUG_NEW CClipper(tag.params[0], CSize(m_size.cx >> 3, m_size.cy >> 3),
sub->m_scalex / (1 << (scale - 1)), sub->m_scaley / (1 << (scale - 1)), invert,
- (sub->m_relativeTo == 1) ? CPoint(m_vidrect.left, m_vidrect.top) : CPoint(0, 0),
+ (sub->m_relativeTo == STSStyle::VIDEO) ? CPoint(m_vidrect.left, m_vidrect.top) : CPoint(0, 0),
m_outlineCache, m_overlayCache);
} else if (nParamsInt == 4) {
sub->m_clipInverse = invert;
@@ -2176,7 +2176,7 @@ bool CRenderedTextSubtitle::CreateSubFromSSATag(CSubtitle* sub, const SSATagsLis double dRight = sub->m_scalex * tag.paramsInt[2];
double dBottom = sub->m_scaley * tag.paramsInt[3];
- if (sub->m_relativeTo == 1) {
+ if (sub->m_relativeTo == STSStyle::VIDEO) {
double dOffsetX = m_vidrect.left / 8.0;
double dOffsetY = m_vidrect.top / 8.0;
dLeft += dOffsetX;
@@ -2373,7 +2373,7 @@ bool CRenderedTextSubtitle::CreateSubFromSSATag(CSubtitle* sub, const SSATagsLis e->param[0] = std::lround(sub->m_scalex * tag.paramsReal[0] * 8.0);
e->param[1] = std::lround(sub->m_scaley * tag.paramsReal[1] * 8.0);
- if (sub->m_relativeTo == 1) {
+ if (sub->m_relativeTo == STSStyle::VIDEO) {
e->param[0] += m_vidrect.left;
e->param[1] += m_vidrect.top;
}
@@ -2691,8 +2691,8 @@ CSubtitle* CRenderedTextSubtitle::GetSubtitle(int entry) sub->m_wrapStyle = m_defaultWrapStyle;
sub->m_fAnimated = false;
sub->m_relativeTo = stss.relativeTo;
- sub->m_scalex = m_dstScreenSize.cx > 0 ? double(stss.relativeTo == 1 ? m_vidrect.Width() : m_size.cx) / (m_dstScreenSize.cx * 8.0) : 1.0;
- sub->m_scaley = m_dstScreenSize.cy > 0 ? double(stss.relativeTo == 1 ? m_vidrect.Height() : m_size.cy) / (m_dstScreenSize.cy * 8.0) : 1.0;
+ sub->m_scalex = m_dstScreenSize.cx > 0 ? double((sub->m_relativeTo == STSStyle::VIDEO) ? m_vidrect.Width() : m_size.cx) / (m_dstScreenSize.cx * 8.0) : 1.0;
+ sub->m_scaley = m_dstScreenSize.cy > 0 ? double((sub->m_relativeTo == STSStyle::VIDEO) ? m_vidrect.Height() : m_size.cy) / (m_dstScreenSize.cy * 8.0) : 1.0;
STSEntry stse = GetAt(entry);
CRect marginRect = stse.marginRect;
@@ -2714,7 +2714,7 @@ CSubtitle* CRenderedTextSubtitle::GetSubtitle(int entry) marginRect.right = std::lround(sub->m_scalex * marginRect.right * 8.0);
marginRect.bottom = std::lround(sub->m_scaley * marginRect.bottom * 8.0);
- if (stss.relativeTo == 1) { // Don't be strict when using undefined mode (relativeTo == 2)
+ if (sub->m_relativeTo == STSStyle::VIDEO) {
// Account for the user trying to fool the renderer by setting negative margins
CRect clipRect = m_vidrect;
if (marginRect.left < 0) {
@@ -2735,7 +2735,7 @@ CSubtitle* CRenderedTextSubtitle::GetSubtitle(int entry) sub->m_clip.SetRect(0, 0, m_size.cx >> 3, m_size.cy >> 3);
}
- if (stss.relativeTo == 1) {
+ if (sub->m_relativeTo == STSStyle::VIDEO) {
marginRect.left += m_vidrect.left;
marginRect.top += m_vidrect.top;
marginRect.right += m_size.cx - m_vidrect.right;
@@ -3021,7 +3021,7 @@ STDMETHODIMP CRenderedTextSubtitle::Render(SubPicDesc& spd, REFERENCE_TIME rt, d s->m_scrAlignment <= 3 ? p.y - spaceNeeded.cy : s->m_scrAlignment <= 6 ? p.y - (spaceNeeded.cy + 1) / 2 : p.y),
spaceNeeded);
- if (s->m_relativeTo == 1) {
+ if (s->m_relativeTo == STSStyle::VIDEO) {
r.OffsetRect(m_vidrect.TopLeft());
}
fPosOverride = true;
@@ -3060,8 +3060,8 @@ STDMETHODIMP CRenderedTextSubtitle::Render(SubPicDesc& spd, REFERENCE_TIME rt, d }
break;
case EF_BANNER: { // Banner;delay=param[0][;leftoright=param[1];fadeawaywidth=param[2]]
- int left = s->m_relativeTo == 1 ? m_vidrect.left : 0,
- right = s->m_relativeTo == 1 ? m_vidrect.right : m_size.cx;
+ int left = (s->m_relativeTo == STSStyle::VIDEO) ? m_vidrect.left : 0,
+ right = (s->m_relativeTo == STSStyle::VIDEO) ? m_vidrect.right : m_size.cx;
r.left = !!s->m_effects[k]->param[1]
? (left/*marginRect.left*/ - spaceNeeded.cx) + (int)(m_time * 8.0 / s->m_effects[k]->param[0])
@@ -3083,11 +3083,12 @@ STDMETHODIMP CRenderedTextSubtitle::Render(SubPicDesc& spd, REFERENCE_TIME rt, d CRect cr(0, (s->m_effects[k]->param[0] + 4) >> 3, spd.w, (s->m_effects[k]->param[1] + 4) >> 3);
- if (s->m_relativeTo == 1)
- r.top += m_vidrect.top,
- r.bottom += m_vidrect.top,
- cr.top += m_vidrect.top >> 3,
- cr.bottom += m_vidrect.top >> 3;
+ if (s->m_relativeTo == STSStyle::VIDEO) {
+ r.top += m_vidrect.top;
+ r.bottom += m_vidrect.top;
+ cr.top += m_vidrect.top >> 3;
+ cr.bottom += m_vidrect.top >> 3;
+ }
clipRect &= cr;
diff --git a/src/Subtitles/RTS.h b/src/Subtitles/RTS.h index 666c08ca0..50e181b55 100644 --- a/src/Subtitles/RTS.h +++ b/src/Subtitles/RTS.h @@ -278,7 +278,7 @@ public: int m_wrapStyle;
bool m_fAnimated;
bool m_bIsAnimated;
- int m_relativeTo;
+ STSStyle::RelativeTo m_relativeTo;
Effect* m_effects[EF_NUMBEROFEFFECTS];
diff --git a/src/Subtitles/STS.cpp b/src/Subtitles/STS.cpp index 6f7725ac2..7509d51c9 100644 --- a/src/Subtitles/STS.cpp +++ b/src/Subtitles/STS.cpp @@ -1479,7 +1479,7 @@ static bool OpenSubStationAlpha(CTextFile* file, CSimpleTextSubtitle& ret, int C }
style->charSet = GetInt(pszBuff, nBuffLength);
if (sver >= 6) {
- style->relativeTo = GetInt(pszBuff, nBuffLength);
+ style->relativeTo = (STSStyle::RelativeTo)GetInt(pszBuff, nBuffLength);
}
if (sver <= 4) {
@@ -2392,8 +2392,16 @@ bool CSimpleTextSubtitle::GetStyle(int i, STSStyle& stss) }
stss = *style;
- if (stss.relativeTo == 2 && defstyle) {
+ if (stss.relativeTo == STSStyle::AUTO && defstyle) {
stss.relativeTo = defstyle->relativeTo;
+ // If relative to is set to "auto" even for the default style, decide based on the subtitle type
+ if (stss.relativeTo == STSStyle::AUTO) {
+ if (m_subtitleType == Subtitle::ASS || m_subtitleType == Subtitle::SSA) {
+ stss.relativeTo = STSStyle::VIDEO;
+ } else {
+ stss.relativeTo = STSStyle::WINDOW;
+ }
+ }
}
return true;
@@ -2413,8 +2421,16 @@ bool CSimpleTextSubtitle::GetStyle(CString styleName, STSStyle& stss) STSStyle* defstyle = nullptr;
m_styles.Lookup(def, defstyle);
- if (defstyle && stss.relativeTo == 2) {
+ if (defstyle && stss.relativeTo == STSStyle::AUTO) {
stss.relativeTo = defstyle->relativeTo;
+ // If relative to is set to "auto" even for the default style, decide based on the subtitle type
+ if (stss.relativeTo == STSStyle::AUTO) {
+ if (m_subtitleType == Subtitle::ASS || m_subtitleType == Subtitle::SSA) {
+ stss.relativeTo = STSStyle::VIDEO;
+ } else {
+ stss.relativeTo = STSStyle::WINDOW;
+ }
+ }
}
return true;
@@ -2975,7 +2991,7 @@ void STSStyle::SetDefault() fBlur = 0;
fGaussianBlur = 0;
fontShiftX = fontShiftY = fontAngleZ = fontAngleX = fontAngleY = 0;
- relativeTo = 2;
+ relativeTo = STSStyle::AUTO;
}
bool STSStyle::operator == (const STSStyle& s) const
@@ -3118,7 +3134,7 @@ STSStyle& operator <<= (STSStyle& s, const CString& style) s.fontAngleZ = GetFloat(pszBuff, nBuffLength, L';');
s.fontAngleX = GetFloat(pszBuff, nBuffLength, L';');
s.fontAngleY = GetFloat(pszBuff, nBuffLength, L';');
- s.relativeTo = GetInt(pszBuff, nBuffLength, L';');
+ s.relativeTo = (STSStyle::RelativeTo)GetInt(pszBuff, nBuffLength, L';');
}
} catch (...) {
s.SetDefault();
diff --git a/src/Subtitles/STS.h b/src/Subtitles/STS.h index f723c77c9..ad3614d39 100644 --- a/src/Subtitles/STS.h +++ b/src/Subtitles/STS.h @@ -32,27 +32,33 @@ enum tmode { TIME, FRAME }; // the meaning of STSEntry::start/end class STSStyle
{
public:
- CRect marginRect; // measured from the sides
- int scrAlignment; // 1 - 9: as on the numpad, 0: default
- int borderStyle; // 0: outline, 1: opaque box
- double outlineWidthX, outlineWidthY;
- double shadowDepthX, shadowDepthY;
- std::array<COLORREF, 4> colors; // usually: {primary, secondary, outline/background, shadow}
+ enum RelativeTo {
+ WINDOW,
+ VIDEO,
+ AUTO // ~video for SSA/ASS, ~window for the rest
+ };
+
+ CRect marginRect; // measured from the sides
+ int scrAlignment; // 1 - 9: as on the numpad, 0: default
+ int borderStyle; // 0: outline, 1: opaque box
+ double outlineWidthX, outlineWidthY;
+ double shadowDepthX, shadowDepthY;
+ std::array<COLORREF, 4> colors; // usually: {primary, secondary, outline/background, shadow}
std::array<BYTE, 4> alpha;
- int charSet;
- CString fontName;
- double fontSize; // height
- double fontScaleX, fontScaleY; // percent
- double fontSpacing; // +/- pixels
- LONG fontWeight;
- int fItalic;
- int fUnderline;
- int fStrikeOut;
- int fBlur;
- double fGaussianBlur;
- double fontAngleZ, fontAngleX, fontAngleY;
- double fontShiftX, fontShiftY;
- int relativeTo; // 0: window, 1: video, 2: undefined (~window)
+ int charSet;
+ CString fontName;
+ double fontSize; // height
+ double fontScaleX, fontScaleY; // percent
+ double fontSpacing; // +/- pixels
+ LONG fontWeight;
+ int fItalic;
+ int fUnderline;
+ int fStrikeOut;
+ int fBlur;
+ double fGaussianBlur;
+ double fontAngleZ, fontAngleX, fontAngleY;
+ double fontShiftX, fontShiftY;
+ RelativeTo relativeTo;
STSStyle();
diff --git a/src/Subtitles/USFSubtitles.cpp b/src/Subtitles/USFSubtitles.cpp index a63327534..7e50225ac 100644 --- a/src/Subtitles/USFSubtitles.cpp +++ b/src/Subtitles/USFSubtitles.cpp @@ -1,6 +1,6 @@ /*
* (C) 2003-2006 Gabest
- * (C) 2006-2013 see Authors.txt
+ * (C) 2006-2014 see Authors.txt
*
* This file is part of MPC-HC.
*
@@ -334,9 +334,9 @@ bool CUSFSubtitles::ConvertToSTS(CSimpleTextSubtitle& sts) stss->scrAlignment = TranslateAlignment(s->pal.alignment);
if (!s->pal.relativeto.IsEmpty()) stss->relativeTo =
- !s->pal.relativeto.CompareNoCase(L"window") ? 0 :
- !s->pal.relativeto.CompareNoCase(L"video") ? 1 :
- 0;
+ !s->pal.relativeto.CompareNoCase(L"window") ? STSStyle::WINDOW :
+ !s->pal.relativeto.CompareNoCase(L"video") ? STSStyle::VIDEO :
+ STSStyle::WINDOW;
stss->borderStyle = 0;
if (!s->fontstyle.outline.IsEmpty()) {
|