[MPlayer-dev-eng] Re: [PATCH] vobsub subtitles (Kim Minh Kaplan)

陆 然 hephooey at hotmail.com
Wed Mar 27 05:47:44 CET 2002


hi,

>Message: 4
>To: mplayer-dev-eng at mplayer.dev.hu
>From: Kim Minh Kaplan <kmkaplan at selfoffice.com>
>Organization: Self Office Interactive
>Date: Tue, 26 Mar 2002 21:58:51 +0100
>Subject: [MPlayer-dev-eng] [PATCH] vobsub subtitles
>Reply-To: mplayer-dev-eng at mplayerhq.hu
>
>--=-=-=
>Content-Type: text/plain; format=flowed
>
>Before commiting I'd like people to try it and see if it works ok.
>
>* New command line switch for mplayer & mencoder:
>
>     -ifo <ifo file>
>
>	Indicate the file that will be used to load palette and
>frame size for MPEG subtitles.
>
>* spudec.c:
>
>     If scaling is needed only do it once.
>
>     Change WITH_NO_ANTIALIASING to ANTIALIASING_ALGORITHM.
>
>* vobsub.c:
>
>     Support reading infos from IDX file instead of IFO file.
>
>     Support streams containing audio or video.
>

i noticed that you patch read palette from .idx, but i have seen at least 
two divx movie with vobsub subtitle but have no palette in the idx. seems 
like they are using custom color, but another strange thing is that the 
value of custom color in one of the file is set to OFF. so I don't know 
have to do with it. when read color from .idx, program have two choice. use 
palette or use custom color, I made a patch use custom color if possible. 
but there is some problem with the color of the subtitles. I think there 
shuold be add some code to choose palette and custom color, but it's not 
complete now. hope the patch will help  you


diff -Nur -x CVS -x '.*' MPlayer-20020326/spudec.c MPlayer-current/spudec.c
--- MPlayer-20020326/spudec.c	Sat Feb 23 01:58:46 2002
+++ MPlayer-current/spudec.c	Tue Mar 26 22:40:15 2002
@@ -3,7 +3,7 @@
    1: aproximate
    2: full (slowest, best looking)
  */
-#define ANTIALIASING_ALGORITHM 1
+#define ANTIALIASING_ALGORITHM 0

 /* SPUdec.c
    Skeleton of function spudec_process_controll() is from xine sources.
@@ -42,6 +42,8 @@
   unsigned int packet_size;	/* size of the packet once all fragments are 
assembled */
   unsigned int control_start;	/* index of start of control data */
   unsigned int palette[4];
+  unsigned int cuspal[4];     /* custom color */
+  unsigned int vobsub;       /* idetifed vobsub */
   unsigned int alpha[4];
   unsigned int now_pts;
   unsigned int start_pts, end_pts;
@@ -121,6 +123,11 @@
     alpha[i] = mkalpha(this->alpha[i]);
     if (alpha[i] == 0)
       cmap[i] = 0;
+    else if(this->vobsub){
+      cmap[i] = ((this->cuspal[i] >> 16) & 0xff);
+      if (cmap[i] + alpha[i] > 255)
+	cmap[i] = 256-alpha[i];
+    }
     else {
       cmap[i] = ((this->global_palette[this->palette[i]] >> 16) & 0xff);
       if (cmap[i] + alpha[i] > 255)
@@ -651,6 +658,25 @@
     }
   }
 }
+void *spudec_new_scaled_vobsub(unsigned int *palette, unsigned int 
*cuspal, unsigned int frame_width, unsigned int frame_height)
+{
+  spudec_handle_t *this = calloc(1, sizeof(spudec_handle_t));
+  if (this) {
+    if (palette) {
+      memcpy(this->global_palette, palette, sizeof(this->global_palette));
+      memcpy(this->cuspal, cuspal, sizeof(this->cuspal));
+    }
+    this->packet = NULL;
+    this->image = NULL;
+    this->scaled_image = NULL;
+    this->orig_frame_width = frame_width;
+    this->orig_frame_height = frame_height;
+    this->vobsub = 1;
+  }
+  else
+    perror("FATAL: spudec_init: calloc");
+  return this;
+}

 void *spudec_new_scaled(unsigned int *palette, unsigned int frame_width, 
unsigned int frame_height)
 {

diff -Nur -x CVS -x '.*' MPlayer-20020326/vobsub.c MPlayer-current/vobsub.c
--- MPlayer-20020326/vobsub.c	Thu Feb 21 23:44:51 2002
+++ MPlayer-current/vobsub.c	Tue Mar 26 17:53:03 2002
@@ -561,6 +561,11 @@
 {
     ssize_t line_size;
     int res = -1;
+    int i;
+    unsigned int orig_frame_x;
+    unsigned int orig_frame_y;
+    unsigned int palette[15];
+    unsigned int cuspal[4];
     do {
 	int line_reserve = 0;
 	char *line = NULL;
@@ -572,6 +577,21 @@
 	}
 	if (*line == 0 || *line == '\r' || *line == '\n' || *line == '#')
 	    continue;
+	else if (strncmp("size:", line, 5) == 0){
+	    orig_frame_x = strtol(line + 5, NULL, 0);
+	    orig_frame_y = strtol(line + 10, NULL, 0);
+	    continue;
+	}
+	else if (strncmp("palette:", line, 8) == 0){
+	    for (i = 0; i<=15; i++)
+		palette[i] = strtol((line + 8 * (i +1)), NULL, 0);
+	    continue;
+	}
+	else if (strncmp("custom color:", line, 13) == 0){
+	    for (i = 0; i<=3; i++)
+		cuspal[i] = strtol ((line + 8 * (i + 5)), NULL, 0);
+	    continue;
+	}
 	else if (strncmp("id:", line, 3) == 0)
 	    res = vobsub_parse_id(vob, line + 3);
 	else if (strncmp("timestamp:", line, 10) == 0)
@@ -585,6 +605,7 @@
 	    fprintf(stderr, "ERROR in %s", line);
 	break;
     } while (1);
+    vob->spudec = spudec_new_scaled_vobsub(palette, cuspal, orig_frame_x, 
orig_frame_y);
     return res;
 }




_________________________________________________________________
享用世界上最大的 Web 电子邮件系统 ―― MSN Hotmail。
http://www.hotmail.com/cn




More information about the MPlayer-dev-eng mailing list