AuxSubtitlesFormats.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:44k
- /**************************************************************
- * AuxSubtitlesFormats.c
- **************************************************************
- * Description:
- * ============
- * Format specific data and functions for subtitles files.
- **************************************************************
- *
- * Hagay Barel 14.11.03
- **************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef USE_AUX_SUBTITLES
- #ifdef _DEBUG
- #undef IFTRACE
- #ifdef DEBUG_AUX_SUBTITLES
- #define IFTRACE if (gTraceNavigator)
- #else
- #define IFTRACE
- #endif // DEBUG_AUX_SUBTITLES
- #include "Debugdbgmain.h"
- #endif // _DEBUG
- #include "PlaycoreNav_ClipsreadTextFile.h"
- #include "PlaycoreNav_ClipsAuxSubtitlesCommonPrivate.h"
- #include "PlaycoreNav_ClipsAuxSubtitles.h"
- #define SF_MICRODVD_PROBE_LIMIT 50
- BOOL readDelimitedTimeString(textFilePtr tfpFile, DWORD *dwPTS, int mult[], int number);
- BOOL probeSubtitlesFileMicroDVD(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize);
- // Robin_1003_2004_E
- BOOL probeSubtitlesFileSubRip (DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize);
- BOOL probeSubtitlesFilePowerDivX (DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize);
- BOOL probeSubtitlesFileAdvancedSubStationAlpha (DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize);
- BOOL probeSubtitlesFileSubViewer(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize);
- BOOL probeSubtitlesFileTMPlayer(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize);
- BOOL probeSubtitlesFileSubViewerVer1(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize);
- BOOL parseSubtitlesFileMicroDVD(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate);
- BOOL parseSubtitlesFileSubRip (DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate);
- BOOL parseSubtitlesFileSubViewer (DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate);
- BOOL parseSubtitlesFileSubViewerVer1 (DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate);
- BOOL parseSubtitlesFilePowerDivX (DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate);
- BOOL parseSubtitlesFileAdvancedSubStationAlpha (DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate);
- BOOL parseSubtitlesFileTMPlayer (DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate);
- BOOL parseSubtitlesFileDummy (DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate);
- BOOL parseSubtitlesFileCommon(DWORD num1, DWORD num2, textFilePtr tfpFile, BOOL bNoStorenum2,BOOL bNoStorenum1);
- #ifdef SUPPORT_SAMI_SUBTITLE
- // <<< Robin_0907_2004
- extern BOOL probeSubtitlesFileSami(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize);
- // >>> Robin_0907_2004
- extern BOOL parseSubtitlesFileSami(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate);
- #endif
- // <<< Robin_1003_2004_E
- BOOL probeSubtitlesFileBitMap(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize);
- BOOL parseSubtitlesFileBitMap (DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate);
- CONST SubtitleFormatAttr availableSubtitleFormats[SF_NUMBER_OF_FORMATS]={
- { probeSubtitlesFileBitMap, parseSubtitlesFileBitMap},
- { probeSubtitlesFileMicroDVD, parseSubtitlesFileMicroDVD },
- { probeSubtitlesFileSubRip,parseSubtitlesFileSubRip },
- #ifdef SUPPORT_SAMI_SUBTITLE
- // <<< Robin_0907_2004
- { probeSubtitlesFileSami, parseSubtitlesFileSami },
- // >>> Robin_0907_2004
- #endif
- { probeSubtitlesFilePowerDivX, parseSubtitlesFilePowerDivX },
- { probeSubtitlesFileAdvancedSubStationAlpha, parseSubtitlesFileAdvancedSubStationAlpha },
- { probeSubtitlesFileSubViewer, parseSubtitlesFileSubViewer },
- { probeSubtitlesFileTMPlayer, parseSubtitlesFileTMPlayer },
- { probeSubtitlesFileSubViewerVer1, parseSubtitlesFileSubViewerVer1 },
- };
- // >>> Robin_1003_2004_E
- // MicroDVD probing
- // Pattern to be identified:
- // {#*}{#*}
- // where #* are numbers of any size
- BOOL probeSubtitlesFileMicroDVD(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize)
- {
- textFilePtr tfpFile;
- DWORD num;
- char c;
- BOOL bSuccess=FALSE;
- // Robin_0715_2004, merge changelist #24407
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
- while(1) {
- // search for the 1st "{"
- if (FALSE == textFileFindString(tfpFile,"{",SF_MICRODVD_PROBE_LIMIT))
- break;
- if(TRUE == textFileIsCurrentChar2(tfpFile, 'D') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'E') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'F') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'A') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'U') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'L') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'T') &&
- TRUE == textFileIsCurrentChar2(tfpFile, '}')
- ) // Robin_0705_2004_B, bypass {DEFAULT} control code
- {
- if(FALSE == textFileFindString(tfpFile,"n",0))
- return FALSE;
- continue;
- }
-
- // check if it's followed by a number
- if (FALSE == textFileReadNumber(tfpFile,&num))
- break;
- // look for the "}{" string
- if (FALSE == textFileIsCurrentChar(tfpFile, '}'))
- break;
- if (FALSE == textFileIsCurrentChar(tfpFile, '{'))
- break;
- if (TRUE == textFileIsCurrentChar2(tfpFile, '}'))
- {
- dbg_printf(("probeSubtitlesFileMicroDVD - MicroDVD format confirmed.n"));
- bSuccess=TRUE;
- break;
- }
-
- // check if it's followed by a number
- if (FALSE == textFileReadNumber(tfpFile,&num))
- break;
- // check for the closing '}'
- if (FALSE == textFileReadChar(tfpFile,0,&c)) {
- tr_printf(("probeSubtitlesFileMicroDVD - can't read charn"));
- break;
- }
- if ( '}' != c )
- break;
- dbg_printf(("probeSubtitlesFileMicroDVD - MicroDVD format confirmed.n"));
- bSuccess=TRUE;
- break;
- }
- if ( NULL != tfpFile )
- textFileClose(tfpFile);
- return bSuccess;
- }
- // <<< Robin_1003_2004_E
- BOOL probeSubtitlesFileSubRip(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize)
- {
- DWORD num1,num2;
- char c;
- BOOL bSuccess=TRUE;
- int mult[]={60,60,1000};
- textFilePtr tfpFile;
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
- while( FALSE == textFileEOF(tfpFile) ) {
- num1=0;
- num2=0;
- // Look for number - should be the number of the 1st subtitle - probably 1
- bSuccess &= textFileFindNumber(tfpFile,0);
- // reading subtitle serial number - not used.
- bSuccess &= textFileReadNumber(tfpFile,&num1);
- bSuccess &= textFileSkipLine(tfpFile);
- // read start time
- bSuccess &= readDelimitedTimeString(tfpFile, &num1, mult,3);
- // skip the "-->" symbol
- bSuccess &= textFileFindString(tfpFile, " --> ",6);
- bSuccess &= readDelimitedTimeString(tfpFile, &num2, mult,3);
- bSuccess &= textFileSkipLine(tfpFile);
- break;
- }
- textFileClose(tfpFile);
- if (TRUE == bSuccess)
- dbg_printf(("probeSubtitlesFileSubRip - SubRip format confirmed.n"));
- return bSuccess;
- }
- BOOL probeSubtitlesFilePowerDivX(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize)
- {
- DWORD num1,num2;
- char c;
- BOOL bSuccess=TRUE;
- BOOL bExpectFormatting=TRUE;
- int mult[]={60,60};
- textFilePtr tfpFile;
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
-
- while( FALSE == textFileEOF(tfpFile) ) {
- // parse the section "{start frame}{end frame}"
- bSuccess &= textFileFindString(tfpFile,"{",0);
- bSuccess &= readDelimitedTimeString(tfpFile, &num1, mult,2);
- bSuccess &= textFileIsCurrentChar(tfpFile, '}');
- bSuccess &= textFileIsCurrentChar(tfpFile, '{');
- bSuccess &= readDelimitedTimeString(tfpFile, &num2, mult,2);
- bSuccess &= textFileIsCurrentChar(tfpFile, '}');
- break;
-
- }
-
- textFileClose(tfpFile);
-
- if (TRUE == bSuccess)
- dbg_printf(("probeSubtitlesFilePowerDivX - PowerDivx format confirmed.n"));
- return bSuccess;
- }
- BOOL probeSubtitlesFileAdvancedSubStationAlpha(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize)
- {
- DWORD num1,num2;
- char c;
- BOOL bSuccess=TRUE;
- BOOL bExpectFormatting=TRUE;
- int mult[]={60,60,100};
- textFilePtr tfpFile;
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
- subtitleStorageInitWriting();
- while( FALSE == textFileEOF(tfpFile) ) {
- bSuccess &= textFileFindString(tfpFile,"Dialogue:",0); // Format
- bSuccess &= textFileFindString(tfpFile,",",0); // Layer
- bSuccess &= readDelimitedTimeString(tfpFile, &num1, mult,3); // Start
- bSuccess &= textFileIsCurrentChar(tfpFile, ',');
- bSuccess &= readDelimitedTimeString(tfpFile, &num2, mult,3); // End
- bSuccess &= textFileIsCurrentChar(tfpFile, ',');
- bSuccess &= textFileFindString(tfpFile,",",0); // Style
- bSuccess &= textFileFindString(tfpFile,",",0); // Actor
- bSuccess &= textFileFindString(tfpFile,",",0); // MarginL
- bSuccess &= textFileFindString(tfpFile,",",0); // MarginR
- bSuccess &= textFileFindString(tfpFile,",",0); // MarginV
- bSuccess &= textFileFindString(tfpFile,",",0); // Effect
- break;
- }
-
- textFileClose(tfpFile);
-
- if (TRUE == bSuccess)
- dbg_printf(("probeSubtitlesFileAdvancedSubStationAlpha - SubStationAlpha format confirmed.n"));
- return bSuccess;
- }
- // >>> Robin_1003_2004_E
- // Robin_0604_2004_C
- // SubViewer 2.0 probing
- // Pattern to be identified:
- // 00:00:03.25,00:00:05.42
- // where #* are numbers of any size
- BOOL probeSubtitlesFileSubViewer(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize)
- {
- textFilePtr tfpFile;
- DWORD num;
- char c;
- BOOL bSuccess=FALSE;
- UINT16 count = 0;
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
-
- while( FALSE == textFileEOF(tfpFile) )
- {
- // Robin_1003_2004_E
- if (count >= 500)
- break;
-
- if ((TRUE == textFileReadNumber(tfpFile,&num)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ':')) &&
- (TRUE == textFileReadNumber(tfpFile,&num)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ':')) &&
- (TRUE == textFileReadNumber(tfpFile,&num)) &&
- ((TRUE == textFileIsCurrentChar2(tfpFile, '.')) ||
- (TRUE == textFileIsCurrentChar2(tfpFile, ':')) ||
- (TRUE == textFileIsCurrentChar(tfpFile, ','))) &&
- (TRUE == textFileReadNumber(tfpFile,&num)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ',')) &&
- (TRUE == textFileReadNumber(tfpFile,&num)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ':')) &&
- (TRUE == textFileReadNumber(tfpFile,&num)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ':')) &&
- (TRUE == textFileReadNumber(tfpFile,&num)) &&
- ((TRUE == textFileIsCurrentChar2(tfpFile, '.')) ||
- (TRUE == textFileIsCurrentChar2(tfpFile, ':')) ||
- (TRUE == textFileIsCurrentChar(tfpFile, ','))) &&
- (TRUE == textFileReadNumber(tfpFile,&num)) )
- {
- dbg_printf(("probeSubtitlesFileSubViewer - SubViewer 2.0 format confirmed.n"));
- bSuccess=TRUE;
- break;
- }
- if (FALSE == textFileReadChar(tfpFile,0,&c)) {
- tr_printf(("probeSubtitlesFileSubViewer - can't read charn"));
- break;
- }
- count++;
-
- }
- if ( NULL != tfpFile )
- textFileClose(tfpFile);
- return bSuccess;
- }
- BOOL probeSubtitlesFileTMPlayer(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize)
- {
- textFilePtr tfpFile;
- DWORD num;
- char c;
- BOOL bSuccess=FALSE;
- UINT16 count = 0;
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
-
- while( FALSE == textFileEOF(tfpFile) )
- {
- // Robin_1003_2004_E
- if (count >= 500)
- break;
-
- if ((TRUE == textFileReadNumber(tfpFile,&num)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ':')) &&
- (TRUE == textFileReadNumber(tfpFile,&num)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ':')) &&
- (TRUE == textFileReadNumber(tfpFile,&num)) &&
- ( (TRUE == textFileIsCurrentChar2(tfpFile, ':')) ||
- (TRUE == textFileIsCurrentChar2(tfpFile, '=')) ||
- ((TRUE == textFileIsCurrentChar(tfpFile, ',')) && (TRUE == textFileReadNumber(tfpFile,&num)) && (TRUE == textFileIsCurrentChar(tfpFile, '=')))
- )
- )
- {
- dbg_printf(("probeSubtitlesFileTMPlayer - TMPlayer format confirmed.n"));
- bSuccess=TRUE;
- break;
- }
- if (FALSE == textFileReadChar(tfpFile,0,&c)) {
- dbg_printf(("probeSubtitlesFileTMPlayer - can't read charn"));
- break;
- }
- count++;
-
- }
- if ( NULL != tfpFile )
- textFileClose(tfpFile);
- return bSuccess;
- }
- // Robin_1125_2004, support SubViewer 1.0
- BOOL probeSubtitlesFileSubViewerVer1(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize)
- {
- textFilePtr tfpFile;
- DWORD num1;
- char c;
- BOOL bSuccess=FALSE;
- UINT16 count = 0;
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
-
- while( FALSE == textFileEOF(tfpFile) )
- {
- // Robin_1003_2004_E
- if (count >= 500)
- break;
-
- if ((TRUE == textFileFindString(tfpFile,"[",0)) &&
- (TRUE == textFileReadNumber(tfpFile,&num1)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ':')) &&
- (TRUE == textFileReadNumber(tfpFile,&num1)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ':')) &&
- (TRUE == textFileReadNumber(tfpFile,&num1)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ']')) &&
- (TRUE == textFileIsCurrentChar(tfpFile, 'r')) &&
- (TRUE == textFileIsCurrentChar(tfpFile, 'n')))
- {
- dbg_printf(("probeSubtitlesFileSubViewerVer1 - SubViewer 1.0 format confirmed.n"));
- bSuccess=TRUE;
- break;
- }
- if (FALSE == textFileReadChar(tfpFile,0,&c)) {
- tr_printf(("probeSubtitlesFileSubViewerVer1 - can't read charn"));
- break;
- }
- count++;
-
- }
- if ( NULL != tfpFile )
- textFileClose(tfpFile);
- return bSuccess;
- }
- BOOL parseSubtitlesFileMicroDVD(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate)
- {
- DWORD num1,num2,dwTmp1,dwTmp2;
- char c;
- BOOL bSuccess=TRUE;
- BOOL bExpectFormatting=TRUE;
- BOOL bNoExistNum2 = FALSE;
- textFilePtr tfpFile;
- dbg_printf(("parseSubtitlesFileMicroDVD - Startingn"));
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
- subtitleStorageInitWriting();
-
- while( FALSE == textFileEOF(tfpFile) ) {
- // parse the section "{start frame}{end frame}"
- bSuccess &= textFileFindString(tfpFile,"{",0);
- // Robin_0715_2004, merge changlist #24407
- if(TRUE == textFileIsCurrentChar2(tfpFile, 'D') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'E') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'F') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'A') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'U') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'L') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'T') &&
- TRUE == textFileIsCurrentChar2(tfpFile, '}')
- ) // Robin_0705_2004_B, bypass {DEFAULT} control code
- {
- if(FALSE == textFileFindString(tfpFile,"n",0))
- return FALSE;
- continue;
- }
- bSuccess &= textFileReadNumber(tfpFile,&num1);
- bSuccess &= textFileIsCurrentChar(tfpFile, '}');
- bSuccess &= textFileIsCurrentChar(tfpFile, '{');
- if (TRUE == textFileIsCurrentChar2(tfpFile, '}'))
- {
- dwTmp1=FRAME_TO_TIME(num1, dwScale, dwRate);
- if (TRUE == bNoExistNum2)
- if ( FALSE == subtitleStorageEndEntry(dwTmp1))
- return FALSE;
-
- bNoExistNum2 = TRUE;
- }
- else
- {
- bNoExistNum2 = FALSE;
- bSuccess &= textFileReadNumber(tfpFile,&num2);
- bSuccess &= textFileIsCurrentChar(tfpFile, '}');
- }
-
- if (FALSE == bSuccess)
- break;
- // deals with a subtitle of the form "{1}{1}fps_int.fps_fract", that specifies fps for interpreting
- // the timing info.
- if ( 1 == num1 && 1 == num2 ) {
- // it's possible to overwrite num1 - it's no longer important
- bSuccess &= textFileReadNumber(tfpFile,&num1);
- // I'll asume that the fraction isn't mandatory
- if (TRUE == textFileIsCurrentChar(tfpFile, '.'))
- bSuccess &= textFileReadNumber(tfpFile,&num2);
- else {
- // set fraction to 0, and go back to the char that could've been '.'
- num2=0;
- bSuccess &= textFileSeek(tfpFile,-1,TF_SEEK_CUR);
- }
- if ( FALSE == bSuccess)
- // Robin_0328_2005, search the next '{'
- {
- textFileFindString(tfpFile,"{",SF_MICRODVD_PROBE_LIMIT*5);
- textFileSeek(tfpFile,-1,TF_SEEK_CUR);
- bSuccess = TRUE;
- continue;
- }
- // As far as I understand, the accuracy of the fps is 3 digits at the most, so 1000 is used as multiplier
- dwRate=num1*1000+num2;
- dwScale=1000;
- // that's all there is in this line.
- continue;
- }
- if ( FALSE == bSuccess)
- break;
- // write the timing
- dwTmp1=FRAME_TO_TIME(num1, dwScale, dwRate); // Robin_0531_2004_A
- dwTmp2=FRAME_TO_TIME(num2, dwScale, dwRate);// Robin_0531_2004_A
- if(FALSE == parseSubtitlesFileCommon(dwTmp1, dwTmp2, tfpFile, bNoExistNum2,FALSE))
- return FALSE;
-
- }
- if (TRUE == bNoExistNum2)
- if ( FALSE == subtitleStorageEndEntry(0xFFFFFFFF))
- return FALSE;
-
- subtitleStorageMarkLastEntry();
- textFileClose(tfpFile);
- // Files were found in which the last subtitle ends in EOF, without new line
- dbg_printf(("parseSubtitlesFileMicroDVD - Exitingn"));
- return (bSuccess || textFileEOF(tfpFile));
- }
- BOOL parseSubtitlesFileSubRip(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate)
- {
- DWORD num1,num2;
- char c;
- BOOL bSuccess=TRUE;
- BOOL bLastWasNewLine=FALSE;
- int mult[]={60,60,1000};
- textFilePtr tfpFile;
- //Byte Order Mark (BOM)
- dbg_printf(("parseSubtitlesFileSubRip - Startingn"));
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
- subtitleStorageInitWriting();
- while( FALSE == textFileEOF(tfpFile) ) {
- num1=0;
- num2=0;
- // Look for number - should be the number of the 1st subtitle - probably 1
- bSuccess &= textFileFindNumber(tfpFile,0);
- // reading subtitle serial number - not used.
- bSuccess &= textFileReadNumber(tfpFile,&num1);
- bSuccess &= textFileSkipLine(tfpFile);
- // read start time
- bSuccess &= readDelimitedTimeString(tfpFile, &num1, mult,3);
- // skip the "-->" symbol
- bSuccess &= textFileFindString(tfpFile, " --> ",6);
- bSuccess &= readDelimitedTimeString(tfpFile, &num2, mult,3);
- bSuccess &= textFileSkipLine(tfpFile);
-
- if (FALSE == bSuccess)
- break;
-
- // write the timing
- if ( FALSE == subtitleStorageStartEntry(num1))
- return FALSE;
-
- bLastWasNewLine = FALSE;
-
- while ( FALSE != (bSuccess &= textFileReadChar(tfpFile, 0, &c)) )
- {
- // end of subtitle or subtitle line
- if (( 'r' == c ) || ('n' == c))
- {
- // if file uses CR-LF combination, read both chars in the same iteration
- if ('r' == c ) {
- textFileIsCurrentChar(tfpFile,'n');
- if (textFileEOF(tfpFile))
- {
- bSuccess = FALSE; // leads to ending the entry after the break
- // is executed
- break;
- }
- }
- // only 2 adjacent new lines signify subtitle end
- if ( TRUE == bLastWasNewLine ) {
- // double new line - subtitle end
- if ( FALSE == subtitleStorageEndEntry(num2))
- return FALSE;
- break;
- }
- else
- {
- // new line
- bLastWasNewLine = TRUE;
- #ifdef _DEBUG
- if ( g_pSubtitleStorage->wMaxLineLength < g_pSubtitleStorage->wCurrentLineLength )
- g_pSubtitleStorage->wMaxLineLength = g_pSubtitleStorage->wCurrentLineLength;
- #endif
- if (FALSE == subtitleStorageWriteByte(FORMAT_NEW_LINE))
- return FALSE;
- #ifdef _DEBUG
- g_pSubtitleStorage->wCurrentLineLength = 0;
- #endif
- }
- }
- // beginning of formatting information symbol
- else if ( '<' == c )
- {
- int i;
- char d;
- char style[] = {'i','b','u'};
- BOOL bFoundSymbol1,bFoundSymbol2;
- bLastWasNewLine = FALSE;
- textFileIsCurrentChar2(tfpFile,'/');
- // Robin_0113_2005, remove the font text
- // <FONT COLOR="######">text text text text text</FONT>
- if((TRUE == textFileIsCurrentChar2(tfpFile, 'f') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'o') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'n') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 't')) ||
- (TRUE == textFileIsCurrentChar2(tfpFile, 'F') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'O') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'N') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'T')))
- {
- if (FALSE == textFileFindString(tfpFile, ">",0))
- {
- return FALSE;
- }
- continue;
- }
-
- bFoundSymbol1 = FALSE;
- bFoundSymbol2 = FALSE;
- for (i =0; i<3; i++ )
- {
- d=style[i];
- if (TRUE == textFileIsCurrentChar2(tfpFile,d))
- {
- bFoundSymbol1 = TRUE;
- if (TRUE == textFileIsCurrentChar2(tfpFile,'>'))
- {
- bFoundSymbol2 = TRUE;
- }
- break;
- }
- }
-
- if (FALSE == bFoundSymbol1)
- {
- if (FALSE == subtitleStorageWriteByte((BYTE)c))
- return FALSE;
- }
- else if (FALSE == bFoundSymbol2)
- {
- if (FALSE == subtitleStorageWriteByte((BYTE)c))
- return FALSE;
- if (FALSE == subtitleStorageWriteByte((BYTE)d))
- return FALSE;
- }
- }
- // character to be displayed
- else
- {
- bLastWasNewLine = FALSE;
- if (FALSE == subtitleStorageWriteByte((BYTE)c))
- return FALSE;
- }
- }
- // The last entry in the subtitles file may end in EOF, without a new line
- if ( FALSE == bSuccess ) {
- if (TRUE == textFileEOF(tfpFile)) {
- if ( FALSE == subtitleStorageEndEntry(num2))
- return FALSE;
- }
- }
- }
- subtitleStorageMarkLastEntry();
- textFileClose(tfpFile);
- // Files were found in which the last subtitle ends in EOF, without new line
- dbg_printf(("parseSubtitlesFileSubRip - Exitingn"));
- return (bSuccess || textFileEOF(tfpFile));
- }
- // Robin_0604_2004_C
- BOOL parseSubtitlesFileSubViewer(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate)
- {
- DWORD num1,num2;
- char c;
- BOOL bSuccess=TRUE;
- BOOL bLastWasNewLine=FALSE;
- int mult[]={60,60,100};
- textFilePtr tfpFile;
- dbg_printf(("parseSubtitlesFileSubViewer - Startingn"));
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
- subtitleStorageInitWriting();
- while( FALSE == textFileEOF(tfpFile) ) {
- if ((TRUE == textFileReadNumber(tfpFile,&num1)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ':')) &&
- (TRUE == textFileReadNumber(tfpFile,&num1)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ':')) &&
- (TRUE == textFileReadNumber(tfpFile,&num1)) &&
- ((TRUE == textFileIsCurrentChar2(tfpFile, '.')) ||
- (TRUE == textFileIsCurrentChar2(tfpFile, ':')) ||
- (TRUE == textFileIsCurrentChar(tfpFile, ','))) &&
- (TRUE == textFileReadNumber(tfpFile,&num1)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ',')) &&
- (TRUE == textFileReadNumber(tfpFile,&num1)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ':')) &&
- (TRUE == textFileReadNumber(tfpFile,&num1)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ':')) &&
- (TRUE == textFileReadNumber(tfpFile,&num1)) &&
- ((TRUE == textFileIsCurrentChar2(tfpFile, '.')) ||
- (TRUE == textFileIsCurrentChar2(tfpFile, ':')) ||
- (TRUE == textFileIsCurrentChar(tfpFile, ','))) &&
- (TRUE == textFileReadNumber(tfpFile,&num1)) )
- {
- bSuccess = textFileSeek(tfpFile,-23,TF_SEEK_CUR);
- break;
- }
-
- if (FALSE == textFileReadChar(tfpFile,0,&c)) {
- tr_printf(("parseSubtitlesFileSubViewer - can't read charn"));
- break;
- }
- }
- while( FALSE == textFileEOF(tfpFile) ) {
- num1=0;
- num2=0;
- // read start time
- bSuccess &= readDelimitedTimeString(tfpFile, &num1,mult,3);
- // skip the "-->" symbol
- bSuccess &= textFileFindString(tfpFile, ",",1);
- bSuccess &= readDelimitedTimeString(tfpFile, &num2,mult,3);
- bSuccess &= textFileSkipLine(tfpFile);
-
- if (FALSE == bSuccess)
- break;
- num1 *= 10; // in unit of ms
- num2 *= 10; // in unit of ms
- // write the timing
- if ( FALSE == subtitleStorageStartEntry(num1))
- return FALSE;
-
- bLastWasNewLine = FALSE;
-
- while ( FALSE != (bSuccess &= textFileReadChar(tfpFile, 0, &c)) )
- {
- // end of subtitle or subtitle line
- if (( 'r' == c ) || ('n' == c)) {
- // if file uses CR-LF combination, read both chars in the same iteration
- if ('r' == c ) {
- textFileIsCurrentChar(tfpFile,'n');
- if (textFileEOF(tfpFile))
- {
- bSuccess = FALSE; // leads to ending the entry after the break
- // is executed
- break;
- }
- }
- // only 2 adjacent new lines signify subtitle end
- if ( TRUE == bLastWasNewLine ) {
- // double new line - subtitle end
- if ( FALSE == subtitleStorageEndEntry(num2))
- return FALSE;
- break;
- }
- else
- {
- // new line
- bLastWasNewLine = TRUE;
- #ifdef _DEBUG
- if ( g_pSubtitleStorage->wMaxLineLength < g_pSubtitleStorage->wCurrentLineLength )
- g_pSubtitleStorage->wMaxLineLength = g_pSubtitleStorage->wCurrentLineLength;
- #endif
- if (FALSE == subtitleStorageWriteByte(FORMAT_NEW_LINE))
- return FALSE;
- #ifdef _DEBUG
- g_pSubtitleStorage->wCurrentLineLength = 0;
- #endif
- }
- }
- else if ( '<' == c )
- {
- int i;
- char d;
- char style[] = {'i','b','u'};
- BOOL bFoundSymbol1,bFoundSymbol2;
- bLastWasNewLine = FALSE;
- textFileIsCurrentChar2(tfpFile,'/');
- bFoundSymbol1 = FALSE;
- bFoundSymbol2 = FALSE;
- for (i =0; i<3; i++ )
- {
- d=style[i];
- if (TRUE == textFileIsCurrentChar2(tfpFile,d))
- {
- bFoundSymbol1 = TRUE;
- if (TRUE == textFileIsCurrentChar2(tfpFile,'>'))
- {
- bFoundSymbol2 = TRUE;
- }
- break;
- }
- }
-
- if (FALSE == bFoundSymbol1)
- {
- if (FALSE == subtitleStorageWriteByte((BYTE)c))
- return FALSE;
- }
- else if (FALSE == bFoundSymbol2)
- {
- if (FALSE == subtitleStorageWriteByte((BYTE)c))
- return FALSE;
- if (FALSE == subtitleStorageWriteByte((BYTE)d))
- return FALSE;
- }
- }
- // Robin_0408_2005, [br] mean new line
- else if ( '[' == c )
- {
- if (textFileIsCurrentChar(tfpFile,'b'))
- {
- if (textFileIsCurrentChar(tfpFile,'r'))
- {
- if (textFileIsCurrentChar(tfpFile,']'))
- {
- if (FALSE == subtitleStorageWriteByte(FORMAT_NEW_LINE))
- return FALSE;
- continue;
- }
- else
- {
- textFileSeek(tfpFile,-3,TF_SEEK_CUR);
- }
- }
- else
- {
- textFileSeek(tfpFile,-2,TF_SEEK_CUR);
- }
- }
- else
- {
- textFileSeek(tfpFile,-1,TF_SEEK_CUR);
- }
- if (FALSE == subtitleStorageWriteByte((BYTE)c))
- return FALSE;
- }
- // character to be displayed
- else {
- bLastWasNewLine = FALSE;
- if (FALSE == subtitleStorageWriteByte((BYTE)c))
- return FALSE;
- }
- }
- // The last entry in the subtitles file may end in EOF, without a new line
- if ( FALSE == bSuccess ) {
- bSuccess = TRUE;
- if (TRUE == textFileEOF(tfpFile)) {
- if ( FALSE == subtitleStorageEndEntry(num2))
- return FALSE;
- }
- }
- }
- subtitleStorageMarkLastEntry();
- textFileClose(tfpFile);
- // Files were found in which the last subtitle ends in EOF, without new line
- dbg_printf(("parseSubtitlesFileSubViewer- Exitingn"));
- return (bSuccess || textFileEOF(tfpFile));
- }
- BOOL parseSubtitlesFilePowerDivX(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate)
- {
- DWORD num1,num2;
- char c;
- BOOL bSuccess=TRUE;
- BOOL bExpectFormatting=TRUE;
- int mult[]={60,60};
- textFilePtr tfpFile;
- dbg_printf(("parseSubtitlesFilePowerDivX - Startingn"));
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
- subtitleStorageInitWriting();
-
- while( FALSE == textFileEOF(tfpFile) ) {
- // parse the section "{start frame}{end frame}"
- bSuccess &= textFileFindString(tfpFile,"{",0);
- bSuccess &= readDelimitedTimeString(tfpFile, &num1, mult,2);
- bSuccess &= textFileIsCurrentChar(tfpFile, '}');
- bSuccess &= textFileIsCurrentChar(tfpFile, '{');
- bSuccess &= readDelimitedTimeString(tfpFile, &num2, mult,2);
- bSuccess &= textFileIsCurrentChar(tfpFile, '}');
- if ( FALSE == bSuccess)
- break;
- num1 *= 1000; // in unit of ms
- num2 *= 1000; // in unit of ms
- if(FALSE == parseSubtitlesFileCommon(num1, num2, tfpFile,FALSE,FALSE))
- return FALSE;
-
- }
- subtitleStorageMarkLastEntry();
-
- textFileClose(tfpFile);
- // Files were found in which the last subtitle ends in EOF, without new line
- dbg_printf(("parseSubtitlesFilePowerDivX - Exitingn"));
- return (bSuccess || textFileEOF(tfpFile));
- }
- BOOL parseSubtitlesFileAdvancedSubStationAlpha(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate)
- {
- DWORD num1,num2;
- char c;
- BOOL bSuccess=TRUE;
- BOOL bExpectFormatting=TRUE;
- int mult[]={60,60,100};
- textFilePtr tfpFile;
- dbg_printf(("parseSubtitlesFileAdvancedSubStationAlpha - Startingn"));
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
- subtitleStorageInitWriting();
- while( FALSE == textFileEOF(tfpFile) ) {
- bSuccess &= textFileFindString(tfpFile,"Dialogue:",0); // Format
- bSuccess &= textFileFindString(tfpFile,",",0); // Layer
- bSuccess &= readDelimitedTimeString(tfpFile, &num1, mult,3); // Start
- bSuccess &= textFileIsCurrentChar(tfpFile, ',');
- bSuccess &= readDelimitedTimeString(tfpFile, &num2, mult,3); // End
- bSuccess &= textFileIsCurrentChar(tfpFile, ',');
- bSuccess &= textFileFindString(tfpFile,",",0); // Style
- bSuccess &= textFileFindString(tfpFile,",",0); // Actor
- bSuccess &= textFileFindString(tfpFile,",",0); // MarginL
- bSuccess &= textFileFindString(tfpFile,",",0); // MarginR
- bSuccess &= textFileFindString(tfpFile,",",0); // MarginV
- bSuccess &= textFileFindString(tfpFile,",",0); // Effect
- if ( FALSE == bSuccess)
- break;
-
- num1 *= 10; // in unit of ms
- num2 *= 10; // in unit of ms
- if(FALSE == parseSubtitlesFileCommon(num1, num2, tfpFile,FALSE,FALSE))
- return FALSE;
- }
- subtitleStorageMarkLastEntry();
-
- textFileClose(tfpFile);
- // Files were found in which the last subtitle ends in EOF, without new line
- dbg_printf(("parseSubtitlesFileAdvancedSubStationAlpha - Exitingn"));
- return (bSuccess || textFileEOF(tfpFile));
- }
- // TMPlayer Format
- // hh:mm:ss:
- // TMPlayer + Format
- // hh:mm:ss=
- // TMPlayer Multiline Format
- // hh:mm:ss,1=
- // hh:mm:ss,2=
- BOOL parseSubtitlesFileTMPlayer(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate)
- {
- DWORD num1,num2;
- char c;
- BOOL bSuccess=TRUE;
- BOOL bExpectFormatting=TRUE;
- int mult[]={60,60};
- textFilePtr tfpFile;
- BOOL bStorednum2 = FALSE;
- BOOL bMultiline2 = FALSE;
- BOOL bFirstLine = TRUE;
-
- dbg_printf(("parseSubtitlesFileTMPlayer - Startingn"));
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
- subtitleStorageInitWriting();
- num1 = 0;
- num2 = 0xFFFFFFFF;
-
- while( FALSE == textFileEOF(tfpFile) ) {
- bMultiline2 = FALSE;
-
- bSuccess &= readDelimitedTimeString(tfpFile, &num1, mult,2);
- if (TRUE == textFileIsCurrentChar2(tfpFile, ','))
- {
- if (TRUE == textFileIsCurrentChar2(tfpFile, '1'))
- {
- bSuccess &= textFileIsCurrentChar2(tfpFile, '=');
- }
- else if (TRUE == textFileIsCurrentChar2(tfpFile, '2'))
- {
- bSuccess &= textFileIsCurrentChar2(tfpFile, '=');
- bMultiline2 = TRUE;
- }
- else
- bSuccess = FALSE;
- }
- else
- bSuccess &= textFileIsCurrentChar2(tfpFile, ':') || textFileIsCurrentChar(tfpFile, '=');
- if ( FALSE == bSuccess)
- break;
- num1 *= 1000; // in unit of ms
-
- if ((TRUE == textFileIsCurrentChar2(tfpFile, 'r')) && (TRUE == textFileIsCurrentChar2(tfpFile, 'n')))
- {
- if (TRUE == bMultiline2)
- continue;
-
- if ( FALSE == subtitleStorageEndEntry(num1))
- return FALSE;
- bStorednum2 = TRUE;
- continue;
- }
- if (TRUE == bMultiline2)
- if (FALSE == subtitleStorageWriteByte(FORMAT_NEW_LINE))
- return FALSE;
-
- if ((FALSE == bFirstLine) && (FALSE == bStorednum2) && (FALSE == bMultiline2))
- if ( FALSE == subtitleStorageEndEntry(num1))
- return FALSE;
-
- if(FALSE == parseSubtitlesFileCommon(num1, num2, tfpFile,TRUE,bMultiline2))
- return FALSE;
- bStorednum2 = FALSE;
- bFirstLine = FALSE;
-
- }
- if (FALSE == bStorednum2)
- if ( FALSE == subtitleStorageEndEntry(num2))
- return FALSE;
-
- subtitleStorageMarkLastEntry();
-
- textFileClose(tfpFile);
- // Files were found in which the last subtitle ends in EOF, without new line
- dbg_printf(("parseSubtitlesFileTMPlayer - Exitingn"));
- return (bSuccess || textFileEOF(tfpFile));
- }
- // Robin_1125_2004, support SubViewer 1.0
- BOOL parseSubtitlesFileSubViewerVer1(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate)
- {
- DWORD num1,num2;
- char c;
- BOOL bSuccess=TRUE;
- BOOL bEnd = FALSE;
- BOOL bExpectFormatting=TRUE;
- int mult[]={60,60};
- textFilePtr tfpFile;
-
- dbg_printf(("parseSubtitlesFileSubViewerVer1 - Startingn"));
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
- subtitleStorageInitWriting();
- while( FALSE == textFileEOF(tfpFile) ) {
- if ((TRUE == textFileFindString(tfpFile,"[",0)) &&
- (TRUE == textFileReadNumber(tfpFile,&num1)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ':')) &&
- (TRUE == textFileReadNumber(tfpFile,&num1)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ':')) &&
- (TRUE == textFileReadNumber(tfpFile,&num1)) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ']')) &&
- (TRUE == textFileIsCurrentChar(tfpFile, 'r')) &&
- (TRUE == textFileIsCurrentChar(tfpFile, 'n')))
- {
- bSuccess = textFileSeek(tfpFile,-12,TF_SEEK_CUR);
- break;
- }
-
- if (FALSE == textFileReadChar(tfpFile,0,&c)) {
- tr_printf(("parseSubtitlesFileSubViewerVer1 - can't read charn"));
- break;
- }
- }
- num1 = 0;
- num2 = 0xFFFFFFFF;
-
- while( FALSE == textFileEOF(tfpFile) ) {
- bSuccess &= textFileFindString(tfpFile,"[",0);
- if ((TRUE == textFileIsCurrentChar2(tfpFile, 'e')) &&
- (TRUE == textFileIsCurrentChar(tfpFile, 'n')) &&
- (TRUE == textFileIsCurrentChar(tfpFile, 'd')) &&
- (TRUE == textFileIsCurrentChar(tfpFile, ']')))
- break; // [end]
-
- bSuccess &= readDelimitedTimeString(tfpFile, &num1, mult,2);
- bSuccess &= (textFileIsCurrentChar(tfpFile, ']') && textFileIsCurrentChar(tfpFile, 'r') && textFileIsCurrentChar(tfpFile, 'n')) ;
- if ( FALSE == bSuccess)
- break;
- num1 *= 1000; // in unit of ms
- if(FALSE == parseSubtitlesFileCommon(num1, num2, tfpFile,TRUE,FALSE))
- return FALSE;
- bSuccess &= textFileFindString(tfpFile,"[",0);
-
- if(TRUE == textFileIsCurrentChar2(tfpFile, 'e') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'n') &&
- TRUE == textFileIsCurrentChar2(tfpFile, 'd') &&
- TRUE == textFileIsCurrentChar2(tfpFile, ']'))
- bEnd = TRUE; // [end/END]
-
- if (bEnd == FALSE)
- {
- bSuccess &= readDelimitedTimeString(tfpFile, &num2, mult,2);
- bSuccess &= textFileIsCurrentChar(tfpFile, ']');
- }
- else
- num2 = num1/1000 + 1;
- if ( FALSE == bSuccess)
- break;
- num2 *= 1000; // in unit of ms
- if ( FALSE == subtitleStorageEndEntry(num2))
- return FALSE;
- if (TRUE == bEnd)
- break;
- }
-
- subtitleStorageMarkLastEntry();
-
- textFileClose(tfpFile);
- // Files were found in which the last subtitle ends in EOF, without new line
- dbg_printf(("parseSubtitlesFileSubViewerVer1 - Exitingn"));
- return (bSuccess || textFileEOF(tfpFile));
- }
- BOOL parseSubtitlesFileCommon(DWORD num1, DWORD num2,textFilePtr tfpFile, BOOL bNoStorenum2, BOOL bNoStorenum1)
- {
- char c,c_next;
- BOOL bSuccess=TRUE;
- BOOL bExpectFormatting=TRUE;
- // write the timing
- if ((FALSE == bNoStorenum1) && (FALSE == subtitleStorageStartEntry(num1)))
- return FALSE;
-
- while ( FALSE != (bSuccess &= textFileReadChar(tfpFile, 0, &c)) ) {
- // end of subtitle
- if ( 'n' == c || 'r' == c ) {
- // Robin_0328_2005, search next char, not 'r' or 'n'
- if (FALSE != textFileReadChar(tfpFile, 0, &c_next))
- {
- textFileSeek(tfpFile,-1,TF_SEEK_CUR);
- if ( 'n' == c_next || 'r' == c_next)
- continue;
- }
- bExpectFormatting=TRUE;
- if ((FALSE == bNoStorenum2) && ( FALSE == subtitleStorageEndEntry(num2)))
- return FALSE;
- break;
- }
- // new line symbol
- else if ( '|' == c ) {
- bExpectFormatting=TRUE;
- //writeNewLine
- #ifdef _DEBUG
- if ( g_pSubtitleStorage->wMaxLineLength < g_pSubtitleStorage->wCurrentLineLength )
- g_pSubtitleStorage->wMaxLineLength = g_pSubtitleStorage->wCurrentLineLength;
- #endif
- if (FALSE == subtitleStorageWriteByte(FORMAT_NEW_LINE))
- return FALSE;
- #ifdef _DEBUG
- g_pSubtitleStorage->wCurrentLineLength = 0;
- #endif
- }
- // Robin_0715_2004, merge changelist #24309
- else if ('\' == c) // Robin_0701_2004, 'N' or 'n' mean new line in *.ssa/*.ass
- {
- if( (TRUE == textFileIsCurrentChar2(tfpFile, 'N')) || (TRUE == textFileIsCurrentChar2(tfpFile, 'n')))
- {
- if (FALSE == subtitleStorageWriteByte(FORMAT_NEW_LINE))
- return FALSE;
- }
- else
- {
- if (FALSE == subtitleStorageWriteByte((BYTE)c))
- return FALSE;
- }
- }
- // beginning of formatting information symbol
- // apparently can only appear as first char in subtitle
- // line, and should otherwise be stored and displayed.
- else if (( '{' == c ) && (TRUE == bExpectFormatting)) {
- // handle formatting
- // for now skip
- bSuccess &= textFileFindString(tfpFile,"}",0);
- // don't set bExpectFormatting to FALSE - additional format tags
- // are possible
- }
- else if ( '<' == c )
- {
- int i;
- char d;
- char style[] = {'i','b','u'};
- BOOL bFoundSymbol1,bFoundSymbol2;
- textFileIsCurrentChar2(tfpFile,'/');
- bFoundSymbol1 = FALSE;
- bFoundSymbol2 = FALSE;
- for (i =0; i<3; i++ )
- {
- d=style[i];
- if (TRUE == textFileIsCurrentChar2(tfpFile,d))
- {
- bFoundSymbol1 = TRUE;
- if (TRUE == textFileIsCurrentChar2(tfpFile,'>'))
- {
- bFoundSymbol2 = TRUE;
- }
- break;
- }
- }
-
- if (FALSE == bFoundSymbol1)
- {
- if (FALSE == subtitleStorageWriteByte((BYTE)c))
- return FALSE;
- }
- else if (FALSE == bFoundSymbol2)
- {
- if (FALSE == subtitleStorageWriteByte((BYTE)c))
- return FALSE;
- if (FALSE == subtitleStorageWriteByte((BYTE)d))
- return FALSE;
- }
- }
- //// Robin_0408_2005, [br] mean new line
- else if ( '[' == c )
- {
- if (textFileIsCurrentChar(tfpFile,'b'))
- {
- if (textFileIsCurrentChar(tfpFile,'r'))
- {
- if (textFileIsCurrentChar(tfpFile,']'))
- {
- bExpectFormatting=TRUE;
- if (FALSE == subtitleStorageWriteByte(FORMAT_NEW_LINE))
- return FALSE;
- continue;
- }
- else
- {
- textFileSeek(tfpFile,-3,TF_SEEK_CUR);
- }
- }
- else
- {
- textFileSeek(tfpFile,-2,TF_SEEK_CUR);
- }
- }
- else
- {
- textFileSeek(tfpFile,-1,TF_SEEK_CUR);
- }
- if (FALSE == subtitleStorageWriteByte((BYTE)c))
- return FALSE;
- }
- // character to be displayed
- else {
- if (FALSE == subtitleStorageWriteByte((BYTE)c))
- return FALSE;
- bExpectFormatting = FALSE;
- }
- }
- // The last entry in the subtitles file may end in EOF, without a new line
- if ( FALSE == bSuccess ) {
- if (TRUE == textFileEOF(tfpFile)) {
- if ( FALSE == subtitleStorageEndEntry(num2))
- return FALSE;
- }
- }
- return TRUE;
- }
- BOOL readDelimitedTimeString(textFilePtr tfpFile, DWORD *dwPTS, int mult[], int number)
- {
- BOOL bSuccess=TRUE;
- int i;
- DWORD dwTmp;
-
- bSuccess &= textFileReadNumber(tfpFile,dwPTS);
- for (i=0; i<number ; i++ )
- {
- bSuccess &= textFileSeek(tfpFile,1,TF_SEEK_CUR);
- bSuccess &= textFileReadNumber(tfpFile,&dwTmp);
- *dwPTS = (*dwPTS) * mult[i] + dwTmp;
- }
- // if less than 3 delimiters - continue to multiply
- for ( ; i < number ; i++ )
- *dwPTS = (*dwPTS) * mult[i];
- return bSuccess;
- }
- /*
- BOOL parseSubtitlesFileDummy(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate)
- {
- textFilePtr tfpFile;
- BYTE c;
- dbg_printf(("parseSubtitlesFileDummy - Startingn"));
- tfpFile=textFileOpen(dwSubtitlesFileAddress,dwSubtitlesFileSize);
- if ( NULL == tfpFile )
- return FALSE;
- subtitleStorageInitWriting();
- while ( FALSE != textFileReadChar(tfpFile, 0, &c))
- {
- if (FALSE == subtitleStorageWriteByte(c))
- return FALSE;
- }
- textFileClose(tfpFile);
- return FALSE;
- } */
- /****************************************************************************************************
- * Function : probeSubtitlesFileBitMap
- * Input : dwSubtitlesFileAddress - file address
- dwSubtitlesFileSize - file size
- * Output :
- * Return : TRUE - subpicture format
- FLASE - not
- * Description : probe if it is a subpicture format (Bitmap)
- ****************************************************************************************************/
- BOOL probeSubtitlesFileBitMap(DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize)
- {
- DWORD dwOffset = 0UL;
- DWORD startCode;
- BYTE stuffingLength;
- if (dwSubtitlesFileSize < 32)
- return FALSE;
- // get the pack start code "0x000001BA"
- if (FALSE == AuxCache_GetBytes(dwSubtitlesFileAddress, dwOffset, 4, (BYTE*)&startCode))
- return FALSE;
- dwOffset += 4;
- if (startCode != 0xBA010000UL)
- return FALSE;
- // get the stuffing length
- dwOffset += 9;
- if (FALSE == AuxCache_GetBytes(dwSubtitlesFileAddress, dwOffset, 1, (BYTE*)&stuffingLength))
- return FALSE;
- dwOffset ++;
- stuffingLength &= 0x7;
- dwOffset += stuffingLength;
- // get the next start code
- if (FALSE == AuxCache_GetBytes(dwSubtitlesFileAddress, dwOffset, 4, (BYTE*)&startCode))
- return FALSE;
- startCode &= 0xFFFFFFUL;
- if (startCode != 0x010000UL)
- return FALSE;
- dbg_printf(("probeSubtitlesFileBitMap - Subpicture format confirmed.n"));
- return TRUE;
- }
- /****************************************************************************************************
- * Function : parseSubtitlesFileBitMap
- * Input : dwSubtitlesFileAddress - file address
- dwSubtitlesFileSize - file size
- * Output :
- * Return : FALSE - dont process the subtitle
- * Description :
- ****************************************************************************************************/
- BOOL parseSubtitlesFileBitMap (DWORD dwSubtitlesFileAddress, DWORD dwSubtitlesFileSize,DWORD dwScale, DWORD dwRate)
- {
- return FALSE;
- }
- #endif // USE_AUX_SUBTITLES