Commit 8cd77839 authored by Rocky Bernstein's avatar Rocky Bernstein

Add horizontal and vertical subtitle offset corrections. Some cleanup

and work done to allow for palettized rendering (by not expanding
inline colormap entries when RGB2).
parent 63515e2f
......@@ -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
......
......@@ -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 );
......
......@@ -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") );
......
......@@ -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;
......
......@@ -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 );
......
......@@ -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;
}
......
......@@ -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 )
......
......@@ -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 )
......
......@@ -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:
......@@ -68,6 +68,22 @@
"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...) \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment