[MPlayer-dev-eng] [PATCH]patch for vobsub subtitles

陆 然 hephooey at hotmail.com
Tue Apr 23 08:48:42 CEST 2002


hi,
i send a patch few days ago and got no reply, so i send the patch again and 
add some new function like read the "delay" item to adjust the time of the 
subtitle to be displayed and "langidx" item so mplayer will use it when 
there is no -vobsubid in the command line or config file, I hope it can be 
tested and please let me know what need to be improved, thank you very 
much.


diff -Nur -x CVS -x '.*' main/spudec.c main_dev/spudec.c
--- main/spudec.c	Tue Apr 23 14:17:42 2002
+++ main_dev/spudec.c	Tue Apr 23 14:15:25 2002
@@ -43,6 +43,8 @@
   unsigned int control_start;	/* index of start of control data */
   unsigned int palette[4];
   unsigned int alpha[4];
+  unsigned int cuspal[4];
+  unsigned int custom;
   unsigned int now_pts;
   unsigned int start_pts, end_pts;
   unsigned int start_col, end_col;
@@ -122,6 +124,11 @@
     alpha[i] = mkalpha(this->alpha[i]);
     if (alpha[i] == 0)
       cmap[i] = 0;
+    else if (this->custom){
+      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)
@@ -692,6 +699,27 @@
   return this;
 }

+/* get palette custom color, width, height from .idx file */
+void *spudec_new_scaled_vobsub(unsigned int *palette, unsigned int 
*cuspal, unsigned int custom, 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));
+    }
+    fprintf(stderr,"\n%d,%d,%d,%d", this->cuspal[0], this->cuspal[1], 
this->cuspal[2],this->cuspal[3]);
+    this->packet = NULL;
+    this->image = NULL;
+    this->scaled_image = NULL;
+    this->orig_frame_width = frame_width;
+    this->orig_frame_height = frame_height;
+    this->custom = custom;
+  }
+  else
+    perror("FATAL: spudec_init: calloc");
+  return this;
+}
 void *spudec_new(unsigned int *palette)
 {
     return spudec_new_scaled(palette, 0, 0);
diff -Nur -x CVS -x '.*' main/vobsub.c main_dev/vobsub.c
--- main/vobsub.c	Tue Apr 23 14:17:51 2002
+++ main_dev/vobsub.c	Tue Apr 23 14:23:02 2002
@@ -409,6 +409,10 @@
 typedef struct {
     void *spudec;
     unsigned int palette[16];
+    unsigned int cuspal[4];
+    int delay;
+    unsigned int custom;
+    unsigned int have_palette;
     unsigned int orig_frame_width, orig_frame_height;
     unsigned int origin_x, origin_y;
     /* index */
@@ -568,7 +572,7 @@
     if (! isxdigit(*line))
 	return -1;
     filepos = strtol(line, NULL, 16);
-    return vobsub_add_timestamp(vob, filepos, ms + 1000 * (s + 60 * (m + 
60 * h)));
+    return vobsub_add_timestamp(vob, filepos, vob->delay + ms + 1000 * (s 
+ 60 * (m + 60 * h)));
 }

 static int
@@ -627,6 +631,91 @@
 	    ++p;
 	line = p;
     }
+    vob->have_palette = 1;
+    return 0;
+}
+
+static int
+vobsub_parse_custom(vobsub_t *vob, const char *line)
+{
+    //custom colors: OFF/ON(0/1)
+    if ((strncmp("ON", line + 15, 2) == 0)||strncmp("1", line + 15, 1))
+        vob->custom=1;
+    else if ((strncmp("OFF", line + 15, 3) == 0)||strncmp("0", line + 15, 
1))
+        vob->custom=0;
+    else
+        return -1;
+    return 0;
+}
+
+static int
+vobsub_parse_cuspal(vobsub_t *vob, const char *line)
+{
+    //colors: XXXXXX, XXXXXX, XXXXXX, XXXXXX
+    unsigned int n;
+    n = 0;
+    line += 40;
+    while(1){
+    	const char *p;
+	while (isspace(*line))
+	    ++line;
+	p=line;
+	while (isxdigit(*p))
+	    ++p;
+	if (p - line !=6)
+	    return -1;
+	vob->cuspal[n++] = strtoul(line, NULL,16);
+	if (n==4)
+	    break;
+	if(*p == ',')
+	    ++p;
+	line = p;
+    }
+    return 0;
+}
+
+/* don't know how to use tridx */
+static int
+vobsub_parse_tridx(vobsub_t *vob, const char *line)
+{
+    //tridx: XXXX
+    int i;
+    int tridx;
+    tridx = strtoul((line + 26), NULL, 16);
+    tridx = ((tridx&0x1000)>>12) | ((tridx&0x100)>>7) | ((tridx&0x10)>>2) 
| ((tridx&1)<<3);
+}
+
+static int
+vobsub_parse_delay(vobsub_t *vob, const char *line)
+{
+    int h, m, s, ms;
+    int forward = 1;
+    if (*(line + 7) == '+'){
+    	forward = 1;
+	line++;
+    }
+    else if (*(line + 7) == '-'){
+    	forward = -1;
+	line++;
+    }
+    fprintf(stderr, "forward=%d", forward);
+    h = atoi(line + 7);
+    fprintf(stderr, "h=%d," ,h);
+    m = atoi(line + 10);
+    fprintf(stderr, "m=%d,", m);
+    s = atoi(line + 13);
+    fprintf(stderr, "s=%d,", s);
+    ms = atoi(line + 16);
+    fprintf(stderr, "ms=%d", ms);
+    vob->delay = ms + 1000 * (s + 60 * (m + 60 * h)) * forward;
+    return 0;
+}
+
+static int
+vobsub_set_lang(vobsub_t *vob, const char *line)
+{
+    if (vobsub_id == -1)
+        vobsub_id = atoi(line + 8);
     return 0;
 }

@@ -646,6 +735,10 @@
 	}
 	if (*line == 0 || *line == '\r' || *line == '\n' || *line == '#')
 	    continue;
+	else if (strncmp("langidx:", line, 8) == 0)
+	    res = vobsub_set_lang(vob, line);
+	else if (strncmp("delay:", line, 6) == 0)
+	    res = vobsub_parse_delay(vob, line);
 	else if (strncmp("id:", line, 3) == 0)
 	    res = vobsub_parse_id(vob, line + 3);
 	else if (strncmp("palette:", line, 8) == 0)
@@ -656,6 +749,9 @@
 	    res = vobsub_parse_origin(vob, line + 4);
 	else if (strncmp("timestamp:", line, 10) == 0)
 	    res = vobsub_parse_timestamp(vob, line + 10);
+	else if (strncmp("custom colors:", line, 14) == 0)
+	    //custom colors: ON/OFF, tridx: XXXX, colors: XXXXXX, XXXXXX, 
XXXXXX,XXXXXX
+	    res = vobsub_parse_cuspal(vob, line) + vobsub_parse_tridx(vob, line) 
+ vobsub_parse_custom(vob, line);
 	else {
 	    if (verbose)
 		fprintf(stderr, "vobsub: ignoring %s", line);
@@ -719,6 +815,7 @@
 		    unsigned char *p = block + pgc_offset + 0xa4 + 4 * idx;
 		    palette[idx] = p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
 		}
+		//vob->have_palette = 1;
 		res = 0;
 	    }
 	}
@@ -739,6 +836,7 @@
 	vob->spu_streams = NULL;
 	vob->spu_streams_size = 0;
 	vob->spu_streams_current = 0;
+	vob->delay = 0;
 	buf = malloc((strlen(name) + 5) * sizeof(char));
 	if (buf) {
 	    FILE *fd;
@@ -761,8 +859,11 @@
 		    /* NOOP */ ;
 		fclose(fd);
 	    }
+	    /* if no palette in .idx then use custom colors */
+	    if ((vob->custom == 0)&&(vob->have_palette!=1))
+		vob->custom = 1;
 	    if (vob->orig_frame_width && vob->orig_frame_height)
-		vob->spudec = spudec_new_scaled(vob->palette, vob->orig_frame_width, 
vob->orig_frame_height);
+		vob->spudec = spudec_new_scaled_vobsub(vob->palette, vob->cuspal, 
vob->custom, vob->orig_frame_width, vob->orig_frame_height);

 	    /* read the indexed mpeg_stream */
 	    strcpy(buf, name);




-----------------
Best Regards,
LR

_________________________________________________________________
与联机的朋友进行交流,请使用 MSN Messenger: 
http://messenger.microsoft.com/cn




More information about the MPlayer-dev-eng mailing list