⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subtitle.c

📁 dvd里面的一个文件系统的代码
💻 C
📖 第 1 页 / 共 5 页
字号:
            hr  = (bufptr[0]-'0');
            bufptr += 2;
        }

        min = ((bufptr[0]-'0') * 10) + (bufptr[1]-'0');
        sec = ((bufptr[3]-'0') * 10) + (bufptr[4]-'0');
        ms  = ((bufptr[6]-'0') * 100) + ((bufptr[7]-'0') * 10);
         #ifdef Support_SubExName_Changed  //lyc add-2006-2-20
          if((!_isdigit(bufptr[1]))||(!_isdigit(bufptr[4]))||(!_isdigit(bufptr[7])))
           goto Change_To_Next_SubT;
        #endif
        endtime = (hr*3600 + min*60 + sec) * STC_CLK + ms * MS_STC_CLK;

        bufptr += 8;

        bcnt = 0;
        while(bcnt < 7)
        {
            if( *bufptr == ',' )
                bcnt++;
            bufptr++;
        }
        
        suptr = bufptr;

        while( !_iseol( bufptr ) )
            bufptr++;

        *idxptr++ = sttime;
        *idxptr++ = endtime;
        *idxptr++ = suptr + uiOffset - base;
        *idxptr++ = bufptr - suptr;

        if( idxptr + 3 >= s_pSubIdxBaseEndPtr )
        {
#ifdef DBG_KEYFRAME
            printf( "Subpicture index buffer too small, can't record all index\n" );            
#endif            
            break;
        }
        
#ifdef DBG_KEYFRAME
        printf( "st = %d, end = %d, offset = %d, cnt = %d\n", sttime, endtime, suptr + uiOffset - base, bufptr  - suptr );
#endif
    } while (1);

    s_pSupIdxPtr    = s_pSupIdxBasePtr;
    s_pSupIdxEnd    = idxptr;
    s_pSupBufPtr    = s_pSupBufPtr;

    printf("SSA subtitile initialized!! %x %x %x\n\n", s_pSupIdxPtr, s_pSupIdxEnd, s_pSupBufPtr );
    #ifdef Support_SubExName_Changed  //hongfeng 2006/8/9 15:59
	if(s_uiSupType != INTERNAL_SUBTITLE_SSA)  //hongfeng 2006/8/9 15:41
	    s_uiSupType = INTERNAL_SUBTITLE_SSA;
    #endif

    return 1;
   err_sub:
     return 0;
       #ifdef Support_SubExName_Changed  //lyc add-2006-2-20
        Change_To_Next_SubT:
         return  0; 
       #endif
}
#endif

// **************************************************************************************** //
#ifdef SUBTITLE_SUPPORT_ASS
static int ParsingSubtitleASS()
{
    BYTE    tbuf[10];
    UINT32  bcnt;
    UINT32  hr, min, sec, ms;
    UINT32  sttime, endtime;

    UINT32  uiByteRead  = s_uiSupBufSize;
    UINT32  uiOffset    = 0;
    BYTE*   base        = s_pSupBufPtr;
    BYTE*   bufend      = s_pSupBufEndPtr;
    BYTE*   bufptr      = base;
    BYTE*   suptr       = NULL;
    UINT32* idxptr      = s_pSupIdxBasePtr;

    // parse header  ... until "[Events]"
    while( strncmp( (const char*) bufptr, "[Events]", 8 ) != 0 )
      {
      	 if( bufptr >= bufend )
     	   {
     	      #ifdef Support_SubExName_Changed  //lyc add-2006-2-20
                goto Change_To_Next_SubT;
              #endif
     	   	 goto err_sub;
     	   }
        bufptr++;
      } 
    while( !_iseol( bufptr ) )
        bufptr++;

    // parse subpicture
    do
    {
        if(( bufend - bufptr <= SUBTITLE_RELOAD_LIMIT)&&(s_uiSupLen>s_uiSupBufSize)) //lyc update 2006-8-9;only fileszie>supbufsize,do supFillBuffer
        {            
            if( !supFillBuffer( &bufptr, &uiByteRead ) )
                break;

            uiOffset += ( s_uiSupBufSize - SUBTITLE_RELOAD_LIMIT );
        }

        // error check omitted, should be "0x0D 0x0A" or "0x20"
        while( _isspace( *bufptr ) )
            bufptr++;

        //until start time  
        while (*bufptr != ',')
            bufptr++;
        bufptr++;    
        
        if( (UINT32)( bufptr + uiOffset - base ) > s_uiSupLen )
            break;
        
        // get start time, x:xx:xx,xx format, 10 bytes
        memcpy(tbuf, bufptr, 10);
        bufptr += 10;
        hr  = (tbuf[0]-'0');
        min = ((tbuf[2]-'0') * 10) + (tbuf[3]-'0');
        sec = ((tbuf[5]-'0') * 10) + (tbuf[6]-'0');
        ms  = ((tbuf[8]-'0') * 100) + ((tbuf[9]-'0') * 10);
        #ifdef Support_SubExName_Changed  //lyc add-2006-2-20
          if((!_isdigit(tbuf[3]))||(!_isdigit(tbuf[6]))||(!_isdigit(tbuf[9])))
           goto Change_To_Next_SubT;
        #endif
        sttime = (hr*3600 + min*60 + sec) * STC_CLK + ms * MS_STC_CLK;

        // drop seperation, ","
        while ( !_isdigit( *bufptr ) )
            bufptr++;

        // get end time, x:xx:xx,xx format, 10 bytes
        memcpy(tbuf, bufptr, 10);
        bufptr += 10;
        hr  = (tbuf[0]-'0');
        min = ((tbuf[2]-'0') * 10) + (tbuf[3]-'0');
        sec = ((tbuf[5]-'0') * 10) + (tbuf[6]-'0');
        ms  = ((tbuf[8]-'0') * 100) + ((tbuf[9]-'0') * 10);
        #ifdef Support_SubExName_Changed  //lyc add-2006-2-20
          if((!_isdigit(tbuf[3]))||(!_isdigit(tbuf[6]))||(!_isdigit(tbuf[9])))
           goto Change_To_Next_SubT;
        #endif
        endtime = (hr*3600 + min*60 + sec) * STC_CLK + ms * MS_STC_CLK;

        bcnt = 0;
        while(bcnt < 7)
        {
            if( *bufptr == ',' )
                bcnt++;
            bufptr++;
        }
        
        suptr = bufptr;

        while( !_iseol( bufptr ) )
            bufptr++;

        *idxptr++ = sttime;
        *idxptr++ = endtime;
        *idxptr++ = suptr + uiOffset - base;
        *idxptr++ = bufptr - suptr;

        if( idxptr + 3 >= s_pSubIdxBaseEndPtr )
        {
#ifdef DBG_KEYFRAME
            printf( "Subpicture index buffer too small, can't record all index\n" );            
#endif            
            break;
        }

#ifdef DBG_KEYFRAME
        printf( "st = %d, end = %d, offset = %d, cnt = %d\n", sttime, endtime, suptr + uiOffset - base, bcnt );
#endif
    } while (1);

    s_pSupIdxPtr    = s_pSupIdxBasePtr;
    s_pSupIdxEnd    = idxptr;
    s_pSupBufPtr    = s_pSupBufPtr;

    printf("ASS subtitile initialized!! %x %x %x\n\n", s_pSupIdxPtr, s_pSupIdxEnd, s_pSupBufPtr );
    #ifdef Support_SubExName_Changed  //hongfeng 2006/8/9 15:59
	if(s_uiSupType != INTERNAL_SUBTITLE_ASS)  //hongfeng 2006/8/9 15:41
	    s_uiSupType = INTERNAL_SUBTITLE_ASS;
    #endif

    return 1;
   err_sub:
    return 0;  
       #ifdef Support_SubExName_Changed  //lyc add-2006-2-20
        Change_To_Next_SubT:
          return  0;  
       #endif
}
#endif

// **************************************************************************************** //
#ifdef SUBTITLE_SUPPORT_SMI
#if defined (SUPPORT_SMI_MultiLanguage)||defined(SUPPORT_SMI_MultiColor)//2005-8-16 20:38 zhoulin
static int ParsingSubtitleSMI()
{       
    UINT32  hr, min, sec, ms;
    UINT32  val, cnt, bcnt=0;
    UINT32  sttime = 0;
    BYTE* pTmp;
    BYTE    aTmpBuf[16];
    UINT32  uiByteRead  = s_uiSupBufSize;
    UINT32  uiOffset    = 0;
    BYTE*   base        = s_pSupBufPtr;
    BYTE*   bufend      = s_pSupBufEndPtr;
    BYTE*   bufptr      = base;
    UINT32  suptr=0 ;
    UINT32* idxptr      = s_pSupIdxBasePtr;

    BYTE    firstSupflg =0;
   
    UINT8   state       =0;

    UINT8    i;
    
    #ifdef  SUPPORT_SMI_MultiColor//2005-8-16 20:38 zhoulin
    UINT8    j;
    BYTE*  bufptrb=NULL;
    
    for(i=0;i<MAX_palette_colors;i++)//initialize palette
    {
         for(j=0;j<20;j++)
            color_temp[i][j]='\0';
         palette_16color_MP4_SUB[i]=CLUTE_TRANS;
    }
    palette_16color_MP4_SUB[1]=0xf3f3f3ff;//set default color
    palette_color_num=2;
    #endif
    
    #ifdef  SUPPORT_SMI_MultiLanguage//2005-8-16 20:38 zhoulin
    lang_num=0;
    #endif
 
 //pre-parse SAMI   
    while(!(state==0xff||state==0xf0))//if state==0xff,end of parse
    {                                  //state==0xf0,error
        if( bufend - bufptr <= SUBTITLE_RELOAD_LIMIT )
        {     
            if( !supFillBuffer( &bufptr, &uiByteRead ) )             
                break;
                   
            uiOffset += ( s_uiSupBufSize - SUBTITLE_RELOAD_LIMIT );
        }
        
        switch(state)
        {   //check <SAMI>
            case 0:
                while( bufend - bufptr > SUBTITLE_RELOAD_LIMIT)
                {   
                if( *bufptr == '<' )
                    break;
                       bufptr++;
                }
                if( bufend - bufptr <= SUBTITLE_RELOAD_LIMIT )
                    state=0xf0;//error,end parse                
                else if( strncmpIgnoreCase(  bufptr, "<SAMI>", 6 )==0)
                {
                    bufptr+=6;
                    state=1;//to check HEAD
                }
                else  bufptr++;
            
                break;
            //check <HEAD> 
            case 1:
                while(bufend - bufptr > SUBTITLE_RELOAD_LIMIT)
                {   
                    if( *bufptr == '<' )
                        break;
                    bufptr++;
                }
                if( bufend - bufptr <= SUBTITLE_RELOAD_LIMIT )
                    state=0xf0;//error,end parse 
                else if(strncmpIgnoreCase(  bufptr, "<HEAD>", 6 )==0 )
                {
                  bufptr+=6;
                  state=2;//to check style
                }   
                else if((strncmpIgnoreCase(  bufptr, "<BODY>", 6 )==0) || (strncmpIgnoreCase(  bufptr, "<body>", 6 )==0))
                { 
                  bufptr+=6;
                  state=5;//to check body
                }
                else bufptr++;
                break;
        
                
            //check style
            case 2:
               while( bufend - bufptr > SUBTITLE_RELOAD_LIMIT)
                {   
                    if( *bufptr == '<' )
                        break;
                    bufptr++;
                }
                if( bufend - bufptr <= SUBTITLE_RELOAD_LIMIT )
                    state=0xf0;//error,end parse 
                else if(strncmpIgnoreCase(  bufptr, "<STYLE", 6 )==0 )
                {
                  bufptr+=6;
                  state=3;//to check language info 
                }   
                else if(strncmpIgnoreCase(  bufptr, "</HEAD>", 7 )==0 )
                {
                  bufptr+=7;
                  state=5;//to check body
                }
                else bufptr++;
                break;
                
             //check  language info. & default color
             case 3:
                while(bufend - bufptr > SUBTITLE_RELOAD_LIMIT)
                {   
                    if( *bufptr == '<'
                    #if defined(SUPPORT_SMI_MultiColor)    
                        ||*bufptr == 'P'||*bufptr == 'p'
                    #endif
                    #if defined (SUPPORT_SMI_MultiLanguage)
                        ||*bufptr == '.'
                    #endif    
                         )
                        break;
                    bufptr++;
                }
                if( bufend - bufptr <= SUBTITLE_RELOAD_LIMIT )
                    state=0xf0;//error,end parse 
              #if defined(SUPPORT_SMI_MultiColor)   
                else if(*bufptr == 'P'||*bufptr == 'p')
                {   if(*(bufptr-1)=='-'||*(bufptr-1)==0x0A||*(bufptr-1)==' '||*(bufptr-1)==0x09)
                    {
                        bufptr++;
                        while(*bufptr==' '||*bufptr==0x09) bufptr++;
                        if(*bufptr==0x7B)                    
                             state=4;//to check default color
                        
                    }     
                    else bufptr++; 
                    
                }
             #endif
             #if defined (SUPPORT_SMI_MultiLanguage)
                else if(*bufptr == '.')//check language info
                {   bufptr++;
                   
                    read_lang_info(&bufptr);
                }
             #endif
                else if(strncmpIgnoreCase( bufptr, "</STYLE>", 8 )==0 )
                {
                  bufptr+=8;
                  state=5;//to check body
                  
                }
                else 
                  bufptr++;
                 
                break;
           #if defined(SUPPORT_SMI_MultiColor) 
            //check default color      
            case 4:
                while( bufend - bufptr > SUBTITLE_RELOAD_LIMIT)
                {   
                    if( *bufptr == 0x7D||*bufptr == 'C'||*bufptr == 'c')
                        break;
                    bufptr++;
                    
                }
                if( bufend - bufptr <= SUBTITLE_RELOAD_LIMIT )
            

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -