summaryrefslogtreecommitdiff
path: root/src/libsputext/xine_sputext_decoder.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libsputext/xine_sputext_decoder.c')
-rw-r--r--src/libsputext/xine_sputext_decoder.c91
1 files changed, 42 insertions, 49 deletions
diff --git a/src/libsputext/xine_sputext_decoder.c b/src/libsputext/xine_sputext_decoder.c
index d0cab9cbf..7d5e73ce9 100644
--- a/src/libsputext/xine_sputext_decoder.c
+++ b/src/libsputext/xine_sputext_decoder.c
@@ -18,6 +18,10 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
@@ -63,7 +67,7 @@
#define rgb2yuv(R,G,B) ((((((66*R+129*G+25*B+128)>>8)+16)<<8)|(((112*R-94*G-18*B+128)>>8)+128))<<8|(((-38*R-74*G+112*B+128)>>8)+128))
-static uint32_t sub_palette[22]={
+static const uint32_t sub_palette[22]={
/* RED */
rgb2yuv(0,0,0),
rgb2yuv(0,0,0),
@@ -90,7 +94,7 @@ static uint32_t sub_palette[22]={
rgb2yuv(0,170,255)
};
-static uint8_t sub_trans[22]={
+static const uint8_t sub_trans[22]={
0, 0, 3, 6, 8, 10, 12, 14, 15, 15, 15,
0, 0, 3, 6, 8, 10, 12, 14, 15, 15, 15
};
@@ -185,7 +189,7 @@ static inline char *get_font (sputext_class_t *class)
}
static void update_font_size (sputext_decoder_t *this, int force_update) {
- static int sizes[SUBTITLE_SIZE_NUM] = { 16, 20, 24, 32, 48, 64 };
+ static const int sizes[SUBTITLE_SIZE_NUM] = { 16, 20, 24, 32, 48, 64 };
if ((this->subtitle_size != this->class->subtitle_size) ||
(this->vertical_offset != this->class->vertical_offset) ||
@@ -214,11 +218,9 @@ static void update_font_size (sputext_decoder_t *this, int force_update) {
}
static void update_output_size (sputext_decoder_t *this) {
- int unscaled;
-
- unscaled = this->class->use_unscaled &&
- (this->stream->video_out->get_capabilities(this->stream->video_out) &
- VO_CAP_UNSCALED_OVERLAY);
+ const int unscaled = this->class->use_unscaled &&
+ (this->stream->video_out->get_capabilities(this->stream->video_out) &
+ VO_CAP_UNSCALED_OVERLAY);
if( unscaled != this->unscaled ) {
this->unscaled = unscaled;
@@ -303,7 +305,7 @@ static void update_output_size (sputext_decoder_t *this) {
}
}
-static int parse_utf8_size(unsigned char *c)
+static int parse_utf8_size(const uint8_t *c)
{
if ( c[0]<0x80 )
return 1;
@@ -329,13 +331,8 @@ static int parse_utf8_size(unsigned char *c)
static int ogm_render_line_internal(sputext_decoder_t *this, int x, int y, const char *text, int render)
{
- int i = 0, w, value;
- char* end;
- char letter[5]={0, 0, 0, 0, 0};
- const char *encoding = this->buf_encoding ? this->buf_encoding
- : this->class->src_encoding;
- int shift, isutf8 = !strcmp(encoding, "utf-8");
- size_t length = strlen (text);
+ const size_t length = strlen (text);
+ size_t i = 0;
while (i <= length) {
@@ -379,6 +376,7 @@ static int ogm_render_line_internal(sputext_decoder_t *this, int x, int y, const
if (text[i] == '{') {
if (!strncmp("{\\", text+i, 2)) {
+ int value;
if (sscanf(text+i, "{\\b%d}", &value) == 1) {
if (render) {
@@ -395,7 +393,7 @@ static int ogm_render_line_internal(sputext_decoder_t *this, int x, int y, const
this->current_osd_text = OSD_TEXT1;
}
}
- end = strstr(text+i+2, "}");
+ char *const end = strstr(text+i+2, "}");
if (end) {
i=end-text+1;
continue;
@@ -403,15 +401,20 @@ static int ogm_render_line_internal(sputext_decoder_t *this, int x, int y, const
}
}
- shift = isutf8 ? parse_utf8_size (&text[i]) : 1;
+ char letter[5];
+ const char *const encoding = this->buf_encoding ? : this->class->src_encoding;
+ const int isutf8 = !strcmp(encoding, "utf-8");
+ const size_t shift = isutf8 ? parse_utf8_size (&text[i]) : 1;
memcpy(letter,&text[i],shift);
letter[shift]=0;
if (render)
this->renderer->render_text(this->osd, x, y, letter, this->current_osd_text);
- this->renderer->get_text_size(this->osd, letter, &w, &value);
- x=x+w;
- i+=shift;
+
+ int w, dummy;
+ this->renderer->get_text_size(this->osd, letter, &w, &dummy);
+ x += w;
+ i += shift;
}
return x;
@@ -547,15 +550,9 @@ static int is_cjk_encoding(const char *enc) {
static void draw_subtitle(sputext_decoder_t *this, int64_t sub_start, int64_t sub_end ) {
- int line, y;
- int font_size;
- char *font;
- const char *encoding = (this->buf_encoding)?this->buf_encoding:
- this->class->src_encoding;
+ int y;
int sub_x, sub_y, max_width;
int alignment;
- int rebuild_all;
-
_x_assert(this->renderer != NULL);
if ( ! this->renderer )
@@ -565,21 +562,20 @@ static void draw_subtitle(sputext_decoder_t *this, int64_t sub_start, int64_t su
update_font_size(this, 0);
- font = get_font (this->class);
+ const char *const font = get_font (this->class);
if( strcmp(this->font, font) ) {
strncpy(this->font, font, FILENAME_MAX);
this->font[FILENAME_MAX - 1] = '\0';
this->renderer->set_font (this->osd, font, this->font_size);
}
- font_size = this->font_size;
- if (this->buf_encoding)
- this->renderer->set_encoding(this->osd, this->buf_encoding);
- else
- this->renderer->set_encoding(this->osd, this->class->src_encoding);
+ int font_size = this->font_size;
+ const char *const encoding = this->buf_encoding ? : this->class->src_encoding;
+ this->renderer->set_encoding(this->osd, encoding);
- rebuild_all = 0;
+ int rebuild_all = 0;
+ int line;
for (line = 0; line < this->lines; line++) {
int line_width = ogm_get_width(this, this->text[line]);
@@ -637,30 +633,27 @@ static void draw_subtitle(sputext_decoder_t *this, int64_t sub_start, int64_t su
/* regenerate all the lines to find something that better fits */
if (rebuild_all) {
- int line, line_width;
- char *stream, *current_cut, *best_cut;
- char buf[SUB_BUFSIZE * SUB_MAX_TEXT];
+ char buf[SUB_BUFSIZE * SUB_MAX_TEXT] = { 0, };
- buf[0] = 0;
+ int line;
for(line = 0; line < this->lines; line++) {
- int len = strlen(buf);
- if (len) {
+ const size_t len = strlen(buf);
+ if (len)
buf[len] = ' ';
- len++;
- }
- strncpy(buf + len, this->text[line], SUB_BUFSIZE);
- *(buf + len + SUB_BUFSIZE) = 0;
+
+ strncat(buf, this->text[line], SUB_BUFSIZE-len-1);
}
- stream = buf;
+ char *stream = buf;
this->lines = 0;
+ char *current_cut, *best_cut;
do {
if (this->lines + 1 < SUB_MAX_TEXT) {
/* find the longest sequence witch fit */
- line_width = 0;
+ int line_width = 0;
current_cut = stream;
best_cut = NULL;
while (line_width < max_width) {
@@ -1081,7 +1074,7 @@ static spu_decoder_t *sputext_class_open_plugin (spu_decoder_class_t *class_gen,
sputext_class_t *class = (sputext_class_t *)class_gen;
sputext_decoder_t *this ;
- this = (sputext_decoder_t *) xine_xmalloc (sizeof (sputext_decoder_t));
+ this = (sputext_decoder_t *) calloc(1, sizeof(sputext_decoder_t));
this->spu_decoder.decode_data = spudec_decode_data;
this->spu_decoder.reset = spudec_reset;
@@ -1135,7 +1128,7 @@ static void *init_spu_decoder_plugin (xine_t *xine, void *data) {
lprintf("init class\n");
- this = (sputext_class_t *) xine_xmalloc (sizeof (sputext_class_t));
+ this = (sputext_class_t *) calloc(1, sizeof(sputext_class_t));
this->class.open_plugin = sputext_class_open_plugin;
this->class.get_identifier = sputext_class_get_identifier;