Skip to content

Commit

Permalink
Merge pull request #46 from TheOneric/pinterf_backport+encoding
Browse files Browse the repository at this point in the history
Backports from Cyberbeing + negative Encoding
  • Loading branch information
pinterf authored Dec 13, 2023
2 parents 15390e5 + 1028971 commit 0e6c749
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
run: |
export VS160COMNTOOLS="C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/Common7/Tools/"
bash ./build_vsfilter.sh -platform "${{ matrix.vsfplat }}" -compiler VS2019
cp License.txt bin/
- name: Prune incompatible files
if: steps.config.outputs.delete != ''
Expand All @@ -89,3 +90,4 @@ jobs:
name: xy-${{ steps.config.outputs.name }}_nightly_${{ matrix.namesuf }}
path: |
bin/lib*/*/Release
bin/License.txt
2 changes: 1 addition & 1 deletion src/filters/transform/vsfilter/VSFilter.rc
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ BEGIN
RTEXT "Cache LV2",IDC_LABEL_OVERLAY_NO_BLUR,20,56,57,8
PUSHBUTTON "caches info",IDC_CACHES_INFO_BTN,147,21,50,14
COMBOBOX IDC_COMBO_LAYOUT_SIZE_OPT,27,106,74,64,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
GROUPBOX "Renderer Layout Options",IDC_STATIC,7,97,233,27
GROUPBOX "Renderer Layout Default",IDC_STATIC,7,97,233,27
LTEXT "H:",IDC_STATIC,112,107,9,8
LTEXT "V:",IDC_STATIC,157,107,8,8
EDITTEXT IDC_EDIT_LAYOUT_SIZE_X,122,107,32,12,ES_RIGHT | ES_AUTOHSCROLL | ES_NUMBER
Expand Down
54 changes: 12 additions & 42 deletions src/filters/transform/vsfilter/csriapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@ CSRIAPI void csri_close(csri_inst *inst)

CSRIAPI int csri_request_fmt(csri_inst *inst, const struct csri_fmt *fmt)
{
if (!inst) return -1;

if (!fmt->width || !fmt->height)
if (!inst || !fmt->width || !fmt->height) {
return -1;
}

// Check if pixel format is supported
switch (fmt->pixfmt) {
Expand Down Expand Up @@ -159,51 +158,22 @@ CSRIAPI void csri_render(csri_inst *inst, struct csri_frame *frame, double time)


// No extensions supported
CSRIAPI void *csri_query_ext(csri_rend *rend, csri_ext_id extname)
{
return 0;
}
CSRIAPI void *csri_query_ext(csri_rend *rend, csri_ext_id extname) { return 0; }

// Get info for renderer
static struct csri_info csri_vsfilter_info = {
#ifdef _DEBUG
"vsfilter_textsub_debug", // name
"2.39", // version (assumed version number, svn revision, patchlevel)
"pf-xy-vsfilter_textsub_debug", // name
#else
"vsfilter_textsub", // name
"2.39", // version (assumed version number, svn revision, patchlevel)
"pf-xy-vsfilter_textsub", // name
#endif
// 2.38-0611 is base svn 611
// 2.38-0611-1 is with clipfix and fax/fay patch
// 2.38-0611-2 adds CSRI
// 2.38-0611-3 fixes a bug in CSRI and adds fontcrash-fix and float-pos
// 2.38-0611-4 fixes be1-dots and ugly-fade bugs and adds xbord/ybord/xshad/yshad/blur tags and extends be
// 2.39 merges with guliverkli2 fork
"VSFilter/TextSub (guliverkli2)", // longname
"3.2", // version
"xy-VSFilter/TextSub", // longname
"Gabest", // author
"Copyright (c) 2003-2008 by Gabest and others" // copyright
"Copyright (c) 2003-2014 by Gabest et al." // copyright
};
CSRIAPI struct csri_info *csri_renderer_info(csri_rend *rend)
{
return &csri_vsfilter_info;
}
// Only one supported, obviously
CSRIAPI csri_rend *csri_renderer_byname(const char *name, const char *specific)
{
if (strcmp(name, csri_vsfilter_info.name))
return 0;
if (specific && strcmp(specific, csri_vsfilter_info.specific))
return 0;
return &csri_vsfilter;
}
// Still just one
CSRIAPI csri_rend *csri_renderer_default()
{
return &csri_vsfilter;
}
// And no further
CSRIAPI csri_rend *csri_renderer_next(csri_rend *prev)
{
return 0;
}

CSRIAPI struct csri_info *csri_renderer_info(csri_rend *rend) { return &csri_vsfilter_info; }
CSRIAPI csri_rend *csri_renderer_byname(const char *name, const char *specific) { return &csri_vsfilter; }
CSRIAPI csri_rend *csri_renderer_default() { return &csri_vsfilter; }
CSRIAPI csri_rend *csri_renderer_next(csri_rend *prev) { return 0; }
14 changes: 13 additions & 1 deletion src/subtitles/HdmvSub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ HRESULT CHdmvSub::ParseSample(BYTE* pData, int lSampleLen, REFERENCE_TIME rtStar

int CHdmvSub::ParsePresentationSegment(REFERENCE_TIME rt, CGolombBuffer* pGBuffer)
{
if (pGBuffer->RemainingSize() < 11) {
return 0;
}

m_pCurrentPresentationSegment = DEBUG_NEW HDMV_PRESENTATION_SEGMENT();

m_pCurrentPresentationSegment->rtStart = rt;
Expand All @@ -222,6 +226,10 @@ int CHdmvSub::ParsePresentationSegment(REFERENCE_TIME rt, CGolombBuffer* pGBuffe
TRACE_HDMVSUB( (_T("CHdmvSub::ParsePresentationSegment Size = %d, state = %#x, nObjectNumber = %d\n"), pGBuffer->GetSize(),
m_pCurrentPresentationSegment->composition_descriptor.bState, m_pCurrentPresentationSegment->objectCount) );

if (pGBuffer->RemainingSize() < (m_pCurrentPresentationSegment->objectCount * 8)) {
return 0;
}

for (int i = 0; i < m_pCurrentPresentationSegment->objectCount; i++) {
CompositionObject* pCompositionObject = DEBUG_NEW CompositionObject();
ParseCompositionObject(pGBuffer, pCompositionObject);
Expand Down Expand Up @@ -287,7 +295,11 @@ void CHdmvSub::ParsePalette(CGolombBuffer* pGBuffer, unsigned short nSize) // #
void CHdmvSub::ParseObject(CGolombBuffer* pGBuffer, unsigned short nUnitSize) // #498
{
short object_id = pGBuffer->ReadShort();
ASSERT(object_id < _countof(m_compositionObjects));

if (object_id >= _countof(m_compositionObjects)) {
TRACE_HDMVSUB((_T("CHdmvSub::ParseObject() : FAILED, object_id - %d"), object_id));
return;
}

CompositionObject& pObject = m_compositionObjects[object_id];

Expand Down
1 change: 1 addition & 0 deletions src/subtitles/RTS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2415,6 +2415,7 @@ bool CRenderedTextSubtitle::ParseSSATag( CSubtitle* sub, const AssTagList& assTa
case CMD_fe:
{
int n = wcstol(p, NULL, 10);
if (n < 0) n = DEFAULT_CHARSET;
style.charSet = !p.IsEmpty()
? n
: org.charSet;
Expand Down
5 changes: 4 additions & 1 deletion src/subtitles/STS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1978,6 +1978,7 @@ static bool OpenSubStationAlpha(CTextFile* file, CSimpleTextSubtitle& ret, int C
{
CString StyleName;
int alpha;
int encoding;
CRect tmp_rect;

StyleName = GetStr(buff);
Expand All @@ -2002,9 +2003,11 @@ if(sver >= 4) style->borderStyle = GetInt(buff);
if(sver >= 6) tmp_rect.bottom = GetInt(buff);
style->marginRect = tmp_rect;
if(sver <= 4) alpha = GetInt(buff);
style->charSet = GetInt(buff);
encoding = GetInt(buff);
if(sver >= 6) style->relativeTo = GetInt(buff);

// Map unsupported extension to the most permissive charSet
style->charSet = encoding < 0 ? DEFAULT_CHARSET : encoding;
if(sver <= 4) style->colors[2] = style->colors[3]; // style->colors[2] is used for drawing the outline
if(sver <= 4) alpha = max(min(alpha, 0xff), 0);
if(sver <= 4) {for(size_t i = 0; i < 3; i++) style->alpha[i] = alpha; style->alpha[3] = 0x80;}
Expand Down
9 changes: 6 additions & 3 deletions src/subtitles/hdmv_subtitle_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,22 +472,25 @@ DWORD SupFileSubtitleProvider::ThreadProc()
while ((len = f.Read(buff, sizeof(buff))) > 0) {
sub.Write(buff, len);
}
f.Close();
sub.SeekToBegin();

WORD sync = 0;
USHORT size = 0;
REFERENCE_TIME rtStart = 0;
REFERENCE_TIME rtStop = 0;

CAutoLock cAutoLock(&m_csCritSec);
while (sub.GetPosition() < (sub.GetLength() - 10)) {
sync = (WORD)ReadByte(&sub, 2);
if (sync == 'PG') {
rtStart = UINT64(ReadByte(&sub, 4) * (1000 / 9));
sub.Seek(4 + 1, CFile::current); // rtStop + Segment type
rtStart = UINT64(ReadByte(&sub, 4) * 1000 / 9);
rtStop = UINT64(ReadByte(&sub, 4) * 1000 / 9);
sub.Seek(1, CFile::current); // Segment type
size = ReadByte(&sub, 2) + 3; // Segment size
sub.Seek(-3, CFile::current);
sub.Read(buff, size);
m_pSub->ParseSample(buff, size, rtStart, 0);
m_pSub->ParseSample(buff, size, rtStart, rtStop);
} else {
break;
}
Expand Down

0 comments on commit 0e6c749

Please sign in to comment.