summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libsputext/xine_decoder.c50
-rw-r--r--src/xine-engine/osd.c73
-rw-r--r--src/xine-engine/osd.h129
-rw-r--r--src/xine-engine/xine.c5
4 files changed, 222 insertions, 35 deletions
diff --git a/src/libsputext/xine_decoder.c b/src/libsputext/xine_decoder.c
index 83d18e8d6..7c342b0d8 100644
--- a/src/libsputext/xine_decoder.c
+++ b/src/libsputext/xine_decoder.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: xine_decoder.c,v 1.7 2001/12/09 00:01:17 guenter Exp $
+ * $Id: xine_decoder.c,v 1.8 2001/12/13 18:32:15 miguelfreitas Exp $
*
* code based on mplayer module:
*
@@ -50,7 +50,6 @@
#define ERR (void *)-1
#define SUB_MAX_TEXT 5
-#define LINE_HEIGHT 30
typedef struct {
@@ -62,7 +61,7 @@ typedef struct {
char *text[SUB_MAX_TEXT];
osd_object_t *osd;
-
+
} subtitle_t;
@@ -79,6 +78,8 @@ typedef struct sputext_decoder_s {
float mpsub_position;
int width; /* frame width */
+ int font_size;
+ int line_height;
int uses_time;
int errs;
subtitle_t *subtitles;
@@ -750,14 +751,28 @@ static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) {
this->width = buf->decoder_info[1];
+ /* trying to make better sized fonts...
+ another idea would be changing font size just
+ if we detect the text line wont fit.
+ */
+ this->font_size = 16;
+ if( this->width >= 320 )
+ this->font_size = 20;
+ if( this->width >= 384 )
+ this->font_size = 24;
+ if( this->width >= 512 )
+ this->font_size = 32;
+ this->line_height = this->font_size + 10;
+
this->renderer = this->xine->osd_renderer;
this->osd = this->renderer->new_object (this->renderer,
this->width,
- SUB_MAX_TEXT * LINE_HEIGHT);
+ SUB_MAX_TEXT * this->line_height);
- this->renderer->set_font (this->osd, this->font, 16);
+
+ this->renderer->set_font (this->osd, this->font, this->font_size);
- y = buf->decoder_info[2] - (SUB_MAX_TEXT * LINE_HEIGHT) - 5;
+ y = buf->decoder_info[2] - (SUB_MAX_TEXT * this->line_height) - 5;
this->renderer->set_position (this->osd, 0, y);
@@ -846,21 +861,22 @@ static void spudec_decode_data (spu_decoder_t *this_gen, buf_element_t *buf) {
if (subtitle) {
int line, y;
- this->renderer->filled_rect (this->osd, 0, 0, this->width-1, LINE_HEIGHT * SUB_MAX_TEXT - 1, 0);
+ this->renderer->filled_rect (this->osd, 0, 0, this->width-1, this->line_height * SUB_MAX_TEXT - 1, 0);
- y = (SUB_MAX_TEXT - subtitle->lines) * LINE_HEIGHT;
+ y = (SUB_MAX_TEXT - subtitle->lines) * this->line_height;
for (line=0; line<subtitle->lines; line++) {
int w,h,x;
this->renderer->get_text_size( this->osd, subtitle->text[line],
&w, &h);
-
+
x = (this->width - w) / 2;
- this->renderer->render_text (this->osd, x, y + line*20, subtitle->text[line]);
+ this->renderer->render_text (this->osd, x, y + line*this->line_height, subtitle->text[line]);
}
+ this->renderer->set_text_palette (this->osd, -1);
this->renderer->show (this->osd, pts );
this->renderer->hide (this->osd, pts_end);
@@ -891,6 +907,16 @@ static char *spudec_get_id(void) {
return "sputext";
}
+static void update_osd_font(void *this_gen, cfg_entry_t *entry)
+{
+ sputext_decoder_t *this = (sputext_decoder_t *)this_gen;
+
+ this->font = entry->str_value;
+
+ this->renderer->set_font (this->osd, this->font, this->font_size);
+ printf("libsputext: spu_font = %s\n", this->font );
+}
+
spu_decoder_t *init_spu_decoder_plugin (int iface_version, xine_t *xine) {
sputext_decoder_t *this ;
@@ -904,7 +930,7 @@ spu_decoder_t *init_spu_decoder_plugin (int iface_version, xine_t *xine) {
this = (sputext_decoder_t *) xine_xmalloc (sizeof (sputext_decoder_t));
- this->spu_decoder.interface_version = 4;
+ this->spu_decoder.interface_version = iface_version;
this->spu_decoder.can_handle = spudec_can_handle;
this->spu_decoder.init = spudec_init;
this->spu_decoder.decode_data = spudec_decode_data;
@@ -917,7 +943,7 @@ spu_decoder_t *init_spu_decoder_plugin (int iface_version, xine_t *xine) {
"codec.spu_font",
"sans",
"font for avi subtitles",
- NULL, NULL, NULL);
+ NULL, update_osd_font, this);
return (spu_decoder_t *) this;
}
diff --git a/src/xine-engine/osd.c b/src/xine-engine/osd.c
index 7035399e8..59a4a2e25 100644
--- a/src/xine-engine/osd.c
+++ b/src/xine-engine/osd.c
@@ -20,6 +20,8 @@
* OSD stuff (text and graphic primitives)
*/
+#define __OSD_C__
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -102,6 +104,7 @@ static osd_object_t *osd_new_object (osd_renderer_t *this, int width, int height
osd_object_t *osd;
+#if 0
static clut_t default_color[] = {
CLUT_Y_CR_CB_INIT(0x00, 0x00, 0x00),
CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80),
@@ -120,6 +123,7 @@ static osd_object_t *osd_new_object (osd_renderer_t *this, int width, int height
*/
};
static uint8_t default_trans[] = {0, 10, 12, 15, 15, 15, 15};
+#endif
pthread_mutex_lock (&this->osd_mutex);
@@ -137,8 +141,8 @@ static osd_object_t *osd_new_object (osd_renderer_t *this, int width, int height
osd->x2 = 0;
osd->y2 = 0;
- memcpy(osd->color, default_color, sizeof(default_color));
- memcpy(osd->trans, default_trans, sizeof(default_trans));
+ memcpy(osd->color, textpalettes_color[0], sizeof(textpalettes_color[0]));
+ memcpy(osd->trans, textpalettes_trans[0], sizeof(textpalettes_trans[0]));
osd->handle = -1;
@@ -399,6 +403,23 @@ static void osd_set_palette(osd_object_t *osd, uint32_t *color, uint8_t *trans )
}
/*
+ * set on existing text palette
+ * (-1 to set user specified palette)
+ */
+
+static void osd_set_text_palette(osd_object_t *osd, int palette_number ) {
+
+ if( palette_number < 0 )
+ palette_number = osd->renderer->textpalette;
+
+ memcpy(osd->color, textpalettes_color[palette_number],
+ sizeof(textpalettes_color[palette_number]));
+ memcpy(osd->trans, textpalettes_trans[palette_number],
+ sizeof(textpalettes_trans[palette_number]));
+}
+
+
+/*
* get palette (color and transparency)
*/
@@ -662,7 +683,7 @@ static int osd_get_text_size(osd_object_t *osd, char *text, int *width, int *hei
*width = 0;
*height = 0;
- while( *text ) {
+ while( font && *text ) {
for( i = 0; i < font->num_fontchars; i++ ) {
if( font->fontchar[i].code == *text )
@@ -765,17 +786,28 @@ static void osd_renderer_close (osd_renderer_t *this) {
free(this);
}
+
+static void update_text_palette(void *this_gen, cfg_entry_t *entry)
+{
+ osd_renderer_t *this = (osd_renderer_t *)this_gen;
+
+ this->textpalette = entry->num_value;
+ printf("osd: text palette will be %s\n", textpalettes_str[this->textpalette] );
+}
+
+
/*
* initialize the osd rendering engine
*/
-osd_renderer_t *osd_renderer_init( video_overlay_instance_t *video_overlay ) {
+osd_renderer_t *osd_renderer_init( video_overlay_instance_t *video_overlay, config_values_t *config ) {
osd_renderer_t *this;
char str[1024];
this = xine_xmalloc(sizeof(osd_renderer_t));
this->video_overlay = video_overlay;
+ this->config = config;
this->event.object.overlay = xine_xmalloc( sizeof(vo_overlay_t) );
pthread_mutex_init (&this->osd_mutex, NULL);
@@ -794,24 +826,29 @@ osd_renderer_t *osd_renderer_init( video_overlay_instance_t *video_overlay ) {
osd_load_fonts (this, str);
-
+ this->textpalette = config->register_enum (config, "misc.osd_text_palette", 0,
+ textpalettes_str,
+ "Palette (foreground-border-background) to use on subtitles",
+ NULL, update_text_palette, this);
+
/*
* set up function pointer
*/
- this->new_object = osd_new_object;
- this->free_object = osd_free_object;
- this->show = osd_show;
- this->hide = osd_hide;
- this->set_palette = osd_set_palette;
- this->get_palette = osd_get_palette;
- this->set_position = osd_set_position;
- this->set_font = osd_set_font;
- this->line = osd_line;
- this->filled_rect = osd_filled_rect;
- this->render_text = osd_render_text;
- this->get_text_size = osd_get_text_size;
- this->close = osd_renderer_close;
+ this->new_object = osd_new_object;
+ this->free_object = osd_free_object;
+ this->show = osd_show;
+ this->hide = osd_hide;
+ this->set_palette = osd_set_palette;
+ this->set_text_palette = osd_set_text_palette;
+ this->get_palette = osd_get_palette;
+ this->set_position = osd_set_position;
+ this->set_font = osd_set_font;
+ this->line = osd_line;
+ this->filled_rect = osd_filled_rect;
+ this->render_text = osd_render_text;
+ this->get_text_size = osd_get_text_size;
+ this->close = osd_renderer_close;
return this;
}
diff --git a/src/xine-engine/osd.h b/src/xine-engine/osd.h
index f22924492..33086e869 100644
--- a/src/xine-engine/osd.h
+++ b/src/xine-engine/osd.h
@@ -24,6 +24,7 @@
#define HAVE_OSD_H
#include "video_overlay.h"
+#include "video_out/alphablend.h"
typedef struct osd_object_s osd_object_t;
@@ -78,6 +79,12 @@ struct osd_renderer_s {
void (*set_palette) (osd_object_t *osd, uint32_t *color, uint8_t *trans );
/*
+ * set on existing text palette
+ * (-1 to set used specified palette)
+ */
+ void (*set_text_palette) (osd_object_t *osd, int palette_number );
+
+ /*
* get palette (color and transparency)
*/
void (*get_palette) (osd_object_t *osd, uint32_t *color,
@@ -120,14 +127,130 @@ struct osd_renderer_s {
pthread_mutex_t osd_mutex;
video_overlay_instance_t *video_overlay;
video_overlay_event_t event;
- osd_object_t *osds;
- osd_font_t *fonts;
+ osd_object_t *osds; /* instances of osd */
+ osd_font_t *fonts; /* loaded fonts */
+ int textpalette; /* default textpalette */
+
+ config_values_t *config;
+
};
/*
* initialize the osd rendering engine
*/
-osd_renderer_t *osd_renderer_init( video_overlay_instance_t *video_overlay );
+osd_renderer_t *osd_renderer_init( video_overlay_instance_t *video_overlay, config_values_t *config );
+
+
+
+/*
+ * Defined palettes for rendering osd text
+ * (more can be added later)
+ */
+
+#define NUMBER_OF_TEXT_PALETTES 4
+#define TEXTPALETTE_WHITE_BLACK_TRANSPARENT 0
+#define TEXTPALETTE_WHITE_NONE_TRANSLUCID 1
+#define TEXTPALETTE_WHITE_NONE_TRANSPUCID 2
+#define TEXTPALETTE_YELLOW_BLACK_TRANSPARENT 3
+
+#ifdef __OSD_C__
+
+/* This text descriptions are used for config screen */
+static char *textpalettes_str[NUMBER_OF_TEXT_PALETTES+1] = {
+ "white-black-transparent",
+ "white-none-transparent",
+ "white-none-translucid",
+ "yellow-black-transparent",
+ NULL};
+
+
+/*
+ Palette entries as used by osd fonts:
+
+ 0: not used by font, always transparent
+ 1: font background, usually transparent, may be used to implement
+ translucid boxes where the font will be printed.
+ 2-5: transition between background and border (usually only alpha
+ value changes).
+ 6: font border. if the font is to be displayed without border this
+ will probably be adjusted to font background or near.
+ 7-9: transition between border and foreground
+ 10: font color (foreground)
+*/
+
+/*
+ The palettes below were made by hand, ie, i just throw
+ values that seemed to do the transitions i wanted.
+ This can surelly be improved a lot. [Miguel]
+*/
+
+static clut_t textpalettes_color[NUMBER_OF_TEXT_PALETTES][11] = {
+/* white, black border, transparent */
+ {
+ CLUT_Y_CR_CB_INIT(0x00, 0x00, 0x00), //0
+ CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80), //1
+ CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80), //2
+ CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80), //3
+ CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80), //4
+ CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80), //5
+ CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80), //6
+ CLUT_Y_CR_CB_INIT(0x40, 0x80, 0x80), //7
+ CLUT_Y_CR_CB_INIT(0x80, 0x80, 0x80), //8
+ CLUT_Y_CR_CB_INIT(0xc0, 0x80, 0x80), //9
+ CLUT_Y_CR_CB_INIT(0xff, 0x80, 0x80), //10
+ },
+ /* white, no border, transparent */
+ {
+ CLUT_Y_CR_CB_INIT(0x00, 0x00, 0x00), //0
+ CLUT_Y_CR_CB_INIT(0xff, 0x80, 0x80), //1
+ CLUT_Y_CR_CB_INIT(0xff, 0x80, 0x80), //2
+ CLUT_Y_CR_CB_INIT(0xff, 0x80, 0x80), //3
+ CLUT_Y_CR_CB_INIT(0xff, 0x80, 0x80), //4
+ CLUT_Y_CR_CB_INIT(0xff, 0x80, 0x80), //5
+ CLUT_Y_CR_CB_INIT(0xff, 0x80, 0x80), //6
+ CLUT_Y_CR_CB_INIT(0xff, 0x80, 0x80), //7
+ CLUT_Y_CR_CB_INIT(0xff, 0x80, 0x80), //8
+ CLUT_Y_CR_CB_INIT(0xff, 0x80, 0x80), //9
+ CLUT_Y_CR_CB_INIT(0xff, 0x80, 0x80), //10
+ },
+ /* white, no border, translucid */
+ {
+ CLUT_Y_CR_CB_INIT(0x00, 0x00, 0x00), //0
+ CLUT_Y_CR_CB_INIT(0x80, 0x80, 0x80), //1
+ CLUT_Y_CR_CB_INIT(0x80, 0x80, 0x80), //2
+ CLUT_Y_CR_CB_INIT(0x80, 0x80, 0x80), //3
+ CLUT_Y_CR_CB_INIT(0x80, 0x80, 0x80), //4
+ CLUT_Y_CR_CB_INIT(0x80, 0x80, 0x80), //5
+ CLUT_Y_CR_CB_INIT(0x80, 0x80, 0x80), //6
+ CLUT_Y_CR_CB_INIT(0xa0, 0x80, 0x80), //7
+ CLUT_Y_CR_CB_INIT(0xc0, 0x80, 0x80), //8
+ CLUT_Y_CR_CB_INIT(0xe0, 0x80, 0x80), //9
+ CLUT_Y_CR_CB_INIT(0xff, 0x80, 0x80), //10
+ },
+ /* yellow, black border, transparent */
+ {
+ CLUT_Y_CR_CB_INIT(0x00, 0x00, 0x00), //0
+ CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80), //1
+ CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80), //2
+ CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80), //3
+ CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80), //4
+ CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80), //5
+ CLUT_Y_CR_CB_INIT(0x00, 0x80, 0x80), //6
+ CLUT_Y_CR_CB_INIT(0x40, 0x84, 0x60), //7
+ CLUT_Y_CR_CB_INIT(0xd0, 0x88, 0x40), //8
+ CLUT_Y_CR_CB_INIT(0xe0, 0x8a, 0x00), //9
+ CLUT_Y_CR_CB_INIT(0xff, 0x90, 0x00), //10
+ },
+};
+
+static uint8_t textpalettes_trans[NUMBER_OF_TEXT_PALETTES][11] = {
+ {0, 0, 3, 6, 8, 10, 12, 14, 15, 15, 15 },
+ {0, 0, 0, 0, 0, 0, 2, 6, 9, 12, 15 },
+ {0, 8, 9, 10, 11, 12, 13, 14, 15, 15, 15 },
+ {0, 0, 3, 6, 8, 10, 12, 14, 15, 15, 15 },
+};
+
+#endif /* __OSD_C__ */
#endif
diff --git a/src/xine-engine/xine.c b/src/xine-engine/xine.c
index 79ea1142f..36ca880d0 100644
--- a/src/xine-engine/xine.c
+++ b/src/xine-engine/xine.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: xine.c,v 1.89 2001/12/13 00:52:01 f1rmb Exp $
+ * $Id: xine.c,v 1.90 2001/12/13 18:32:16 miguelfreitas Exp $
*
* top-level xine functions
*
@@ -478,10 +478,11 @@ xine_t *xine_init (vo_driver_t *vo,
this->video_out = vo_new_instance (vo, this->metronom);
video_decoder_init (this);
- this->osd_renderer = osd_renderer_init( this->video_out->overlay_source );
+ this->osd_renderer = osd_renderer_init( this->video_out->overlay_source, config );
this->osd = this->osd_renderer->new_object (this->osd_renderer, 300, 100);
this->osd_renderer->set_font (this->osd, "cetus", 24);
+ this->osd_renderer->set_text_palette (this->osd, TEXTPALETTE_WHITE_BLACK_TRANSPARENT );
this->osd_renderer->set_position (this->osd, 10,10);
if(ao)