srt外挂字幕合并器源代码

本文档提供了一个用于合并SRT字幕文件的C语言源代码实现,包括字幕节点结构定义、内存管理、字幕合并算法及Windows GUI应用程序的创建。主要功能包括读取SRT文件、合并字幕、设置延迟时间和错误容限,并通过Windows API创建简单的用户界面进行操作。
摘要由CSDN通过智能技术生成
有点乱...嘿嘿
 
第一次用c编写Windows的窗口程序。
SubTitleCombination.cpp关于窗口界面的,足足花了我一个星期,在上班的时候自己偷偷写的。
StrCombination.cpp,处理字幕整合。花了我一天的时间,主要是malloc的问题。

写好之后,很不满意,如果有时间的话,再把代码好好整理整理。

ps:
用vs编译代码之前,要先将unicode 改成 multicode。
在项目属性里面。

程序运行效果见:
http://blog.csdn.net/zhanjh/archive/2008/11/09/3261000.aspx
下载地址(在csdn上下东西还真够麻烦的,可惜找不到其他的地方):
http://d.download.csdn.net/down/762283/zhanjh

StrCombination.cpp
  1. #include "StrCombination.h"
  2. #include <stdlib.h>
  3. #define ST_SIZE 50
  4. #define ST_TIME_SIZE 29
  5. #define ST_NUM_SIZE 10
  6. #define ST_CONTENT_SIZE 250
  7. #define ST_MALLOC_SIZE 50
  8. typedef struct tagSubTitle {
  9.     unsigned long   index;
  10.     unsigned long   time;
  11.     unsigned int    csize;
  12.     char            strTime[ST_TIME_SIZE];
  13.     char            *content;
  14.     tagSubTitle     *next;
  15. }SubTitle, *PSubtitile;
  16. typedef struct tagSTNode {
  17.     PSubtitile      item;
  18.     tagSTNode       *next;
  19. }STNode, *PSTNode;
  20. unsigned int stm_index = 0;
  21. unsigned int stm_size = 0;
  22. PSubtitile head = NULL;
  23. int error;
  24. int delay;
  25. char *allchars;
  26. unsigned long allcIndex = 0;
  27. unsigned long mergedSize = 0;
  28. unsigned long subtIndex = 0;
  29. PSTNode pstNodeHead = NULL;
  30. PSTNode pstNode = NULL;
  31. bool getSubTitle(PSubtitile pst, char *subT, unsigned long &index);
  32. void extendPChar(PSubtitile pst,int oldSize, int newSize);
  33. void st_free(PSubtitile pst);
  34. PSubtitile mergeSubTitle(PSubtitile pst1, PSubtitile pst2);
  35. PSubtitile newPst()
  36. {
  37.     
  38.     if(stm_index == 0 || stm_index >= ST_MALLOC_SIZE)
  39.     {
  40.         if(pstNodeHead == NULL)
  41.         {
  42.             pstNodeHead = (PSTNode)malloc(sizeof(tagSTNode));
  43.             pstNodeHead->item = NULL;
  44.             pstNodeHead->next = NULL;
  45.             pstNode =pstNodeHead;
  46.         }
  47.         stm_size += ST_MALLOC_SIZE;
  48.         PSTNode pstnode = (PSTNode)malloc(sizeof(tagSTNode));
  49.         pstnode->item = (PSubtitile)malloc(ST_MALLOC_SIZE * sizeof(tagSubTitle));
  50.         pstnode->next = NULL;
  51.         pstNode->next = pstnode;
  52.         pstNode = pstnode;
  53.         stm_index = 0;
  54.     }
  55.     PSubtitile pst = pstNode->item + stm_index;
  56.     pst->content = NULL;
  57.     pst->next = NULL;
  58.     stm_index++;
  59.     return pst;
  60. }
  61. int tenExp(unsigned int i)
  62. {
  63.     if(i==0)
  64.         return 0;
  65.     int result = 10;
  66.     while(i>0)
  67.     {
  68.         result *= 10;
  69.         i --;
  70.     }
  71.         
  72. }
  73. char *getMergedChars()
  74. {
  75.     unsigned long tempSBTIndex = subtIndex;
  76.     int tempDigitSize = 0;
  77.     while(tempSBTIndex != 0)
  78.     {
  79.         tempSBTIndex /= 10;
  80.         tempDigitSize ++;
  81.     }
  82.     unsigned long numberSize = 0;
  83.     for(int i = 1; i<tempDigitSize; i++)
  84.     {
  85.         numberSize += i * (tenExp(i) - tenExp(i-1));
  86.     }
  87.     numberSize += tempDigitSize * (subtIndex - tenExp(tempDigitSize-1));
  88.     mergedSize += numberSize;
  89.     char *result = (char *)malloc(mergedSize * sizeof(char));
  90.     unsigned long stIndex = 1;
  91.     unsigned long index = 0;
  92.     while(head->next != NULL)
  93.     {
  94.         head = head->next;
  95.         int digitSize = 0;
  96.         int tempIndex = stIndex;
  97.         while(tempIndex != 0)
  98.         {
  99.             for(int i= 0; i < digitSize; i++)
  100.             {
  101.                 result[index - i] = result[index -i - 1];
  102.             }
  103.             result[index - digitSize] = tempIndex % 10 + 48;
  104.             tempIndex /= 10;
  105.             index ++;
  106.             digitSize ++;
  107.         }
  108.         stIndex ++;
  109.         
  110.         result[index++] = 13;
  111.         result[index++] = 10;
  112.         for(int i = 0; i < ST_TIME_SIZE; i++)
  113.         {
  114.             result[index++] = head->strTime[i];
  115.         }
  116.         result[index++] = 13;
  117.         result[index++] = 10;
  118.         for(int i = 0; i < head->csize; i++)
  119.         {
  120.             result[index++] = head->content[i];
  121.         }
  122.         result[index++] = 13;
  123.         result[index++] = 10;
  124.         result[index++] = 13;
  125.         result[index++] = 10;
  126.         
  127.     }
  128.     result[index] = 0;
  129.     mergedSize = index + 1;
  130.     return result;
  131. }
  132. char *newPChar()
  133. {
  134.     char *result = allchars + allcIndex;
  135.     return result;
  136. }
  137. void addToAllChars(char c)
  138. {
  139.     allchars[allcIndex] = c;
  140.     allcIndex ++;
  141. }
  142. char* ST_Merge(char subT1[], char subT2[],unsigned long &mgSize, int stcSize,int parameterDelay, int parameterError)
  143. {
  144.     allchars = (
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值