]> git.sesse.net Git - vlc/commitdiff
Add horizontal and vertical subtitle offset corrections. Some cleanup
authorRocky Bernstein <rocky@videolan.org>
Fri, 16 Jan 2004 13:32:37 +0000 (13:32 +0000)
committerRocky Bernstein <rocky@videolan.org>
Fri, 16 Jan 2004 13:32:37 +0000 (13:32 +0000)
and work done to allow for palettized rendering (by not expanding
inline colormap entries when RGB2).

modules/codec/ogt/common.c
modules/codec/ogt/common.h
modules/codec/ogt/cvd.c
modules/codec/ogt/cvd_parse.c
modules/codec/ogt/ogt.c
modules/codec/ogt/ogt_parse.c
modules/codec/ogt/pixmap.h
modules/codec/ogt/render.c
modules/codec/ogt/subtitle.h

index 54f261a91e082f2836eb0959f5cb837fd0739603..fcf0c40a526cf4ef99849ad3f28f7a7cb36d4ca4 100644 (file)
@@ -2,7 +2,7 @@
  * Common SVCD and VCD subtitle routines.
  *****************************************************************************
  * Copyright (C) 2003, 2004 VideoLAN
- * $Id: common.c,v 1.7 2004/01/16 04:14:54 rocky Exp $
+ * $Id: common.c,v 1.8 2004/01/16 13:32:37 rocky Exp $
  *
  * Author: Rocky Bernstein
  *   based on code from:
@@ -179,10 +179,11 @@ vout_thread_t *VCDSubFindVout( decoder_t *p_dec )
    palette values. We work from the free space at the end to the
    beginning so we can expand inline.
 */
-void
-VCDInlinePalette ( /*inout*/ uint8_t *p_dest, decoder_sys_t *p_sys,
-                  unsigned int i_height, unsigned int i_width ) 
+static void
+InlinePalette ( /*inout*/ uint8_t *p_dest, decoder_sys_t *p_sys )
 {
+  const unsigned int i_width  = p_sys->i_width;
+  const unsigned int i_height = p_sys->i_height;
   int n = (i_height * i_width) - 1;
   uint8_t    *p_from = p_dest;
   ogt_yuvt_t *p_to   = (ogt_yuvt_t *) p_dest;
@@ -201,7 +202,7 @@ VCDInlinePalette ( /*inout*/ uint8_t *p_dest, decoder_sys_t *p_sys,
 unsigned int 
 VCDSubGetAROverride(vlc_object_t * p_input, vout_thread_t *p_vout)
 {
-  char *psz_string = config_GetPsz( p_input, "sub-aspect-ratio" );
+  char *psz_string = config_GetPsz( p_input, MODULE_STRING "-aspect-ratio" );
 
   /* Check whether the user tried to override aspect ratio */
   if( !psz_string ) return 0;
@@ -327,7 +328,8 @@ VCDSubScaleX( decoder_t *p_dec, subpicture_t *p_spu,
 
 }
 
-/* The video may be scaled. However subtitle bitmaps assume an 1:1
+/**
+   The video may be scaled. However subtitle bitmaps assume an 1:1
    aspect ratio. So unless the user has specified otherwise, we
    need to scale to compensate for or undo the effects of video
    output scaling.
@@ -335,6 +337,9 @@ VCDSubScaleX( decoder_t *p_dec, subpicture_t *p_spu,
    Perhaps this should go in the Render routine? The advantage would
    be that it will deal with a dynamically changing aspect ratio.
    The downside is having to scale many times for each render call.
+
+   We also expand palette entries here, unless we are dealing with a 
+   palettized chroma (e.g. RGB2).
 */
 
 void 
@@ -344,9 +349,22 @@ VCDSubHandleScaling( subpicture_t *p_spu, decoder_t *p_dec )
   vout_thread_t *p_vout = vlc_object_find( p_input, VLC_OBJECT_VOUT, 
                                            FIND_CHILD );
   unsigned int i_aspect_x, i_aspect_y;
+  uint8_t *p_dest = (uint8_t *)p_spu->p_sys->p_data;
+
   if (p_vout) {
     /* Check for user-configuration override. */
-    unsigned int i_new_aspect = VCDSubGetAROverride( p_input, p_vout );
+    unsigned int i_new_aspect;
+    
+    if ( p_vout->output.i_chroma == VLC_FOURCC('R','G','B','2') ) {
+      /* This is an unscaled palettized format. We don't allow 
+         user scaling here. And to make the render process faster,
+         we don't expand the palette entries into a color value.
+       */
+      return;
+    }
+        
+    InlinePalette( p_dest, p_dec->p_sys );
+    i_new_aspect = VCDSubGetAROverride( p_input, p_vout );
 
     if (i_new_aspect == VOUT_ASPECT_FACTOR) {
       /* For scaling 1:1, nothing needs to be done. Note this means
index a2ecc65da7a33ac4c4a506fc6a2697e08fa7df81..e11a2f42caf87a4e5b1d676e0416d13079c54421 100644 (file)
@@ -2,7 +2,7 @@
  * Header for Common SVCD and VCD subtitle routines.
  *****************************************************************************
  * Copyright (C) 2003, 2004 VideoLAN
- * $Id: common.h,v 1.5 2004/01/14 11:47:19 rocky Exp $
+ * $Id: common.h,v 1.6 2004/01/16 13:32:37 rocky Exp $
  *
  * Author: Rocky Bernstein
  *
@@ -45,10 +45,6 @@ int            VCDSubCropCallback( vlc_object_t *p_object, char const *psz_var,
 
 void           VCDSubUpdateSPU( subpicture_t *p_spu, vlc_object_t *p_object );
 
-void           VCDInlinePalette ( /*inout*/ uint8_t *p_dest, 
-                                 decoder_sys_t *p_sys, unsigned int i_height, 
-                                 unsigned int i_width );
-
 void           VCDSubDumpImage( uint8_t *p_image, uint32_t i_height, 
                                uint32_t i_width );
 
index 67a632fbae8b7cb6f2ccb7af8c4e50cd3c5e0d5b..7f9fc8f29198b420c99feea25a67b62c701c89b0 100644 (file)
@@ -2,7 +2,7 @@
  * cvd.c : CVD Subtitle decoder thread
  *****************************************************************************
  * Copyright (C) 2003 VideoLAN
- * $Id: cvd.c,v 1.11 2004/01/16 04:14:54 rocky Exp $
+ * $Id: cvd.c,v 1.12 2004/01/16 13:32:37 rocky Exp $
  *
  * Authors: Rocky Bernstein
  *   based on code from:
@@ -51,9 +51,15 @@ vlc_module_begin();
                   N_("set debug mask for additional debugging."),
                   N_(DEBUG_LONGTEXT), VLC_TRUE );
 
-    add_integer( MODULE_STRING "-duration-scaling", 9, NULL,
-                DURATION_SCALE_TEXT, DURATION_SCALE_LONGTEXT,
-                VLC_TRUE );
+    add_integer ( MODULE_STRING "-horizontal-correct", 0, NULL,
+                  HORIZONTAL_CORRECT, HORIZONTAL_CORRECT_LONGTEXT, VLC_FALSE );
+
+    add_integer ( MODULE_STRING "-vertical-correct", 0, NULL,
+                  VERTICAL_CORRECT, VERTICAL_CORRECT_LONGTEXT, VLC_FALSE );
+
+    add_string( MODULE_STRING "-aspect-ratio", "", NULL,
+                SUB_ASPECT_RATIO_TEXT, SUB_ASPECT_RATIO_LONGTEXT, 
+               VLC_TRUE );
 
     add_submodule();
     set_description( _("Chaoji VCD subtitle packetizer") );
index e0de44b6d8134c53d99b04c7c07ebe53eeeecc6a..c35325c079c3621a7ba88f1e05f98576283eb883 100644 (file)
@@ -2,7 +2,7 @@
  * parse.c: Philips OGT (SVCD subtitle) packet parser
  *****************************************************************************
  * Copyright (C) 2003, 2004 VideoLAN
- * $Id: cvd_parse.c,v 1.11 2004/01/14 11:47:19 rocky Exp $
+ * $Id: cvd_parse.c,v 1.12 2004/01/16 13:32:37 rocky Exp $
  *
  * Authors: Rocky Bernstein 
  *   based on code from: 
@@ -315,9 +315,14 @@ E_(ParsePacket)( decoder_t *p_dec)
     p_spu->p_sys->i_x_end        = p_sys->i_x_start + p_sys->i_width - 1;
     p_spu->p_sys->i_y_end        = p_sys->i_y_start + p_sys->i_height - 1;
 
+    p_spu->i_x        = p_sys->i_x_start 
+      + config_GetInt( p_dec, MODULE_STRING "-horizontal-correct" );
+
     /* FIXME: use aspect ratio for x? */
-    p_spu->i_x        = p_sys->i_x_start * 3 / 4; 
-    p_spu->i_y        = p_sys->i_y_start;
+    p_spu->i_x        = (p_spu->i_x * 3) / 4; 
+    p_spu->i_y        = p_sys->i_y_start 
+      + config_GetInt( p_dec, MODULE_STRING "-vertical-correct" );
+
     p_spu->i_width    = p_sys->i_width;
     p_spu->i_height   = p_sys->i_height;
 
@@ -530,7 +535,6 @@ ParseImage( decoder_t *p_dec, subpicture_t * p_spu )
     }
 #endif /*HAVE_LIBPNG*/
 
-    VCDInlinePalette( p_dest, p_sys, i_height, i_width );
     VCDSubHandleScaling( p_spu, p_dec );
 
     return VLC_SUCCESS;
index 948e8cb469a03f5a6338a15168883285714c4bac..72ed303e8d3bfd554925641aa5bbea4e218f9410 100644 (file)
@@ -2,7 +2,7 @@
  * ogt.c : Overlay Graphics Text (SVCD subtitles) decoder thread
  *****************************************************************************
  * Copyright (C) 2003, 2004 VideoLAN
- * $Id: ogt.c,v 1.10 2004/01/14 11:47:19 rocky Exp $
+ * $Id: ogt.c,v 1.11 2004/01/16 13:32:37 rocky Exp $
  *
  * Author: Rocky Bernstein
  *   based on code from:
@@ -49,9 +49,15 @@ vlc_module_begin();
 
     add_integer ( MODULE_STRING "-debug", 0, NULL,
                   N_("set debug mask for additional debugging."),
-                  N_(DEBUG_LONGTEXT), VLC_TRUE );
+                  DEBUG_LONGTEXT, VLC_TRUE );
 
-    add_string( "sub-aspect-ratio", "", NULL,
+    add_integer ( MODULE_STRING "-horizontal-correct", 0, NULL,
+                  HORIZONTAL_CORRECT, HORIZONTAL_CORRECT_LONGTEXT, VLC_FALSE );
+
+    add_integer ( MODULE_STRING "-vertical-correct", 0, NULL,
+                  VERTICAL_CORRECT, VERTICAL_CORRECT_LONGTEXT, VLC_FALSE );
+
+    add_string( MODULE_STRING "-aspect-ratio", "", NULL,
                 SUB_ASPECT_RATIO_TEXT, SUB_ASPECT_RATIO_LONGTEXT, 
                VLC_TRUE );
 
index 85b78dbb717bb5d8bf01fe593d062ce73db2d65a..48c7b91a0d4da61a20a7e1e2b40a07d2a206dcc5 100644 (file)
@@ -2,7 +2,7 @@
  * Philips OGT (SVCD subtitle) packet parser
  *****************************************************************************
  * Copyright (C) 2003, 2004 VideoLAN
- * $Id: ogt_parse.c,v 1.9 2004/01/14 11:47:19 rocky Exp $
+ * $Id: ogt_parse.c,v 1.10 2004/01/16 13:32:37 rocky Exp $
  *
  * Author: Rocky Bernstein 
  *   based on code from: 
@@ -188,9 +188,13 @@ E_(ParsePacket)( decoder_t *p_dec)
     p_spu->p_sys->i_x_end        = p_sys->i_x_start + p_sys->i_width - 1;
     p_spu->p_sys->i_y_end        = p_sys->i_y_start + p_sys->i_height - 1;
 
+    p_spu->i_x        = p_sys->i_x_start 
+      + config_GetInt( p_dec, MODULE_STRING "-horizontal-correct" );
+
     /* FIXME: use aspect ratio for x? */
-    p_spu->i_x        = p_sys->i_x_start * 3 / 4; 
-    p_spu->i_y        = p_sys->i_y_start;
+    p_spu->i_x        = (p_spu->i_x * 3) / 4; 
+    p_spu->i_y        = p_sys->i_y_start 
+      + config_GetInt( p_dec, MODULE_STRING "-vertical-correct" );
     p_spu->i_width    = p_sys->i_width;
     p_spu->i_height   = p_sys->i_height;
 
@@ -368,7 +372,6 @@ ParseImage( decoder_t *p_dec, subpicture_t * p_spu )
     }
 #endif /*HAVE_LIBPNG*/
     
-    VCDInlinePalette( p_dest, p_sys, i_height, i_width );
     VCDSubHandleScaling( p_spu, p_dec );
     return VLC_SUCCESS;
 }
index 4a406c8dd65cf819f9125270440a3989a0fbc912..2bfa9541813df8c9b288eaad2d1ad41174df7eba 100644 (file)
@@ -2,7 +2,7 @@
  * Common pixel/chroma manipulation routines.
  *****************************************************************************
  * Copyright (C) 2003, 2004 VideoLAN
- * $Id: pixmap.h,v 1.1 2004/01/16 04:14:54 rocky Exp $
+ * $Id: pixmap.h,v 1.2 2004/01/16 13:32:37 rocky Exp $
  *
  * Author: Rocky Bernstein
  *
@@ -35,14 +35,11 @@ typedef union {
   } s;
 } ogt_yuvt_t;
 
-/* Force v in the range 0.255 */
-static inline uint8_t 
-clip_8_bit(int v)
-{
-  if (v<0)   return 0;
-  if (v>255) return 255;
-  return (uint8_t) v;
-}
+/* Force v in the range 0.255. In video_chroma/i420_rgb.c, this
+   is macro is called CLIP. FIXME: Combine with that.
+*/
+#define clip_8_bit(v) \
+  ((v < 0) ? 0 : (v > 255) ? 255 : v)
 
 static inline void
 yuv2rgb(ogt_yuvt_t *p_yuv, uint8_t *p_rgb_out )
index 337faf5a5fdd7dd0e54afc1fd8867483b059fedc..cec23b6811de7876c867097891e171f981332c75 100644 (file)
@@ -2,7 +2,7 @@
  * render.c : Philips OGT (SVCD Subtitle) renderer
  *****************************************************************************
  * Copyright (C) 2003, 2004 VideoLAN
- * $Id: render.c,v 1.14 2004/01/16 04:14:54 rocky Exp $
+ * $Id: render.c,v 1.15 2004/01/16 13:32:37 rocky Exp $
  *
  * Author: Rocky Bernstein 
  *   based on code from: 
@@ -103,7 +103,10 @@ void VCDSubRender( vout_thread_t *p_vout, picture_t *p_pic,
             RenderYUY2( p_vout, p_pic, p_spu, p_spu->p_sys->b_crop );
            break;
 
-        /* Used in ASCII Art. */
+        /* Palettized 8 bits per pixel (256 colors). Each
+           pixel is an uint8_t index in the palette
+           Used in ASCII Art. 
+        */
         case VLC_FOURCC('R','G','B','2'):
             msg_Err( p_vout, "RGB2 not implemented yet" );
            break;
@@ -498,6 +501,10 @@ yuv2rgb555(ogt_yuvt_t *p_yuv, uint8_t *p_rgb1, uint8_t *p_rgb2 )
 #undef BLUE_PIXEL  
 }
 
+/* 
+   Should be Same as p_pic->p_format.i_bits_per_pixel / 8. But since
+   we know it here, why try to compute it?
+*/
 #define BYTES_PER_PIXEL 2
 
 static void 
@@ -728,6 +735,10 @@ RenderRV16( vout_thread_t *p_vout, picture_t *p_pic,
     }
 }
 
+/* 
+   Should be Same as p_pic->p_format.i_bits_per_pixel / 8. But since
+   we know it here, why try to compute it?
+*/
 #undef  BYTES_PER_PIXEL
 #define BYTES_PER_PIXEL 4
 
@@ -846,10 +857,12 @@ RenderRV32( vout_thread_t *p_vout, picture_t *p_pic,
                    /* This is the location that's going to get changed.
                     */
                    uint8_t *p_dest = p_pixel_base_y + i_x * BYTES_PER_PIXEL;
-                    uint8_t rgb[3];
+                    uint8_t rgb[4];
 
                     yuv2rgb(p_source, rgb);
-                    memcpy(p_dest, rgb, 3);
+                    *p_dest++ = rgb[2];
+                    *p_dest++ = rgb[1];
+                    *p_dest++ = rgb[0];
                    break;
                  }
 
@@ -919,14 +932,14 @@ RenderRV32( vout_thread_t *p_vout, picture_t *p_pic,
                     */
                    uint8_t *p_pixel_base_x = p_pixel_base 
                                             + i_x * BYTES_PER_PIXEL;
-                    uint8_t rgb[3];
+                    uint8_t rgb[4];
                     yuv2rgb(p_source, rgb); 
 
                     for(  ; i_ytmp < i_ynext ; i_ytmp += p_pic->p->i_pitch )
                     {
                      /* This is the location that's going to get changed.  */
                      uint8_t *p_dest = p_pixel_base_x + i_ytmp;
-                      memcpy(p_dest, rgb, 3);
+                      memcpy(p_dest, rgb, 4);
                     }
                     break;
                  }
@@ -934,7 +947,7 @@ RenderRV32( vout_thread_t *p_vout, picture_t *p_pic,
                 default: 
                   {
                     
-                    uint8_t rgb[3];
+                    uint8_t rgb[4];
                     yuv2rgb(p_source, rgb);
 
                     for(  ; i_ytmp < i_ynext ; y_ytmp += p_pic->p->i_pitch )
index 09b88779ad9d7f46aef330cdc8e97ba61069c795..9e6cb2be620d73e99741cec085b5d0b77112d2fb 100644 (file)
@@ -2,7 +2,7 @@
  * subtitle.h : Common SVCD and CVD subtitles header
  *****************************************************************************
  * Copyright (C) 2003,2004 VideoLAN
- * $Id: subtitle.h,v 1.8 2004/01/16 04:14:54 rocky Exp $
+ * $Id: subtitle.h,v 1.9 2004/01/16 13:32:37 rocky Exp $
  *
  * Author: Rocky Bernstein
  *   based on code from:
   "time by that amount. Use 0 to mean until the next "         \
   "subtitle.")
 
+#define HORIZONTAL_CORRECT \
+  N_("Add this to starting horizontal position of subtitle.")
+#define HORIZONTAL_CORRECT_LONGTEXT N_(                            \
+  "If you need to adjust the subtitle starting position horizontally, " \
+  "set this. Negative values can be used to shift left. 0 would "      \
+  "be no deviation from where the position specified in the subtitle." \
+  )
+
+#define VERTICAL_CORRECT \
+  N_("Add this to starting vertical position of subtitle.")
+#define VERTICAL_CORRECT_LONGTEXT N_(                      \
+  "If you need to adjust the subtitle starting position horizontally, " \
+  "set this. Negative values can be used to shift left. 0 would "      \
+  "be no deviation from where the position specified in the subtitle." \
+  )
+
 #define DECODE_DEBUG 1
 #if DECODE_DEBUG
 #define dbg_print(mask, s, args...) \