[MPlayer-dev-eng] [PATCH] subtitles out of film area

Tomas Konir moje at molly.vabo.cz
Sun Mar 10 20:13:58 CET 2002


Hi
This is my second patch to show subtitles out of film area. I add two 
options '-subbox num', '-autosubbox'. I create black box under film area 
for showing subtitles. '-subbox num' create box with num% height of film 
(max 100), and '-autosubbox' create box to fill the screnn. Now i made it 
for XV and X11 and probably can be made for other drivers. Me and my 
friends are using it becouse dislike subtitles in film area.

	MOJE

P.S. There was no response when i send my prev patch. Please can you send 
me least 'You make bad work and leave it alone'. Everything is better, 
than no response.

best regards

-- 
Tomas Konir
Brno
ICQ 25849167

-------------- next part --------------
diff -Nura main/cfg-mplayer.h main_sub/cfg-mplayer.h
--- main/cfg-mplayer.h	Sun Mar 10 16:55:42 2002
+++ main_sub/cfg-mplayer.h	Sun Mar 10 16:55:04 2002
@@ -58,6 +58,8 @@
 extern char *sub_cp;
 #endif
 extern int sub_pos;
+extern int sub_box;
+extern int auto_sub_box;
 #endif
 
 #ifdef USE_OSD
@@ -178,6 +180,8 @@
 	{"utf8", &sub_utf8, CONF_TYPE_FLAG, 0, 0, 1, NULL},
 	{"noutf8", &sub_utf8, CONF_TYPE_FLAG, 0, 1, 0, NULL},
  	{"subpos",&sub_pos,  CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
+	{"subbox",&sub_box,  CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
+	{"autosubbox",&auto_sub_box,  CONF_TYPE_FLAG, 0, 0, 1, NULL},
 #endif
 #ifdef USE_OSD
 	{"font", &font_name, CONF_TYPE_STRING, 0, 0, 0, NULL},
diff -Nura main/libvo/sub.c main_sub/libvo/sub.c
--- main/libvo/sub.c	Sun Mar 10 16:55:42 2002
+++ main_sub/libvo/sub.c	Sun Mar 10 16:55:04 2002
@@ -171,6 +171,7 @@
    int lastStripPosition;
    int xsize,lastxsize;
    int h,lasth;
+   extern int sub_y_start,sub_y_end;
    
    if ((memsub!=vo_sub)||(memdxs!=dxs)||(memdys!=dys)){
       
@@ -257,6 +258,7 @@
    
 //   printf("lines=%d  y=%d\n",lines,y);
 
+   sub_y_start=y;
    i=j=0;
    if ((l=lines)) for (;;) {
  	 x=xtbl[i++]; 
@@ -270,10 +272,13 @@
 			     vo_font->pic_a[font]->w);
 	          x+=vo_font->width[c]+vo_font->charspace;
 	 }
-         if (!--l) 
+         if (!--l){
+			 sub_y_end=y+vo_font->height+10; /*need to add 10 because any chars are below and there are artefacts*/
 	    return;
+		 }
          y+=vo_font->height;
    }
+   
 }
 
 void *vo_spudec=NULL;
diff -Nura main/libvo/vo_x11.c main_sub/libvo/vo_x11.c
--- main/libvo/vo_x11.c	Sun Mar 10 16:55:42 2002
+++ main_sub/libvo/vo_x11.c	Sun Mar 10 16:55:04 2002
@@ -91,6 +91,12 @@
 static int srcH=-1;
 static int aspect; // 1<<16 based fixed point aspect, so that the aspect stays correct during resizing
 
+/*extern values*/
+extern int sub_box;
+extern int sub_clear;
+extern int sub_y_start;
+extern int sub_y_end;
+
 static void check_events(){
   int ret = vo_x11_check_events(mDisplay);
   
@@ -139,7 +145,7 @@
 
  if ( Shmem_Flag )
   {
-   myximage=XShmCreateImage( mDisplay,vinfo.visual,depth,ZPixmap,NULL,&Shminfo[0],image_width,image_height );
+   myximage=XShmCreateImage( mDisplay,vinfo.visual,depth,ZPixmap,NULL,&Shminfo[0],image_width,image_height+sub_box );
    if ( myximage == NULL )
     {
      if ( myximage != NULL ) XDestroyImage( myximage );
@@ -201,7 +207,7 @@
    Shmem_Flag=0;
 #endif
    myximage=XGetImage( mDisplay,vo_window,0,0,
-   image_width,image_height,AllPlanes,ZPixmap );
+   image_width,image_height + sub_box,AllPlanes,ZPixmap );
    ImageData=myximage->data;
 #ifdef HAVE_SHM
   }
@@ -343,7 +349,7 @@
     else
       vo_window=XCreateWindow( mDisplay,RootWindow( mDisplay,mScreen ),
                          hint.x,hint.y,
-                         hint.width,hint.height,
+                         hint.width,hint.height + sub_box,
                          xswa.border_pixel,depth,CopyFromParent,vinfo.visual,xswamask,&xswa );
 
     vo_x11_classhint( mDisplay,vo_window,"x11" );
@@ -352,6 +358,7 @@
     XSelectInput( mDisplay,vo_window,StructureNotifyMask );
     XSetStandardProperties( mDisplay,vo_window,title,title,None,NULL,0,&hint );
     XMapWindow( mDisplay,vo_window );
+	XResizeWindow(mDisplay,vo_window,hint.width+1,hint.height +sub_box+1); /*Because of bad film position when using subbox*/
 #ifdef HAVE_XINERAMA
    vo_x11_xinerama_move(mDisplay,vo_window);
 #endif
@@ -448,8 +455,13 @@
 #endif
 }
 
-static void draw_osd(void)
-{ vo_draw_text(image_width,image_height,draw_alpha_fnc); }
+static void draw_osd(void){
+if(sub_clear){                                                                                                
+ bzero(ImageData+image_width*(image_height)*bpp/8,image_width*sub_box*bpp/8);
+ sub_clear=0;
+ }
+vo_draw_text(image_width,image_height + sub_box,draw_alpha_fnc);
+}
 
 static void flip_page( void ){
     Display_Image( myximage,ImageData );
diff -Nura main/libvo/vo_xv.c main_sub/libvo/vo_xv.c
--- main/libvo/vo_xv.c	Sun Mar 10 16:55:42 2002
+++ main_sub/libvo/vo_xv.c	Sun Mar 10 16:55:04 2002
@@ -71,6 +71,11 @@
 static XvAdaptorInfo        *ai;
 static XvImageFormatValues  *fo;
 
+extern int sub_box;
+extern int sub_y_start;
+extern int sub_y_end;
+extern int sub_clear;
+
 static int current_buf=0;
 static int num_buffers=1; // default
 static XvImage* xvimage[NUM_BUFFERS];
@@ -94,6 +99,8 @@
 static uint32_t               drwX,drwY,drwWidth,drwHeight,drwBorderWidth,drwDepth;
 static uint32_t               drwcX,drwcY,dwidth,dheight;
 
+static uint32_t clear_region(int w,int h,int x,int y);
+
 static void (*draw_alpha_fnc)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride);
 
 static void draw_alpha_yv12(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){
@@ -325,9 +332,6 @@
  static uint32_t vm_height;
 #endif
 
- aspect_save_orig(width,height);
- aspect_save_prescale(d_width,d_height);
-
  image_height = height;
  image_width = width;
  image_format=format;
@@ -341,7 +345,12 @@
 #endif
  flip_flag=flags&8;
  num_buffers=vo_doublebuffering?NUM_BUFFERS:1;
- 
+  
+ if(vo_fs) d_height=(d_height*(height+sub_box))/height;
+                                                                                                                    
+ aspect_save_orig(width,height);                                                                                
+ aspect_save_prescale(d_width,d_height);                                                                        
+                                                                                                                   
  if (!vo_init()) return -1;
 
  aspect_save_screenres(vo_screenwidth,vo_screenheight);
@@ -404,7 +413,7 @@
     } else 
 
    vo_window = XCreateWindow(mDisplay, RootWindow(mDisplay,mScreen),
-       hint.x, hint.y, hint.width, hint.height,
+       hint.x, hint.y , hint.width, hint.height + sub_box,
        0, depth,CopyFromParent,vinfo.visual,xswamask,&xswa);
 
    vo_x11_classhint( mDisplay,vo_window,"xv" );
@@ -475,7 +484,8 @@
    if (xv_port != 0)
     {
      printf( "using Xvideo port %d for hw scaling\n",xv_port );
-       
+		
+   
        switch (xv_format){
 	case IMGFMT_YV12:  
 	case IMGFMT_I420:
@@ -529,7 +539,7 @@
   * allocate XvImages.  FIXME: no error checking, without
   * mit-shm this will bomb...
   */
- xvimage[foo] = XvShmCreateImage(mDisplay, xv_port, xv_format, 0, image_width, image_height, &Shminfo[foo]);
+ xvimage[foo] = XvShmCreateImage(mDisplay, xv_port, xv_format, 0, image_width, image_height+sub_box, &Shminfo[foo]);
 
  Shminfo[foo].shmid    = shmget(IPC_PRIVATE, xvimage[foo]->data_size, IPC_CREAT | 0777);
  Shminfo[foo].shmaddr  = (char *) shmat(Shminfo[foo].shmid, 0, 0);
@@ -582,13 +592,86 @@
   }
 }
 
-static void draw_osd(void)
-{ vo_draw_text(image_width,image_height,draw_alpha_fnc);}
+static uint32_t clear_region(int w,int h,int x,int y)                                                           
+{                                                                                                               
+ uint8_t *dst;                                                                                                  
+ uint16_t count;                                                                                                
+ int i;                                                                                                         
+                                                                                                             
+switch (image_format) {                                                                                         
+ case IMGFMT_YUY2:                                                                                              
+ case IMGFMT_UYVY:                                                                                              
+ case IMGFMT_YVYU:                                                                                              
+    dst=xvimage[current_buf]->data+image_width*y*2;                                                           
+    count=(image_width*h)>>1;                                                                                   
+#ifdef ARCH_X86                                                                                                 
+    //longset(dst,2130738944,count); /*WARNING This routine clear full lines (need to upgrade)*/             
+    asm volatile(                                                                                            
+   "rep\n"                                                                                                   
+   "stosl":                                                                                                  
+   "=D" (dst), "=c" (count) :                                                                                
+   "0" (dst), "1" (count), "a" (2130738944) :                                                                
+   "memory");                                                                                                
+#else                                                                                                           
+   for(i=0;i<image_width*h*2;i+=2){                                                                          
+             dst[i]=(uint16_t)(32512);                                                                       
+     }                                                                                                       
+#endif                                                                                                          
+                                                                                                             
+  break;                                                                                                     
+                                                                                                             
+ case IMGFMT_YV12:                                                                                              
+ case IMGFMT_I420:                                                                                              
+ case IMGFMT_IYUV:                                                                                              
+                                                                                                             
+ image_height+=sub_box;                                                                                
+                                                                                                             
+ dst = xvimage[current_buf]->data + image_width * y + x;                                                        
+  if(w==image_width) memset(dst,0,w*h);                                                                         
+  else                                                                                                         
+    for(i=0;i<h;i++){                                                                                           
+	memset(dst,0,w);                                                                                        
+	dst+=image_width;                                                                                         
+    }                  
+                                                                                                                 
+  x/=2;y/=2;w/=2;h/=2;                                                                                           
+                                                                                                                 
+  dst = xvimage[current_buf]->data + image_width * image_height + image_width/2 * y + x;                         
+  if(w==image_width/2) memset(dst,127,w*h);                                                                     
+  else                                                                                                         
+    for(i=0;i<h;i++){                                                                                            
+        memset(dst,127,w);                                                                                       
+	dst+=image_width/2;                                                                                        
+    }                                                                                                            
+                                                                                                                 
+  dst = xvimage[current_buf]->data + image_width * image_height * 5 / 4 + image_width/2 * y + x;                 
+  if(w==image_width/2) memset(dst,127,w*h);                                                                     
+  else                                                                                                         
+    for(i=0;i<h;i++){                                                                                            
+        memset(dst,127,w);                                                                                       
+	dst+=image_width/2;                                                                                        
+    }                                                                                                           
+                                                                                                                 
+  image_height-=sub_box;                                                                           
+  break;                                                                                                         
+  }                                                                                                               
+ return 0;                                                                                                      
+}                                                                                                               
+  
+static void draw_osd(void){                                                                                                               
+   if(sub_clear){                                                                                                
+        if(sub_y_start<image_height) sub_y_start=image_height;                                                   
+        if(sub_y_end>sub_y_start) clear_region(image_width,sub_y_end-sub_y_start,0,sub_y_start);                 
+        sub_y_start=sub_y_end=0;                                                                                 
+        sub_clear=0;                                                                                             
+  }                                                                                                              
+  vo_draw_text(image_width,image_height+sub_box,draw_alpha_fnc);                                                 
+}
 
 static void flip_page(void)
 {
  XvShmPutImage(mDisplay, xv_port, vo_window, vo_gc, xvimage[current_buf],
-         0, 0,  image_width, image_height,
+	  0, 0,  image_width, image_height+sub_box,
          drwX,drwY,drwWidth,(vo_fs?drwHeight - 1:drwHeight),
          False);
  if (num_buffers>1){
@@ -607,6 +690,8 @@
  uint8_t *dst;
  int i;
 
+image_height+=sub_box;
+
  dst = xvimage[current_buf]->data + image_width * y + x;
  src = image[0];
  if(w==stride[0] && w==image_width) memcpy(dst,src,w*h);
@@ -640,6 +725,9 @@
      src+=stride[1];
      dst+=image_width/2;
     }
+    
+    image_height-=sub_box;
+    
  return 0;
 }
 
diff -Nura main/mplayer.c main_sub/mplayer.c
--- main/mplayer.c	Sun Mar 10 16:55:42 2002
+++ main_sub/mplayer.c	Sun Mar 10 16:55:04 2002
@@ -282,6 +282,11 @@
 float sub_fps=0;
 int   sub_auto = 1;
 char *vobsub_name=NULL;
+int sub_box=0;
+int auto_sub_box=0;
+int sub_y_start=0;
+int sub_y_end=0;
+int sub_clear=0;
 /*DSP!!char *dsp=NULL;*/
 
 extern char *vo_subdevice;
@@ -1314,6 +1319,28 @@
 
 current_module="init_libvo";
 
+if(sub_box>100) sub_box=0;
+
+sub_box=(sub_box*sh_video->disp_h)/100;                                                                            
+                                                                                                                   
+ if(auto_sub_box){                                                                                              
+    if(sub_box>(((float)sh_video->disp_w/monitor_aspect)-sh_video->disp_h) || sub_box==0) sub_box=((float)sh_video->disp_w/monitor_aspect)-sh_video->disp_h;
+    if(sub_box>sh_video->disp_h) sub_box=0; /*film have bad w/h*/
+    }                                                                                                              
+
+ if(sub_box>0 && sub_pos==100){
+    sub_pos=(sh_video->disp_h*100)/(sh_video->disp_h+sub_box);
+    printf("sub_pos changed to: %i \n",sub_pos);
+    }
+                                                                                                                   
+ printf("SUB_BOX value: %i\n",sub_box);                                                                         
+ sub_box=(sub_box>>1)<<1;                                                                                       
+ sub_y_start=sh_video->disp_h;                                                                                      
+ sub_y_end=sh_video->disp_h+sub_box;
+#ifdef HAVE_NEW_GUI
+ if( use_gui ) sub_box=0;
+#endif
+
 #if 0 /* was X11_FULLSCREEN hack -> moved to libvo/vo_xv.c where it belongs ::atmos */
    if(fullscreen){
      if(vo_init()){
@@ -1663,6 +1690,7 @@
   
     float frame_time=0;
     int blit_frame=0;
+	extern int sub_clear;
     
     //--------------------  Decode a frame: -----------------------
     vdecode_time=video_time_usage;
@@ -1680,7 +1708,8 @@
     }
     vdecode_time=video_time_usage-vdecode_time;
     //------------------------ frame decoded. --------------------
-    
+	
+	sub_clear=1;    
 //------------------------ add OSD to frame contents ---------
 #ifndef USE_LIBVO2
     current_module="draw_osd";


More information about the MPlayer-dev-eng mailing list