[Mplayer-users] Patch to 20010808 snapshot

Adam Tla/lka atlka at pg.gda.pl
Wed Aug 8 15:15:33 CEST 2001


Hi,
	this patch is optimized version of the previous one 
	and additionally checks for *.utf sub files now and automagically
	forces sub_utf8 to 1.  Of course -utf8 option work as previously.
	More optimizations in OSD code.

Regards
-- 
 . .  Adam Tla/lka      mailto:atlka at pg.gda.pl    ^v^ ^v^ ^v^
     PGP public key:   finger atlka at sunrise.pg.gda.pl
-------------- next part --------------
diff -ruN MPlayer-20010808/cfg-mplayer.h MPlayer-20010808n/cfg-mplayer.h
--- MPlayer-20010808/cfg-mplayer.h	Mon Aug  6 02:30:29 2001
+++ MPlayer-20010808n/cfg-mplayer.h	Wed Aug  8 13:07:51 2001
@@ -35,6 +35,7 @@
 
 #ifdef USE_SUB
 extern int sub_unicode;
+extern int sub_utf8;
 #endif
 
 #ifdef USE_OSD
@@ -92,6 +93,8 @@
         {"noautosub", &sub_auto, CONF_TYPE_FLAG, 0, 1, 0},
 	{"unicode", &sub_unicode, CONF_TYPE_FLAG, 0, 0, 1},
 	{"nounicode", &sub_unicode, CONF_TYPE_FLAG, 0, 1, 0},
+	{"utf8", &sub_utf8, CONF_TYPE_FLAG, 0, 0, 1},
+	{"noutf8", &sub_utf8, CONF_TYPE_FLAG, 0, 1, 0},
 #endif
 #ifdef USE_OSD
 	{"font", &font_name, CONF_TYPE_STRING, 0, 0, 0},
@@ -196,6 +199,7 @@
 	{"idx", &index_mode, CONF_TYPE_FLAG, 0, -1, 1},
 	{"forceidx", &index_mode, CONF_TYPE_FLAG, 0, -1, 2},
         
+	{"q", &quiet, CONF_TYPE_FLAG, 0, 0, 1},
 	{"quiet", &quiet, CONF_TYPE_FLAG, 0, 0, 1},
 	{"verbose", &verbose, CONF_TYPE_INT, CONF_RANGE, 0, 100},
 	{"v", cfg_inc_verbose, CONF_TYPE_FUNC, 0, 0, 0},
diff -ruN MPlayer-20010808/libvo/sub.c MPlayer-20010808n/libvo/sub.c
--- MPlayer-20010808/libvo/sub.c	Tue Jun 12 16:03:18 2001
+++ MPlayer-20010808n/libvo/sub.c	Wed Aug  8 14:38:20 2001
@@ -6,34 +6,33 @@
 
 unsigned char* vo_osd_text="00:00:00";
 int sub_unicode=0;
+int sub_utf8=0;
 
-static void vo_draw_text_osd(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
-        int len=strlen(vo_osd_text);
-        int j;
+inline static void vo_draw_text_osd(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
+	unsigned char *cp=vo_osd_text;
+	int c;
+	int font;
         int y=10;
         int x=20;
 
-        for(j=0;j<len;j++){
-          int c=vo_osd_text[j];
-          int font=vo_font->font[c];
-          if(font>=0)
-            draw_alpha(x,y,
-              vo_font->width[c],
-              vo_font->pic_a[font]->h,
-              vo_font->pic_b[font]->bmp+vo_font->start[c],
-              vo_font->pic_a[font]->bmp+vo_font->start[c],
-              vo_font->pic_a[font]->w);
-          x+=vo_font->width[c]+vo_font->charspace;
+        while ((c=*cp++)){
+              if ((font=vo_font->font[c])>=0)
+	   	 draw_alpha(x,y,
+			    vo_font->width[c],
+			    vo_font->pic_a[font]->h,
+			    vo_font->pic_b[font]->bmp+vo_font->start[c],
+			    vo_font->pic_a[font]->bmp+vo_font->start[c],
+			    vo_font->pic_a[font]->w);
+	   x+=vo_font->width[c]+vo_font->charspace;
         }
-
 }
 
 int vo_osd_progbar_type=-1;
 int vo_osd_progbar_value=100;   // 0..255
 
-static void vo_draw_text_progbar(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
+inline static void vo_draw_text_progbar(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
         int i;
-        int y=dys/2;
+        int y=(dys-vo_font->height)/2;
         int x;
         int c,font;
         int width=(dxs*2/3-vo_font->width[0x10]-vo_font->width[0x12]);
@@ -42,8 +41,8 @@
         x=(dxs-width)/2;
 //        printf("osd.progbar  width=%d  xpos=%d\n",width,x);
 
-        c=vo_osd_progbar_type;font=vo_font->font[c];
-        if(vo_osd_progbar_type>0 && font>=0)
+        c=vo_osd_progbar_type;
+        if(c>0 && (font=vo_font->font[c])>=0)
             draw_alpha(x-vo_font->width[c]-vo_font->spacewidth,y,
               vo_font->width[c],
               vo_font->pic_a[font]->h,
@@ -51,8 +50,8 @@
               vo_font->pic_a[font]->bmp+vo_font->start[c],
               vo_font->pic_a[font]->w);
 
-        c=OSD_PB_START;font=vo_font->font[c];
-        if(font>=0)
+        c=OSD_PB_START;
+        if ((font=vo_font->font[c])>=0)
             draw_alpha(x,y,
               vo_font->width[c],
               vo_font->pic_a[font]->h,
@@ -61,26 +60,38 @@
               vo_font->pic_a[font]->w);
         x+=vo_font->width[c];
 
-        for(i=0;i<elems;i++){
-          c=(i<mark)?OSD_PB_0:OSD_PB_1;font=vo_font->font[c];
-          if(font>=0)
-            draw_alpha(x,y,
-              vo_font->width[c],
-              vo_font->pic_a[font]->h,
-              vo_font->pic_b[font]->bmp+vo_font->start[c],
-              vo_font->pic_a[font]->bmp+vo_font->start[c],
-              vo_font->pic_a[font]->w);
-          x+=vo_font->width[c];
-        }
-
-        c=OSD_PB_END;font=vo_font->font[c];
-        if(font>=0)
-            draw_alpha(x,y,
-              vo_font->width[c],
-              vo_font->pic_a[font]->h,
-              vo_font->pic_b[font]->bmp+vo_font->start[c],
-              vo_font->pic_a[font]->bmp+vo_font->start[c],
-              vo_font->pic_a[font]->w);
+   	c=OSD_PB_0; 
+   	if ((font=vo_font->font[c])>=0)
+     	   for (i=mark;i--;){
+	       draw_alpha(x,y,
+			  vo_font->width[c],
+			  vo_font->pic_a[font]->h,
+			  vo_font->pic_b[font]->bmp+vo_font->start[c],
+			  vo_font->pic_a[font]->bmp+vo_font->start[c],
+			  vo_font->pic_a[font]->w);
+	       x+=vo_font->width[c];
+	   }
+  
+   	c=OSD_PB_1;
+	if ((font=vo_font->font[c])>=0)
+     	   for (i=elems-mark;i--;){
+	       draw_alpha(x,y,
+			  vo_font->width[c],
+			  vo_font->pic_a[font]->h,
+			  vo_font->pic_b[font]->bmp+vo_font->start[c],
+			  vo_font->pic_a[font]->bmp+vo_font->start[c],
+			  vo_font->pic_a[font]->w);
+	       x+=vo_font->width[c];
+	   }
+
+   	c=OSD_PB_END;
+        if ((font=vo_font->font[c])>=0)
+     	   draw_alpha(x,y,
+		      vo_font->width[c],
+		      vo_font->pic_a[font]->h,
+		      vo_font->pic_b[font]->bmp+vo_font->start[c],
+		      vo_font->pic_a[font]->bmp+vo_font->start[c],
+		      vo_font->pic_a[font]->w);
 //        x+=vo_font->width[c];
 
 
@@ -90,97 +101,110 @@
 
 subtitle* vo_sub=NULL;
 
-static void vo_draw_text_sub(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
-    int i;
-    int y;
-    y=dys-(1+vo_sub->lines-1)*vo_font->height-10;
-
-    // too long lines divide into smaller ones
-    for(i=0;i<vo_sub->lines;i++){
-        unsigned char* text=vo_sub->text[i];
-        int len=strlen(text);
-	int j;
-        int xsize=-vo_font->charspace;
-	int lastStripPosition=-1;
-	int previousStrip=0;
-	int lastxsize=0;
-
-	for(j=0;j<len;j++){
-          int c=text[j];
-          int w;
-          if (sub_unicode && (c>=0x80)) c=(c<<8)+text[++j];
-          w = vo_font->width[c];
-	  if (text[j]==' ' && dxs>xsize)
-	  {
-	    lastStripPosition=j;
-	    lastxsize=xsize;
-	  }
-          xsize+=w+vo_font->charspace;
-	  if (dxs<xsize && lastStripPosition>0)
-	  {
-	    xsize=lastxsize;
-	    j=lastStripPosition;
-            y-=vo_font->height;
-	    previousStrip=lastStripPosition;
-            xsize=-vo_font->charspace;
-	  }
-        }
-    }
-
-
-    for(i=0;i<vo_sub->lines;i++){
-        unsigned char* text=vo_sub->text[i];//  "Hello World! H?DEJ?!";
-        int len=strlen(text);
-        int j,k;
-        int xsize=-vo_font->charspace;
-        int x=0;
-
-	int lastStripPosition=-1;
-	int previousStrip=0;
-	int lastxsize=xsize;
-
-	for(j=0;j<len;j++){
-          int c=text[j];
-          int w;
-          if (sub_unicode && (c>=0x80)) c=(c<<8)+text[++j];
-          w = vo_font->width[c];
-          if (c==' ' && dxs>xsize)
-	  {
-	    lastStripPosition=j;
-	    lastxsize=xsize;
+#define MAX_UCS 1600
+#define MAX_UCSLINES 16
+  
+static inline void vo_draw_text_sub(int dxs,int dys,void (*draw_alpha)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride)){
+   static int utbl[MAX_UCS+1];
+   static int xtbl[MAX_UCSLINES];
+   static int lines;
+   static subtitle *memsub=NULL;
+   static int memy;
+   static int memdxs;
+   static int memdys;
+   unsigned char *t;
+   int i;
+   int j;
+   int k;
+   int l;
+   int x;
+   int y;
+
+   int c;
+   int len;
+   int line;
+   int font;
+   int lastStripPosition;
+   int xsize;
+   int lastxsize;
+   int lastk;
+   
+   if ((memsub!=vo_sub)||(memdxs!=dxs)||(memdys!=dys)){
+      memsub=vo_sub;
+      memdxs=dxs;
+      memdys=dys;
+      
+      memy=dys-vo_font->height/4;
+      
+      // too long lines divide into smaller ones
+      i=k=lines=0; l=vo_sub->lines;
+      while (l--){
+	  t=vo_sub->text[i++];	  
+	  len=strlen(t)-1;
+	  xsize=lastxsize=-vo_font->charspace;
+	  lastStripPosition=-1;
+
+	  for (j=0;j<=len;j++){
+	      if ((c=t[j])>=0x80){
+		 if (sub_unicode) 
+		    c = (c<<8) + t[++j]; 
+		 else
+		    if (sub_utf8){
+		       if ((c & 0xe0) == 0xc0)    /* 2 bytes U+00080..U+0007FF*/
+			  c = (c & 0x1f)<<6 | (t[++j] & 0x3f);
+		       else if((c & 0xf0) == 0xe0)/* 3 bytes U+00800..U+00FFFF*/
+			  c = ((c & 0x0f)<<6 |
+			       (t[++j] & 0x3f))<<6 | (t[++j] & 0x3f);
+		    }
+	      }
+	      if (k==MAX_UCS){
+		 utbl[k]=l=0;
+		 break;
+	      } else
+	         utbl[k++]=c;
+	      if (c==' '){
+		 lastk=k;
+		 lastStripPosition=j;
+		 lastxsize=xsize;
+	      }
+	      xsize+=vo_font->width[c]+vo_font->charspace;
+	      if (dxs<xsize && lastStripPosition>0){
+		 j=lastStripPosition;
+		 k=lastk;
+	      } else if (j==len){
+		 lastxsize=xsize;
+	      } else
+	         continue;	       	       	       
+	      utbl[k++]=0;
+	      xtbl[lines++]=(dxs-lastxsize)/2;
+	      if (lines==MAX_UCSLINES||k>MAX_UCS){
+		 l=0;
+		 break;
+	      }
+	      memy-=vo_font->height;
+	      xsize=lastxsize=-vo_font->charspace;
 	  }
-          xsize+=w+vo_font->charspace;
-	  if ((dxs<xsize && lastStripPosition>0) || j==len-1)
-	  {
-	    if (j==len-1) lastStripPosition=len;
-	      else xsize=lastxsize;
-	    j=lastStripPosition;
-
-            x=dxs/2-xsize/2;
-
-            for(k=previousStrip;k<lastStripPosition;k++){
-              int c=text[k];
-	      int font;
-              if (sub_unicode && (c>=0x80)) c=(c<<8)+text[++k];
-              font=vo_font->font[c];
-              if(x>=0 && x+vo_font->width[c]<dxs)
-                if(font>=0)
-                  draw_alpha(x,y,
-                    vo_font->width[c],
-                    vo_font->pic_a[font]->h,
-                    vo_font->pic_b[font]->bmp+vo_font->start[c],
-                    vo_font->pic_a[font]->bmp+vo_font->start[c],
-                    vo_font->pic_a[font]->w);
-              x+=vo_font->width[c]+vo_font->charspace;
-            }
-            x=0;
-            y+=vo_font->height;
-	    previousStrip=lastStripPosition;
-            xsize=lastxsize=-vo_font->charspace;
-	  }
-        }
-    }
-
+      }
+   }
+   
+   y = memy;
+
+   k=i=0; l=lines;
+   while (l--){
+       x = xtbl[i++];
+       while ((c=utbl[k++])){
+	     if ((x>=0) && (x+vo_font->width[c]<=dxs))
+		if ((font=vo_font->font[c])>=0)
+	           draw_alpha(x,y,
+			      vo_font->width[c],
+			      vo_font->pic_a[font]->h,
+			      vo_font->pic_b[font]->bmp+vo_font->start[c],
+			      vo_font->pic_a[font]->bmp+vo_font->start[c],
+			      vo_font->pic_a[font]->w);
+	  x+=vo_font->width[c]+vo_font->charspace;
+       }
+       y+=vo_font->height;
+   }
 }
 
 static int draw_alpha_init_flag=0;
diff -ruN MPlayer-20010808/libvo/x11_common.c MPlayer-20010808n/libvo/x11_common.c
--- MPlayer-20010808/libvo/x11_common.c	Tue Aug  7 01:59:50 2001
+++ MPlayer-20010808n/libvo/x11_common.c	Wed Aug  8 13:07:51 2001
@@ -137,7 +137,8 @@
    case wsM:	     mplayer_put_key('m'); break;
    case wso:
    case wsO:         mplayer_put_key('o'); break;
-   default: if((key>='a' && key<='z')||(key>='A' && key<='Z')) mplayer_put_key(key);
+   default: if ((key>='a' && key<='z')||(key>='A' && key<='Z')||
+		(key>='0' && key<='9')) mplayer_put_key(key);
   }
 
 }
diff -ruN MPlayer-20010808/mplayer.c MPlayer-20010808n/mplayer.c
--- MPlayer-20010808/mplayer.c	Tue Aug  7 18:03:30 2001
+++ MPlayer-20010808n/mplayer.c	Wed Aug  8 13:07:51 2001
@@ -1635,8 +1635,11 @@
     case 'x':
       sub_delay += 0.1;
       break;
+    case '9': c='/'; goto _jump1;
+    case '0': c='*';
+_jump1:
     case '*':
-    case '/': {
+    case '/': {       
         float mixer_l, mixer_r;
         mixer_getvolume( &mixer_l,&mixer_r );
         if(c=='*'){
diff -ruN MPlayer-20010808/seek.c MPlayer-20010808n/seek.c
--- MPlayer-20010808/seek.c	Tue Aug  7 22:53:13 2001
+++ MPlayer-20010808n/seek.c	Wed Aug  8 13:07:52 2001
@@ -187,6 +187,7 @@
       }
 
   }
+  d_video->pts=avi_video_pts; // for displaying time while seeking AST
   break;
 
   //FIXME: OFF_T - didn't test ASF case yet (don't have a large asf...)
diff -ruN MPlayer-20010808/subreader.c MPlayer-20010808n/subreader.c
--- MPlayer-20010808/subreader.c	Sat Jun  9 22:09:18 2001
+++ MPlayer-20010808n/subreader.c	Wed Aug  8 13:07:52 2001
@@ -435,6 +435,8 @@
 }
 #endif
 
+extern int sub_utf8;
+
 char * sub_filename(char* path,  char * fname )
 {
  char * sub_name1;
@@ -444,7 +446,10 @@
  FILE * f;
  int pos=0;
  char * sub_exts[] = 
-  { ".sub",
+  { 
+    ".utf",
+    ".UTF",
+    ".sub",
     ".SUB",
     ".srt",
     ".SRT",
@@ -484,6 +489,7 @@
    if((f=fopen( sub_name,"rt" ))) {
      fclose( f );
      printf( "SUB: Detected sub file: %s\n",sub_name );
+     if (i<2) sub_utf8=1;
      return sub_name;
    }
   }


More information about the MPlayer-users mailing list