From c9026cb3210205b07e2e068467a18ee40f9259a3 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Wed, 26 Jan 2011 19:40:52 +0200 Subject: sub/OSD: move some related files to sub/ --- sub/ass_mp.c | 355 ++++++++ sub/ass_mp.h | 82 ++ sub/av_sub.c | 119 +++ sub/av_sub.h | 30 + sub/find_sub.c | 175 ++++ sub/font_load.c | 356 ++++++++ sub/font_load.h | 115 +++ sub/font_load_ft.c | 1176 ++++++++++++++++++++++++ sub/osd_font.h | 545 ++++++++++++ sub/sd_ass.c | 2 +- sub/spudec.c | 1390 +++++++++++++++++++++++++++++ sub/spudec.h | 45 + sub/sub.c | 1348 ++++++++++++++++++++++++++++ sub/sub.h | 167 ++++ sub/sub_cc.c | 347 ++++++++ sub/sub_cc.h | 29 + sub/subreader.c | 2504 ++++++++++++++++++++++++++++++++++++++++++++++++++++ sub/subreader.h | 114 +++ sub/unrar_exec.c | 235 +++++ sub/unrar_exec.h | 54 ++ sub/vobsub.c | 1443 ++++++++++++++++++++++++++++++ sub/vobsub.h | 47 + 22 files changed, 10677 insertions(+), 1 deletion(-) create mode 100644 sub/ass_mp.c create mode 100644 sub/ass_mp.h create mode 100644 sub/av_sub.c create mode 100644 sub/av_sub.h create mode 100644 sub/find_sub.c create mode 100644 sub/font_load.c create mode 100644 sub/font_load.h create mode 100644 sub/font_load_ft.c create mode 100644 sub/osd_font.h create mode 100644 sub/spudec.c create mode 100644 sub/spudec.h create mode 100644 sub/sub.c create mode 100644 sub/sub.h create mode 100644 sub/sub_cc.c create mode 100644 sub/sub_cc.h create mode 100644 sub/subreader.c create mode 100644 sub/subreader.h create mode 100644 sub/unrar_exec.c create mode 100644 sub/unrar_exec.h create mode 100644 sub/vobsub.c create mode 100644 sub/vobsub.h (limited to 'sub') diff --git a/sub/ass_mp.c b/sub/ass_mp.c new file mode 100644 index 0000000000..98602ace03 --- /dev/null +++ b/sub/ass_mp.c @@ -0,0 +1,355 @@ +/* + * Copyright (C) 2006 Evgeniy Stepanov + * + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with libass; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include "config.h" +#include "mp_msg.h" +#include "path.h" +#include "ass_mp.h" +#include "subreader.h" +#include "stream/stream.h" + +#ifdef CONFIG_FONTCONFIG +#include +#endif + +// libass-related command line options +ASS_Library *ass_library; +float ass_font_scale = 1.; +float ass_line_spacing = 0.; +int ass_top_margin = 0; +int ass_bottom_margin = 0; +int use_embedded_fonts = 1; +char **ass_force_style_list = NULL; +int ass_use_margins = 0; +char *ass_color = NULL; +char *ass_border_color = NULL; +char *ass_styles_file = NULL; +int ass_hinting = ASS_HINTING_LIGHT + 4; // light hinting for unscaled osd + +#ifdef CONFIG_FONTCONFIG +extern int font_fontconfig; +#else +static int font_fontconfig = -1; +#endif +extern char *font_name; +extern char *sub_font_name; +extern float text_font_scale_factor; +extern int subtitle_autoscale; + +#ifdef CONFIG_ICONV +extern char *sub_cp; +#else +static char *sub_cp = 0; +#endif + +ASS_Track *mp_ass_default_track(ASS_Library *library) +{ + ASS_Track *track = ass_new_track(library); + + track->track_type = TRACK_TYPE_ASS; + track->Timer = 100.; + track->PlayResY = 288; + track->WrapStyle = 0; + + if (ass_styles_file) + ass_read_styles(track, ass_styles_file, sub_cp); + + if (track->n_styles == 0) { + track->Kerning = true; + int sid = ass_alloc_style(track); + ASS_Style *style = track->styles + sid; + style->Name = strdup("Default"); + style->FontName = (font_fontconfig >= 0 + && sub_font_name) ? strdup(sub_font_name) + : (font_fontconfig >= 0 + && font_name) ? strdup(font_name) : strdup("Sans"); + style->treat_fontname_as_pattern = 1; + + double fs = track->PlayResY * text_font_scale_factor / 100.; + /* The font size is always proportional to video height only; + * real -subfont-autoscale behavior is not implemented. + * Apply a correction that corresponds to about 4:3 aspect ratio + * video to get a size somewhat closer to what non-libass rendering + * would produce with the same text_font_scale_factor + * and subtitle_autoscale. + */ + if (subtitle_autoscale == 2) + fs *= 1.3; + else if (subtitle_autoscale == 3) + fs *= 1.7; + + uint32_t c1 = 0xFFFFFF00; + uint32_t c2 = 0x00000000; + if (ass_color) + c1 = strtoll(ass_color, NULL, 16); + if (ass_border_color) + c2 = strtoll(ass_border_color, NULL, 16); + + style->FontSize = fs; + style->PrimaryColour = c1; + style->SecondaryColour = c1; + style->OutlineColour = c2; + style->BackColour = 0x00000000; + style->BorderStyle = 1; + style->Alignment = 2; + style->Outline = fs / 16; + style->MarginL = 10; + style->MarginR = 10; + style->MarginV = 5; + style->ScaleX = 1.; + style->ScaleY = 1.; + } + + ass_process_force_style(track); + return track; +} + +static int check_duplicate_plaintext_event(ASS_Track *track) +{ + int i; + ASS_Event *evt = track->events + track->n_events - 1; + + for (i = 0; i < track->n_events - 1; ++i) // ignoring last event, it is the one we are comparing with + if (track->events[i].Start == evt->Start && + track->events[i].Duration == evt->Duration && + strcmp(track->events[i].Text, evt->Text) == 0) + return 1; + return 0; +} + +/** + * \brief Convert subtitle to ASS_Events for the given track + * \param track track + * \param sub subtitle to convert + * \return event id + * note: assumes that subtitle is _not_ fps-based; caller must manually correct + * Start and Duration in other case. + **/ +static int ass_process_subtitle(ASS_Track *track, subtitle *sub) +{ + int eid; + ASS_Event *event; + int len = 0, j; + char *p; + char *end; + + eid = ass_alloc_event(track); + event = track->events + eid; + + event->Start = sub->start * 10; + event->Duration = (sub->end - sub->start) * 10; + event->Style = 0; + + for (j = 0; j < sub->lines; ++j) + len += sub->text[j] ? strlen(sub->text[j]) : 0; + + len += 2 * sub->lines; // '\N', including the one after the last line + len += 6; // {\anX} + len += 1; // '\0' + + event->Text = malloc(len); + end = event->Text + len; + p = event->Text; + + if (sub->alignment) + p += snprintf(p, end - p, "{\\an%d}", sub->alignment); + + for (j = 0; j < sub->lines; ++j) + p += snprintf(p, end - p, "%s\\N", sub->text[j]); + + if (sub->lines > 0) + p -= 2; // remove last "\N" + *p = 0; + + if (check_duplicate_plaintext_event(track)) { + ass_free_event(track, eid); + track->n_events--; + return -1; + } + + mp_msg(MSGT_ASS, MSGL_V, + "plaintext event at %" PRId64 ", +%" PRId64 ": %s \n", + (int64_t) event->Start, (int64_t) event->Duration, event->Text); + + return eid; +} + + +/** + * \brief Convert subdata to ASS_Track + * \param subdata subtitles struct from subreader + * \param fps video framerate + * \return newly allocated ASS_Track, filled with subtitles from subdata + */ +ASS_Track *mp_ass_read_subdata(ASS_Library *library, sub_data *subdata, + double fps) +{ + ASS_Track *track; + int i; + + track = mp_ass_default_track(library); + track->name = subdata->filename ? strdup(subdata->filename) : 0; + + for (i = 0; i < subdata->sub_num; ++i) { + int eid = ass_process_subtitle(track, subdata->subtitles + i); + if (eid < 0) + continue; + if (!subdata->sub_uses_time) { + track->events[eid].Start *= 100. / fps; + track->events[eid].Duration *= 100. / fps; + } + } + return track; +} + +ASS_Track *mp_ass_read_stream(ASS_Library *library, const char *fname, + char *charset) +{ + int i; + char *buf = NULL; + ASS_Track *track; + size_t sz = 0; + size_t buf_alloc = 0; + stream_t *fd; + + fd = open_stream(fname, NULL, NULL); + if (!fd) + // Stream code should have printed an error already + return NULL; + if (fd->end_pos > STREAM_BUFFER_SIZE) + /* read entire file if size is known */ + buf_alloc = fd->end_pos; + else + buf_alloc = 1000; + for (;;) { + if (sz > 100000000) { + mp_tmsg(MSGT_ASS, MSGL_ERR, "Refusing to load subtitle file " + "larger than 100 MB: %s\n", fname); + sz = 0; + break; + } + buf_alloc = FFMAX(buf_alloc, sz + (sz >> 1)); + buf_alloc = FFMIN(buf_alloc, 100000001); + buf = realloc(buf, buf_alloc + 1); + i = stream_read(fd, buf + sz, buf_alloc - sz); + if (i <= 0) + break; + sz += i; + } + free_stream(fd); + if (!sz) { + free(buf); + return NULL; + } + buf[sz] = 0; + buf = realloc(buf, sz + 1); + track = ass_read_memory(library, buf, sz, charset); + if (track) { + free(track->name); + track->name = strdup(fname); + } + free(buf); + return track; +} + +void mp_ass_configure(ASS_Renderer *priv, int w, int h, bool unscaled) +{ + int hinting; + ass_set_frame_size(priv, w, h); + ass_set_margins(priv, ass_top_margin, ass_bottom_margin, 0, 0); + ass_set_use_margins(priv, ass_use_margins); + ass_set_font_scale(priv, ass_font_scale); + if (!unscaled && (ass_hinting & 4)) + hinting = 0; + else + hinting = ass_hinting & 3; + ass_set_hinting(priv, hinting); + ass_set_line_spacing(priv, ass_line_spacing); +} + +void mp_ass_configure_fonts(ASS_Renderer *priv) +{ + char *dir, *path, *family; + dir = get_path("fonts"); + if (font_fontconfig < 0 && sub_font_name) + path = strdup(sub_font_name); + else if (font_fontconfig < 0 && font_name) + path = strdup(font_name); + else + path = get_path("subfont.ttf"); + if (font_fontconfig >= 0 && sub_font_name) + family = strdup(sub_font_name); + else if (font_fontconfig >= 0 && font_name) + family = strdup(font_name); + else + family = 0; + + ass_set_fonts(priv, path, family, font_fontconfig + 1, NULL, 1); + + free(dir); + free(path); + free(family); +} + +static void message_callback(int level, const char *format, va_list va, void *ctx) +{ + mp_msg(MSGT_ASS, level, "[ass] "); + mp_msg_va(MSGT_ASS, level, format, va); + // libass messages lack trailing \n + mp_msg(MSGT_ASS, level, "\n"); +} + +ASS_Library *mp_ass_init(void) +{ + ASS_Library *priv; + char *path = get_path("fonts"); + priv = ass_library_init(); + ass_set_message_cb(priv, message_callback, NULL); + ass_set_fonts_dir(priv, path); + ass_set_extract_fonts(priv, use_embedded_fonts); + ass_set_style_overrides(priv, ass_force_style_list); + free(path); + return priv; +} + +int ass_force_reload = 0; // flag set if global ass-related settings were changed + +ASS_Image *mp_ass_render_frame(ASS_Renderer *priv, ASS_Track *track, + long long now, int *detect_change) +{ + if (ass_force_reload) { + ass_set_margins(priv, ass_top_margin, ass_bottom_margin, 0, 0); + ass_set_use_margins(priv, ass_use_margins); + ass_set_font_scale(priv, ass_font_scale); + ass_force_reload = 0; + } + return ass_render_frame(priv, track, now, detect_change); +} diff --git a/sub/ass_mp.h b/sub/ass_mp.h new file mode 100644 index 0000000000..965b063403 --- /dev/null +++ b/sub/ass_mp.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2006 Evgeniy Stepanov + * + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with libass; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPLAYER_ASS_MP_H +#define MPLAYER_ASS_MP_H + +#include +#include + +#include "config.h" +#include "subreader.h" + +#ifdef CONFIG_ASS +#include +#include + +extern ASS_Library *ass_library; +extern float ass_font_scale; +extern float ass_line_spacing; +extern int ass_top_margin; +extern int ass_bottom_margin; +extern int use_embedded_fonts; +extern char **ass_force_style_list; +extern int ass_use_margins; +extern char *ass_color; +extern char *ass_border_color; +extern char *ass_styles_file; +extern int ass_hinting; + +ASS_Track *mp_ass_default_track(ASS_Library *library); +ASS_Track *mp_ass_read_subdata(ASS_Library *library, sub_data *subdata, + double fps); +ASS_Track *mp_ass_read_stream(ASS_Library *library, const char *fname, + char *charset); + +void mp_ass_configure(ASS_Renderer *priv, int w, int h, bool unscaled); +void mp_ass_configure_fonts(ASS_Renderer *priv); +ASS_Library *mp_ass_init(void); + +extern int ass_force_reload; +ASS_Image *mp_ass_render_frame(ASS_Renderer *priv, ASS_Track *track, + long long now, int *detect_change); + +#else /* CONFIG_ASS */ + +/* Needed for EOSD code using this type to compile */ + +typedef struct ass_image { + int w, h; + int stride; + unsigned char *bitmap; + uint32_t color; + int dst_x, dst_y; + struct ass_image *next; +} ASS_Image; + +#endif + +typedef struct { + ASS_Image *imgs; + int changed; +} mp_eosd_images_t; + + +#endif /* MPLAYER_ASS_MP_H */ diff --git a/sub/av_sub.c b/sub/av_sub.c new file mode 100644 index 0000000000..a68fbce083 --- /dev/null +++ b/sub/av_sub.c @@ -0,0 +1,119 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include + +#include "libmpdemux/stheader.h" +#include "sub.h" +#include "spudec.h" +#include "av_sub.h" + +void reset_avsub(struct sh_sub *sh) +{ + if (sh->context) { + avcodec_close(sh->context); + av_freep(&sh->context); + } +} + +/** + * Decode a subtitle packet via libavcodec. + * \return < 0 on error, > 0 if further processing is needed + */ +int decode_avsub(struct sh_sub *sh, uint8_t *data, int size, + double pts, double duration) +{ + AVCodecContext *ctx = sh->context; + enum CodecID cid = CODEC_ID_NONE; + int res; + int got_sub; + AVSubtitle sub; + AVPacket pkt; + + switch (sh->type) { + case 'b': + cid = CODEC_ID_DVB_SUBTITLE; break; + case 'p': + cid = CODEC_ID_HDMV_PGS_SUBTITLE; break; + case 'x': + cid = CODEC_ID_XSUB; break; + } + + av_init_packet(&pkt); + pkt.data = data; + pkt.size = size; + pkt.pts = pts * 1000; + if (duration >= 0) + pkt.convergence_duration = duration * 1000; + if (!ctx) { + AVCodec *sub_codec; + avcodec_init(); + avcodec_register_all(); + ctx = avcodec_alloc_context(); + sub_codec = avcodec_find_decoder(cid); + if (!ctx || !sub_codec || avcodec_open(ctx, sub_codec) < 0) { + mp_msg(MSGT_SUBREADER, MSGL_FATAL, + "Could not open subtitle decoder\n"); + av_freep(&ctx); + return -1; + } + sh->context = ctx; + } + res = avcodec_decode_subtitle2(ctx, &sub, &got_sub, &pkt); + if (res < 0) + return res; + if (pts != MP_NOPTS_VALUE) { + if (sub.end_display_time > sub.start_display_time) + duration = (sub.end_display_time - sub.start_display_time) / 1000.0; + pts += sub.start_display_time / 1000.0; + } + double endpts = MP_NOPTS_VALUE; + if (pts != MP_NOPTS_VALUE && duration >= 0) + endpts = pts + duration; + if (got_sub && vo_spudec && sub.num_rects == 0) + spudec_set_paletted(vo_spudec, NULL, 0, NULL, 0, 0, 0, 0, pts, endpts); + if (got_sub && sub.num_rects > 0) { + switch (sub.rects[0]->type) { + case SUBTITLE_BITMAP: + if (!vo_spudec) + vo_spudec = spudec_new_scaled(NULL, ctx->width, ctx->height, NULL, 0); + spudec_set_paletted(vo_spudec, + sub.rects[0]->pict.data[0], + sub.rects[0]->pict.linesize[0], + sub.rects[0]->pict.data[1], + sub.rects[0]->x, + sub.rects[0]->y, + sub.rects[0]->w, + sub.rects[0]->h, + pts, + endpts); + vo_osd_changed(OSDTYPE_SPU); + break; + default: + mp_msg(MSGT_SUBREADER, MSGL_ERR, "sd_avsub: unsupported subtitle " + "type from libavcodec\n"); + res = -1; + break; + } + } +#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 82, 0) + if (got_sub) + avsubtitle_free(&sub); +#endif + return res; +} diff --git a/sub/av_sub.h b/sub/av_sub.h new file mode 100644 index 0000000000..af3edc4d34 --- /dev/null +++ b/sub/av_sub.h @@ -0,0 +1,30 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPLAYER_AV_SUB_H +#define MPLAYER_AV_SUB_H + +#include + +struct sh_sub; + +void reset_avsub(struct sh_sub *sh); +int decode_avsub(struct sh_sub *sh, uint8_t *data, int size, + double pts, double endpts); + +#endif /* MPLAYER_AV_SUB_H */ diff --git a/sub/find_sub.c b/sub/find_sub.c new file mode 100644 index 0000000000..97c232b1db --- /dev/null +++ b/sub/find_sub.c @@ -0,0 +1,175 @@ +/* + * .SUB + * + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include + +#include "libvo/video_out.h" +#include "sub.h" +#include "subreader.h" + +#include "mp_msg.h" +#include "mpcommon.h" +#include "mplayer.h" + +static int current_sub=0; + +//static subtitle* subtitles=NULL; +static int nosub_range_start=-1; +static int nosub_range_end=-1; +static const sub_data *last_sub_data = NULL; + +void step_sub(sub_data *subd, float pts, int movement) { + subtitle *subs; + int key; + + if (subd == NULL) return; + subs = subd->subtitles; + key = (pts+sub_delay) * (subd->sub_uses_time ? 100 : sub_fps); + + /* Tell the OSD subsystem that the OSD contents will change soon */ + vo_osd_changed(OSDTYPE_SUBTITLE); + + /* If we are moving forward, don't count the next (current) subtitle + * if we haven't displayed it yet. Same when moving other direction. + */ + if (movement > 0 && key < subs[current_sub].start) + movement--; + if (movement < 0 && key >= subs[current_sub].end) + movement++; + + /* Never move beyond first or last subtitle. */ + if (current_sub+movement < 0) + movement = 0-current_sub; + if (current_sub+movement >= subd->sub_num) + movement = subd->sub_num - current_sub - 1; + + current_sub += movement; + sub_delay = subs[current_sub].start / (subd->sub_uses_time ? 100 : sub_fps) - pts; +} + +void find_sub(struct MPContext *mpctx, sub_data* subd,int key){ + subtitle *subs; + subtitle *new_sub = NULL; + int i,j; + + if ( !subd || subd->sub_num == 0) return; + subs = subd->subtitles; + + if (last_sub_data != subd) { + // Sub data changed, reset nosub range. + last_sub_data = subd; + nosub_range_start = -1; + nosub_range_end = -1; + } + + if(vo_sub){ + if(key>=vo_sub->start && key<=vo_sub->end) return; // OK! + } else { + if(key>nosub_range_start && key=0 && current_sub+1 < subd->sub_num){ + if(key>subs[current_sub].end && key=new_sub->start && key<=new_sub->end) goto update; // OK! + } + +// printf("\r---- sub log search... ----\n"); + + // use logarithmic search: + i=0; + j = subd->sub_num - 1; +// printf("Searching %d in %d..%d\n",key,subs[i].start,subs[j].end); + while(j>=i){ + current_sub=(i+j+1)/2; + new_sub=&subs[current_sub]; + if(keystart) j=current_sub-1; + else if(key>new_sub->end) i=current_sub+1; + else goto update; // found! + } +// if(key>=new_sub->start && key<=new_sub->end) return; // OK! + + // check where are we... + if(keystart){ + if(current_sub<=0){ + // before the first sub + nosub_range_start=key-1; // tricky + nosub_range_end=new_sub->start; +// printf("FIRST... key=%d end=%d \n",key,new_sub->start); + new_sub=NULL; + goto update; + } + --current_sub; + if(key>subs[current_sub].end && keyend) printf("JAJJ! "); else + if(current_sub+1 >= subd->sub_num){ + // at the end? + nosub_range_start=new_sub->end; + nosub_range_end=0x7FFFFFFF; // MAXINT +// printf("END!?\n"); + new_sub=NULL; + goto update; + } else + if(key>subs[current_sub].end && keystart,(int)new_sub->end,current_sub); + + new_sub=NULL; // no sub here +update: + set_osd_subtitle(mpctx, new_sub); +} diff --git a/sub/font_load.c b/sub/font_load.c new file mode 100644 index 0000000000..e9980b8e41 --- /dev/null +++ b/sub/font_load.c @@ -0,0 +1,356 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include +#include +#include +#include +#include +#include + +#include "font_load.h" +#include "mp_msg.h" + +raw_file* load_raw(char *name,int verbose){ + int bpp; + raw_file* raw=malloc(sizeof(raw_file)); + unsigned char head[32]; + FILE *f=fopen(name,"rb"); + if(!f) goto err_out; // can't open + if(fread(head,32,1,f)<1) goto err_out; // too small + if(memcmp(head,"mhwanh",6)) goto err_out; // not raw file + raw->w=head[8]*256+head[9]; + raw->h=head[10]*256+head[11]; + raw->c=head[12]*256+head[13]; + if(raw->w == 0) // 2 bytes were not enough for the width... read 4 bytes from the end of the header + raw->w = ((head[28]*0x100 + head[29])*0x100 + head[30])*0x100 + head[31]; + if(raw->c>256) goto err_out; // too many colors!? + mp_msg(MSGT_OSD, MSGL_DBG2, "RAW: %s %d x %d, %d colors\n",name,raw->w,raw->h,raw->c); + if(raw->c){ + raw->pal=malloc(raw->c*3); + fread(raw->pal,3,raw->c,f); + bpp=1; + } else { + raw->pal=NULL; + bpp=3; + } + raw->bmp=malloc(raw->h*raw->w*bpp); + fread(raw->bmp,raw->h*raw->w*bpp,1,f); + fclose(f); + return raw; + +err_out: + if (f) + fclose(f); + free(raw); + return NULL; +} + +extern int sub_unicode; + +font_desc_t* read_font_desc(const char* fname,float factor,int verbose){ +unsigned char sor[1024]; +unsigned char sor2[1024]; +font_desc_t *desc; +FILE *f = NULL; +char *dn; +//struct stat fstate; +char section[64]; +int i,j; +int chardb=0; +int fontdb=-1; +int version=0; +int first=1; + +desc=malloc(sizeof(font_desc_t));if(!desc) goto fail_out; +memset(desc,0,sizeof(font_desc_t)); + +f=fopen(fname,"rt");if(!f){ mp_msg(MSGT_OSD, MSGL_V, "font: can't open file: %s\n",fname); goto fail_out;} + +i = strlen (fname) - 9; +if ((dn = malloc(i+1))){ + strncpy (dn, fname, i); + dn[i]='\0'; +} + +desc->fpath = dn; // search in the same dir as fonts.desc + +// desc->fpath=get_path("font/"); +// if (stat(desc->fpath, &fstate)!=0) desc->fpath=DATADIR"/font"; + + + + +// set up some defaults, and erase table +desc->charspace=2; +desc->spacewidth=12; +desc->height=0; +for(i=0;i<65536;i++) desc->start[i]=desc->width[i]=desc->font[i]=-1; + +section[0]=0; + +while(fgets(sor,1020,f)){ + unsigned char* p[8]; + int pdb=0; + unsigned char *s=sor; + unsigned char *d=sor2; + int ec=' '; + int id=0; + sor[1020]=0; + + /* skip files that look like: TTF (0x00, 0x01), PFM (0x00, 0x01), PFB + * (0x80, 0x01), PCF (0x01, 0x66), fon ("MZ"), gzipped (0x1f, 0x8b) */ + + if (first) { + if (!sor[0] || sor[1] == 1 || (sor[0] == 'M' && sor[1] == 'Z') || (sor[0] == 0x1f && sor[1] == 0x8b) || (sor[0] == 1 && sor[1] == 0x66)) { + mp_msg(MSGT_OSD, MSGL_ERR, "%s doesn't look like a bitmap font description, ignoring.\n", fname); + goto fail_out; + } + first = 0; + } + + p[0]=d;++pdb; + while(1){ + int c=*s++; + if(c==0 || c==13 || c==10) break; + if(!id){ + if(c==39 || c==34){ id=c;continue;} // idezojel + if(c==';' || c=='#') break; + if(c==9) c=' '; + if(c==' '){ + if(ec==' ') continue; + *d=0; ++d; + p[pdb]=d;++pdb; + if(pdb>=8) break; + continue; + } + } else { + if(id==c){ id=0;continue;} // idezojel + + } + *d=c;d++; + ec=c; + } + if(d==sor2) continue; // skip empty lines + *d=0; + +// printf("params=%d sor=%s\n",pdb,sor); +// for(i=0;i=16){ mp_msg(MSGT_OSD, MSGL_ERR, "font: Too many bitmaps defined.\n");goto fail_out;} + } + continue; + } + } + + if(strcmp(section,"[fpath]")==0){ + if(pdb==1){ + free (desc->fpath); // release previously allocated memory + desc->fpath=strdup(p[0]); + continue; + } + } else + +#ifdef __AMIGAOS4__ +#define FONT_PATH_SEP "" +#else +//! path seperator for font paths, may not be more than one character +#define FONT_PATH_SEP "/" +#endif + + if(strcmp(section,"[files]")==0){ + char *default_dir=MPLAYER_DATADIR FONT_PATH_SEP "font"; + if(pdb==2 && strcmp(p[0],"alpha")==0){ + char *cp; + if (!(cp=malloc(strlen(desc->fpath)+strlen(p[1])+2))) goto fail_out; + + snprintf(cp,strlen(desc->fpath)+strlen(p[1])+2,"%s" FONT_PATH_SEP "%s", + desc->fpath,p[1]); + if(!((desc->pic_a[fontdb]=load_raw(cp,verbose)))){ + free(cp); + if (!(cp=malloc(strlen(default_dir)+strlen(p[1])+2))) + goto fail_out; + snprintf(cp,strlen(default_dir)+strlen(p[1])+2,"%s" FONT_PATH_SEP "%s", + default_dir,p[1]); + if (!((desc->pic_a[fontdb]=load_raw(cp,verbose)))){ + mp_msg(MSGT_OSD, MSGL_ERR, "Can't load font bitmap: %s\n",p[1]); + free(cp); + goto fail_out; + } + } + free(cp); + continue; + } + if(pdb==2 && strcmp(p[0],"bitmap")==0){ + char *cp; + if (!(cp=malloc(strlen(desc->fpath)+strlen(p[1])+2))) goto fail_out; + + snprintf(cp,strlen(desc->fpath)+strlen(p[1])+2,"%s" FONT_PATH_SEP "%s", + desc->fpath,p[1]); + if(!((desc->pic_b[fontdb]=load_raw(cp,verbose)))){ + free(cp); + if (!(cp=malloc(strlen(default_dir)+strlen(p[1])+2))) + goto fail_out; + snprintf(cp,strlen(default_dir)+strlen(p[1])+2,"%s" FONT_PATH_SEP "%s", + default_dir,p[1]); + if (!((desc->pic_b[fontdb]=load_raw(cp,verbose)))){ + mp_msg(MSGT_OSD, MSGL_ERR, "Can't load font bitmap: %s\n",p[1]); + free(cp); + goto fail_out; + } + } + free(cp); + continue; + } + } else + + if(strcmp(section,"[info]")==0){ + if(pdb==2 && strcmp(p[0],"name")==0){ + desc->name=strdup(p[1]); + continue; + } + if(pdb==2 && strcmp(p[0],"descversion")==0){ + version=atoi(p[1]); + continue; + } + if(pdb==2 && strcmp(p[0],"spacewidth")==0){ + desc->spacewidth=atoi(p[1]); + continue; + } + if(pdb==2 && strcmp(p[0],"charspace")==0){ + desc->charspace=atoi(p[1]); + continue; + } + if(pdb==2 && strcmp(p[0],"height")==0){ + desc->height=atoi(p[1]); + continue; + } + } else + + if(strcmp(section,"[characters]")==0){ + if(pdb==3){ + int chr=p[0][0]; + int start=atoi(p[1]); + int end=atoi(p[2]); + if(sub_unicode && (chr>=0x80)) chr=(chr<<8)+p[0][1]; + else if(strlen(p[0])!=1) chr=strtol(p[0],NULL,0); + if(endstart[chr]=start; + desc->width[chr]=end-start+1; + desc->font[chr]=fontdb; +// printf("char %d '%c' start=%d width=%d\n",chr,chr,desc->start[chr],desc->width[chr]); + ++chardb; + } + continue; + } + } + mp_msg(MSGT_OSD, MSGL_ERR, "Syntax error in font desc: %s",sor); + goto fail_out; + +} +fclose(f); +f = NULL; + + if (first == 1) { + mp_msg(MSGT_OSD, MSGL_ERR, "%s is empty or a directory, ignoring.\n", fname); + goto fail_out; + } + +//printf("font: pos of U = %d\n",desc->start[218]); + +for(i=0;i<=fontdb;i++){ + if(!desc->pic_a[i] || !desc->pic_b[i]){ + mp_msg(MSGT_OSD, MSGL_ERR, "font: Missing bitmap(s) for sub-font #%d\n",i); + goto fail_out; + } + //if(factor!=1.0f) + { + // re-sample alpha + int f=factor*256.0f; + int size=desc->pic_a[i]->w*desc->pic_a[i]->h; + int j; + mp_msg(MSGT_OSD, MSGL_DBG2, "font: resampling alpha by factor %5.3f (%d) ",factor,f);fflush(stdout); + for(j=0;jpic_a[i]->bmp[j]; // alpha + int y=desc->pic_b[i]->bmp[j]; // bitmap + +#ifdef FAST_OSD + x=(x<(255-f))?0:1; +#else + + x=255-((x*f)>>8); // scale + //if(x<0) x=0; else if(x>255) x=255; + //x^=255; // invert + + if(x+y>255) x=255-y; // to avoid overflows + + //x=0; + //x=((x*f*(255-y))>>16); + //x=((x*f*(255-y))>>16)+y; + //x=(x*f)>>8;if(x=252) x=0; +#endif + + desc->pic_a[i]->bmp[j]=x; +// desc->pic_b[i]->bmp[j]=0; // hack + } + mp_msg(MSGT_OSD, MSGL_DBG2, "DONE!\n"); + } + if(!desc->height) desc->height=desc->pic_a[i]->h; +} + +j='_';if(desc->font[j]<0) j='?'; +for(i=0;i<65536;i++) + if(desc->font[i]<0){ + desc->start[i]=desc->start[j]; + desc->width[i]=desc->width[j]; + desc->font[i]=desc->font[j]; + } +desc->font[' ']=-1; +desc->width[' ']=desc->spacewidth; + +mp_msg(MSGT_OSD, MSGL_V, "Bitmap font %s loaded successfully! (%d chars)\n",fname,chardb); + +return desc; + +fail_out: + if (f) + fclose(f); + free(desc->fpath); + free(desc->name); + free(desc); + return NULL; +} + +#ifndef CONFIG_FREETYPE +void render_one_glyph(font_desc_t *desc, int c) {} +int kerning(font_desc_t *desc, int prevc, int c) { return 0; } +#endif diff --git a/sub/font_load.h b/sub/font_load.h new file mode 100644 index 0000000000..7efe067aaf --- /dev/null +++ b/sub/font_load.h @@ -0,0 +1,115 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPLAYER_FONT_LOAD_H +#define MPLAYER_FONT_LOAD_H + +#include "config.h" + +#ifdef CONFIG_FREETYPE +#include +#include FT_FREETYPE_H +#endif + +typedef struct { + unsigned char *bmp; + unsigned char *pal; + int w,h,c; +#ifdef CONFIG_FREETYPE + int charwidth,charheight,pen,baseline,padding; + int current_count, current_alloc; +#endif +} raw_file; + +typedef struct font_desc { +#ifdef CONFIG_FREETYPE + int dynamic; +#endif + char *name; + char *fpath; + int spacewidth; + int charspace; + int height; +// char *fname_a; +// char *fname_b; + raw_file* pic_a[16]; + raw_file* pic_b[16]; + short font[65536]; + int start[65536]; // short is not enough for unicode fonts + short width[65536]; + int freetype; + +#ifdef CONFIG_FREETYPE + int face_cnt; + + FT_Face faces[16]; + FT_UInt glyph_index[65536]; + + int max_width, max_height; + + struct + { + int g_r; + int o_r; + int g_w; + int o_w; + int o_size; + unsigned volume; + + unsigned *g; + unsigned *gt2; + unsigned *om; + unsigned char *omt; + unsigned short *tmp; + } tables; +#endif + +} font_desc_t; + +extern font_desc_t* vo_font; + +extern char *subtitle_font_encoding; +extern float text_font_scale_factor; +extern float osd_font_scale_factor; +extern float subtitle_font_radius; +extern float subtitle_font_thickness; +extern int subtitle_autoscale; + +extern int vo_image_width; +extern int vo_image_height; + +extern int force_load_font; + +int init_freetype(void); +int done_freetype(void); + +font_desc_t* read_font_desc_ft(const char* fname,int face_index,int movie_width, int movie_height, float font_scale_factor); +void free_font_desc(font_desc_t *desc); + +void render_one_glyph(font_desc_t *desc, int c); +int kerning(font_desc_t *desc, int prevc, int c); + +void load_font_ft(int width, int height, font_desc_t **desc, const char *name, float font_scale_factor); + +void blur(unsigned char *buffer, unsigned short *tmp2, int width, int height, + int stride, int *m2, int r, int mwidth); + +raw_file* load_raw(char *name,int verbose); +font_desc_t* read_font_desc(const char* fname,float factor,int verbose); + +#endif /* MPLAYER_FONT_LOAD_H */ diff --git a/sub/font_load_ft.c b/sub/font_load_ft.c new file mode 100644 index 0000000000..41a0f886cb --- /dev/null +++ b/sub/font_load_ft.c @@ -0,0 +1,1176 @@ +/* + * Renders antialiased fonts for mplayer using freetype library. + * Should work with TrueType, Type1 and any other font supported by libfreetype. + * + * Artur Zaprzala + * + * ported inside MPlayer by Jindrich Makovicka + * + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include +#include +#include +#include + +#ifdef CONFIG_ICONV +#include +#endif + +#include +#include FT_FREETYPE_H +#include FT_GLYPH_H + +#ifdef CONFIG_FONTCONFIG +#include +#endif + +#include "libavutil/common.h" +#include "mpbswap.h" +#include "font_load.h" +#include "mp_msg.h" +#include "mplayer.h" +#include "path.h" +#include "osd_font.h" + +#if (FREETYPE_MAJOR > 2) || (FREETYPE_MAJOR == 2 && FREETYPE_MINOR >= 1) +#define HAVE_FREETYPE21 +#endif + +char *subtitle_font_encoding = NULL; +float text_font_scale_factor = 3.5; +float osd_font_scale_factor = 4.0; +float subtitle_font_radius = 2.0; +float subtitle_font_thickness = 2.0; +// 0 = no autoscale +// 1 = video height +// 2 = video width +// 3 = diagonal +int subtitle_autoscale = 3; + +int vo_image_width = 0; +int vo_image_height = 0; +int force_load_font; + +int using_freetype = 0; +#ifdef CONFIG_FONTCONFIG +int font_fontconfig = 1; +#else +int font_fontconfig = -1; +#endif + +//// constants +static unsigned int const colors = 256; +static unsigned int const maxcolor = 255; +static unsigned const base = 256; +static unsigned const first_char = 33; +#define MAX_CHARSET_SIZE 60000 + +static FT_Library library; + +#define OSD_CHARSET_SIZE 15 + +static const FT_ULong osd_charset[OSD_CHARSET_SIZE] = +{ + 0xe001, 0xe002, 0xe003, 0xe004, 0xe005, 0xe006, 0xe007, 0xe008, + 0xe009, 0xe00a, 0xe00b, 0xe010, 0xe011, 0xe012, 0xe013 +}; + +static const FT_ULong osd_charcodes[OSD_CHARSET_SIZE] = +{ + 0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08, + 0x09,0x0a,0x0b,0x10,0x11,0x12,0x13 +}; + +#define f266ToInt(x) (((x)+32)>>6) // round fractional fixed point number to integer + // coordinates are in 26.6 pixels (i.e. 1/64th of pixels) +#define f266CeilToInt(x) (((x)+63)>>6) // ceiling +#define f266FloorToInt(x) ((x)>>6) // floor +#define f1616ToInt(x) (((x)+0x8000)>>16) // 16.16 +#define floatTof266(x) ((int)((x)*(1<<6)+0.5)) + +#define ALIGN(x) (((x)+7)&~7) // 8 byte align + +#define WARNING(msg, args...) mp_msg(MSGT_OSD, MSGL_WARN, msg "\n", ## args) + +#define DEBUG 0 + +//static double ttime; + + +static void paste_bitmap(unsigned char *bbuffer, FT_Bitmap *bitmap, int x, int y, int width, int height, int bwidth) { + int drow = x+y*width; + int srow = 0; + int sp, dp, w, h; + if (bitmap->pixel_mode==ft_pixel_mode_mono) + for (h = bitmap->rows; h>0 && height > 0; --h, height--, drow+=width, srow+=bitmap->pitch) + for (w = bwidth, sp=dp=0; w>0; --w, ++dp, ++sp) + bbuffer[drow+dp] = (bitmap->buffer[srow+sp/8] & (0x80>>(sp%8))) ? 255:0; + else + for (h = bitmap->rows; h>0 && height > 0; --h, height--, drow+=width, srow+=bitmap->pitch) + for (w = bwidth, sp=dp=0; w>0; --w, ++dp, ++sp) + bbuffer[drow+dp] = bitmap->buffer[srow+sp]; +} + + +static int check_font(font_desc_t *desc, float ppem, int padding, int pic_idx, + int charset_size, FT_ULong *charset, FT_ULong *charcodes, + int unicode) { + FT_Error error; + FT_Face face = desc->faces[pic_idx]; + int const load_flags = FT_LOAD_DEFAULT; + int ymin = INT_MAX, ymax = INT_MIN; + int space_advance = 20; + int width, height; + unsigned char *bbuffer; + int i, uni_charmap = 1; + + error = FT_Select_Charmap(face, ft_encoding_unicode); +// fprintf(stderr, "select unicode charmap: %d\n", error); + + if (face->charmap==NULL || face->charmap->encoding!=ft_encoding_unicode) { + WARNING("Unicode charmap not available for this font. Very bad!"); + uni_charmap = 0; + error = FT_Set_Charmap(face, face->charmaps[0]); + if (error) WARNING("No charmaps! Strange."); + } + + /* set size */ + if (FT_IS_SCALABLE(face)) { + error = FT_Set_Char_Size(face, 0, floatTof266(ppem), 0, 0); + if (error) WARNING("FT_Set_Char_Size failed."); + } else { + int j = 0; + int jppem = face->available_sizes[0].height; + /* find closest size */ + for (i = 0; inum_fixed_sizes; ++i) { + if (fabs(face->available_sizes[i].height - ppem) < abs(face->available_sizes[i].height - jppem)) { + j = i; + jppem = face->available_sizes[i].height; + } + } + WARNING("Selected font is not scalable. Using ppem=%i.", face->available_sizes[j].height); + error = FT_Set_Pixel_Sizes(face, face->available_sizes[j].width, face->available_sizes[j].height); + if (error) WARNING("FT_Set_Pixel_Sizes failed."); + } + + if (FT_IS_FIXED_WIDTH(face)) + WARNING("Selected font is fixed-width."); + + /* compute space advance */ + error = FT_Load_Char(face, ' ', load_flags); + if (error) WARNING("spacewidth set to default."); + else space_advance = f266ToInt(face->glyph->advance.x); + + if (!desc->spacewidth) desc->spacewidth = 2*padding + space_advance; + if (!desc->charspace) desc->charspace = -2*padding; + if (!desc->height) desc->height = f266ToInt(face->size->metrics.height); + + + for (i= 0; ifont[unicode?character:code] = pic_idx; + // get glyph index + if (character==0) + glyph_index = 0; + else { + glyph_index = FT_Get_Char_Index(face, uni_charmap ? character:code); + if (glyph_index==0) { + WARNING("Glyph for char 0x%02lx|U+%04lX|%c not found.", code, character, + code<' '||code>255 ? '.':(char)code); + desc->font[unicode?character:code] = -1; + continue; + } + } + desc->glyph_index[unicode?character:code] = glyph_index; + } +// fprintf(stderr, "font height: %f\n", (double)(face->bbox.yMax-face->bbox.yMin)/(double)face->units_per_EM*ppem); +// fprintf(stderr, "font width: %f\n", (double)(face->bbox.xMax-face->bbox.xMin)/(double)face->units_per_EM*ppem); + + ymax = (double)(face->bbox.yMax)/(double)face->units_per_EM*ppem+1; + ymin = (double)(face->bbox.yMin)/(double)face->units_per_EM*ppem-1; + + width = ppem*(face->bbox.xMax-face->bbox.xMin)/face->units_per_EM+3+2*padding; + if (desc->max_width < width) desc->max_width = width; + width = ALIGN(width); + desc->pic_b[pic_idx]->charwidth = width; + + if (width <= 0) { + mp_msg(MSGT_OSD, MSGL_ERR, "Wrong bounding box, width <= 0 !\n"); + return -1; + } + + if (ymax<=ymin) { + mp_msg(MSGT_OSD, MSGL_ERR, "Something went wrong. Use the source!\n"); + return -1; + } + + height = ymax - ymin + 2*padding; + if (height <= 0) { + mp_msg(MSGT_OSD, MSGL_ERR, "Wrong bounding box, height <= 0 !\n"); + return -1; + } + + if (desc->max_height < height) desc->max_height = height; + desc->pic_b[pic_idx]->charheight = height; + +// fprintf(stderr, "font height2: %d\n", height); + desc->pic_b[pic_idx]->baseline = ymax + padding; + desc->pic_b[pic_idx]->padding = padding; + desc->pic_b[pic_idx]->current_alloc = 0; + desc->pic_b[pic_idx]->current_count = 0; + + bbuffer = NULL; + + desc->pic_b[pic_idx]->w = width; + desc->pic_b[pic_idx]->h = height; + desc->pic_b[pic_idx]->c = colors; + desc->pic_b[pic_idx]->bmp = bbuffer; + desc->pic_b[pic_idx]->pen = 0; + return 0; +} + +// general outline +static void outline( + unsigned char *s, + unsigned char *t, + int width, + int height, + int stride, + unsigned char *m, + int r, + int mwidth, + int msize) { + + int x, y; + + for (y = 0; y=width ) ? r+width -x : 2*r+1; + const int y2=(y+r>=height) ? r+height-y : 2*r+1; + register unsigned char *dstp= t + (y1+y-r)* stride + x-r; + //register int *mp = m + y1 *mwidth; + register unsigned char *mp= m + msize*src + y1*mwidth; + int my; + + for(my= y1; mymaxcolor ? maxcolor : v; + } + *t++ = *s++; + s += skip; + t += skip; + } + for (x = 0; x>8; + unsigned *m3= m2 + src2*mwidth; + + int mx; + *srcp= 128; + for(mx=r-1; mx>8; + unsigned *m3= m2 + src2*mwidth; + + int mx; + *srcp= 128; + for(mx=0; mx>8; + unsigned *m3= m2 + src2*mwidth; + + int mx; + *srcp= 128; + for(mx=0; mx>8; + } + s+= stride; + t+= width + 1; + } +} + +static void resample_alpha(unsigned char *abuf, unsigned char *bbuf, int width, int height, int stride, float factor) +{ + int f=factor*256.0f; + int i,j; + for (i = 0; i < height; i++) { + unsigned char *a = abuf+i*stride; + unsigned char *b = bbuf+i*stride; + for(j=0;j>8); // scale + if (x+y>255) x=255-y; // to avoid overflows + if (x<1) x=1; else if (x>=252) x=0; + *a=x; + } + } +} + +#define ALLOC_INCR 32 +void render_one_glyph(font_desc_t *desc, int c) +{ + FT_GlyphSlot slot; + FT_UInt glyph_index; + FT_BitmapGlyph glyph; + int width, height, stride, maxw, off; + unsigned char *abuffer, *bbuffer; + + int const load_flags = FT_LOAD_DEFAULT; + int pen_xa; + int font = desc->font[c]; + int error; + +// fprintf(stderr, "render_one_glyph %d\n", c); + + if (!desc->dynamic) return; + if (desc->width[c] != -1) return; + if (desc->font[c] == -1) return; + + glyph_index = desc->glyph_index[c]; + + // load glyph + error = FT_Load_Glyph(desc->faces[font], glyph_index, load_flags); + if (error) { + WARNING("FT_Load_Glyph 0x%02x (char 0x%04x) failed.", glyph_index, c); + desc->font[c] = -1; + return; + } + slot = desc->faces[font]->glyph; + + // render glyph + if (slot->format != ft_glyph_format_bitmap) { + error = FT_Render_Glyph(slot, ft_render_mode_normal); + if (error) { + WARNING("FT_Render_Glyph 0x%04x (char 0x%04x) failed.", glyph_index, c); + desc->font[c] = -1; + return; + } + } + + // extract glyph image + error = FT_Get_Glyph(slot, (FT_Glyph*)&glyph); + if (error) { + WARNING("FT_Get_Glyph 0x%04x (char 0x%04x) failed.", glyph_index, c); + desc->font[c] = -1; + return; + } + +// fprintf(stderr, "glyph generated\n"); + + maxw = desc->pic_b[font]->charwidth; + + if (glyph->bitmap.width > maxw) { + fprintf(stderr, "glyph too wide!\n"); + } + + // allocate new memory, if needed +// fprintf(stderr, "\n%d %d %d\n", desc->pic_b[font]->charwidth, desc->pic_b[font]->charheight, desc->pic_b[font]->current_alloc); + if (desc->pic_b[font]->current_count >= desc->pic_b[font]->current_alloc) { + int newsize = desc->pic_b[font]->charwidth*desc->pic_b[font]->charheight*(desc->pic_b[font]->current_alloc+ALLOC_INCR); + int increment = desc->pic_b[font]->charwidth*desc->pic_b[font]->charheight*ALLOC_INCR; + desc->pic_b[font]->current_alloc += ALLOC_INCR; + +// fprintf(stderr, "\nns = %d inc = %d\n", newsize, increment); + + desc->pic_b[font]->bmp = realloc(desc->pic_b[font]->bmp, newsize); + desc->pic_a[font]->bmp = realloc(desc->pic_a[font]->bmp, newsize); + + off = desc->pic_b[font]->current_count*desc->pic_b[font]->charwidth*desc->pic_b[font]->charheight; + memset(desc->pic_b[font]->bmp+off, 0, increment); + memset(desc->pic_a[font]->bmp+off, 0, increment); + } + + abuffer = desc->pic_a[font]->bmp; + bbuffer = desc->pic_b[font]->bmp; + + off = desc->pic_b[font]->current_count*desc->pic_b[font]->charwidth*desc->pic_b[font]->charheight; + + paste_bitmap(bbuffer+off, + &glyph->bitmap, + desc->pic_b[font]->padding + glyph->left, + desc->pic_b[font]->baseline - glyph->top, + desc->pic_b[font]->charwidth, desc->pic_b[font]->charheight, + glyph->bitmap.width <= maxw ? glyph->bitmap.width : maxw); + +// fprintf(stderr, "glyph pasted\n"); + FT_Done_Glyph((FT_Glyph)glyph); + + /* advance pen */ + pen_xa = f266ToInt(slot->advance.x) + 2*desc->pic_b[font]->padding; + if (pen_xa > maxw) pen_xa = maxw; + + desc->start[c] = off; + width = desc->width[c] = pen_xa; + height = desc->pic_b[font]->charheight; + stride = desc->pic_b[font]->w; + + if (desc->tables.o_r == 0) { + outline0(bbuffer+off, abuffer+off, width, height, stride); + } else if (desc->tables.o_r == 1) { + outline1(bbuffer+off, abuffer+off, width, height, stride); + } else { + outline(bbuffer+off, abuffer+off, width, height, stride, + desc->tables.omt, desc->tables.o_r, desc->tables.o_w, + desc->tables.o_size); + } +// fprintf(stderr, "fg: outline t = %f\n", GetTimer()-t); + + if (desc->tables.g_r) { + blur(abuffer+off, desc->tables.tmp, width, height, stride, + desc->tables.gt2, desc->tables.g_r, + desc->tables.g_w); +// fprintf(stderr, "fg: blur t = %f\n", GetTimer()-t); + } + + resample_alpha(abuffer+off, bbuffer+off, width, height, stride, font_factor); + + desc->pic_b[font]->current_count++; +} + + +static int prepare_font(font_desc_t *desc, FT_Face face, float ppem, int pic_idx, + int charset_size, FT_ULong *charset, FT_ULong *charcodes, int unicode, + double thickness, double radius) +{ + int i, err; + int padding = ceil(radius) + ceil(thickness); + + desc->faces[pic_idx] = face; + + desc->pic_a[pic_idx] = malloc(sizeof(raw_file)); + if (!desc->pic_a[pic_idx]) return -1; + desc->pic_b[pic_idx] = malloc(sizeof(raw_file)); + if (!desc->pic_b[pic_idx]) return -1; + + desc->pic_a[pic_idx]->bmp = NULL; + desc->pic_a[pic_idx]->pal = NULL; + desc->pic_b[pic_idx]->bmp = NULL; + desc->pic_b[pic_idx]->pal = NULL; + + desc->pic_a[pic_idx]->pal = malloc(sizeof(unsigned char)*256*3); + if (!desc->pic_a[pic_idx]->pal) return -1; + for (i = 0; i<768; ++i) desc->pic_a[pic_idx]->pal[i] = i/3; + + desc->pic_b[pic_idx]->pal = malloc(sizeof(unsigned char)*256*3); + if (!desc->pic_b[pic_idx]->pal) return -1; + for (i = 0; i<768; ++i) desc->pic_b[pic_idx]->pal[i] = i/3; + +// ttime = GetTimer(); + err = check_font(desc, ppem, padding, pic_idx, charset_size, charset, charcodes, unicode); +// ttime=GetTimer()-ttime; +// printf("render: %7f us\n",ttime); + if (err) return -1; +// fprintf(stderr, "fg: render t = %f\n", GetTimer()-t); + + desc->pic_a[pic_idx]->w = desc->pic_b[pic_idx]->w; + desc->pic_a[pic_idx]->h = desc->pic_b[pic_idx]->h; + desc->pic_a[pic_idx]->c = colors; + + desc->pic_a[pic_idx]->bmp = NULL; + +// fprintf(stderr, "fg: w = %d, h = %d\n", desc->pic_a[pic_idx]->w, desc->pic_a[pic_idx]->h); + return 0; + +} + +static int generate_tables(font_desc_t *desc, double thickness, double radius) +{ + int width = desc->max_height; + int height = desc->max_width; + + double A = log(1.0/base)/(radius*radius*2); + int mx, my, i; + double volume_diff, volume_factor = 0; + unsigned char *omtp; + + desc->tables.g_r = ceil(radius); + desc->tables.o_r = ceil(thickness); + desc->tables.g_w = 2*desc->tables.g_r+1; + desc->tables.o_w = 2*desc->tables.o_r+1; + desc->tables.o_size = desc->tables.o_w * desc->tables.o_w; + +// fprintf(stderr, "o_r = %d\n", desc->tables.o_r); + + if (desc->tables.g_r) { + desc->tables.g = malloc(desc->tables.g_w * sizeof(unsigned)); + desc->tables.gt2 = malloc(256 * desc->tables.g_w * sizeof(unsigned)); + if (desc->tables.g==NULL || desc->tables.gt2==NULL) { + return -1; + } + } + desc->tables.om = malloc(desc->tables.o_w*desc->tables.o_w * sizeof(unsigned)); + desc->tables.omt = malloc(desc->tables.o_size*256); + + omtp = desc->tables.omt; + desc->tables.tmp = malloc((width+1)*height*sizeof(short)); + + if (desc->tables.om==NULL || desc->tables.omt==NULL || desc->tables.tmp==NULL) { + return -1; + }; + + if (desc->tables.g_r) { + // gaussian curve with volume = 256 + for (volume_diff=10000000; volume_diff>0.0000001; volume_diff*=0.5){ + volume_factor+= volume_diff; + desc->tables.volume=0; + for (i = 0; itables.g_w; ++i) { + desc->tables.g[i] = (unsigned)(exp(A * (i-desc->tables.g_r)*(i-desc->tables.g_r)) * volume_factor + .5); + desc->tables.volume+= desc->tables.g[i]; + } + if(desc->tables.volume>256) volume_factor-= volume_diff; + } + desc->tables.volume=0; + for (i = 0; itables.g_w; ++i) { + desc->tables.g[i] = (unsigned)(exp(A * (i-desc->tables.g_r)*(i-desc->tables.g_r)) * volume_factor + .5); + desc->tables.volume+= desc->tables.g[i]; + } + + // gauss table: + for(mx=0;mxtables.g_w;mx++){ + for(i=0;i<256;i++){ + desc->tables.gt2[mx+i*desc->tables.g_w] = i*desc->tables.g[mx]; + } + } + } + + /* outline matrix */ + for (my = 0; mytables.o_w; ++my) { + for (mx = 0; mxtables.o_w; ++mx) { + // antialiased circle would be perfect here, but this one is good enough + double d = thickness + 1 - sqrt((mx-desc->tables.o_r)*(mx-desc->tables.o_r)+(my-desc->tables.o_r)*(my-desc->tables.o_r)); + desc->tables.om[mx+my*desc->tables.o_w] = d>=1 ? base : d<=0 ? 0 : (d*base + .5); + } + } + + // outline table: + for(i=0;i<256;i++){ + for(mx=0;mxtables.o_size;mx++) *(omtp++) = (i*desc->tables.om[mx] + (base/2))/base; + } + + return 0; +} + +#ifdef CONFIG_ICONV +/* decode from 'encoding' to unicode */ +static FT_ULong decode_char(iconv_t *cd, char c) { + FT_ULong o; + char *inbuf = &c; + char *outbuf = (char*)&o; + size_t inbytesleft = 1; + size_t outbytesleft = sizeof(FT_ULong); + + iconv(*cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft); + + /* convert unicode BigEndian -> MachineEndian */ + o = be2me_32(o); + + // if (count==-1) o = 0; // not OK, at least my iconv() returns E2BIG for all + if (outbytesleft!=0) o = 0; + + /* we don't want control characters */ + if (o>=0x7f && o<0xa0) o = 0; + return o; +} + +static int prepare_charset(char *charmap, char *encoding, FT_ULong *charset, FT_ULong *charcodes) { + FT_ULong i; + int count = 0; + int charset_size; + iconv_t cd; + + // check if ucs-4 is available + cd = iconv_open(charmap, charmap); + if (cd==(iconv_t)-1) { + mp_msg(MSGT_OSD, MSGL_ERR, "iconv doesn't know %s encoding. Use the source!\n", charmap); + return -1; + } + + iconv_close(cd); + + cd = iconv_open(charmap, encoding); + if (cd==(iconv_t)-1) { + mp_msg(MSGT_OSD, MSGL_ERR, "Unsupported encoding `%s', use iconv --list to list character sets known on your system.\n", encoding); + return -1; + } + + charset_size = 256 - first_char; + for (i = 0; icharmap==NULL || face->charmap->encoding!=ft_encoding_unicode) { + WARNING("Unicode charmap not available for this font. Very bad!"); + return -1; + } +#ifdef HAVE_FREETYPE21 + i = 0; + charcode = FT_Get_First_Char( face, &gindex ); + while (gindex != 0) { + if (charcode < 65536 && charcode >= 33) { // sanity check + charset[i] = charcode; + charcodes[i] = 0; + i++; + } + charcode = FT_Get_Next_Char( face, charcode, &gindex ); + } +#else + // for FT < 2.1 we have to use brute force enumeration + i = 0; + for (j = 33; j < 65536; j++) { + gindex = FT_Get_Char_Index(face, j); + if (gindex > 0) { + charset[i] = j; + charcodes[i] = 0; + i++; + } + } +#endif + mp_msg(MSGT_OSD, MSGL_V, "Unicode font: %d glyphs.\n", i); + + return i; +} +#endif + +static font_desc_t* init_font_desc(void) +{ + font_desc_t *desc; + + desc = calloc(1, sizeof(*desc)); + if(!desc) return NULL; + + desc->dynamic = 1; + + /* setup sane defaults */ + desc->freetype = 1; + + memset(desc->start, 0xff, sizeof(desc->start)); + memset(desc->width, 0xff, sizeof(desc->width)); + memset(desc->font, 0xff, sizeof(desc->font)); + + return desc; +} + +void free_font_desc(font_desc_t *desc) +{ + int i; + + if (!desc) return; + +// if (!desc->dynamic) return; // some vo_aa crap, better leaking than crashing + + free(desc->name); + free(desc->fpath); + + for(i = 0; i < 16; i++) { + if (desc->pic_a[i]) { + free(desc->pic_a[i]->bmp); + free(desc->pic_a[i]->pal); + free(desc->pic_a[i]); + } + if (desc->pic_b[i]) { + free(desc->pic_b[i]->bmp); + free(desc->pic_b[i]->pal); + free(desc->pic_b[i]); + } + } + + free(desc->tables.g); + free(desc->tables.gt2); + free(desc->tables.om); + free(desc->tables.omt); + free(desc->tables.tmp); + + for(i = 0; i < desc->face_cnt; i++) { + FT_Done_Face(desc->faces[i]); + } + + free(desc); +} + +static int load_sub_face(const char *name, int face_index, FT_Face *face) +{ + int err = -1; + + if (name) err = FT_New_Face(library, name, face_index, face); + + if (err) { + char *font_file = get_path("subfont.ttf"); + err = FT_New_Face(library, font_file, 0, face); + free(font_file); + if (err) { + err = FT_New_Face(library, MPLAYER_DATADIR "/subfont.ttf", 0, face); + if (err) { + mp_tmsg(MSGT_OSD, MSGL_ERR, "New_Face failed. Maybe the font path is wrong.\nPlease supply the text font file (~/.mplayer/subfont.ttf).\n"); + return -1; + } + } + } + return err; +} + +static int load_osd_face(FT_Face *face) +{ + if ( FT_New_Memory_Face(library, osd_font_pfb, sizeof(osd_font_pfb), 0, face) ) { + mp_tmsg(MSGT_OSD, MSGL_ERR, "New_Memory_Face failed..\n"); + return -1; + } + return 0; +} + +int kerning(font_desc_t *desc, int prevc, int c) +{ + FT_Vector kern; + + if (!desc->dynamic) return 0; + if (prevc < 0 || c < 0) return 0; + if (desc->font[prevc] != desc->font[c]) return 0; + if (desc->font[prevc] == -1 || desc->font[c] == -1) return 0; + FT_Get_Kerning(desc->faces[desc->font[c]], + desc->glyph_index[prevc], desc->glyph_index[c], + ft_kerning_default, &kern); + +// fprintf(stderr, "kern: %c %c %d\n", prevc, c, f266ToInt(kern.x)); + + return f266ToInt(kern.x); +} + +font_desc_t* read_font_desc_ft(const char *fname, int face_index, int movie_width, int movie_height, float font_scale_factor) +{ + font_desc_t *desc = NULL; + + FT_Face face; + + FT_ULong *my_charset = malloc(MAX_CHARSET_SIZE * sizeof(FT_ULong)); /* characters we want to render; Unicode */ + FT_ULong *my_charcodes = malloc(MAX_CHARSET_SIZE * sizeof(FT_ULong)); /* character codes in 'encoding' */ + + char *charmap = "ucs-4"; + int err; + int charset_size; + int i, j; + int unicode; + + float movie_size; + + float subtitle_font_ppem; + float osd_font_ppem; + + if (my_charset == NULL || my_charcodes == NULL) { + mp_msg(MSGT_OSD, MSGL_ERR, "subtitle font: malloc failed.\n"); + goto err_out; + } + + switch (subtitle_autoscale) { + case 1: + movie_size = movie_height; + break; + case 2: + movie_size = movie_width; + break; + case 3: + movie_size = sqrt(movie_height*movie_height+movie_width*movie_width); + break; + default: + movie_size = 100; + break; + } + + subtitle_font_ppem = movie_size*font_scale_factor/100.0; + osd_font_ppem = movie_size*(font_scale_factor+1)/100.0; + + if (subtitle_font_ppem < 5) subtitle_font_ppem = 5; + if (osd_font_ppem < 5) osd_font_ppem = 5; + + if (subtitle_font_ppem > 128) subtitle_font_ppem = 128; + if (osd_font_ppem > 128) osd_font_ppem = 128; + + if ((subtitle_font_encoding == NULL) + || (strcasecmp(subtitle_font_encoding, "unicode") == 0)) { + unicode = 1; + } else { + unicode = 0; + } + + desc = init_font_desc(); + if(!desc) goto err_out; + +// t=GetTimer(); + + /* generate the subtitle font */ + err = load_sub_face(fname, face_index, &face); + if (err) { + mp_tmsg(MSGT_OSD, MSGL_WARN, "subtitle font: load_sub_face failed.\n"); + goto gen_osd; + } + desc->face_cnt++; + +#ifdef CONFIG_ICONV + if (unicode) { + charset_size = prepare_charset_unicode(face, my_charset, my_charcodes); + } else { + if (subtitle_font_encoding) { + charset_size = prepare_charset(charmap, subtitle_font_encoding, my_charset, my_charcodes); + } else { + charset_size = prepare_charset(charmap, "iso-8859-1", my_charset, my_charcodes); + } + } + + if (charset_size < 0) { + mp_tmsg(MSGT_OSD, MSGL_ERR, "subtitle font: prepare_charset failed.\n"); + goto err_out; + } +#else + goto err_out; +#endif + +// fprintf(stderr, "fg: prepare t = %f\n", GetTimer()-t); + + err = prepare_font(desc, face, subtitle_font_ppem, desc->face_cnt-1, + charset_size, my_charset, my_charcodes, unicode, + subtitle_font_thickness, subtitle_font_radius); + + if (err) { + mp_tmsg(MSGT_OSD, MSGL_ERR, "Cannot prepare subtitle font.\n"); + goto err_out; + } + +gen_osd: + + /* generate the OSD font */ + err = load_osd_face(&face); + if (err) { + goto err_out; + } + desc->face_cnt++; + + err = prepare_font(desc, face, osd_font_ppem, desc->face_cnt-1, + OSD_CHARSET_SIZE, osd_charset, osd_charcodes, 0, + subtitle_font_thickness, subtitle_font_radius); + + if (err) { + mp_tmsg(MSGT_OSD, MSGL_ERR, "Cannot prepare OSD font.\n"); + goto err_out; + } + + err = generate_tables(desc, subtitle_font_thickness, subtitle_font_radius); + + if (err) { + mp_tmsg(MSGT_OSD, MSGL_ERR, "Cannot generate tables.\n"); + goto err_out; + } + + // final cleanup + desc->font[' ']=-1; + desc->width[' ']=desc->spacewidth; + + j = '_'; + if (desc->font[j] < 0) j = '?'; + if (desc->font[j] < 0) j = ' '; + render_one_glyph(desc, j); + for(i = 0; i < 65536; i++) { + if (desc->font[i] < 0 && i != ' ') { + desc->start[i] = desc->start[j]; + desc->width[i] = desc->width[j]; + desc->font[i] = desc->font[j]; + } + } + free(my_charset); + free(my_charcodes); + return desc; + +err_out: + if (desc) + free_font_desc(desc); + free(my_charset); + free(my_charcodes); + return NULL; +} + +int init_freetype(void) +{ + int err; + + /* initialize freetype */ + err = FT_Init_FreeType(&library); + if (err) { + mp_msg(MSGT_OSD, MSGL_ERR, "Init_FreeType failed.\n"); + return -1; + } + mp_msg(MSGT_OSD, MSGL_V, "init_freetype\n"); + using_freetype = 1; + return 0; +} + +int done_freetype(void) +{ + int err; + + if (!using_freetype) + return 0; + + err = FT_Done_FreeType(library); + if (err) { + mp_tmsg(MSGT_OSD, MSGL_ERR, "FT_Done_FreeType failed.\n"); + return -1; + } + + return 0; +} + +void load_font_ft(int width, int height, font_desc_t** fontp, const char *font_name, float font_scale_factor) +{ +#ifdef CONFIG_FONTCONFIG + FcPattern *fc_pattern; + FcPattern *fc_pattern2; + FcChar8 *s; + int face_index; + FcBool scalable; + FcResult result; +#endif + font_desc_t *vo_font = *fontp; + vo_image_width = width; + vo_image_height = height; + + // protection against vo_aa font hacks + if (vo_font && !vo_font->dynamic) return; + + if (vo_font) free_font_desc(vo_font); + +#ifdef CONFIG_FONTCONFIG + if (font_fontconfig > 0) + { + FcInit(); + fc_pattern = FcNameParse(font_name ? font_name : "sans-serif"); + FcConfigSubstitute(0, fc_pattern, FcMatchPattern); + FcDefaultSubstitute(fc_pattern); + fc_pattern2 = fc_pattern; + fc_pattern = FcFontMatch(0, fc_pattern, &result); + if (fc_pattern) { + FcPatternDestroy(fc_pattern2); + FcPatternGetBool(fc_pattern, FC_SCALABLE, 0, &scalable); + if (scalable != FcTrue) { + FcPatternDestroy(fc_pattern); + fc_pattern = FcNameParse("sans-serif"); + FcConfigSubstitute(0, fc_pattern, FcMatchPattern); + FcDefaultSubstitute(fc_pattern); + fc_pattern2 = fc_pattern; + fc_pattern = FcFontMatch(0, fc_pattern, 0); + FcPatternDestroy(fc_pattern2); + } + // s doesn't need to be freed according to fontconfig docs + FcPatternGetString(fc_pattern, FC_FILE, 0, &s); + FcPatternGetInteger(fc_pattern, FC_INDEX, 0, &face_index); + *fontp=read_font_desc_ft(s, face_index, width, height, font_scale_factor); + FcPatternDestroy(fc_pattern); + return; + } + mp_tmsg(MSGT_OSD, MSGL_ERR, "Fontconfig failed to select a font. " + "Trying without fontconfig...\n"); + } +#endif + *fontp=read_font_desc_ft(font_name, 0, width, height, font_scale_factor); +} diff --git a/sub/osd_font.h b/sub/osd_font.h new file mode 100644 index 0000000000..6be45bc1fa --- /dev/null +++ b/sub/osd_font.h @@ -0,0 +1,545 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPLAYER_OSD_FONT_H +#define MPLAYER_OSD_FONT_H + +const unsigned char osd_font_pfb[] = { +0x80,0x01,0x02,0x17,0x00,0x00,0x25,0x21,0x50,0x53,0x2d,0x41,0x64,0x6f,0x62,0x65, +0x46,0x6f,0x6e,0x74,0x2d,0x31,0x2e,0x30,0x3a,0x20,0x4f,0x53,0x44,0x20,0x31,0x2e, +0x30,0x30,0x0a,0x25,0x25,0x43,0x72,0x65,0x61,0x74,0x69,0x6f,0x6e,0x44,0x61,0x74, +0x65,0x3a,0x20,0x53,0x75,0x6e,0x20,0x4a,0x75,0x6c,0x20,0x32,0x32,0x20,0x31,0x32, +0x3a,0x33,0x38,0x3a,0x32,0x38,0x20,0x32,0x30,0x30,0x31,0x0a,0x25,0x0a,0x25,0x25, +0x45,0x6e,0x64,0x43,0x6f,0x6d,0x6d,0x65,0x6e,0x74,0x73,0x0a,0x31,0x32,0x20,0x64, +0x69,0x63,0x74,0x20,0x62,0x65,0x67,0x69,0x6e,0x0a,0x2f,0x46,0x6f,0x6e,0x74,0x49, +0x6e,0x66,0x6f,0x20,0x39,0x20,0x64,0x69,0x63,0x74,0x20,0x64,0x75,0x70,0x20,0x62, +0x65,0x67,0x69,0x6e,0x0a,0x2f,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x28,0x56, +0x65,0x72,0x73,0x69,0x6f,0x6e,0x20,0x31,0x2e,0x30,0x30,0x29,0x20,0x72,0x65,0x61, +0x64,0x6f,0x6e,0x6c,0x79,0x20,0x64,0x65,0x66,0x0a,0x2f,0x4e,0x6f,0x74,0x69,0x63, +0x65,0x20,0x28,0x54,0x68,0x69,0x73,0x20,0x69,0x73,0x20,0x67,0x65,0x6e,0x65,0x72, +0x61,0x74,0x65,0x64,0x20,0x66,0x69,0x6c,0x65,0x2e,0x29,0x20,0x72,0x65,0x61,0x64, +0x6f,0x6e,0x6c,0x79,0x20,0x64,0x65,0x66,0x0a,0x2f,0x46,0x75,0x6c,0x6c,0x4e,0x61, +0x6d,0x65,0x20,0x28,0x4f,0x53,0x44,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c, +0x79,0x20,0x64,0x65,0x66,0x0a,0x2f,0x46,0x61,0x6d,0x69,0x6c,0x79,0x4e,0x61,0x6d, +0x65,0x20,0x28,0x4f,0x53,0x44,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79, +0x20,0x64,0x65,0x66,0x0a,0x2f,0x57,0x65,0x69,0x67,0x68,0x74,0x20,0x28,0x52,0x65, +0x67,0x75,0x6c,0x61,0x72,0x29,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79,0x20, +0x64,0x65,0x66,0x0a,0x2f,0x49,0x74,0x61,0x6c,0x69,0x63,0x41,0x6e,0x67,0x6c,0x65, +0x20,0x30,0x2e,0x30,0x30,0x30,0x30,0x30,0x30,0x20,0x64,0x65,0x66,0x0a,0x2f,0x69, +0x73,0x46,0x69,0x78,0x65,0x64,0x50,0x69,0x74,0x63,0x68,0x20,0x66,0x61,0x6c,0x73, +0x65,0x20,0x64,0x65,0x66,0x0a,0x2f,0x55,0x6e,0x64,0x65,0x72,0x6c,0x69,0x6e,0x65, +0x50,0x6f,0x73,0x69,0x74,0x69,0x6f,0x6e,0x20,0x2d,0x31,0x33,0x33,0x20,0x64,0x65, +0x66,0x0a,0x2f,0x55,0x6e,0x64,0x65,0x72,0x6c,0x69,0x6e,0x65,0x54,0x68,0x69,0x63, +0x6b,0x6e,0x65,0x73,0x73,0x20,0x34,0x39,0x20,0x64,0x65,0x66,0x0a,0x65,0x6e,0x64, +0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79,0x20,0x64,0x65,0x66,0x0a,0x2f,0x46, +0x6f,0x6e,0x74,0x4e,0x61,0x6d,0x65,0x20,0x2f,0x4f,0x53,0x44,0x20,0x64,0x65,0x66, +0x0a,0x2f,0x50,0x61,0x69,0x6e,0x74,0x54,0x79,0x70,0x65,0x20,0x30,0x20,0x64,0x65, +0x66,0x0a,0x2f,0x53,0x74,0x72,0x6f,0x6b,0x65,0x57,0x69,0x64,0x74,0x68,0x20,0x30, +0x20,0x64,0x65,0x66,0x0a,0x2f,0x46,0x6f,0x6e,0x74,0x4d,0x61,0x74,0x72,0x69,0x78, +0x20,0x5b,0x30,0x2e,0x30,0x30,0x31,0x20,0x30,0x20,0x30,0x20,0x30,0x2e,0x30,0x30, +0x31,0x20,0x30,0x20,0x30,0x5d,0x20,0x64,0x65,0x66,0x0a,0x2f,0x46,0x6f,0x6e,0x74, +0x42,0x42,0x6f,0x78,0x20,0x7b,0x30,0x20,0x2d,0x31,0x30,0x20,0x31,0x30,0x30,0x30, +0x20,0x38,0x31,0x30,0x7d,0x20,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c,0x79,0x20,0x64, +0x65,0x66,0x0a,0x2f,0x45,0x6e,0x63,0x6f,0x64,0x69,0x6e,0x67,0x20,0x32,0x35,0x36, +0x20,0x61,0x72,0x72,0x61,0x79,0x0a,0x64,0x75,0x70,0x20,0x30,0x20,0x2f,0x2e,0x6e, +0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x20, +0x2f,0x75,0x6e,0x69,0x45,0x30,0x30,0x31,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x32,0x20,0x2f,0x75,0x6e,0x69,0x45,0x30,0x30,0x32,0x20,0x70,0x75,0x74,0x0a, +0x64,0x75,0x70,0x20,0x33,0x20,0x2f,0x75,0x6e,0x69,0x45,0x30,0x30,0x33,0x20,0x70, +0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x34,0x20,0x2f,0x75,0x6e,0x69,0x45,0x30,0x30, +0x34,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x35,0x20,0x2f,0x75,0x6e,0x69, +0x45,0x30,0x30,0x35,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x36,0x20,0x2f, +0x75,0x6e,0x69,0x45,0x30,0x30,0x36,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20, +0x37,0x20,0x2f,0x75,0x6e,0x69,0x45,0x30,0x30,0x37,0x20,0x70,0x75,0x74,0x0a,0x64, +0x75,0x70,0x20,0x38,0x20,0x2f,0x75,0x6e,0x69,0x45,0x30,0x30,0x38,0x20,0x70,0x75, +0x74,0x0a,0x64,0x75,0x70,0x20,0x39,0x20,0x2f,0x75,0x6e,0x69,0x45,0x30,0x30,0x39, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x30,0x20,0x2f,0x75,0x6e,0x69, +0x45,0x30,0x30,0x41,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x31,0x20, +0x2f,0x75,0x6e,0x69,0x45,0x30,0x30,0x42,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x31,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x31,0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x34,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x35,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x31,0x36,0x20,0x2f,0x75,0x6e,0x69,0x45,0x30,0x31,0x30,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x31,0x37,0x20,0x2f,0x75,0x6e,0x69,0x45,0x30,0x31,0x31, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x38,0x20,0x2f,0x75,0x6e,0x69, +0x45,0x30,0x31,0x32,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x39,0x20, +0x2f,0x75,0x6e,0x69,0x45,0x30,0x31,0x33,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x32,0x30,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x32,0x31,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x32,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x33,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x32,0x34,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x32,0x35,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x36,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x37,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x32,0x38,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x32,0x39,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x33,0x30,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x33,0x31,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x33,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x33,0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x33,0x34,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x33,0x35,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x33,0x36,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x33,0x37,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x33,0x38,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x33,0x39,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x34,0x30,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x34,0x31,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x34,0x32,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x34,0x33,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x34,0x34,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x34,0x35,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x34,0x36,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x34,0x37,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x34,0x38,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x34,0x39,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x35,0x30,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x35,0x31,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x35,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x35,0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x35,0x34,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x35,0x35,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x35,0x36,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x35,0x37,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x35,0x38,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x35,0x39,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x36,0x30,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x36,0x31,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x36,0x32,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x36,0x33,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x36,0x34,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x36,0x35,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x36,0x36,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x36,0x37,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x36,0x38,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x36,0x39,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x37,0x30,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x37,0x31,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x37,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x37,0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x37,0x34,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x37,0x35,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x37,0x36,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x37,0x37,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x37,0x38,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x37,0x39,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x38,0x30,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x38,0x31,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x38,0x32,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x38,0x33,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x38,0x34,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x38,0x35,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x38,0x36,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x38,0x37,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x38,0x38,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x38,0x39,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x39,0x30,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x39,0x31,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x39,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x39,0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x39,0x34,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x39,0x35,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x39,0x36,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x39,0x37,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x39,0x38,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x39,0x39,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x31,0x30,0x30,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75, +0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x30,0x31,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64, +0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x30,0x32,0x20,0x2f, +0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20, +0x31,0x30,0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x31,0x30,0x34,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65, +0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x30,0x35,0x20,0x2f,0x2e, +0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31, +0x30,0x36,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a, +0x64,0x75,0x70,0x20,0x31,0x30,0x37,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x30,0x38,0x20,0x2f,0x2e,0x6e, +0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x30, +0x39,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64, +0x75,0x70,0x20,0x31,0x31,0x30,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20, +0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x31,0x31,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x31,0x32, +0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75, +0x70,0x20,0x31,0x31,0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70, +0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x31,0x34,0x20,0x2f,0x2e,0x6e,0x6f,0x74, +0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x31,0x35,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x31,0x31,0x36,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75, +0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x31,0x37,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64, +0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x31,0x38,0x20,0x2f, +0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20, +0x31,0x31,0x39,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x31,0x32,0x30,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65, +0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x32,0x31,0x20,0x2f,0x2e, +0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31, +0x32,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a, +0x64,0x75,0x70,0x20,0x31,0x32,0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x32,0x34,0x20,0x2f,0x2e,0x6e, +0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x32, +0x35,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64, +0x75,0x70,0x20,0x31,0x32,0x36,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20, +0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x32,0x37,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x32,0x38, +0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75, +0x70,0x20,0x31,0x32,0x39,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70, +0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x33,0x30,0x20,0x2f,0x2e,0x6e,0x6f,0x74, +0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x33,0x31,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x31,0x33,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75, +0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x33,0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64, +0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x33,0x34,0x20,0x2f, +0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20, +0x31,0x33,0x35,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x31,0x33,0x36,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65, +0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x33,0x37,0x20,0x2f,0x2e, +0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31, +0x33,0x38,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a, +0x64,0x75,0x70,0x20,0x31,0x33,0x39,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x34,0x30,0x20,0x2f,0x2e,0x6e, +0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x34, +0x31,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64, +0x75,0x70,0x20,0x31,0x34,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20, +0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x34,0x33,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x34,0x34, +0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75, +0x70,0x20,0x31,0x34,0x35,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70, +0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x34,0x36,0x20,0x2f,0x2e,0x6e,0x6f,0x74, +0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x34,0x37,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x31,0x34,0x38,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75, +0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x34,0x39,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64, +0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x35,0x30,0x20,0x2f, +0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20, +0x31,0x35,0x31,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x31,0x35,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65, +0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x35,0x33,0x20,0x2f,0x2e, +0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31, +0x35,0x34,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a, +0x64,0x75,0x70,0x20,0x31,0x35,0x35,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x35,0x36,0x20,0x2f,0x2e,0x6e, +0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x35, +0x37,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64, +0x75,0x70,0x20,0x31,0x35,0x38,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20, +0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x35,0x39,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x36,0x30, +0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75, +0x70,0x20,0x31,0x36,0x31,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70, +0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x36,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74, +0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x36,0x33,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x31,0x36,0x34,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75, +0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x36,0x35,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64, +0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x36,0x36,0x20,0x2f, +0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20, +0x31,0x36,0x37,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x31,0x36,0x38,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65, +0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x36,0x39,0x20,0x2f,0x2e, +0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31, +0x37,0x30,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a, +0x64,0x75,0x70,0x20,0x31,0x37,0x31,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x37,0x32,0x20,0x2f,0x2e,0x6e, +0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x37, +0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64, +0x75,0x70,0x20,0x31,0x37,0x34,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20, +0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x37,0x35,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x37,0x36, +0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75, +0x70,0x20,0x31,0x37,0x37,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70, +0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x37,0x38,0x20,0x2f,0x2e,0x6e,0x6f,0x74, +0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x37,0x39,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x31,0x38,0x30,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75, +0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x38,0x31,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64, +0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x38,0x32,0x20,0x2f, +0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20, +0x31,0x38,0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x31,0x38,0x34,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65, +0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x38,0x35,0x20,0x2f,0x2e, +0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31, +0x38,0x36,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a, +0x64,0x75,0x70,0x20,0x31,0x38,0x37,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x38,0x38,0x20,0x2f,0x2e,0x6e, +0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x38, +0x39,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64, +0x75,0x70,0x20,0x31,0x39,0x30,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20, +0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x39,0x31,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x39,0x32, +0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75, +0x70,0x20,0x31,0x39,0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70, +0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x39,0x34,0x20,0x2f,0x2e,0x6e,0x6f,0x74, +0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x39,0x35,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x31,0x39,0x36,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75, +0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x39,0x37,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64, +0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x31,0x39,0x38,0x20,0x2f, +0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20, +0x31,0x39,0x39,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x32,0x30,0x30,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65, +0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x30,0x31,0x20,0x2f,0x2e, +0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32, +0x30,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a, +0x64,0x75,0x70,0x20,0x32,0x30,0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x30,0x34,0x20,0x2f,0x2e,0x6e, +0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x30, +0x35,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64, +0x75,0x70,0x20,0x32,0x30,0x36,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20, +0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x30,0x37,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x30,0x38, +0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75, +0x70,0x20,0x32,0x30,0x39,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70, +0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x31,0x30,0x20,0x2f,0x2e,0x6e,0x6f,0x74, +0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x31,0x31,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x32,0x31,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75, +0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x31,0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64, +0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x31,0x34,0x20,0x2f, +0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20, +0x32,0x31,0x35,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x32,0x31,0x36,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65, +0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x31,0x37,0x20,0x2f,0x2e, +0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32, +0x31,0x38,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a, +0x64,0x75,0x70,0x20,0x32,0x31,0x39,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x32,0x30,0x20,0x2f,0x2e,0x6e, +0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x32, +0x31,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64, +0x75,0x70,0x20,0x32,0x32,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20, +0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x32,0x33,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x32,0x34, +0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75, +0x70,0x20,0x32,0x32,0x35,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70, +0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x32,0x36,0x20,0x2f,0x2e,0x6e,0x6f,0x74, +0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x32,0x37,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x32,0x32,0x38,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75, +0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x32,0x39,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64, +0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x33,0x30,0x20,0x2f, +0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20, +0x32,0x33,0x31,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x32,0x33,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65, +0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x33,0x33,0x20,0x2f,0x2e, +0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32, +0x33,0x34,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a, +0x64,0x75,0x70,0x20,0x32,0x33,0x35,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x33,0x36,0x20,0x2f,0x2e,0x6e, +0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x33, +0x37,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64, +0x75,0x70,0x20,0x32,0x33,0x38,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20, +0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x33,0x39,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x34,0x30, +0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75, +0x70,0x20,0x32,0x34,0x31,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70, +0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x34,0x32,0x20,0x2f,0x2e,0x6e,0x6f,0x74, +0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x34,0x33,0x20, +0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70, +0x20,0x32,0x34,0x34,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75, +0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x34,0x35,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64, +0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x34,0x36,0x20,0x2f, +0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20, +0x32,0x34,0x37,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74, +0x0a,0x64,0x75,0x70,0x20,0x32,0x34,0x38,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65, +0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x34,0x39,0x20,0x2f,0x2e, +0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32, +0x35,0x30,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a, +0x64,0x75,0x70,0x20,0x32,0x35,0x31,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66, +0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x35,0x32,0x20,0x2f,0x2e,0x6e, +0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x35, +0x33,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x64, +0x75,0x70,0x20,0x32,0x35,0x34,0x20,0x2f,0x2e,0x6e,0x6f,0x74,0x64,0x65,0x66,0x20, +0x70,0x75,0x74,0x0a,0x64,0x75,0x70,0x20,0x32,0x35,0x35,0x20,0x2f,0x2e,0x6e,0x6f, +0x74,0x64,0x65,0x66,0x20,0x70,0x75,0x74,0x0a,0x72,0x65,0x61,0x64,0x6f,0x6e,0x6c, +0x79,0x20,0x64,0x65,0x66,0x0a,0x63,0x75,0x72,0x72,0x65,0x6e,0x74,0x64,0x69,0x63, +0x74,0x20,0x65,0x6e,0x64,0x0a,0x63,0x75,0x72,0x72,0x65,0x6e,0x74,0x66,0x69,0x6c, +0x65,0x20,0x65,0x65,0x78,0x65,0x63,0x0a,0x80,0x02,0x64,0x07,0x00,0x00,0xd9,0xd6, +0x6f,0x63,0x3b,0x84,0x6a,0x98,0x9b,0x99,0x74,0xb0,0x17,0x9f,0xc6,0xcc,0x44,0x5b, +0xc2,0xc0,0x31,0x03,0xc6,0x85,0x70,0xa7,0xb3,0x54,0xa4,0xa2,0x80,0xae,0x6f,0xbf, +0x7f,0x98,0x88,0xe0,0x62,0xac,0xe9,0x21,0x16,0xed,0xa3,0x16,0x4a,0xb4,0x31,0xb6, +0xaa,0x5d,0x94,0xf1,0xc3,0x04,0x34,0xfb,0xeb,0xfd,0x8d,0xb1,0xf9,0xaf,0xd6,0x14, +0x0e,0x48,0xa2,0xd1,0xdf,0x43,0xa3,0x52,0xac,0xb2,0xa0,0x05,0xe8,0xd4,0x3c,0xdf, +0x44,0xb0,0xfb,0x04,0xb4,0x6b,0xf5,0x7c,0xb2,0x5a,0xcf,0x59,0x2b,0xa6,0x84,0xf3, +0xb8,0x18,0x21,0xbe,0xfe,0xf4,0xfd,0x83,0x30,0x31,0x19,0x63,0x70,0x76,0xcc,0x17, +0x8d,0xf5,0xbb,0x1b,0x08,0xb2,0x39,0x99,0x74,0x40,0xfc,0xe8,0xa5,0x75,0xb0,0xe8, +0x06,0x4f,0x42,0xa4,0xed,0x7b,0xd4,0xde,0x19,0xf8,0x85,0x97,0x5a,0x82,0xe9,0x7a, +0xda,0xf9,0xe9,0x9e,0x70,0x7f,0xd5,0xd6,0x50,0x4e,0x24,0xfe,0xad,0xb3,0xd1,0x83, +0xb0,0x63,0x04,0xb0,0x43,0x5d,0xcf,0xe8,0xe0,0xf7,0x01,0xb5,0xae,0x80,0xa2,0xab, +0xf3,0xf9,0x02,0x5e,0xe4,0x71,0x0d,0x72,0x9d,0x9a,0xfd,0x81,0x96,0xc5,0xde,0x19, +0xf8,0xbc,0x12,0xc0,0x52,0xc0,0xa8,0x55,0x8c,0x7f,0xa0,0x5f,0x84,0x46,0x75,0x46, +0xfc,0x13,0x5e,0x05,0x11,0xce,0xfc,0xd4,0x96,0xfd,0xf0,0xa9,0xc4,0xbb,0xcf,0x07, +0x97,0x37,0x93,0xc2,0xab,0x48,0x78,0xa5,0x80,0xc2,0xf6,0xfa,0x62,0x90,0x77,0x74, +0x29,0x53,0x8e,0xcc,0x7c,0xb2,0x30,0xd2,0x4c,0x74,0xe5,0xd9,0x8c,0x5a,0x06,0x83, +0x90,0x47,0xd8,0xbb,0x48,0x86,0x93,0xbf,0xdb,0x87,0x79,0xca,0xaf,0xd0,0xb0,0x8b, +0x3d,0x0e,0x27,0xc0,0xda,0xda,0x4e,0xf9,0xc7,0x77,0x11,0xff,0x10,0xc9,0x6a,0x74, +0xfb,0xe5,0x0d,0xd2,0x43,0x70,0x44,0xbb,0x41,0xf3,0x15,0x92,0x57,0x90,0xd9,0x47, +0x6f,0x46,0x8e,0x4a,0x56,0x72,0x4f,0x39,0xee,0xfc,0x19,0x45,0xb2,0x89,0x9a,0xf0, +0xa7,0x0f,0x14,0x78,0xaf,0xf3,0x87,0x09,0x86,0xd9,0xfa,0x4b,0x3e,0x72,0x96,0xc1, +0x3b,0x39,0xfa,0x7e,0x7c,0x2e,0xa2,0xd0,0x78,0xa9,0xce,0x4f,0x3d,0x0c,0x71,0x3e, +0xca,0x52,0xa0,0x3a,0xe9,0x33,0xe8,0x9b,0x41,0xc6,0xec,0x13,0x2d,0x22,0x8a,0x66, +0x21,0xc1,0x8f,0x98,0xce,0xa5,0xf9,0xe5,0x44,0x76,0xb4,0xc8,0x46,0x8d,0xcd,0x65, +0xc9,0x61,0xdf,0xa7,0xa9,0xd7,0x58,0x0a,0xc1,0x5b,0xc8,0xd9,0x87,0xda,0xc6,0x1e, +0x8b,0x64,0xca,0x08,0x75,0x5a,0x86,0xba,0xb2,0x57,0x96,0x23,0xfb,0xf9,0xb2,0x42, +0xd5,0x13,0x8f,0xaa,0x7e,0x97,0xa2,0xd6,0x0e,0x17,0xcb,0xdf,0x6f,0xdb,0xb0,0xb2, +0x68,0x8a,0xf6,0x9b,0x6c,0x9f,0x77,0xd7,0x33,0xa9,0x36,0x1f,0x50,0xe1,0xa0,0x1f, +0xd9,0xb8,0x3b,0xa9,0x1c,0x2b,0x1e,0xa4,0x31,0x24,0x5b,0x48,0x95,0xc1,0x26,0x3f, +0x62,0x24,0x71,0x2e,0xe6,0xae,0xdd,0xd0,0xa1,0x51,0x83,0x2c,0x3b,0x2d,0x14,0xea, +0x94,0xda,0x77,0x87,0xe2,0xd2,0x97,0x4d,0x5a,0x28,0x6b,0x64,0x19,0x37,0xc9,0x3f, +0x90,0x66,0xb8,0x91,0x2f,0x17,0xd6,0xb6,0xa9,0x55,0xc1,0x7b,0x04,0xb0,0x96,0xa0, +0x34,0x9a,0x14,0xea,0x12,0xf0,0x33,0xc3,0xc2,0x79,0x2a,0x42,0x33,0x8d,0x75,0x17, +0xf4,0x05,0x79,0x36,0x89,0x22,0x8d,0xdb,0xd6,0x28,0xae,0xaa,0x22,0x0c,0x86,0x60, +0xe0,0x66,0x5c,0x7a,0x43,0x0b,0x7f,0xd4,0x74,0x59,0x48,0x2b,0xd8,0xb7,0xd1,0x05, +0xee,0xbe,0x91,0xe4,0x67,0x8d,0x4d,0xd2,0x25,0xe0,0x13,0xd7,0x85,0x53,0x8b,0x9c, +0xd0,0x5f,0x09,0x09,0xfd,0xff,0xe1,0x59,0x37,0xe4,0x6d,0x9e,0x65,0x34,0x2e,0xfd, +0x34,0x67,0x2a,0x1d,0x6e,0xc6,0x51,0x4d,0x69,0x55,0x9c,0xf7,0xfc,0xe7,0x4e,0x75, +0xd5,0x2c,0x01,0xd5,0x70,0x29,0x8b,0xd0,0x6a,0xa5,0x69,0x1c,0x98,0x98,0x81,0xda, +0xbf,0xc0,0x8a,0xf6,0x30,0x6c,0xf9,0xb0,0x0d,0xf4,0xf9,0x6a,0x35,0x55,0x02,0x2d, +0x97,0xe6,0xd0,0x15,0xa8,0xbe,0xf5,0x80,0xe0,0x73,0xd5,0xb8,0xae,0xdc,0x5b,0x6a, +0xa2,0x4d,0x67,0x7d,0x61,0xcd,0xa9,0xf0,0xe0,0x0a,0x63,0x3e,0x03,0x01,0x7d,0xcf, +0x56,0x91,0x48,0x74,0x65,0x4c,0xdc,0xcd,0xe3,0xfe,0xdf,0xc0,0x82,0x5e,0x25,0xb4, +0xea,0x04,0xe0,0x6f,0x16,0x5b,0x94,0x5d,0xf7,0x62,0xce,0xc3,0xa8,0xb9,0x9b,0x0f, +0xd9,0x5c,0x92,0x56,0x59,0x58,0x41,0x50,0x85,0xbb,0x20,0x13,0xcc,0xff,0xa9,0xd0, +0xa1,0x88,0x91,0x02,0x4e,0x44,0xe6,0x2e,0x36,0xc1,0x8b,0x53,0xb5,0xc7,0x47,0xad, +0xb1,0x10,0xe7,0xb7,0x1c,0x27,0xbf,0xf0,0x16,0x79,0x39,0xaa,0x4f,0xa4,0x05,0x79, +0x00,0x7f,0x3f,0xc6,0xfc,0x0f,0xf9,0x6b,0x21,0xbf,0x57,0x9f,0x64,0x10,0xfe,0xcd, +0xd9,0x80,0x1c,0xab,0xb0,0x21,0x6a,0x84,0x4e,0x8a,0x07,0x93,0xc6,0x76,0x54,0x41, +0x8e,0x2d,0x2d,0x72,0xc9,0x52,0xa2,0x16,0xdf,0x0d,0x84,0x09,0x43,0x88,0x3e,0x25, +0x21,0x5a,0xf3,0x28,0xec,0x4d,0x08,0x41,0xce,0x55,0x7e,0xf9,0x34,0x54,0xcc,0xa2, +0x2d,0xe0,0x95,0x4a,0x78,0xd5,0x8c,0xd4,0xd4,0x1b,0x3c,0x17,0xe0,0xb7,0x2f,0xf5, +0x8a,0xc7,0x2b,0x71,0x2a,0x42,0x44,0x04,0x58,0xcf,0x03,0x1a,0x43,0x2e,0xf5,0xf0, +0x68,0xbf,0x90,0x54,0x83,0xc8,0x57,0xed,0xbb,0xbc,0xc0,0x07,0x13,0x7d,0x71,0x17, +0x37,0x2c,0x3e,0x3c,0xce,0x31,0xdb,0x68,0xac,0xd4,0x8c,0xca,0xd7,0x6e,0x52,0x51, +0x0a,0x2d,0xa0,0x09,0xbf,0xfa,0x80,0xce,0xd9,0xe8,0x2c,0xfa,0x34,0xce,0x8c,0x85, +0x95,0xd5,0x7a,0xd3,0x63,0x02,0x49,0x44,0x4e,0xee,0x34,0xa9,0x23,0x56,0x88,0x69, +0xf1,0xf8,0x6d,0x28,0xc9,0x2d,0xd2,0x63,0x72,0x64,0xe2,0xd7,0xb6,0x6a,0x74,0xb8, +0xf3,0xda,0xca,0x56,0xa9,0xbd,0xff,0x04,0x03,0xca,0xc2,0x08,0x27,0x54,0x17,0x5c, +0xa1,0x71,0xb4,0x32,0x70,0x85,0x52,0x0a,0xc0,0x65,0x37,0x97,0x9f,0xb5,0xef,0xe6, +0x26,0xc5,0xad,0x7b,0x2a,0x2a,0xd9,0x39,0xb2,0x27,0x56,0x43,0xf6,0x4a,0xce,0x84, +0x3e,0x90,0x97,0xe3,0x62,0xcc,0xe5,0xa6,0x2c,0x4a,0xf3,0x10,0x91,0xf3,0x37,0x98, +0x61,0x69,0xdf,0x5b,0x11,0x49,0xe0,0x43,0x56,0xed,0xe9,0x03,0x98,0x17,0x6e,0x41, +0xc9,0x55,0xa8,0x77,0x5e,0x02,0xd5,0x08,0x9f,0x04,0x5e,0x18,0x79,0x8d,0xf9,0xed, +0xc7,0x46,0x93,0x4f,0xd7,0xb9,0x46,0x19,0xd4,0x48,0xc7,0xf9,0x73,0x61,0xac,0x5b, +0x3d,0x18,0x52,0x8f,0x73,0xc6,0x77,0xad,0x57,0x3a,0x8a,0xd7,0x3a,0xee,0xae,0xf9, +0x80,0x47,0xbc,0xdb,0x44,0x49,0x01,0x5d,0x9d,0x3e,0xeb,0x1a,0xb3,0x53,0x37,0xca, +0x4b,0x42,0xda,0x09,0xd9,0x4c,0xcd,0x85,0xc0,0x94,0x37,0x22,0x5e,0x74,0x73,0xda, +0x60,0x56,0x4e,0x07,0x0c,0x4d,0x46,0x29,0x66,0x08,0x74,0x80,0xc2,0x38,0xfb,0x76, +0xd5,0x94,0x03,0xa0,0x41,0x3b,0x66,0xc3,0xfa,0x2c,0x1a,0xdd,0x9e,0x5f,0x17,0x77, +0xa1,0x0c,0x8c,0x47,0xc4,0x0d,0x51,0x29,0x47,0xb9,0xb9,0xed,0xbb,0xee,0xde,0xb3, +0xf9,0x33,0xec,0x59,0xda,0x02,0xf9,0xa3,0x6c,0x8c,0x52,0x59,0x8d,0xbc,0x86,0x89, +0xa0,0x0d,0xd0,0x68,0x6d,0xa0,0xb1,0x54,0x0c,0xbc,0x2e,0xe9,0xa0,0x8d,0x2e,0xad, +0x37,0xdb,0x95,0x9b,0xb0,0x77,0xb6,0x4f,0x02,0xba,0x0b,0xe2,0xbd,0x7c,0x4b,0xa7, +0x4d,0xab,0x45,0x96,0x64,0xef,0x2d,0x6b,0x66,0x3e,0x10,0x67,0x79,0x63,0x0a,0x96, +0x7e,0x76,0x98,0xcf,0x4e,0x13,0xa0,0x3c,0x8e,0xbf,0xf3,0xd7,0x60,0x9e,0xb9,0xd0, +0xe0,0xbd,0x14,0xfb,0x89,0xaf,0x2d,0xcf,0xd7,0x90,0x22,0xc1,0x77,0x54,0x4a,0x6c, +0x42,0x5c,0xab,0x68,0x75,0xbd,0xeb,0x05,0x3e,0x5e,0x3b,0xfb,0x1a,0x87,0xc6,0x20, +0x15,0x3f,0x62,0x03,0xf7,0x7d,0xf6,0x9c,0x1d,0x5f,0x80,0x93,0x13,0xb6,0x76,0xbe, +0x90,0xbc,0x1d,0x87,0x66,0xa4,0xfe,0xfd,0x11,0x91,0x1f,0x8f,0x1e,0x35,0x9b,0x88, +0x59,0xf6,0x85,0x8f,0x07,0xe9,0x15,0x45,0x59,0x07,0xf4,0xb5,0x66,0x1a,0xcd,0x19, +0x12,0xe0,0xe4,0x88,0x5d,0xc9,0x8c,0xa6,0x9b,0x23,0x29,0x19,0x07,0x89,0xe5,0x4a, +0x83,0xc7,0xcf,0xf5,0x10,0xc5,0x80,0x56,0xde,0x3e,0xa7,0x68,0x8b,0x71,0x15,0x63, +0x12,0x24,0x12,0xbb,0xc4,0xb0,0xfe,0x65,0x4f,0xe9,0xe9,0x13,0x80,0xbf,0x3a,0x33, +0xbd,0xba,0x9f,0x70,0x42,0x33,0xc4,0x5d,0x3b,0xeb,0x66,0x99,0x0e,0xff,0x66,0x39, +0x1e,0xea,0x00,0x13,0x13,0x49,0xa7,0xef,0x7c,0x55,0xb0,0x36,0x9f,0xe3,0x2d,0x7d, +0x1a,0xb9,0x0e,0x2f,0xff,0x9b,0x03,0xa1,0xaa,0xb6,0x6d,0x7b,0x8d,0xe3,0x0e,0x4b, +0x2b,0x7c,0x96,0xdb,0xb8,0xf0,0xd3,0xa5,0xbf,0xbb,0x3e,0xda,0x95,0xa2,0xc7,0xd2, +0x8e,0x8e,0xdc,0xfe,0x77,0x93,0x4b,0x6e,0x1f,0x13,0x21,0x6a,0x60,0x9f,0x8c,0xe1, +0x05,0x50,0x53,0x58,0x3f,0xdc,0xab,0x20,0x96,0xdb,0xb0,0xb5,0x08,0xdb,0xb9,0xc4, +0x62,0xce,0x47,0x1b,0x0c,0xcd,0xb6,0x78,0xfb,0x68,0x14,0x42,0xf3,0x75,0x3f,0x4f, +0x44,0xec,0x75,0x12,0x7b,0x10,0x0e,0x2b,0x39,0x64,0x2c,0xea,0xaf,0xf2,0x11,0x08, +0xfc,0xca,0x61,0xc1,0xcc,0x8b,0xc7,0xb4,0xc3,0x73,0x7f,0x30,0xc9,0xb8,0x9c,0xa5, +0xce,0xb6,0xa7,0xc4,0x1c,0xf0,0xe6,0x17,0x5a,0x18,0x7e,0x7f,0xbb,0xc0,0x8f,0x08, +0x3d,0xf7,0xa4,0x9a,0x99,0xb4,0x7b,0x4d,0x81,0xfc,0xe1,0x36,0x1b,0xb5,0x9a,0xa7, +0xdc,0xdc,0x6e,0x1c,0xe3,0x4a,0x4e,0x57,0x80,0x86,0xb4,0xfa,0x01,0x94,0x3d,0x92, +0x49,0xa4,0x0f,0x95,0x00,0x57,0xcf,0xe6,0x74,0xd7,0xaf,0x8a,0x93,0x23,0x83,0x67, +0x1f,0xcd,0xb9,0xe1,0x3b,0x9f,0x86,0x04,0x3c,0x6b,0x88,0x5f,0x7f,0x87,0x54,0x98, +0xf7,0x2f,0x0c,0x5c,0x23,0x95,0x11,0xe1,0x01,0x28,0x56,0x5c,0x5e,0x82,0xe2,0x22, +0x12,0x6b,0x1e,0x90,0x27,0x16,0x80,0x50,0x65,0x28,0xc1,0x67,0xf5,0x36,0xf2,0xfb, +0xff,0x30,0xf1,0x06,0x28,0x72,0x2e,0xb8,0x64,0xca,0xa6,0xd0,0x14,0xc7,0x50,0xca, +0xb2,0xa3,0x82,0xda,0xe8,0xb2,0x77,0x60,0xac,0xc9,0x94,0x93,0x8a,0xcf,0xb5,0xfe, +0x28,0x90,0x96,0x1d,0x5c,0x80,0x1e,0xcb,0xf3,0xdb,0x3c,0x3a,0x03,0xeb,0xc7,0x29, +0x2c,0xa2,0x55,0x5e,0x66,0x6b,0xd4,0xa7,0x60,0xa7,0xe9,0x56,0xdc,0x1e,0xf2,0x02, +0x5f,0x49,0xb7,0x29,0x31,0x4f,0x94,0x2b,0xd3,0xd7,0x1a,0x51,0x16,0xe1,0x0b,0x5b, +0xcf,0xa1,0x98,0x70,0x24,0x50,0x11,0x3b,0x97,0x84,0x9f,0x5c,0xdc,0x81,0xfe,0x64, +0x64,0xee,0x2a,0xa5,0x91,0xd3,0x14,0xc6,0x6e,0xe6,0x3b,0xf8,0x77,0x2b,0x35,0xa3, +0x2d,0x6c,0x3b,0xc2,0xd5,0x8e,0x28,0x1a,0x67,0xf0,0x56,0x55,0x11,0xf0,0x78,0x91, +0x81,0xa9,0xf4,0xd2,0xbb,0x06,0xe4,0x21,0x7f,0x9d,0x33,0x49,0x30,0x22,0x06,0x96, +0x85,0x31,0xe6,0xd7,0x9b,0xd0,0x27,0x53,0x6c,0xe2,0x0c,0xcf,0x73,0x0d,0x18,0x26, +0x56,0x21,0xcd,0xf8,0xad,0x1d,0xfb,0x82,0x6b,0x01,0x21,0x45,0x17,0x96,0x11,0x88, +0x27,0xc1,0x2e,0x11,0xa9,0x23,0x95,0xf2,0xbe,0xaa,0xba,0xc7,0xa0,0xf5,0x42,0x21, +0xed,0xa0,0x7d,0x02,0xf8,0xbe,0x58,0x23,0x8f,0xdb,0x0d,0x7b,0xdc,0xd8,0x8f,0xe2, +0xe4,0xd9,0x99,0x26,0x08,0x7b,0x97,0x6b,0x4f,0xfe,0x3f,0x6a,0x49,0xb0,0x8e,0x7b, +0xe5,0xf9,0x0d,0x8c,0x4e,0x39,0x8c,0x95,0x81,0x80,0xd9,0x3a,0xc2,0x9f,0x65,0x3f, +0xd9,0x2f,0xa3,0xd7,0x4c,0xa3,0xf6,0x93,0xd7,0x84,0xb0,0xaf,0x2d,0xe2,0xcd,0x04, +0x56,0x9e,0x63,0x08,0x1b,0x23,0x61,0xad,0xdd,0x17,0xa3,0x94,0x51,0xaa,0x7a,0xd3, +0xac,0x90,0xc2,0x58,0x61,0x86,0xec,0x0e,0x97,0xfc,0x45,0xb4,0x3b,0xa2,0xdc,0xb2, +0xdd,0xe2,0x80,0x01,0x08,0x02,0x00,0x00,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x0a,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x0a,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x0a,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x0a,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x0a,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x0a,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x0a,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30, +0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x0a, +0x80,0x03,}; + +#endif /* MPLAYER_OSD_FONT_H */ diff --git a/sub/sd_ass.c b/sub/sd_ass.c index be2740bfa6..ba5710611e 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -25,7 +25,7 @@ #include "mpcommon.h" #include "libmpdemux/stheader.h" -#include "libvo/sub.h" +#include "sub.h" #include "ass_mp.h" #include "sd.h" #include "subassconvert.h" diff --git a/sub/spudec.c b/sub/spudec.c new file mode 100644 index 0000000000..f48d47fd2a --- /dev/null +++ b/sub/spudec.c @@ -0,0 +1,1390 @@ +/* + * Skeleton of function spudec_process_controll() is from xine sources. + * Further works: + * LGB,... (yeah, try to improve it and insert your name here! ;-) + * + * Kim Minh Kaplan + * implement fragments reassembly, RLE decoding. + * read brightness from the IFO. + * + * For information on SPU format see + * and + * + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include "mp_msg.h" + +#include +#include +#include +#include +#include +#include +#include +#include "libvo/video_out.h" +#include "spudec.h" +#include "vobsub.h" +#include "libavutil/avutil.h" +#include "ffmpeg_files/intreadwrite.h" +#include "libswscale/swscale.h" +#include "mpcommon.h" + +/* Valid values for spu_aamode: + 0: none (fastest, most ugly) + 1: approximate + 2: full (slowest) + 3: bilinear (similiar to vobsub, fast and not too bad) + 4: uses swscaler gaussian (this is the only one that looks good) + */ + +int spu_aamode = 3; +int spu_alignment = -1; +float spu_gaussvar = 1.0; +extern int sub_pos; + +typedef struct packet_t packet_t; +struct packet_t { + int is_decoded; + unsigned char *packet; + int data_len; + unsigned int palette[4]; + unsigned int alpha[4]; + unsigned int control_start; /* index of start of control data */ + unsigned int current_nibble[2]; /* next data nibble (4 bits) to be + processed (for RLE decoding) for + even and odd lines */ + int deinterlace_oddness; /* 0 or 1, index into current_nibble */ + unsigned int start_col; + unsigned int start_row; + unsigned int width, height, stride; + unsigned int start_pts, end_pts; + packet_t *next; +}; + +struct palette_crop_cache { + int valid; + uint32_t palette; + int sx, sy, ex, ey; + int result; +}; + +typedef struct { + packet_t *queue_head; + packet_t *queue_tail; + unsigned int global_palette[16]; + unsigned int orig_frame_width, orig_frame_height; + unsigned char* packet; + size_t packet_reserve; /* size of the memory pointed to by packet */ + unsigned int packet_offset; /* end of the currently assembled fragment */ + unsigned int packet_size; /* size of the packet once all fragments are assembled */ + int packet_pts; /* PTS for this packet */ + unsigned int palette[4]; + unsigned int alpha[4]; + unsigned int cuspal[4]; + unsigned int custom; + unsigned int now_pts; + unsigned int start_pts, end_pts; + unsigned int start_col; + unsigned int start_row; + unsigned int width, height, stride; + size_t image_size; /* Size of the image buffer */ + unsigned char *image; /* Grayscale value */ + unsigned char *aimage; /* Alpha value */ + unsigned int pal_start_col, pal_start_row; + unsigned int pal_width, pal_height; + unsigned char *pal_image; /* palette entry value */ + unsigned int scaled_frame_width, scaled_frame_height; + unsigned int scaled_start_col, scaled_start_row; + unsigned int scaled_width, scaled_height, scaled_stride; + size_t scaled_image_size; + unsigned char *scaled_image; + unsigned char *scaled_aimage; + int auto_palette; /* 1 if we lack a palette and must use an heuristic. */ + int font_start_level; /* Darkest value used for the computed font */ + struct vo *hw_spu; + int spu_changed; + unsigned int forced_subs_only; /* flag: 0=display all subtitle, !0 display only forced subtitles */ + unsigned int is_forced_sub; /* true if current subtitle is a forced subtitle */ + + struct palette_crop_cache palette_crop_cache; +} spudec_handle_t; + +static void spudec_queue_packet(spudec_handle_t *this, packet_t *packet) +{ + if (this->queue_head == NULL) + this->queue_head = packet; + else + this->queue_tail->next = packet; + this->queue_tail = packet; +} + +static packet_t *spudec_dequeue_packet(spudec_handle_t *this) +{ + packet_t *retval = this->queue_head; + + this->queue_head = retval->next; + if (this->queue_head == NULL) + this->queue_tail = NULL; + + return retval; +} + +static void spudec_free_packet(packet_t *packet) +{ + free(packet->packet); + free(packet); +} + +static inline unsigned int get_be16(const unsigned char *p) +{ + return (p[0] << 8) + p[1]; +} + +static inline unsigned int get_be24(const unsigned char *p) +{ + return (get_be16(p) << 8) + p[2]; +} + +static void next_line(packet_t *packet) +{ + if (packet->current_nibble[packet->deinterlace_oddness] % 2) + packet->current_nibble[packet->deinterlace_oddness]++; + packet->deinterlace_oddness = (packet->deinterlace_oddness + 1) % 2; +} + +static inline unsigned char get_nibble(packet_t *packet) +{ + unsigned char nib; + unsigned int *nibblep = packet->current_nibble + packet->deinterlace_oddness; + if (*nibblep / 2 >= packet->control_start) { + mp_msg(MSGT_SPUDEC,MSGL_WARN, "SPUdec: ERROR: get_nibble past end of packet\n"); + return 0; + } + nib = packet->packet[*nibblep / 2]; + if (*nibblep % 2) + nib &= 0xf; + else + nib >>= 4; + ++*nibblep; + return nib; +} + +/* Cut the sub to visible part */ +static inline void spudec_cut_image(spudec_handle_t *this) +{ + unsigned int fy, ly; + unsigned int first_y, last_y; + + if (this->stride == 0 || this->height == 0) { + return; + } + + for (fy = 0; fy < this->image_size && !this->aimage[fy]; fy++); + for (ly = this->stride * this->height-1; ly && !this->aimage[ly]; ly--); + first_y = fy / this->stride; + last_y = ly / this->stride; + //printf("first_y: %d, last_y: %d\n", first_y, last_y); + this->start_row += first_y; + + // Some subtitles trigger this condition + if (last_y + 1 > first_y ) { + this->height = last_y - first_y +1; + } else { + this->height = 0; + return; + } + +// printf("new h %d new start %d (sz %d st %d)---\n\n", this->height, this->start_row, this->image_size, this->stride); + + if (first_y > 0) { + memmove(this->image, this->image + this->stride * first_y, this->stride * this->height); + memmove(this->aimage, this->aimage + this->stride * first_y, this->stride * this->height); + } +} + + +static int spudec_alloc_image(spudec_handle_t *this, int stride, int height) +{ + if (this->width > stride) // just a safeguard + this->width = stride; + this->stride = stride; + this->height = height; + if (this->image_size < this->stride * this->height) { + if (this->image != NULL) { + free(this->image); + free(this->pal_image); + this->image_size = 0; + this->pal_width = this->pal_height = 0; + } + this->image = malloc(2 * this->stride * this->height); + if (this->image) { + this->image_size = this->stride * this->height; + this->aimage = this->image + this->image_size; + // use stride here as well to simplify reallocation checks + this->pal_image = malloc(this->stride * this->height); + } + } + return this->image != NULL; +} + +/** + * \param pal palette in MPlayer-style gray-alpha values, i.e. + * alpha == 0 means transparent, 1 fully opaque, + * gray value <= 256 - alpha. + */ +static void pal2gray_alpha(const uint16_t *pal, + const uint8_t *src, int src_stride, + uint8_t *dst, uint8_t *dsta, + int dst_stride, int w, int h) +{ + int x, y; + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + uint16_t pixel = pal[src[x]]; + *dst++ = pixel; + *dsta++ = pixel >> 8; + } + for (; x < dst_stride; x++) + *dsta++ = *dst++ = 0; + src += src_stride; + } +} + +static int apply_palette_crop(spudec_handle_t *this, + unsigned crop_x, unsigned crop_y, + unsigned crop_w, unsigned crop_h) +{ + int i; + uint8_t *src; + uint16_t pal[4]; + unsigned stride = (crop_w + 7) & ~7; + if (crop_x > this->pal_width || crop_y > this->pal_height || + crop_w > this->pal_width - crop_x || crop_h > this->pal_width - crop_y || + crop_w > 0x8000 || crop_h > 0x8000 || + stride * crop_h > this->image_size) { + return 0; + } + for (i = 0; i < 4; ++i) { + int color; + int alpha = this->alpha[i]; + // extend 4 -> 8 bit + alpha |= alpha << 4; + if (this->custom && (this->cuspal[i] >> 31) != 0) + alpha = 0; + color = this->custom ? this->cuspal[i] : + this->global_palette[this->palette[i]]; + color = (color >> 16) & 0xff; + // convert to MPlayer-style gray/alpha palette + color = FFMIN(color, alpha); + pal[i] = (-alpha << 8) | color; + } + src = this->pal_image + crop_y * this->pal_width + crop_x; + pal2gray_alpha(pal, src, this->pal_width, + this->image, this->aimage, stride, + crop_w, crop_h); + this->width = crop_w; + this->height = crop_h; + this->stride = stride; + this->start_col = this->pal_start_col + crop_x; + this->start_row = this->pal_start_row + crop_y; + spudec_cut_image(this); + + // reset scaled image + this->scaled_frame_width = 0; + this->scaled_frame_height = 0; + this->palette_crop_cache.valid = 0; + return 1; +} + +int spudec_apply_palette_crop(void *this, uint32_t palette, + int sx, int sy, int ex, int ey) +{ + spudec_handle_t *spu = this; + struct palette_crop_cache *c = &spu->palette_crop_cache; + if (c->valid && c->palette == palette && + c->sx == sx && c->sy == sy && c->ex == ex && c->ey == ey) + return c->result; + spu->palette[0] = (palette >> 28) & 0xf; + spu->palette[1] = (palette >> 24) & 0xf; + spu->palette[2] = (palette >> 20) & 0xf; + spu->palette[3] = (palette >> 16) & 0xf; + spu->alpha[0] = (palette >> 12) & 0xf; + spu->alpha[1] = (palette >> 8) & 0xf; + spu->alpha[2] = (palette >> 4) & 0xf; + spu->alpha[3] = palette & 0xf; + spu->spu_changed = 1; + c->result = apply_palette_crop(spu, + sx - spu->pal_start_col, sy - spu->pal_start_row, + ex - sx, ey - sy); + c->palette = palette; + c->sx = sx; c->sy = sy; + c->ex = ex; c->ey = ey; + c->valid = 1; + return c->result; +} + +static void spudec_process_data(spudec_handle_t *this, packet_t *packet) +{ + unsigned int i, x, y; + uint8_t *dst; + + if (!spudec_alloc_image(this, packet->stride, packet->height)) + return; + + this->pal_start_col = packet->start_col; + this->pal_start_row = packet->start_row; + this->pal_height = packet->height; + this->pal_width = packet->width; + this->stride = packet->stride; + memcpy(this->palette, packet->palette, sizeof(this->palette)); + memcpy(this->alpha, packet->alpha, sizeof(this->alpha)); + + i = packet->current_nibble[1]; + x = 0; + y = 0; + dst = this->pal_image; + while (packet->current_nibble[0] < i + && packet->current_nibble[1] / 2 < packet->control_start + && y < this->pal_height) { + unsigned int len, color; + unsigned int rle = 0; + rle = get_nibble(packet); + if (rle < 0x04) { + if (rle == 0) { + rle = (rle << 4) | get_nibble(packet); + if (rle < 0x04) + rle = (rle << 4) | get_nibble(packet); + } + rle = (rle << 4) | get_nibble(packet); + } + color = 3 - (rle & 0x3); + len = rle >> 2; + x += len; + if (len == 0 || x >= this->pal_width) { + len += this->pal_width - x; + next_line(packet); + x = 0; + ++y; + } + memset(dst, color, len); + dst += len; + } + apply_palette_crop(this, 0, 0, this->pal_width, this->pal_height); +} + + +/* + This function tries to create a usable palette. + It determines how many non-transparent colors are used, and assigns different +gray scale values to each color. + I tested it with four streams and even got something readable. Half of the +times I got black characters with white around and half the reverse. +*/ +static void compute_palette(spudec_handle_t *this, packet_t *packet) +{ + int used[16],i,cused,start,step,color; + + memset(used, 0, sizeof(used)); + for (i=0; i<4; i++) + if (packet->alpha[i]) /* !Transparent? */ + used[packet->palette[i]] = 1; + for (cused=0, i=0; i<16; i++) + if (used[i]) cused++; + if (!cused) return; + if (cused == 1) { + start = 0x80; + step = 0; + } else { + start = this->font_start_level; + step = (0xF0-this->font_start_level)/(cused-1); + } + memset(used, 0, sizeof(used)); + for (i=0; i<4; i++) { + color = packet->palette[i]; + if (packet->alpha[i] && !used[color]) { /* not assigned? */ + used[color] = 1; + this->global_palette[color] = start<<16; + start += step; + } + } +} + +static void spudec_process_control(spudec_handle_t *this, int pts100) +{ + int a,b,c,d; /* Temporary vars */ + unsigned int date, type; + unsigned int off; + unsigned int start_off = 0; + unsigned int next_off; + unsigned int start_pts = 0; + unsigned int end_pts = 0; + unsigned int current_nibble[2] = {0, 0}; + unsigned int control_start; + unsigned int display = 0; + unsigned int start_col = 0; + unsigned int end_col = 0; + unsigned int start_row = 0; + unsigned int end_row = 0; + unsigned int width = 0; + unsigned int height = 0; + unsigned int stride = 0; + + control_start = get_be16(this->packet + 2); + next_off = control_start; + while (start_off != next_off) { + start_off = next_off; + date = get_be16(this->packet + start_off) * 1024; + next_off = get_be16(this->packet + start_off + 2); + mp_msg(MSGT_SPUDEC,MSGL_DBG2, "date=%d\n", date); + off = start_off + 4; + for (type = this->packet[off++]; type != 0xff; type = this->packet[off++]) { + mp_msg(MSGT_SPUDEC,MSGL_DBG2, "cmd=%d ",type); + switch(type) { + case 0x00: + /* Menu ID, 1 byte */ + mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Menu ID\n"); + /* shouldn't a Menu ID type force display start? */ + start_pts = pts100 < 0 && -pts100 >= date ? 0 : pts100 + date; + end_pts = UINT_MAX; + display = 1; + this->is_forced_sub=~0; // current subtitle is forced + break; + case 0x01: + /* Start display */ + mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Start display!\n"); + start_pts = pts100 < 0 && -pts100 >= date ? 0 : pts100 + date; + end_pts = UINT_MAX; + display = 1; + this->is_forced_sub=0; + break; + case 0x02: + /* Stop display */ + mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Stop display!\n"); + end_pts = pts100 < 0 && -pts100 >= date ? 0 : pts100 + date; + break; + case 0x03: + /* Palette */ + this->palette[0] = this->packet[off] >> 4; + this->palette[1] = this->packet[off] & 0xf; + this->palette[2] = this->packet[off + 1] >> 4; + this->palette[3] = this->packet[off + 1] & 0xf; + mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Palette %d, %d, %d, %d\n", + this->palette[0], this->palette[1], this->palette[2], this->palette[3]); + off+=2; + break; + case 0x04: + /* Alpha */ + a = this->packet[off] >> 4; + b = this->packet[off] & 0xf; + c = this->packet[off + 1] >> 4; + d = this->packet[off + 1] & 0xf; + // Note: some DVDs change these values to create a fade-in/fade-out effect + // We can not handle this, so just keep the highest value during the display time. + if (display) { + a = FFMAX(a, this->alpha[0]); + b = FFMAX(b, this->alpha[1]); + c = FFMAX(c, this->alpha[2]); + d = FFMAX(d, this->alpha[3]); + } + this->alpha[0] = a; + this->alpha[1] = b; + this->alpha[2] = c; + this->alpha[3] = d; + mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Alpha %d, %d, %d, %d\n", + this->alpha[0], this->alpha[1], this->alpha[2], this->alpha[3]); + off+=2; + break; + case 0x05: + /* Co-ords */ + a = get_be24(this->packet + off); + b = get_be24(this->packet + off + 3); + start_col = a >> 12; + end_col = a & 0xfff; + width = (end_col < start_col) ? 0 : end_col - start_col + 1; + stride = (width + 7) & ~7; /* Kludge: draw_alpha needs width multiple of 8 */ + start_row = b >> 12; + end_row = b & 0xfff; + height = (end_row < start_row) ? 0 : end_row - start_row /* + 1 */; + mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Coords col: %d - %d row: %d - %d (%dx%d)\n", + start_col, end_col, start_row, end_row, + width, height); + off+=6; + break; + case 0x06: + /* Graphic lines */ + current_nibble[0] = 2 * get_be16(this->packet + off); + current_nibble[1] = 2 * get_be16(this->packet + off + 2); + mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Graphic offset 1: %d offset 2: %d\n", + current_nibble[0] / 2, current_nibble[1] / 2); + off+=4; + break; + case 0xff: + /* All done, bye-bye */ + mp_msg(MSGT_SPUDEC,MSGL_DBG2,"Done!\n"); + return; +// break; + default: + mp_msg(MSGT_SPUDEC,MSGL_WARN,"spudec: Error determining control type 0x%02x. Skipping %d bytes.\n", + type, next_off - off); + goto next_control; + } + } + next_control: + if (!display) + continue; + if (end_pts == UINT_MAX && start_off != next_off) { + end_pts = get_be16(this->packet + next_off) * 1024; + end_pts = 1 - pts100 >= end_pts ? 0 : pts100 + end_pts - 1; + } + if (end_pts > 0) { + packet_t *packet = calloc(1, sizeof(packet_t)); + int i; + packet->start_pts = start_pts; + packet->end_pts = end_pts; + packet->current_nibble[0] = current_nibble[0]; + packet->current_nibble[1] = current_nibble[1]; + packet->start_row = start_row; + packet->start_col = start_col; + packet->width = width; + packet->height = height; + packet->stride = stride; + packet->control_start = control_start; + for (i=0; i<4; i++) { + packet->alpha[i] = this->alpha[i]; + packet->palette[i] = this->palette[i]; + } + packet->packet = malloc(this->packet_size); + memcpy(packet->packet, this->packet, this->packet_size); + spudec_queue_packet(this, packet); + } + } +} + +static void spudec_decode(spudec_handle_t *this, int pts100) +{ + if (!this->hw_spu) + spudec_process_control(this, pts100); + else if (pts100 >= 0) { + static vo_mpegpes_t packet = { NULL, 0, 0x20, 0 }; + static vo_mpegpes_t *pkg=&packet; + packet.data = this->packet; + packet.size = this->packet_size; + packet.timestamp = pts100; + vo_draw_frame(this->hw_spu, (uint8_t**)&pkg); + } +} + +int spudec_changed(void * this) +{ + spudec_handle_t * spu = this; + return spu->spu_changed || spu->now_pts > spu->end_pts; +} + +void spudec_assemble(void *this, unsigned char *packet, unsigned int len, int pts100) +{ + spudec_handle_t *spu = this; +// spudec_heartbeat(this, pts100); + if (len < 2) { + mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: packet too short\n"); + return; + } + spu->packet_pts = pts100; + if (spu->packet_offset == 0) { + unsigned int len2 = get_be16(packet); + // Start new fragment + if (spu->packet_reserve < len2) { + free(spu->packet); + spu->packet = malloc(len2); + spu->packet_reserve = spu->packet != NULL ? len2 : 0; + } + if (spu->packet != NULL) { + spu->packet_size = len2; + if (len > len2) { + mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: invalid frag len / len2: %d / %d \n", len, len2); + return; + } + memcpy(spu->packet, packet, len); + spu->packet_offset = len; + spu->packet_pts = pts100; + } + } else { + // Continue current fragment + if (spu->packet_size < spu->packet_offset + len){ + mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUasm: invalid fragment\n"); + spu->packet_size = spu->packet_offset = 0; + return; + } else { + memcpy(spu->packet + spu->packet_offset, packet, len); + spu->packet_offset += len; + } + } +#if 1 + // check if we have a complete packet (unfortunatelly packet_size is bad + // for some disks) + // [cb] packet_size is padded to be even -> may be one byte too long + if ((spu->packet_offset == spu->packet_size) || + ((spu->packet_offset + 1) == spu->packet_size)){ + unsigned int x=0,y; + while(x+4<=spu->packet_offset){ + y=get_be16(spu->packet+x+2); // next control pointer + mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPUtest: x=%d y=%d off=%d size=%d\n",x,y,spu->packet_offset,spu->packet_size); + if(x>=4 && x==y){ // if it points to self - we're done! + // we got it! + mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPUgot: off=%d size=%d \n",spu->packet_offset,spu->packet_size); + spudec_decode(spu, pts100); + spu->packet_offset = 0; + break; + } + if(y<=x || y>=spu->packet_size){ // invalid? + mp_msg(MSGT_SPUDEC,MSGL_WARN,"SPUtest: broken packet!!!!! y=%d < x=%d\n",y,x); + spu->packet_size = spu->packet_offset = 0; + break; + } + x=y; + } + // [cb] packet is done; start new packet + spu->packet_offset = 0; + } +#else + if (spu->packet_offset == spu->packet_size) { + spudec_decode(spu, pts100); + spu->packet_offset = 0; + } +#endif +} + +void spudec_reset(void *this) // called after seek +{ + spudec_handle_t *spu = this; + while (spu->queue_head) + spudec_free_packet(spudec_dequeue_packet(spu)); + spu->now_pts = 0; + spu->end_pts = 0; + spu->packet_size = spu->packet_offset = 0; +} + +void spudec_heartbeat(void *this, unsigned int pts100) +{ + spudec_handle_t *spu = this; + spu->now_pts = pts100; + + // TODO: detect and handle broken timestamps (e.g. due to wrapping) + while (spu->queue_head != NULL && pts100 >= spu->queue_head->start_pts) { + packet_t *packet = spudec_dequeue_packet(spu); + spu->start_pts = packet->start_pts; + spu->end_pts = packet->end_pts; + if (packet->is_decoded) { + free(spu->image); + spu->image_size = packet->data_len; + spu->image = packet->packet; + spu->aimage = packet->packet + packet->stride * packet->height; + packet->packet = NULL; + spu->width = packet->width; + spu->height = packet->height; + spu->stride = packet->stride; + spu->start_col = packet->start_col; + spu->start_row = packet->start_row; + + // reset scaled image + spu->scaled_frame_width = 0; + spu->scaled_frame_height = 0; + } else { + if (spu->auto_palette) + compute_palette(spu, packet); + spudec_process_data(spu, packet); + } + spudec_free_packet(packet); + spu->spu_changed = 1; + } +} + +int spudec_visible(void *this){ + spudec_handle_t *spu = this; + int ret=(spu->start_pts <= spu->now_pts && + spu->now_pts < spu->end_pts && + spu->height > 0); +// printf("spu visible: %d \n",ret); + return ret; +} + +void spudec_set_forced_subs_only(void * const this, const unsigned int flag) +{ + if(this){ + ((spudec_handle_t *)this)->forced_subs_only=flag; + mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPU: Display only forced subs now %s\n", flag ? "enabled": "disabled"); + } +} + +void spudec_draw(void *this, void (*draw_alpha)(void *ctx, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride), void *ctx) +{ + spudec_handle_t *spu = this; + if (spudec_visible(spu)) + { + draw_alpha(ctx, spu->start_col, spu->start_row, spu->width, spu->height, + spu->image, spu->aimage, spu->stride); + spu->spu_changed = 0; + } +} + +/* calc the bbox for spudec subs */ +void spudec_calc_bbox(void *me, unsigned int dxs, unsigned int dys, unsigned int* bbox) +{ + spudec_handle_t *spu = me; + if (spu->orig_frame_width == 0 || spu->orig_frame_height == 0 + || (spu->orig_frame_width == dxs && spu->orig_frame_height == dys)) { + // unscaled + bbox[0] = spu->start_col; + bbox[1] = spu->start_col + spu->width; + bbox[2] = spu->start_row; + bbox[3] = spu->start_row + spu->height; + } + else { + // scaled + unsigned int scalex = 0x100 * dxs / spu->orig_frame_width; + unsigned int scaley = 0x100 * dys / spu->orig_frame_height; + bbox[0] = spu->start_col * scalex / 0x100; + bbox[1] = spu->start_col * scalex / 0x100 + spu->width * scalex / 0x100; + switch (spu_alignment) { + case 0: + bbox[3] = dys*sub_pos/100 + spu->height * scaley / 0x100; + if (bbox[3] > dys) bbox[3] = dys; + bbox[2] = bbox[3] - spu->height * scaley / 0x100; + break; + case 1: + if (sub_pos < 50) { + bbox[2] = dys*sub_pos/100 - spu->height * scaley / 0x200; + bbox[3] = bbox[2] + spu->height; + } else { + bbox[3] = dys*sub_pos/100 + spu->height * scaley / 0x200; + if (bbox[3] > dys) bbox[3] = dys; + bbox[2] = bbox[3] - spu->height * scaley / 0x100; + } + break; + case 2: + bbox[2] = dys*sub_pos/100 - spu->height * scaley / 0x100; + bbox[3] = bbox[2] + spu->height; + break; + default: /* -1 */ + bbox[2] = spu->start_row * scaley / 0x100; + bbox[3] = spu->start_row * scaley / 0x100 + spu->height * scaley / 0x100; + break; + } + } +} +/* transform mplayer's alpha value into an opacity value that is linear */ +static inline int canon_alpha(int alpha) +{ + return (uint8_t)-alpha; +} + +typedef struct { + unsigned position; + unsigned left_up; + unsigned right_down; +}scale_pixel; + + +static void scale_table(unsigned int start_src, unsigned int start_tar, unsigned int end_src, unsigned int end_tar, scale_pixel * table) +{ + unsigned int t; + unsigned int delta_src = end_src - start_src; + unsigned int delta_tar = end_tar - start_tar; + int src = 0; + int src_step; + if (delta_src == 0 || delta_tar == 0) { + return; + } + src_step = (delta_src << 16) / delta_tar >>1; + for (t = 0; t<=delta_tar; src += (src_step << 1), t++){ + table[t].position= FFMIN(src >> 16, end_src - 1); + table[t].right_down = src & 0xffff; + table[t].left_up = 0x10000 - table[t].right_down; + } +} + +/* bilinear scale, similar to vobsub's code */ +static void scale_image(int x, int y, scale_pixel* table_x, scale_pixel* table_y, spudec_handle_t * spu) +{ + int alpha[4]; + int color[4]; + unsigned int scale[4]; + int base = table_y[y].position * spu->stride + table_x[x].position; + int scaled = y * spu->scaled_stride + x; + alpha[0] = canon_alpha(spu->aimage[base]); + alpha[1] = canon_alpha(spu->aimage[base + 1]); + alpha[2] = canon_alpha(spu->aimage[base + spu->stride]); + alpha[3] = canon_alpha(spu->aimage[base + spu->stride + 1]); + color[0] = spu->image[base]; + color[1] = spu->image[base + 1]; + color[2] = spu->image[base + spu->stride]; + color[3] = spu->image[base + spu->stride + 1]; + scale[0] = (table_x[x].left_up * table_y[y].left_up >> 16) * alpha[0]; + if (table_y[y].left_up == 0x10000) // necessary to avoid overflow-case + scale[0] = table_x[x].left_up * alpha[0]; + scale[1] = (table_x[x].right_down * table_y[y].left_up >>16) * alpha[1]; + scale[2] = (table_x[x].left_up * table_y[y].right_down >> 16) * alpha[2]; + scale[3] = (table_x[x].right_down * table_y[y].right_down >> 16) * alpha[3]; + spu->scaled_image[scaled] = (color[0] * scale[0] + color[1] * scale[1] + color[2] * scale[2] + color[3] * scale[3])>>24; + spu->scaled_aimage[scaled] = (scale[0] + scale[1] + scale[2] + scale[3]) >> 16; + if (spu->scaled_aimage[scaled]){ + // ensure that MPlayer's simplified alpha-blending can not overflow + spu->scaled_image[scaled] = FFMIN(spu->scaled_image[scaled], spu->scaled_aimage[scaled]); + // convert to MPlayer-style alpha + spu->scaled_aimage[scaled] = -spu->scaled_aimage[scaled]; + } +} + +static void sws_spu_image(unsigned char *d1, unsigned char *d2, int dw, int dh, + int ds, const unsigned char* s1, unsigned char* s2, + int sw, int sh, int ss) +{ + struct SwsContext *ctx; + static SwsFilter filter; + static int firsttime = 1; + static float oldvar; + int i; + + if (!firsttime && oldvar != spu_gaussvar) sws_freeVec(filter.lumH); + if (firsttime) { + filter.lumH = filter.lumV = + filter.chrH = filter.chrV = sws_getGaussianVec(spu_gaussvar, 3.0); + sws_normalizeVec(filter.lumH, 1.0); + firsttime = 0; + oldvar = spu_gaussvar; + } + + ctx=sws_getContext(sw, sh, PIX_FMT_GRAY8, dw, dh, PIX_FMT_GRAY8, SWS_GAUSS, &filter, NULL, NULL); + sws_scale(ctx,&s1,&ss,0,sh,&d1,&ds); + for (i=ss*sh-1; i>=0; i--) if (!s2[i]) s2[i] = 255; //else s2[i] = 1; + sws_scale(ctx,&s2,&ss,0,sh,&d2,&ds); + for (i=ds*dh-1; i>=0; i--) if (d2[i]==0) d2[i] = 1; else if (d2[i]==255) d2[i] = 0; + sws_freeContext(ctx); +} + +void spudec_draw_scaled(void *me, unsigned int dxs, unsigned int dys, void (*draw_alpha)(void *ctx, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride), void *ctx) +{ + spudec_handle_t *spu = me; + scale_pixel *table_x; + scale_pixel *table_y; + + if (spudec_visible(spu)) { + + // check if only forced subtitles are requested + if( (spu->forced_subs_only) && !(spu->is_forced_sub) ){ + return; + } + + if (!(spu_aamode&16) && (spu->orig_frame_width == 0 || spu->orig_frame_height == 0 + || (spu->orig_frame_width == dxs && spu->orig_frame_height == dys))) { + spudec_draw(spu, draw_alpha, ctx); + } + else { + if (spu->scaled_frame_width != dxs || spu->scaled_frame_height != dys) { /* Resizing is needed */ + /* scaled_x = scalex * x / 0x100 + scaled_y = scaley * y / 0x100 + order of operations is important because of rounding. */ + unsigned int scalex = 0x100 * dxs / spu->orig_frame_width; + unsigned int scaley = 0x100 * dys / spu->orig_frame_height; + spu->scaled_start_col = spu->start_col * scalex / 0x100; + spu->scaled_start_row = spu->start_row * scaley / 0x100; + spu->scaled_width = spu->width * scalex / 0x100; + spu->scaled_height = spu->height * scaley / 0x100; + /* Kludge: draw_alpha needs width multiple of 8 */ + spu->scaled_stride = (spu->scaled_width + 7) & ~7; + if (spu->scaled_image_size < spu->scaled_stride * spu->scaled_height) { + if (spu->scaled_image) { + free(spu->scaled_image); + spu->scaled_image_size = 0; + } + spu->scaled_image = malloc(2 * spu->scaled_stride * spu->scaled_height); + if (spu->scaled_image) { + spu->scaled_image_size = spu->scaled_stride * spu->scaled_height; + spu->scaled_aimage = spu->scaled_image + spu->scaled_image_size; + } + } + if (spu->scaled_image) { + unsigned int x, y; + if (spu->scaled_width <= 1 || spu->scaled_height <= 1) { + goto nothing_to_do; + } + switch(spu_aamode&15) { + case 4: + sws_spu_image(spu->scaled_image, spu->scaled_aimage, + spu->scaled_width, spu->scaled_height, spu->scaled_stride, + spu->image, spu->aimage, spu->width, spu->height, spu->stride); + break; + case 3: + table_x = calloc(spu->scaled_width, sizeof(scale_pixel)); + table_y = calloc(spu->scaled_height, sizeof(scale_pixel)); + if (!table_x || !table_y) { + mp_msg(MSGT_SPUDEC, MSGL_FATAL, "Fatal: spudec_draw_scaled: calloc failed\n"); + } + scale_table(0, 0, spu->width - 1, spu->scaled_width - 1, table_x); + scale_table(0, 0, spu->height - 1, spu->scaled_height - 1, table_y); + for (y = 0; y < spu->scaled_height; y++) + for (x = 0; x < spu->scaled_width; x++) + scale_image(x, y, table_x, table_y, spu); + free(table_x); + free(table_y); + break; + case 0: + /* no antialiasing */ + for (y = 0; y < spu->scaled_height; ++y) { + int unscaled_y = y * 0x100 / scaley; + int strides = spu->stride * unscaled_y; + int scaled_strides = spu->scaled_stride * y; + for (x = 0; x < spu->scaled_width; ++x) { + int unscaled_x = x * 0x100 / scalex; + spu->scaled_image[scaled_strides + x] = spu->image[strides + unscaled_x]; + spu->scaled_aimage[scaled_strides + x] = spu->aimage[strides + unscaled_x]; + } + } + break; + case 1: + { + /* Intermediate antialiasing. */ + for (y = 0; y < spu->scaled_height; ++y) { + const unsigned int unscaled_top = y * spu->orig_frame_height / dys; + unsigned int unscaled_bottom = (y + 1) * spu->orig_frame_height / dys; + if (unscaled_bottom >= spu->height) + unscaled_bottom = spu->height - 1; + for (x = 0; x < spu->scaled_width; ++x) { + const unsigned int unscaled_left = x * spu->orig_frame_width / dxs; + unsigned int unscaled_right = (x + 1) * spu->orig_frame_width / dxs; + unsigned int color = 0; + unsigned int alpha = 0; + unsigned int walkx, walky; + unsigned int base, tmp; + if (unscaled_right >= spu->width) + unscaled_right = spu->width - 1; + for (walky = unscaled_top; walky <= unscaled_bottom; ++walky) + for (walkx = unscaled_left; walkx <= unscaled_right; ++walkx) { + base = walky * spu->stride + walkx; + tmp = canon_alpha(spu->aimage[base]); + alpha += tmp; + color += tmp * spu->image[base]; + } + base = y * spu->scaled_stride + x; + spu->scaled_image[base] = alpha ? color / alpha : 0; + spu->scaled_aimage[base] = + alpha * (1 + unscaled_bottom - unscaled_top) * (1 + unscaled_right - unscaled_left); + /* spu->scaled_aimage[base] = + alpha * dxs * dys / spu->orig_frame_width / spu->orig_frame_height; */ + if (spu->scaled_aimage[base]) { + spu->scaled_aimage[base] = 256 - spu->scaled_aimage[base]; + if (spu->scaled_aimage[base] + spu->scaled_image[base] > 255) + spu->scaled_image[base] = 256 - spu->scaled_aimage[base]; + } + } + } + } + break; + case 2: + { + /* Best antialiasing. Very slow. */ + /* Any pixel (x, y) represents pixels from the original + rectangular region comprised between the columns + unscaled_y and unscaled_y + 0x100 / scaley and the rows + unscaled_x and unscaled_x + 0x100 / scalex + + The original rectangular region that the scaled pixel + represents is cut in 9 rectangular areas like this: + + +---+-----------------+---+ + | 1 | 2 | 3 | + +---+-----------------+---+ + | | | | + | 4 | 5 | 6 | + | | | | + +---+-----------------+---+ + | 7 | 8 | 9 | + +---+-----------------+---+ + + The width of the left column is at most one pixel and + it is never null and its right column is at a pixel + boundary. The height of the top row is at most one + pixel it is never null and its bottom row is at a + pixel boundary. The width and height of region 5 are + integral values. The width of the right column is + what remains and is less than one pixel. The height + of the bottom row is what remains and is less than + one pixel. + + The row above 1, 2, 3 is unscaled_y. The row between + 1, 2, 3 and 4, 5, 6 is top_low_row. The row between 4, + 5, 6 and 7, 8, 9 is (unsigned int)unscaled_y_bottom. + The row beneath 7, 8, 9 is unscaled_y_bottom. + + The column left of 1, 4, 7 is unscaled_x. The column + between 1, 4, 7 and 2, 5, 8 is left_right_column. The + column between 2, 5, 8 and 3, 6, 9 is (unsigned + int)unscaled_x_right. The column right of 3, 6, 9 is + unscaled_x_right. */ + const double inv_scalex = (double) 0x100 / scalex; + const double inv_scaley = (double) 0x100 / scaley; + for (y = 0; y < spu->scaled_height; ++y) { + const double unscaled_y = y * inv_scaley; + const double unscaled_y_bottom = unscaled_y + inv_scaley; + const unsigned int top_low_row = FFMIN(unscaled_y_bottom, unscaled_y + 1.0); + const double top = top_low_row - unscaled_y; + const unsigned int height = unscaled_y_bottom > top_low_row + ? (unsigned int) unscaled_y_bottom - top_low_row + : 0; + const double bottom = unscaled_y_bottom > top_low_row + ? unscaled_y_bottom - floor(unscaled_y_bottom) + : 0.0; + for (x = 0; x < spu->scaled_width; ++x) { + const double unscaled_x = x * inv_scalex; + const double unscaled_x_right = unscaled_x + inv_scalex; + const unsigned int left_right_column = FFMIN(unscaled_x_right, unscaled_x + 1.0); + const double left = left_right_column - unscaled_x; + const unsigned int width = unscaled_x_right > left_right_column + ? (unsigned int) unscaled_x_right - left_right_column + : 0; + const double right = unscaled_x_right > left_right_column + ? unscaled_x_right - floor(unscaled_x_right) + : 0.0; + double color = 0.0; + double alpha = 0.0; + double tmp; + unsigned int base; + /* Now use these informations to compute a good alpha, + and lightness. The sum is on each of the 9 + region's surface and alpha and lightness. + + transformed alpha = sum(surface * alpha) / sum(surface) + transformed color = sum(surface * alpha * color) / sum(surface * alpha) + */ + /* 1: top left part */ + base = spu->stride * (unsigned int) unscaled_y; + tmp = left * top * canon_alpha(spu->aimage[base + (unsigned int) unscaled_x]); + alpha += tmp; + color += tmp * spu->image[base + (unsigned int) unscaled_x]; + /* 2: top center part */ + if (width > 0) { + unsigned int walkx; + for (walkx = left_right_column; walkx < (unsigned int) unscaled_x_right; ++walkx) { + base = spu->stride * (unsigned int) unscaled_y + walkx; + tmp = /* 1.0 * */ top * canon_alpha(spu->aimage[base]); + alpha += tmp; + color += tmp * spu->image[base]; + } + } + /* 3: top right part */ + if (right > 0.0) { + base = spu->stride * (unsigned int) unscaled_y + (unsigned int) unscaled_x_right; + tmp = right * top * canon_alpha(spu->aimage[base]); + alpha += tmp; + color += tmp * spu->image[base]; + } + /* 4: center left part */ + if (height > 0) { + unsigned int walky; + for (walky = top_low_row; walky < (unsigned int) unscaled_y_bottom; ++walky) { + base = spu->stride * walky + (unsigned int) unscaled_x; + tmp = left /* * 1.0 */ * canon_alpha(spu->aimage[base]); + alpha += tmp; + color += tmp * spu->image[base]; + } + } + /* 5: center part */ + if (width > 0 && height > 0) { + unsigned int walky; + for (walky = top_low_row; walky < (unsigned int) unscaled_y_bottom; ++walky) { + unsigned int walkx; + base = spu->stride * walky; + for (walkx = left_right_column; walkx < (unsigned int) unscaled_x_right; ++walkx) { + tmp = /* 1.0 * 1.0 * */ canon_alpha(spu->aimage[base + walkx]); + alpha += tmp; + color += tmp * spu->image[base + walkx]; + } + } + } + /* 6: center right part */ + if (right > 0.0 && height > 0) { + unsigned int walky; + for (walky = top_low_row; walky < (unsigned int) unscaled_y_bottom; ++walky) { + base = spu->stride * walky + (unsigned int) unscaled_x_right; + tmp = right /* * 1.0 */ * canon_alpha(spu->aimage[base]); + alpha += tmp; + color += tmp * spu->image[base]; + } + } + /* 7: bottom left part */ + if (bottom > 0.0) { + base = spu->stride * (unsigned int) unscaled_y_bottom + (unsigned int) unscaled_x; + tmp = left * bottom * canon_alpha(spu->aimage[base]); + alpha += tmp; + color += tmp * spu->image[base]; + } + /* 8: bottom center part */ + if (width > 0 && bottom > 0.0) { + unsigned int walkx; + base = spu->stride * (unsigned int) unscaled_y_bottom; + for (walkx = left_right_column; walkx < (unsigned int) unscaled_x_right; ++walkx) { + tmp = /* 1.0 * */ bottom * canon_alpha(spu->aimage[base + walkx]); + alpha += tmp; + color += tmp * spu->image[base + walkx]; + } + } + /* 9: bottom right part */ + if (right > 0.0 && bottom > 0.0) { + base = spu->stride * (unsigned int) unscaled_y_bottom + (unsigned int) unscaled_x_right; + tmp = right * bottom * canon_alpha(spu->aimage[base]); + alpha += tmp; + color += tmp * spu->image[base]; + } + /* Finally mix these transparency and brightness information suitably */ + base = spu->scaled_stride * y + x; + spu->scaled_image[base] = alpha > 0 ? color / alpha : 0; + spu->scaled_aimage[base] = alpha * scalex * scaley / 0x10000; + if (spu->scaled_aimage[base]) { + spu->scaled_aimage[base] = 256 - spu->scaled_aimage[base]; + if (spu->scaled_aimage[base] + spu->scaled_image[base] > 255) + spu->scaled_image[base] = 256 - spu->scaled_aimage[base]; + } + } + } + } + } +nothing_to_do: + /* Kludge: draw_alpha needs width multiple of 8. */ + if (spu->scaled_width < spu->scaled_stride) + for (y = 0; y < spu->scaled_height; ++y) { + memset(spu->scaled_aimage + y * spu->scaled_stride + spu->scaled_width, 0, + spu->scaled_stride - spu->scaled_width); + } + spu->scaled_frame_width = dxs; + spu->scaled_frame_height = dys; + } + } + if (spu->scaled_image){ + switch (spu_alignment) { + case 0: + spu->scaled_start_row = dys*sub_pos/100; + if (spu->scaled_start_row + spu->scaled_height > dys) + spu->scaled_start_row = dys - spu->scaled_height; + break; + case 1: + spu->scaled_start_row = dys*sub_pos/100 - spu->scaled_height/2; + if (sub_pos >= 50 && spu->scaled_start_row + spu->scaled_height > dys) + spu->scaled_start_row = dys - spu->scaled_height; + break; + case 2: + spu->scaled_start_row = dys*sub_pos/100 - spu->scaled_height; + break; + } + draw_alpha(ctx, spu->scaled_start_col, spu->scaled_start_row, spu->scaled_width, spu->scaled_height, + spu->scaled_image, spu->scaled_aimage, spu->scaled_stride); + spu->spu_changed = 0; + } + } + } + else + { + mp_msg(MSGT_SPUDEC,MSGL_DBG2,"SPU not displayed: start_pts=%d end_pts=%d now_pts=%d\n", + spu->start_pts, spu->end_pts, spu->now_pts); + } +} + +void spudec_update_palette(void * this, unsigned int *palette) +{ + spudec_handle_t *spu = this; + if (spu && palette) { + memcpy(spu->global_palette, palette, sizeof(spu->global_palette)); + if(spu->hw_spu) + vo_control(spu->hw_spu, VOCTRL_SET_SPU_PALETTE, spu->global_palette); + } +} + +void spudec_set_font_factor(void * this, double factor) +{ + spudec_handle_t *spu = this; + spu->font_start_level = (int)(0xF0-(0xE0*factor)); +} + +static void spudec_parse_extradata(spudec_handle_t *this, + uint8_t *extradata, int extradata_len) +{ + uint8_t *buffer, *ptr; + unsigned int *pal = this->global_palette, *cuspal = this->cuspal; + unsigned int tridx; + int i; + + if (extradata_len == 16*4) { + for (i=0; i<16; i++) + pal[i] = AV_RB32(extradata + i*4); + this->auto_palette = 0; + return; + } + + if (!(ptr = buffer = malloc(extradata_len+1))) + return; + memcpy(buffer, extradata, extradata_len); + buffer[extradata_len] = 0; + + do { + if (*ptr == '#') + continue; + if (!strncmp(ptr, "size: ", 6)) + sscanf(ptr + 6, "%dx%d", &this->orig_frame_width, &this->orig_frame_height); + if (!strncmp(ptr, "palette: ", 9) && + sscanf(ptr + 9, "%x, %x, %x, %x, %x, %x, %x, %x, " + "%x, %x, %x, %x, %x, %x, %x, %x", + &pal[ 0], &pal[ 1], &pal[ 2], &pal[ 3], + &pal[ 4], &pal[ 5], &pal[ 6], &pal[ 7], + &pal[ 8], &pal[ 9], &pal[10], &pal[11], + &pal[12], &pal[13], &pal[14], &pal[15]) == 16) { + for (i=0; i<16; i++) + pal[i] = vobsub_palette_to_yuv(pal[i]); + this->auto_palette = 0; + } + if (!strncasecmp(ptr, "forced subs: on", 15)) + this->forced_subs_only = 1; + if (!strncmp(ptr, "custom colors: ON, tridx: ", 26) && + sscanf(ptr + 26, "%x, colors: %x, %x, %x, %x", + &tridx, cuspal+0, cuspal+1, cuspal+2, cuspal+3) == 5) { + for (i=0; i<4; i++) { + cuspal[i] = vobsub_rgb_to_yuv(cuspal[i]); + if (tridx & (1 << (12-4*i))) + cuspal[i] |= 1 << 31; + } + this->custom = 1; + } + } while ((ptr=strchr(ptr,'\n')) && *++ptr); + + free(buffer); +} + +void *spudec_new_scaled(unsigned int *palette, unsigned int frame_width, unsigned int frame_height, uint8_t *extradata, int extradata_len) +{ + spudec_handle_t *this = calloc(1, sizeof(spudec_handle_t)); + if (this){ + this->orig_frame_height = frame_height; + this->orig_frame_width = frame_width; + // set up palette: + if (palette) + memcpy(this->global_palette, palette, sizeof(this->global_palette)); + else + this->auto_palette = 1; + if (extradata) + spudec_parse_extradata(this, extradata, extradata_len); + /* XXX Although the video frame is some size, the SPU frame is + always maximum size i.e. 720 wide and 576 or 480 high */ + // For HD files in MKV the VobSub resolution can be higher though, + // see largeres_vobsub.mkv + if (this->orig_frame_width <= 720 && this->orig_frame_height <= 576) { + this->orig_frame_width = 720; + if (this->orig_frame_height == 480 || this->orig_frame_height == 240) + this->orig_frame_height = 480; + else + this->orig_frame_height = 576; + } + } + else + mp_msg(MSGT_SPUDEC,MSGL_FATAL, "FATAL: spudec_init: calloc"); + return this; +} + +void *spudec_new(unsigned int *palette) +{ + return spudec_new_scaled(palette, 0, 0, NULL, 0); +} + +void spudec_free(void *this) +{ + spudec_handle_t *spu = this; + if (spu) { + while (spu->queue_head) + spudec_free_packet(spudec_dequeue_packet(spu)); + free(spu->packet); + spu->packet = NULL; + free(spu->scaled_image); + spu->scaled_image = NULL; + free(spu->image); + spu->image = NULL; + spu->aimage = NULL; + free(spu->pal_image); + spu->pal_image = NULL; + spu->image_size = 0; + spu->pal_width = spu->pal_height = 0; + free(spu); + } +} + +void spudec_set_hw_spu(void *this, struct vo *hw_spu) +{ + spudec_handle_t *spu = this; + if (!spu) + return; + spu->hw_spu = hw_spu; + vo_control(hw_spu, VOCTRL_SET_SPU_PALETTE, spu->global_palette); +} + +/** + * palette must contain at least 256 32-bit entries, otherwise crashes + * are possible + */ +void spudec_set_paletted(void *this, const uint8_t *pal_img, int pal_stride, + const void *palette, + int x, int y, int w, int h, + double pts, double endpts) +{ + int i; + uint16_t g8a8_pal[256]; + packet_t *packet; + const uint32_t *pal = palette; + spudec_handle_t *spu = this; + uint8_t *img; + uint8_t *aimg; + int stride = (w + 7) & ~7; + if ((unsigned)w >= 0x8000 || (unsigned)h > 0x4000) + return; + packet = calloc(1, sizeof(packet_t)); + packet->is_decoded = 1; + packet->width = w; + packet->height = h; + packet->stride = stride; + packet->start_col = x; + packet->start_row = y; + packet->data_len = 2 * stride * h; + if (packet->data_len) { // size 0 is a special "clear" packet + packet->packet = malloc(packet->data_len); + img = packet->packet; + aimg = packet->packet + stride * h; + for (i = 0; i < 256; i++) { + uint32_t pixel = pal[i]; + int alpha = pixel >> 24; + int gray = (((pixel & 0x000000ff) >> 0) + + ((pixel & 0x0000ff00) >> 7) + + ((pixel & 0x00ff0000) >> 16)) >> 2; + gray = FFMIN(gray, alpha); + g8a8_pal[i] = (-alpha << 8) | gray; + } + pal2gray_alpha(g8a8_pal, pal_img, pal_stride, + img, aimg, stride, w, h); + } + packet->start_pts = 0; + packet->end_pts = 0x7fffffff; + if (pts != MP_NOPTS_VALUE) + packet->start_pts = pts * 90000; + if (endpts != MP_NOPTS_VALUE) + packet->end_pts = endpts * 90000; + spudec_queue_packet(spu, packet); +} diff --git a/sub/spudec.h b/sub/spudec.h new file mode 100644 index 0000000000..2b3828c34c --- /dev/null +++ b/sub/spudec.h @@ -0,0 +1,45 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPLAYER_SPUDEC_H +#define MPLAYER_SPUDEC_H + +#include "libvo/video_out.h" + +void spudec_heartbeat(void *this, unsigned int pts100); +void spudec_assemble(void *this, unsigned char *packet, unsigned int len, int pts100); +void spudec_draw(void *this, void (*draw_alpha)(void *ctx, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride), void *ctx); +void spudec_draw_scaled(void *this, unsigned int dxs, unsigned int dys, void (*draw_alpha)(void *ctx, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride), void *ctx); +int spudec_apply_palette_crop(void *this, uint32_t palette, int sx, int ex, int sy, int ey); +void spudec_update_palette(void *this, unsigned int *palette); +void *spudec_new_scaled(unsigned int *palette, unsigned int frame_width, unsigned int frame_height, uint8_t *extradata, int extradata_len); +void *spudec_new(unsigned int *palette); +void spudec_free(void *this); +void spudec_reset(void *this); // called after seek +int spudec_visible(void *this); // check if spu is visible +void spudec_set_font_factor(void * this, double factor); // sets the equivalent to ffactor +void spudec_set_hw_spu(void *this, struct vo *hw_spu); +int spudec_changed(void *this); +void spudec_calc_bbox(void *me, unsigned int dxs, unsigned int dys, unsigned int* bbox); +void spudec_set_forced_subs_only(void * const this, const unsigned int flag); +void spudec_set_paletted(void *this, const uint8_t *pal_img, int stride, + const void *palette, + int x, int y, int w, int h, + double pts, double endpts); + +#endif /* MPLAYER_SPUDEC_H */ diff --git a/sub/sub.c b/sub/sub.c new file mode 100644 index 0000000000..75d43c2c48 --- /dev/null +++ b/sub/sub.c @@ -0,0 +1,1348 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include + +#include "config.h" +#if HAVE_MALLOC_H +#include +#endif + +#include "stream/stream.h" +#include "stream/stream_dvdnav.h" +#define OSD_NAV_BOX_ALPHA 0x7f + +#include "libmpcodecs/dec_teletext.h" +#include "osdep/timer.h" + +#include "talloc.h" +#include "mplayer.h" +#include "mp_msg.h" +#include "libvo/video_out.h" +#include "font_load.h" +#include "sub.h" +#include "spudec.h" +#include "libavutil/common.h" + +#define NEW_SPLITTING + + +// Structures needed for the new splitting algorithm. +// osd_text_t contains the single subtitle word. +// osd_text_p is used to mark the lines of subtitles +struct osd_text_t { + int osd_kerning, //kerning with the previous word + osd_length, //orizontal length inside the bbox + text_length, //number of characters + *text; //characters + struct osd_text_t *prev, + *next; +}; + +struct osd_text_p { + int value; + struct osd_text_t *ott; + struct osd_text_p *prev, + *next; +}; +//^ + +char * const sub_osd_names[]={ + _("Seekbar"), + _("Play"), + _("Pause"), + _("Stop"), + _("Rewind"), + _("Forward"), + _("Clock"), + _("Contrast"), + _("Saturation"), + _("Volume"), + _("Brightness"), + _("Hue"), + _("Balance") +}; +char * const sub_osd_names_short[] ={ "", "|>", "||", "[]", "<<" , ">>", "", "", "", "", "", "", "" }; + +//static int vo_font_loaded=-1; +font_desc_t* vo_font=NULL; + +void* vo_osd_teletext_page=NULL; +int vo_osd_teletext_half = 0; +int vo_osd_teletext_mode=0; +int vo_osd_teletext_format=0; +int vo_osd_teletext_scale=0; +int sub_unicode=0; +int sub_utf8=0; +int sub_pos=100; +int sub_width_p=100; +int sub_alignment=2; /* 0=top, 1=center, 2=bottom */ +int sub_visibility=1; +int sub_bg_color=0; /* subtitles background color */ +int sub_bg_alpha=0; +int sub_justify=0; +#ifdef CONFIG_DVDNAV +static nav_highlight_t nav_hl; +#endif + +// return the real height of a char: +static inline int get_height(int c,int h){ + int font; + if ((font=vo_font->font[c])>=0) + if(hpic_a[font]->h) h=vo_font->pic_a[font]->h; + return h; +} + +// renders char to a big per-object buffer where alpha and bitmap are separated +static void draw_alpha_buf(mp_osd_obj_t* obj, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) +{ + int dststride = obj->stride; + int dstskip = obj->stride-w; + int srcskip = stride-w; + int i, j; + unsigned char *b = obj->bitmap_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1); + unsigned char *a = obj->alpha_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1); + unsigned char *bs = src; + unsigned char *as = srca; + + if (x0 < obj->bbox.x1 || x0+w > obj->bbox.x2 || y0 < obj->bbox.y1 || y0+h > obj->bbox.y2) { + fprintf(stderr, "osd text out of range: bbox [%d %d %d %d], txt [%d %d %d %d]\n", + obj->bbox.x1, obj->bbox.x2, obj->bbox.y1, obj->bbox.y2, + x0, x0+w, y0, y0+h); + return; + } + + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++, b++, a++, bs++, as++) { + if (*b < *bs) *b = *bs; + if (*as) { + if (*a == 0 || *a > *as) *a = *as; + } + } + b+= dstskip; + a+= dstskip; + bs+= srcskip; + as+= srcskip; + } +} + +// allocates/enlarges the alpha/bitmap buffer +static void alloc_buf(mp_osd_obj_t* obj) +{ + int len; + if (obj->bbox.x2 < obj->bbox.x1) obj->bbox.x2 = obj->bbox.x1; + if (obj->bbox.y2 < obj->bbox.y1) obj->bbox.y2 = obj->bbox.y1; + obj->stride = ((obj->bbox.x2-obj->bbox.x1)+7)&(~7); + len = obj->stride*(obj->bbox.y2-obj->bbox.y1); + if (obj->allocatedallocated = len; + free(obj->bitmap_buffer); + free(obj->alpha_buffer); + obj->bitmap_buffer = (unsigned char *)memalign(16, len); + obj->alpha_buffer = (unsigned char *)memalign(16, len); + } + memset(obj->bitmap_buffer, sub_bg_color, len); + memset(obj->alpha_buffer, sub_bg_alpha, len); +} + +// renders the buffer +inline static void vo_draw_text_from_buffer(mp_osd_obj_t* obj,void (*draw_alpha)(void *ctx, int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride), void *ctx) +{ + if (obj->allocated > 0) { + draw_alpha(ctx, + obj->bbox.x1,obj->bbox.y1, + obj->bbox.x2-obj->bbox.x1, + obj->bbox.y2-obj->bbox.y1, + obj->bitmap_buffer, + obj->alpha_buffer, + obj->stride); + } +} + +unsigned utf8_get_char(const char **str) { + const uint8_t *strp = (const uint8_t *)*str; + unsigned c; + GET_UTF8(c, *strp++, goto no_utf8;); + *str = (const char *)strp; + return c; + +no_utf8: + strp = (const uint8_t *)*str; + c = *strp++; + *str = (const char *)strp; + return c; +} + +inline static void vo_update_text_osd(struct osd_state *osd, mp_osd_obj_t* obj, + int dxs, int dys) +{ + const char *cp = osd->osd_text; + int x=20; + int h=0; + int font; + + obj->bbox.x1=obj->x=x; + obj->bbox.y1=obj->y=10; + + while (*cp){ + uint16_t c=utf8_get_char(&cp); + render_one_glyph(vo_font, c); + x+=vo_font->width[c]+vo_font->charspace; + h=get_height(c,h); + } + + obj->bbox.x2=x-vo_font->charspace; + obj->bbox.y2=obj->bbox.y1+h; + obj->flags|=OSDFLAG_BBOX; + + alloc_buf(obj); + + cp = osd->osd_text; + x = obj->x; + while (*cp){ + uint16_t c=utf8_get_char(&cp); + if ((font=vo_font->font[c])>=0) + draw_alpha_buf(obj,x,obj->y, + vo_font->width[c], + vo_font->pic_a[font]->h, + vo_font->pic_b[font]->bmp+vo_font->start[c], + vo_font->pic_a[font]->bmp+vo_font->start[c], + vo_font->pic_a[font]->w); + x+=vo_font->width[c]+vo_font->charspace; + } +} + +#ifdef CONFIG_DVDNAV +void osd_set_nav_box (uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey) { + nav_hl.sx = sx; + nav_hl.sy = sy; + nav_hl.ex = ex; + nav_hl.ey = ey; +} + +inline static void vo_update_nav (mp_osd_obj_t *obj, int dxs, int dys, int left_border, int top_border, + int right_border, int bottom_border, int orig_w, int orig_h) { + int len; + int sx = nav_hl.sx, sy = nav_hl.sy; + int ex = nav_hl.ex, ey = nav_hl.ey; + int scaled_w = dxs - left_border - right_border; + int scaled_h = dys - top_border - bottom_border; + if (scaled_w != orig_w) { + sx = sx * scaled_w / orig_w; + ex = ex * scaled_w / orig_w; + } + if (scaled_h != orig_h) { + sy = sy * scaled_h / orig_h; + ey = ey * scaled_h / orig_h; + } + sx += left_border; ex += left_border; + sy += top_border; ey += top_border; + sx = FFMIN(FFMAX(sx, 0), dxs); + ex = FFMIN(FFMAX(ex, 0), dxs); + sy = FFMIN(FFMAX(sy, 0), dys); + ey = FFMIN(FFMAX(ey, 0), dys); + + obj->bbox.x1 = obj->x = sx; + obj->bbox.y1 = obj->y = sy; + obj->bbox.x2 = ex; + obj->bbox.y2 = ey; + + alloc_buf (obj); + len = obj->stride * (obj->bbox.y2 - obj->bbox.y1); + memset (obj->bitmap_buffer, OSD_NAV_BOX_ALPHA, len); + memset (obj->alpha_buffer, OSD_NAV_BOX_ALPHA, len); + obj->flags |= OSDFLAG_BBOX | OSDFLAG_CHANGED; + if (obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1) + obj->flags |= OSDFLAG_VISIBLE; +} +#endif + +// renders char to a big per-object buffer where alpha and bitmap are separated +static void tt_draw_alpha_buf(mp_osd_obj_t* obj, int x0,int y0, int w,int h, unsigned char* src, int stride,int fg,int bg,int alpha) +{ + int dststride = obj->stride; + int dstskip = obj->stride-w; + int srcskip = stride-w; + int i, j; + unsigned char *b = obj->bitmap_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1); + unsigned char *a = obj->alpha_buffer + (y0-obj->bbox.y1)*dststride + (x0-obj->bbox.x1); + unsigned char *bs = src; + if (x0 < obj->bbox.x1 || x0+w > obj->bbox.x2 || y0 < obj->bbox.y1 || y0+h > obj->bbox.y2) { + mp_msg(MSGT_OSD,MSGL_ERR,"tt osd text out of range: bbox [%d %d %d %d], txt [%d %d %d %d]\n", + obj->bbox.x1, obj->bbox.x2, obj->bbox.y1, obj->bbox.y2, + x0, x0+w, y0, y0+h); + return; + } + for (i = 0; i < h; i++) { + for (j = 0; j < w; j++, b++, a++, bs++) { + *b=(fg-bg)*(*bs)/255+bg; + *a=alpha; + } + b+= dstskip; + a+= dstskip; + bs+= srcskip; + } +} +inline static void vo_update_text_teletext(mp_osd_obj_t *obj, int dxs, int dys) +{ + int h=0,w=0,i,j,font,flashon; + int wm,hm; + int color; + int x,y,x0,y0; + int cols,rows; + int wm12; + int hm13; + int hm23; + int start_row,max_rows; + int b,ax[6],ay[6],aw[6],ah[6]; + tt_char tc; + tt_char* tdp=vo_osd_teletext_page; + static const uint8_t colors[8]={1,85,150,226,70,105,179,254}; + unsigned char* buf[9]; + + obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE; + if (!tdp || !vo_osd_teletext_mode) { + obj->flags&=~OSDFLAG_VISIBLE; + return; + } + flashon=(GetTimer()/1000000)%2; + switch(vo_osd_teletext_half){ + case TT_ZOOM_TOP_HALF: + start_row=0; + max_rows=VBI_ROWS/2; + break; + case TT_ZOOM_BOTTOM_HALF: + start_row=VBI_ROWS/2; + max_rows=VBI_ROWS/2; + break; + default: + start_row=0; + max_rows=VBI_ROWS; + break; + } + wm=0; + for(i=start_row;iwidth[tc.unicode]) + wm=vo_font->width[tc.unicode]; + } + } + } + + hm=vo_font->height+1; + wm=dxs*hm*max_rows/(dys*VBI_COLUMNS); + +#ifdef CONFIG_FREETYPE + //very simple teletext font auto scaling + if(!vo_osd_teletext_scale && hm*(max_rows+1)>dys){ + osd_font_scale_factor*=1.0*(dys)/((max_rows+1)*hm); + force_load_font=1; + vo_osd_teletext_scale=osd_font_scale_factor; + obj->flags&=~OSDFLAG_VISIBLE; + return; + } +#endif + + cols=dxs/wm; + rows=dys/hm; + + if(cols>VBI_COLUMNS) + cols=VBI_COLUMNS; + if(rows>max_rows) + rows=max_rows; + w=cols*wm-vo_font->charspace; + h=rows*hm-vo_font->charspace; + + if(w>1; + hm13=(hm+1)/3; + hm23=hm13<<1; + + for(i=0;i<6;i+=2){ + ax[i+0]=0; + aw[i+0]=wm12; + + ax[i+1]=wm12; + aw[i+1]=wm-wm12; + } + + for(i=0;i<2;i++){ + ay[i+0]=0; + ah[i+0]=hm13; + + ay[i+2]=hm13; + ah[i+2]=hm-hm23; + + ay[i+4]=hm-hm13; + ah[i+4]=hm13; + } + + obj->x = 0; + obj->y = 0; + obj->bbox.x1 = x0; + obj->bbox.y1 = y0; + obj->bbox.x2 = x0+w; + obj->bbox.y2 = y0+h; + obj->flags |= OSDFLAG_BBOX; + alloc_buf(obj); + + for(i=0;i<9;i++) + buf[i]=malloc(wm*hm); + + //alpha + if(vo_osd_teletext_format==TT_FORMAT_OPAQUE ||vo_osd_teletext_format==TT_FORMAT_OPAQUE_INV) + color=1; + else + color=200; + memset(buf[8],color,wm*hm); + //colors + if(vo_osd_teletext_format==TT_FORMAT_OPAQUE ||vo_osd_teletext_format==TT_FORMAT_TRANSPARENT){ + for(i=0;i<8;i++){ + memset(buf[i],(unsigned char)(1.0*(255-color)*colors[i]/255),wm*hm); + } + }else{ + for(i=0;i<8;i++) + memset(buf[i],(unsigned char)(1.0*(255-color)*colors[7-i]/255),wm*hm); + } + + y=y0; + for(i=0;ifont[tc.unicode])>=0 && y+hmwidth[tc.unicode],vo_font->height, + vo_font->pic_b[font]->bmp+vo_font->start[tc.unicode]-vo_font->charspace*vo_font->pic_a[font]->w, + vo_font->pic_b[font]->w, + buf[tc.fg][0],buf[tc.bg][0],buf[8][0]); + } + }else{ +/* +Rendering one graphics character +TODO: support for separated graphics symbols (where six rectangles does not touch each other) + + +--+ +--+ 87654321 + |01| |12| -------- + |10| <= |34| <= 00100110 <= 0x26 + |01| |56| + +--+ +--+ + +(0:wm/2) (wm/2:wm-wm/2) + +********** *********** (0:hm/3) +*** **** **** **** +*** 1 **** **** 2 **** +*** **** **** **** +********** *********** +********** *********** + +********** *********** (hm/3:hm-2*hm/3) +********** *********** +*** **** **** **** +*** 3 **** **** 4 **** +*** **** **** **** +********** *********** +********** *********** +********** *********** + +********** *********** (hm-hm/3:hm/3) +*** **** **** **** +*** 5 **** **** 6 **** +*** **** **** **** +********** *********** +********** *********** + +*/ + if(tc.gfx>1){ //separated gfx + for(b=0;b<6;b++){ + color=(tc.unicode>>b)&1?tc.fg:tc.bg; + draw_alpha_buf(obj,x+ax[b]+1,y+ay[b]+1,aw[b]-2,ah[b]-2,buf[color],buf[8],wm); + } + //separated gfx (background borders) + //vertical + draw_alpha_buf(obj,x ,y,1,hm,buf[tc.bg],buf[8],wm); + draw_alpha_buf(obj,x+ax[1]-1,y,2,hm,buf[tc.bg],buf[8],wm); + draw_alpha_buf(obj,x+ax[1]+aw[1]-1,y,wm-ax[1]-aw[1]+1,hm,buf[tc.bg],buf[8],wm); + //horizontal + draw_alpha_buf(obj,x,y ,wm,1,buf[tc.bg],buf[8],wm); + draw_alpha_buf(obj,x,y+ay[0]+ah[0]-1,wm,2,buf[tc.bg],buf[8],wm); + draw_alpha_buf(obj,x,y+ay[2]+ah[2]-1,wm,2,buf[tc.bg],buf[8],wm); + draw_alpha_buf(obj,x,y+ay[4]+ah[4]-1,wm,hm-ay[4]-ah[4]+1,buf[tc.bg],buf[8],wm); + }else{ + for(b=0;b<6;b++){ + color=(tc.unicode>>b)&1?tc.fg:tc.bg; + draw_alpha_buf(obj,x+ax[b],y+ay[b],aw[b],ah[b],buf[color],buf[8],wm); + } + } + } + x+=wm; + } + y+=hm; + } + for(i=0;i<9;i++) + free(buf[i]); +} + +int vo_osd_progbar_type=-1; +int vo_osd_progbar_value=100; // 0..256 + +// if we have n=256 bars then OSD progbar looks like below +// +// 0 1 2 3 ... 256 <= vo_osd_progbar_value +// | | | | | +// [ === === === ... === ] +// +// the above schema is rescalled to n=elems bars + +inline static void vo_update_text_progbar(mp_osd_obj_t* obj,int dxs,int dys){ + + obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE; + + if(vo_osd_progbar_type<0 || !vo_font){ + obj->flags&=~OSDFLAG_VISIBLE; + return; + } + + render_one_glyph(vo_font, OSD_PB_START); + render_one_glyph(vo_font, OSD_PB_END); + render_one_glyph(vo_font, OSD_PB_0); + render_one_glyph(vo_font, OSD_PB_1); + render_one_glyph(vo_font, vo_osd_progbar_type); + + // calculate bbox corners: + { int h=0; + int y=(dys-vo_font->height)/2; + int delimw=vo_font->width[OSD_PB_START] + +vo_font->width[OSD_PB_END] + +vo_font->charspace; + int width=(2*dxs-3*delimw)/3; + int charw=vo_font->width[OSD_PB_0]+vo_font->charspace; + int elems=width/charw; + int x=(dxs-elems*charw-delimw)/2; + int delta = 0; + h=get_height(OSD_PB_START,h); + h=get_height(OSD_PB_END,h); + h=get_height(OSD_PB_0,h); + h=get_height(OSD_PB_1,h); + if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){ + delta = vo_font->width[vo_osd_progbar_type]+vo_font->spacewidth; + delta = (x-delta > 0) ? delta : x; + h=get_height(vo_osd_progbar_type,h); + } + obj->bbox.x1=obj->x=x; + obj->bbox.y1=obj->y=y; + obj->bbox.x2=x+width+delimw; + obj->bbox.y2=y+h; //vo_font->height; + obj->flags|=OSDFLAG_BBOX; + obj->params.progbar.elems=elems; + obj->bbox.x1-=delta; // space for an icon + } + + alloc_buf(obj); + + { + int minw = vo_font->width[OSD_PB_START]+vo_font->width[OSD_PB_END]+vo_font->width[OSD_PB_0]; + if (vo_osd_progbar_type>0 && vo_font->font[vo_osd_progbar_type]>=0){ + minw += vo_font->width[vo_osd_progbar_type]+vo_font->charspace+vo_font->spacewidth; + } + if (obj->bbox.x2 - obj->bbox.x1 < minw) return; // space too small, don't render anything + } + + // render it: + { unsigned char *s; + unsigned char *sa; + int i,w,h,st,mark; + int x=obj->x; + int y=obj->y; + int c,font; + int charw=vo_font->width[OSD_PB_0]+vo_font->charspace; + int elems=obj->params.progbar.elems; + + if (vo_osd_progbar_value<=0) + mark=0; + else { + int ev=vo_osd_progbar_value*elems; + mark=ev>>8; + if (ev & 0xFF) mark++; + if (mark>elems) mark=elems; + } + + +// printf("osd.progbar width=%d xpos=%d\n",width,x); + + c=vo_osd_progbar_type; + if(vo_osd_progbar_type>0 && (font=vo_font->font[c])>=0) { + int xp=x-vo_font->width[c]-vo_font->spacewidth; + draw_alpha_buf(obj,(xp<0?0:xp),y, + vo_font->width[c], + vo_font->pic_a[font]->h, + vo_font->pic_b[font]->bmp+vo_font->start[c], + vo_font->pic_a[font]->bmp+vo_font->start[c], + vo_font->pic_a[font]->w); + } + + c=OSD_PB_START; + if ((font=vo_font->font[c])>=0) + draw_alpha_buf(obj,x,y, + vo_font->width[c], + vo_font->pic_a[font]->h, + vo_font->pic_b[font]->bmp+vo_font->start[c], + vo_font->pic_a[font]->bmp+vo_font->start[c], + vo_font->pic_a[font]->w); + x+=vo_font->width[c]+vo_font->charspace; + + c=OSD_PB_0; + if ((font=vo_font->font[c])>=0){ + w=vo_font->width[c]; + h=vo_font->pic_a[font]->h; + s=vo_font->pic_b[font]->bmp+vo_font->start[c]; + sa=vo_font->pic_a[font]->bmp+vo_font->start[c]; + st=vo_font->pic_a[font]->w; + if ((i=mark)) do { + draw_alpha_buf(obj,x,y,w,h,s,sa,st); + x+=charw; + } while(--i); + } + + c=OSD_PB_1; + if ((font=vo_font->font[c])>=0){ + w=vo_font->width[c]; + h=vo_font->pic_a[font]->h; + s =vo_font->pic_b[font]->bmp+vo_font->start[c]; + sa=vo_font->pic_a[font]->bmp+vo_font->start[c]; + st=vo_font->pic_a[font]->w; + if ((i=elems-mark)) do { + draw_alpha_buf(obj,x,y,w,h,s,sa,st); + x+=charw; + } while(--i); + } + + c=OSD_PB_END; + if ((font=vo_font->font[c])>=0) + draw_alpha_buf(obj,x,y, + vo_font->width[c], + vo_font->pic_a[font]->h, + vo_font->pic_b[font]->bmp+vo_font->start[c], + vo_font->pic_a[font]->bmp+vo_font->start[c], + vo_font->pic_a[font]->w); +// x+=vo_font->width[c]+vo_font->charspace; + + } +// vo_osd_progbar_value=(vo_osd_progbar_value+1)&0xFF; + +} + +subtitle* vo_sub=NULL; + +inline static void vo_update_text_sub(struct osd_state *osd, mp_osd_obj_t* obj,int dxs,int dys){ + unsigned char *t; + int c,i,j,l,x,y,font,prevc,counter; + int k; + int lastStripPosition; + int xsize; + int xmin=dxs,xmax=0; + int h,lasth; + int xtblc, utblc; + struct font_desc *sub_font = osd->sub_font; + + obj->flags|=OSDFLAG_CHANGED|OSDFLAG_VISIBLE; + + if(!vo_sub || !osd->sub_font || !sub_visibility || (sub_font->font[40]<0)){ + obj->flags&=~OSDFLAG_VISIBLE; + return; + } + + obj->bbox.y2=obj->y=dys; + obj->params.subtitle.lines=0; + + // too long lines divide into a smaller ones + i=k=lasth=0; + h=sub_font->height; + lastStripPosition=-1; + l=vo_sub->lines; + + { + struct osd_text_t *osl, *cp_ott, *tmp_ott, *tmp; + struct osd_text_p *otp_sub = NULL, *otp_sub_tmp, // these are used to store the whole sub text osd + *otp, *tmp_otp, *pmt; // these are used to manage sub text osd coming from a single sub line + int *char_seq, char_position, xlimit = dxs * sub_width_p / 100, counter; + + while (l) { + xsize = -sub_font->charspace; + l--; + t=vo_sub->text[i++]; + char_position = 0; + char_seq = calloc(strlen(t), sizeof(int)); + + prevc = -1; + + otp = NULL; + osl = NULL; + x = 1; + + // reading the subtitle words from vo_sub->text[] + while (*t) { + if (sub_utf8) + c = utf8_get_char(&t); + else if ((c = *t++) >= 0x80 && sub_unicode) + c = (c<<8) + *t++; + if (k==MAX_UCS){ + t += strlen(t); // end here + mp_msg(MSGT_OSD,MSGL_WARN,"\nMAX_UCS exceeded!\n"); + } + if (!c) c++; // avoid UCS 0 + render_one_glyph(sub_font, c); + + if (c == ' ') { + struct osd_text_t *tmp_ott = calloc(1, sizeof(struct osd_text_t)); + + if (osl == NULL) { + osl = cp_ott = tmp_ott; + } else { + tmp_ott->prev = cp_ott; + cp_ott->next = tmp_ott; + tmp_ott->osd_kerning = + sub_font->charspace + sub_font->width[' ']; + cp_ott = tmp_ott; + } + tmp_ott->osd_length = xsize; + tmp_ott->text_length = char_position; + tmp_ott->text = malloc(char_position * sizeof(int)); + for (counter = 0; counter < char_position; ++counter) + tmp_ott->text[counter] = char_seq[counter]; + char_position = 0; + xsize = 0; + prevc = c; + } else { + int delta_xsize = sub_font->width[c] + sub_font->charspace + kerning(sub_font, prevc, c); + + if (xsize + delta_xsize <= dxs) { + if (!x) x = 1; + prevc = c; + char_seq[char_position++] = c; + xsize += delta_xsize; + if ((!suboverlap_enabled) && ((font = sub_font->font[c]) >= 0)) { + if (sub_font->pic_a[font]->h > h) { + h = sub_font->pic_a[font]->h; + } + } + } else { + if (x) { + mp_msg(MSGT_OSD, MSGL_WARN, "\nSubtitle word '%s' too long!\n", t); + x = 0; + } + } + } + }// for len (all words from subtitle line read) + + // osl holds an ordered (as they appear in the lines) chain of the subtitle words + { + struct osd_text_t *tmp_ott = calloc(1, sizeof(struct osd_text_t)); + + if (osl == NULL) { + osl = cp_ott = tmp_ott; + } else { + tmp_ott->prev = cp_ott; + cp_ott->next = tmp_ott; + tmp_ott->osd_kerning = + sub_font->charspace + sub_font->width[' ']; + cp_ott = tmp_ott; + } + tmp_ott->osd_length = xsize; + tmp_ott->text_length = char_position; + tmp_ott->text = malloc(char_position * sizeof(int)); + for (counter = 0; counter < char_position; ++counter) + tmp_ott->text[counter] = char_seq[counter]; + char_position = 0; + xsize = -sub_font->charspace; + } + free(char_seq); + + if (osl != NULL) { + int value = 0, exit = 0, minimum = 0; + + // otp will contain the chain of the osd subtitle lines coming from the single vo_sub line. + otp = tmp_otp = calloc(1, sizeof(struct osd_text_p)); + tmp_otp->ott = osl; + for (tmp_ott = tmp_otp->ott; exit == 0; ) { + do { + value += tmp_ott->osd_kerning + tmp_ott->osd_length; + tmp_ott = tmp_ott->next; + } while ((tmp_ott != NULL) && (value + tmp_ott->osd_kerning + tmp_ott->osd_length <= xlimit)); + if (tmp_ott != NULL) { + struct osd_text_p *tmp = calloc(1, sizeof(struct osd_text_p)); + + tmp_otp->value = value; + tmp_otp->next = tmp; + tmp->prev = tmp_otp; + tmp_otp = tmp; + tmp_otp->ott = tmp_ott; + value = -2 * sub_font->charspace - sub_font->width[' ']; + } else { + tmp_otp->value = value; + exit = 1; + } + } + + +#ifdef NEW_SPLITTING + // minimum holds the 'sum of the differences in length among the lines', + // a measure of the evenness of the lengths of the lines + for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) { + pmt = tmp_otp->next; + while (pmt != NULL) { + minimum += abs(tmp_otp->value - pmt->value); + pmt = pmt->next; + } + } + + if (otp->next != NULL) { + int mem1, mem2; + struct osd_text_p *mem, *hold; + + exit = 0; + // until the last word of a line can be moved to the beginning of following line + // reducing the 'sum of the differences in length among the lines', it is done + while (exit == 0) { + hold = NULL; + exit = 1; + for (tmp_otp = otp; tmp_otp->next != NULL; tmp_otp = tmp_otp->next) { + pmt = tmp_otp->next; + for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next); + if (pmt->value + tmp->osd_length + pmt->ott->osd_kerning <= xlimit) { + mem1 = tmp_otp->value; + mem2 = pmt->value; + tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning; + pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning; + + value = 0; + for (mem = otp; mem->next != NULL; mem = mem->next) { + pmt = mem->next; + while (pmt != NULL) { + value += abs(mem->value - pmt->value); + pmt = pmt->next; + } + } + if (value < minimum) { + minimum = value; + hold = tmp_otp; + exit = 0; + } + tmp_otp->value = mem1; + tmp_otp->next->value = mem2; + } + } + // merging + if (exit == 0) { + tmp_otp = hold; + pmt = tmp_otp->next; + for (tmp = tmp_otp->ott; tmp->next != pmt->ott; tmp = tmp->next); + mem1 = tmp_otp->value; + mem2 = pmt->value; + tmp_otp->value = mem1 - tmp->osd_length - tmp->osd_kerning; + pmt->value = mem2 + tmp->osd_length + pmt->ott->osd_kerning; + pmt->ott = tmp; + }//~merging + }//~while(exit == 0) + }//~if(otp->next!=NULL) +#endif + + // adding otp (containing splitted lines) to otp chain + if (otp_sub == NULL) { + otp_sub = otp; + for (otp_sub_tmp = otp_sub; otp_sub_tmp->next != NULL; otp_sub_tmp = otp_sub_tmp->next); + } else { + //updating ott chain + tmp = otp_sub->ott; + while (tmp->next != NULL) tmp = tmp->next; + tmp->next = otp->ott; + otp->ott->prev = tmp; + //attaching new subtitle line at the end + otp_sub_tmp->next = otp; + otp->prev = otp_sub_tmp; + do + otp_sub_tmp = otp_sub_tmp->next; + while (otp_sub_tmp->next != NULL); + } + }//~ if(osl != NULL) + } // while + + // write lines into utbl + xtblc = 0; + utblc = 0; + obj->y = dys; + obj->params.subtitle.lines = 0; + for (tmp_otp = otp_sub; tmp_otp != NULL; tmp_otp = tmp_otp->next) { + + if ((obj->params.subtitle.lines++) >= MAX_UCSLINES) + break; + + if (h > obj->y) { // out of the screen so end parsing + obj->y -= lasth - sub_font->height; // correct the y position + break; + } + xsize = tmp_otp->value; + obj->params.subtitle.xtbl[xtblc++] = (dxs - xsize) / 2; + if (xmin > (dxs - xsize) / 2) + xmin = (dxs - xsize) / 2; + if (xmax < (dxs + xsize) / 2) + xmax = (dxs + xsize) / 2; + + tmp = (tmp_otp->next == NULL) ? NULL : tmp_otp->next->ott; + for (tmp_ott = tmp_otp->ott; tmp_ott != tmp; tmp_ott = tmp_ott->next) { + for (counter = 0; counter < tmp_ott->text_length; ++counter) { + if (utblc > MAX_UCS) { + break; + } + c = tmp_ott->text[counter]; + render_one_glyph(sub_font, c); + obj->params.subtitle.utbl[utblc++] = c; + k++; + } + obj->params.subtitle.utbl[utblc++] = ' '; + } + obj->params.subtitle.utbl[utblc - 1] = 0; + obj->y -= sub_font->height; + } + if(obj->params.subtitle.lines) + obj->y = dys - ((obj->params.subtitle.lines - 1) * sub_font->height + sub_font->pic_a[sub_font->font[40]]->h); + + // free memory + if (otp_sub != NULL) { + for (tmp = otp_sub->ott; tmp->next != NULL; free(tmp->prev)) { + free(tmp->text); + tmp = tmp->next; + } + free(tmp->text); + free(tmp); + + for(pmt = otp_sub; pmt->next != NULL; free(pmt->prev)) { + pmt = pmt->next; + } + free(pmt); + } + + } + /// vertical alignment + h = dys - obj->y; + if (sub_alignment == 2) + obj->y = dys * sub_pos / 100 - h; + else if (sub_alignment == 1) + obj->y = dys * sub_pos / 100 - h / 2; + else + obj->y = dys * sub_pos / 100; + + if (obj->y < 0) + obj->y = 0; + if (obj->y > dys - h) + obj->y = dys - h; + + obj->bbox.y2 = obj->y + h; + + // calculate bbox: + if (sub_justify) xmin = 10; + obj->bbox.x1=xmin; + obj->bbox.x2=xmax; + obj->bbox.y1=obj->y; +// obj->bbox.y2=obj->y+obj->params.subtitle.lines*sub_font->height; + obj->flags|=OSDFLAG_BBOX; + + alloc_buf(obj); + + y = obj->y; + + obj->alignment = 0; + switch(vo_sub->alignment) { + case SUB_ALIGNMENT_BOTTOMLEFT: + case SUB_ALIGNMENT_MIDDLELEFT: + case SUB_ALIGNMENT_TOPLEFT: + obj->alignment |= 0x1; + break; + case SUB_ALIGNMENT_BOTTOMRIGHT: + case SUB_ALIGNMENT_MIDDLERIGHT: + case SUB_ALIGNMENT_TOPRIGHT: + obj->alignment |= 0x2; + break; + case SUB_ALIGNMENT_BOTTOMCENTER: + case SUB_ALIGNMENT_MIDDLECENTER: + case SUB_ALIGNMENT_TOPCENTER: + default: + obj->alignment |= 0x0; + } + + i=j=0; + if ((l = obj->params.subtitle.lines)) { + for(counter = dxs; i < l; ++i) + if (obj->params.subtitle.xtbl[i] < counter) counter = obj->params.subtitle.xtbl[i]; + for (i = 0; i < l; ++i) { + switch (obj->alignment&0x3) { + case 1: + // left + x = counter; + break; + case 2: + // right + x = 2 * obj->params.subtitle.xtbl[i] - counter - ((obj->params.subtitle.xtbl[i] == counter) ? 0 : 1); + break; + default: + //center + x = obj->params.subtitle.xtbl[i]; + } + prevc = -1; + while ((c=obj->params.subtitle.utbl[j++])){ + x += kerning(sub_font,prevc,c); + if ((font=sub_font->font[c])>=0) + draw_alpha_buf(obj,x,y, + sub_font->width[c], + sub_font->pic_a[font]->h+ydys ? sub_font->pic_a[font]->h : obj->dys-y, + sub_font->pic_b[font]->bmp+sub_font->start[c], + sub_font->pic_a[font]->bmp+sub_font->start[c], + sub_font->pic_a[font]->w); + x+=sub_font->width[c]+sub_font->charspace; + prevc = c; + } + y+=sub_font->height; + } + } + +} + +inline static void vo_update_spudec_sub(mp_osd_obj_t* obj, int dxs, int dys) +{ + unsigned int bbox[4]; + spudec_calc_bbox(vo_spudec, dxs, dys, bbox); + obj->bbox.x1 = bbox[0]; + obj->bbox.x2 = bbox[1]; + obj->bbox.y1 = bbox[2]; + obj->bbox.y2 = bbox[3]; + obj->flags |= OSDFLAG_BBOX; +} + +inline static void vo_draw_spudec_sub(mp_osd_obj_t* obj, void (*draw_alpha)(void *ctx, int x0, int y0, int w, int h, unsigned char* src, unsigned char* srca, int stride), void *ctx) +{ + spudec_draw_scaled(vo_spudec, obj->dxs, obj->dys, draw_alpha, ctx); +} + +void *vo_spudec=NULL; +void *vo_vobsub=NULL; + +static int draw_alpha_init_flag=0; + +void vo_draw_alpha_init(void); + + mp_osd_obj_t* vo_osd_list=NULL; + +static mp_osd_obj_t* new_osd_obj(int type){ + mp_osd_obj_t* osd=malloc(sizeof(mp_osd_obj_t)); + memset(osd,0,sizeof(mp_osd_obj_t)); + osd->next=vo_osd_list; + vo_osd_list=osd; + osd->type=type; + osd->alpha_buffer = NULL; + osd->bitmap_buffer = NULL; + osd->allocated = -1; + return osd; +} + +void osd_free(struct osd_state *osd) +{ + mp_osd_obj_t* obj=vo_osd_list; + while(obj){ + mp_osd_obj_t* next=obj->next; + free(obj->alpha_buffer); + free(obj->bitmap_buffer); + free(obj); + obj=next; + } + vo_osd_list=NULL; + talloc_free(osd); +} + +#define FONT_LOAD_DEFER 6 + +static int osd_update_ext(struct osd_state *osd, int dxs, int dys, + int left_border, int top_border, int right_border, + int bottom_border, int orig_w, int orig_h) +{ + mp_osd_obj_t* obj=vo_osd_list; + int chg=0; +#ifdef CONFIG_FREETYPE + static int defer_counter = 0, prev_dxs = 0, prev_dys = 0; +#endif + +#ifdef CONFIG_FREETYPE + // here is the right place to get screen dimensions + if (((dxs != vo_image_width) + && (subtitle_autoscale == 2 || subtitle_autoscale == 3)) + || ((dys != vo_image_height) + && (subtitle_autoscale == 1 || subtitle_autoscale == 3))) + { + // screen dimensions changed + // wait a while to avoid useless reloading of the font + if (dxs == prev_dxs || dys == prev_dys) { + defer_counter++; + } else { + prev_dxs = dxs; + prev_dys = dys; + defer_counter = 0; + } + if (defer_counter >= FONT_LOAD_DEFER) force_load_font = 1; + } + + if (force_load_font) { + force_load_font = 0; + load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor); + if (sub_font_name) + load_font_ft(dxs, dys, &osd->sub_font, sub_font_name, text_font_scale_factor); + else + load_font_ft(dxs, dys, &osd->sub_font, font_name, text_font_scale_factor); + prev_dxs = dxs; + prev_dys = dys; + defer_counter = 0; + } else { + if (!vo_font) + load_font_ft(dxs, dys, &vo_font, font_name, osd_font_scale_factor); + if (!osd->sub_font) { + if (sub_font_name) + load_font_ft(dxs, dys, &osd->sub_font, sub_font_name, text_font_scale_factor); + else + load_font_ft(dxs, dys, &osd->sub_font, font_name, text_font_scale_factor); + } + } +#endif + + while(obj){ + if(dxs!=obj->dxs || dys!=obj->dys || obj->flags&OSDFLAG_FORCE_UPDATE){ + int vis=obj->flags&OSDFLAG_VISIBLE; + obj->flags&=~OSDFLAG_BBOX; + switch(obj->type){ +#ifdef CONFIG_DVDNAV + case OSDTYPE_DVDNAV: + vo_update_nav(obj,dxs,dys, left_border, top_border, right_border, bottom_border, orig_w, orig_h); + break; +#endif + case OSDTYPE_SUBTITLE: + vo_update_text_sub(osd, obj,dxs,dys); + break; + case OSDTYPE_TELETEXT: + vo_update_text_teletext(obj,dxs,dys); + break; + case OSDTYPE_PROGBAR: + vo_update_text_progbar(obj,dxs,dys); + break; + case OSDTYPE_SPU: + if(sub_visibility && vo_spudec && spudec_visible(vo_spudec)){ + vo_update_spudec_sub(obj, dxs, dys); + obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED; + } + else + obj->flags&=~OSDFLAG_VISIBLE; + break; + case OSDTYPE_OSD: + if(vo_font && osd->osd_text[0]){ + vo_update_text_osd(osd, obj, dxs, dys); // update bbox + obj->flags|=OSDFLAG_VISIBLE|OSDFLAG_CHANGED; + } else + obj->flags&=~OSDFLAG_VISIBLE; + break; + } + // check bbox: + if(!(obj->flags&OSDFLAG_BBOX)){ + // we don't know, so assume the whole screen changed :( + obj->bbox.x1=obj->bbox.y1=0; + obj->bbox.x2=dxs; + obj->bbox.y2=dys; + obj->flags|=OSDFLAG_BBOX; + } else { + // check bbox, reduce it if it's out of bounds (corners): + if(obj->bbox.x1<0) obj->bbox.x1=0; + if(obj->bbox.y1<0) obj->bbox.y1=0; + if(obj->bbox.x2>dxs) obj->bbox.x2=dxs; + if(obj->bbox.y2>dys) obj->bbox.y2=dys; + if(obj->flags&OSDFLAG_VISIBLE) + // debug: + mp_msg(MSGT_OSD,MSGL_DBG2,"OSD update: %d;%d %dx%d \n", + obj->bbox.x1,obj->bbox.y1,obj->bbox.x2-obj->bbox.x1, + obj->bbox.y2-obj->bbox.y1); + } + // check if visibility changed: + if(vis != (obj->flags&OSDFLAG_VISIBLE) ) obj->flags|=OSDFLAG_CHANGED; + // remove the cause of automatic update: + obj->dxs=dxs; obj->dys=dys; + obj->flags&=~OSDFLAG_FORCE_UPDATE; + } + if(obj->flags&OSDFLAG_CHANGED){ + chg|=1<type; + mp_msg(MSGT_OSD,MSGL_DBG2,"OSD chg: %d V: %s pb:%d \n",obj->type,(obj->flags&OSDFLAG_VISIBLE)?"yes":"no",vo_osd_progbar_type); + } + obj=obj->next; + } + return chg; +} + +int osd_update(struct osd_state *osd, int dxs, int dys) +{ + return osd_update_ext(osd, dxs, dys, 0, 0, 0, 0, dxs, dys); +} + +struct osd_state *osd_create(void) +{ + struct osd_state *osd = talloc_zero(NULL, struct osd_state); + *osd = (struct osd_state){ + }; + if(!draw_alpha_init_flag){ + draw_alpha_init_flag=1; + vo_draw_alpha_init(); + } + // temp hack, should be moved to mplayer/mencoder later + new_osd_obj(OSDTYPE_OSD); + new_osd_obj(OSDTYPE_SUBTITLE); + new_osd_obj(OSDTYPE_PROGBAR); + new_osd_obj(OSDTYPE_SPU); +#ifdef CONFIG_DVDNAV + new_osd_obj(OSDTYPE_DVDNAV); +#endif + new_osd_obj(OSDTYPE_TELETEXT); +#ifdef CONFIG_FREETYPE + force_load_font = 1; +#endif + return osd; +} + +int vo_osd_changed_flag=0; + +void osd_remove_text(struct osd_state *osd, int dxs, int dys, + void (*remove)(int x0, int y0, int w, int h)) +{ + mp_osd_obj_t* obj=vo_osd_list; + osd_update(osd, dxs, dys); + while(obj){ + if(((obj->flags&OSDFLAG_CHANGED) || (obj->flags&OSDFLAG_VISIBLE)) && + (obj->flags&OSDFLAG_OLD_BBOX)){ + int w=obj->old_bbox.x2-obj->old_bbox.x1; + int h=obj->old_bbox.y2-obj->old_bbox.y1; + if(w>0 && h>0){ + vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack + remove(obj->old_bbox.x1,obj->old_bbox.y1,w,h); + } +// obj->flags&=~OSDFLAG_OLD_BBOX; + } + obj=obj->next; + } +} + +void osd_draw_text_ext(struct osd_state *osd, int dxs, int dys, + int left_border, int top_border, int right_border, + int bottom_border, int orig_w, int orig_h, + void (*draw_alpha)(void *ctx, int x0, int y0, int w, + int h, unsigned char* src, + unsigned char *srca, + int stride), + void *ctx) +{ + mp_osd_obj_t* obj=vo_osd_list; + osd_update_ext(osd, dxs, dys, left_border, top_border, right_border, + bottom_border, orig_w, orig_h); + while(obj){ + if(obj->flags&OSDFLAG_VISIBLE){ + vo_osd_changed_flag=obj->flags&OSDFLAG_CHANGED; // temp hack + switch(obj->type){ + case OSDTYPE_SPU: + vo_draw_spudec_sub(obj, draw_alpha, ctx); // FIXME + break; +#ifdef CONFIG_DVDNAV + case OSDTYPE_DVDNAV: +#endif + case OSDTYPE_TELETEXT: + case OSDTYPE_OSD: + case OSDTYPE_SUBTITLE: + case OSDTYPE_PROGBAR: + vo_draw_text_from_buffer(obj, draw_alpha, ctx); + break; + } + obj->old_bbox=obj->bbox; + obj->flags|=OSDFLAG_OLD_BBOX; + } + obj->flags&=~OSDFLAG_CHANGED; + obj=obj->next; + } +} + +void osd_draw_text(struct osd_state *osd, int dxs, int dys, + void (*draw_alpha)(void *ctx, int x0, int y0, int w, int h, + unsigned char* src, unsigned char *srca, + int stride), + void *ctx) +{ + osd_draw_text_ext(osd, dxs, dys, 0, 0, 0, 0, dxs, dys, draw_alpha, ctx); +} + +static int vo_osd_changed_status = 0; + +int vo_osd_changed(int new_value) +{ + mp_osd_obj_t* obj=vo_osd_list; + int ret = vo_osd_changed_status; + vo_osd_changed_status = new_value; + + while(obj){ + if(obj->type==new_value) obj->flags|=OSDFLAG_FORCE_UPDATE; + obj=obj->next; + } + + return ret; +} + +// BBBBBBBBBBBB AAAAAAAAAAAAA BBBBBBBBBBB +// BBBBBBBBBBBB BBBBBBBBBBBBB +// BBBBBBB + +// return TRUE if we have osd in the specified rectangular area: +int vo_osd_check_range_update(int x1,int y1,int x2,int y2){ + mp_osd_obj_t* obj=vo_osd_list; + while(obj){ + if(obj->flags&OSDFLAG_VISIBLE){ + if( (obj->bbox.x1<=x2 && obj->bbox.x2>=x1) && + (obj->bbox.y1<=y2 && obj->bbox.y2>=y1) && + obj->bbox.y2 > obj->bbox.y1 && obj->bbox.x2 > obj->bbox.x1 + ) return 1; + } + obj=obj->next; + } + return 0; +} diff --git a/sub/sub.h b/sub/sub.h new file mode 100644 index 0000000000..8309613ea6 --- /dev/null +++ b/sub/sub.h @@ -0,0 +1,167 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPLAYER_SUB_H +#define MPLAYER_SUB_H + +#include + +typedef struct mp_osd_bbox_s { + int x1,y1,x2,y2; +} mp_osd_bbox_t; + +#define OSDTYPE_OSD 1 +#define OSDTYPE_SUBTITLE 2 +#define OSDTYPE_PROGBAR 3 +#define OSDTYPE_SPU 4 +#define OSDTYPE_DVDNAV 5 +#define OSDTYPE_TELETEXT 6 + +#define OSDFLAG_VISIBLE 1 +#define OSDFLAG_CHANGED 2 +#define OSDFLAG_BBOX 4 +#define OSDFLAG_OLD_BBOX 8 +#define OSDFLAG_FORCE_UPDATE 16 + +#define MAX_UCS 1600 +#define MAX_UCSLINES 16 + +typedef struct mp_osd_obj_s { + struct mp_osd_obj_s* next; + unsigned char type; + unsigned char alignment; // 2 bits: x;y percentages, 2 bits: x;y relative to parent; 2 bits: alignment left/right/center + unsigned short flags; + int x,y; + int dxs,dys; + mp_osd_bbox_t bbox; // bounding box + mp_osd_bbox_t old_bbox; // the renderer will save bbox here + union { + struct { + void* sub; // value of vo_sub at last update + int utbl[MAX_UCS+1]; // subtitle text + int xtbl[MAX_UCSLINES]; // x positions + int lines; // no. of lines + } subtitle; + struct { + int elems; + } progbar; + } params; + int stride; + + int allocated; + unsigned char *alpha_buffer; + unsigned char *bitmap_buffer; +} mp_osd_obj_t; + +struct osd_state { + unsigned char osd_text[128]; + struct font_desc *sub_font; + struct ass_track *ass_track; + bool ass_track_changed; + bool vsfilter_aspect; +}; + +#include "subreader.h" + +extern subtitle* vo_sub; + +extern void* vo_osd_teletext_page; +extern int vo_osd_teletext_half; +extern int vo_osd_teletext_mode; +extern int vo_osd_teletext_format; + +extern int vo_osd_progbar_type; +extern int vo_osd_progbar_value; // 0..255 + +extern void* vo_spudec; +extern void* vo_vobsub; + +#define OSD_PLAY 0x01 +#define OSD_PAUSE 0x02 +#define OSD_STOP 0x03 +#define OSD_REW 0x04 +#define OSD_FFW 0x05 +#define OSD_CLOCK 0x06 +#define OSD_CONTRAST 0x07 +#define OSD_SATURATION 0x08 +#define OSD_VOLUME 0x09 +#define OSD_BRIGHTNESS 0x0A +#define OSD_HUE 0x0B +#define OSD_BALANCE 0x0C +#define OSD_PANSCAN 0x50 + +#define OSD_PB_START 0x10 +#define OSD_PB_0 0x11 +#define OSD_PB_END 0x12 +#define OSD_PB_1 0x13 + +/* now in textform */ +extern char * const sub_osd_names[]; +extern char * const sub_osd_names_short[]; + +extern int sub_unicode; +extern int sub_utf8; + +extern char *sub_cp; +extern int sub_pos; +extern int sub_width_p; +extern int sub_alignment; +extern int sub_visibility; +extern int sub_bg_color; /* subtitles background color */ +extern int sub_bg_alpha; +extern int spu_alignment; +extern int spu_aamode; +extern float spu_gaussvar; + +void osd_draw_text(struct osd_state *osd, int dxs, int dys, + void (*draw_alpha)(void *ctx, int x0, int y0, int w, int h, + unsigned char* src, unsigned char *srca, + int stride), + void *ctx); +void osd_draw_text_ext(struct osd_state *osd, int dxs, int dys, + int left_border, int top_border, int right_border, + int bottom_border, int orig_w, int orig_h, + void (*draw_alpha)(void *ctx, int x0, int y0, int w, + int h, unsigned char* src, + unsigned char *srca, + int stride), + void *ctx); +void osd_remove_text(struct osd_state *osd, int dxs, int dys, + void (*remove)(int x0, int y0, int w, int h)); + +struct osd_state *osd_create(void); +int osd_update(struct osd_state *osd, int dxs, int dys); +int vo_osd_changed(int new_value); +int vo_osd_check_range_update(int,int,int,int); +void osd_free(struct osd_state *osd); + +extern int vo_osd_changed_flag; + +unsigned utf8_get_char(const char **str); + +#ifdef CONFIG_DVDNAV +#include +void osd_set_nav_box (uint16_t sx, uint16_t sy, uint16_t ex, uint16_t ey); +#endif + + +#ifdef IS_OLD_VO +#define vo_remove_text(...) osd_remove_text(global_osd, __VA_ARGS__) +#endif + +#endif /* MPLAYER_SUB_H */ diff --git a/sub/sub_cc.c b/sub/sub_cc.c new file mode 100644 index 0000000000..f18fa28c54 --- /dev/null +++ b/sub/sub_cc.c @@ -0,0 +1,347 @@ +/* + * decoder for Closed Captions + * + * This decoder relies on MPlayer's OSD to display subtitles. + * Be warned that decoding is somewhat preliminary, though it basically works. + * + * Most notably, only the text information is decoded as of now, discarding + * color, background and position info (see source below). + * + * uses source from the xine closed captions decoder + * + * Copyright (C) 2002 Matteo Giani + * + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include + +#include "config.h" +#include "sub_cc.h" + +#include "subreader.h" + +#include "libvo/video_out.h" +#include "sub.h" + + +#define CC_MAX_LINE_LENGTH 64 + +static char chartbl[128]; + +static subtitle buf1,buf2; +static subtitle *fb,*bb; + +static unsigned int cursor_pos=0; + +static int initialized=0; + +#define CC_ROLLON 1 +#define CC_ROLLUP 2 + +static int cc_mode=CC_ROLLON; +static int cc_lines=4; ///< number of visible rows in CC roll-up mode, not used in CC roll-on mode + +static void build_char_table(void) +{ + int i; + /* first the normal ASCII codes */ + for (i = 0; i < 128; i++) + chartbl[i] = (char) i; + /* now the special codes */ + chartbl[0x2a] = 'á'; + chartbl[0x5c] = 'é'; + chartbl[0x5e] = 'í'; + chartbl[0x5f] = 'ó'; + chartbl[0x60] = 'ú'; + chartbl[0x7b] = 'ç'; + chartbl[0x7c] = '÷'; + chartbl[0x7d] = 'Ñ'; + chartbl[0x7e] = 'ñ'; + chartbl[0x7f] = '¤'; /* FIXME: this should be a solid block */ +} + +static void clear_buffer(subtitle *buf) +{ + int i; + buf->lines=0; + for (i = 0; i < SUB_MAX_TEXT; i++) { + free(buf->text[i]); + buf->text[i] = NULL; + } +} + + +/** + \brief scroll buffer one line up + \param buf buffer to scroll +*/ +static void scroll_buffer(subtitle* buf) +{ + int i; + + while(buf->lines > cc_lines) + { + free(buf->text[0]); + + for(i = 0; i < buf->lines - 1; i++) buf->text[i] = buf->text[i+1]; + + buf->text[buf->lines-1] = NULL; + buf->lines--; + } +} + +static int channel; + +void subcc_init(void) +{ + int i; + //printf("subcc_init(): initing...\n"); + build_char_table(); + for(i=0;ilines) {bb->lines++; cursor_pos=0;} + if(bb->text[bb->lines - 1]==NULL) + { + bb->text[bb->lines - 1] = calloc(1, CC_MAX_LINE_LENGTH); + cursor_pos=0; + } + + if(c=='\n') + { + if(cursor_pos>0 && bb->lines < SUB_MAX_TEXT) + { + bb->lines++;cursor_pos=0; + if(cc_mode==CC_ROLLUP){ //Carriage return - scroll buffer one line up + bb->text[bb->lines - 1]=calloc(1, CC_MAX_LINE_LENGTH); + scroll_buffer(bb); + } + } + } + else + { + if(cursor_pos==CC_MAX_LINE_LENGTH-1) + { + fprintf(stderr,"CC: append_char() reached CC_MAX_LINE_LENGTH!\n"); + return; + } + bb->text[bb->lines - 1][cursor_pos++]=c; + } + //In CC roll-up mode data should be shown immediately + if(cc_mode==CC_ROLLUP) display_buffer(bb); +} + + +static void swap_buffers(void) +{ + subtitle *foo; + foo=fb; + fb=bb; + bb=foo; +} + +static int selected_channel(void) +{ + return subcc_enabled - 1; +} + +static void cc_decode_EIA608(unsigned short int data) +{ + + static unsigned short int lastcode=0x0000; + uint8_t c1 = data & 0x7f; + uint8_t c2 = (data >> 8) & 0x7f; + + if (c1 & 0x60) { /* normal character, 0x20 <= c1 <= 0x7f */ + if (channel != (selected_channel() & 1)) + return; + append_char(chartbl[c1]); + if(c2 & 0x60) /*c2 might not be a normal char even if c1 is*/ + append_char(chartbl[c2]); + } + else if (c1 & 0x10) // control code / special char + { + channel = (c1 & 0x08) >> 3; + if (channel != (selected_channel() & 1)) + return; + c1&=~0x08; + if(data!=lastcode) + { + if(c2 & 0x40) { /*PAC, Preamble Address Code */ + append_char('\n'); /*FIXME properly interpret PACs*/ + } + else + switch(c1) + { + case 0x10: break; // ext attribute + case 0x11: + if((c2 & 0x30)==0x30) + { + //printf("[debug]:Special char (ignored)\n"); + /*cc_decode_special_char()*/; + } + else if (c2 & 0x20) + { + //printf("[debug]: midrow_attr (ignored)\n"); + /*cc_decode_midrow_attr()*/; + } + break; + case 0x14: + switch(c2) + { + case 0x00: //CC roll-on mode + cc_mode=CC_ROLLON; + break; + case 0x25: //CC roll-up, 2 rows + case 0x26: //CC roll-up, 3 rows + case 0x27: //CC roll-up, 4 rows + cc_lines=c2-0x23; + cc_mode=CC_ROLLUP; + break; + case 0x2C: display_buffer(NULL); //EDM + clear_buffer(fb); break; + case 0x2d: append_char('\n'); //carriage return + break; + case 0x2e: clear_buffer(bb); //ENM + break; + case 0x2f: swap_buffers(); //Swap buffers + display_buffer(fb); + clear_buffer(bb); + break; + } + break; + case 0x17: + if( c2>=0x21 && c2<=0x23) //TAB + { + break; + } + } + } + } + lastcode=data; +} + +static void subcc_decode(const uint8_t *inputbuffer, unsigned int inputlength) +{ + /* The first number may denote a channel number. I don't have the + * EIA-708 standard, so it is hard to say. + * From what I could figure out so far, the general format seems to be: + * + * repeat + * + * 0xfe starts 2 byte sequence of unknown purpose. It might denote + * field #2 in line 21 of the VBI. + * Treating it identical of 0xff fixes + * http://samples.mplayerhq.hu/MPEG-VOB/ClosedCaptions/Starship_Troopers.vob + * + * 0xff starts 2 byte EIA-608 sequence, field #1 in line 21 of the VBI. + * Followed by a 3-code triplet that starts either with 0xff or + * 0xfe. In either case, the following triplet needs to be ignored + * for line 21, field 1. + * + * 0x00 is padding, followed by 2 more 0x00. + * + * 0x01 always seems to appear at the beginning, always seems to + * be followed by 0xf8, 8-bit number. + * The lower 7 bits of this 8-bit number seem to denote the + * number of code triplets that follow. + * The most significant bit denotes whether the Line 21 field 1 + * captioning information is at odd or even triplet offsets from this + * beginning triplet. 1 denotes odd offsets, 0 denotes even offsets. + * + * Most captions are encoded with odd offsets, so this is what we + * will assume. + * + * until end of packet + */ + const uint8_t *current = inputbuffer; + unsigned int curbytes = 0; + uint8_t data1, data2; + uint8_t cc_code; + int odd_offset = 1; + + while (curbytes < inputlength) { + cc_code = current[0]; + + if (inputlength - curbytes < 2) { +#ifdef LOG_DEBUG + fprintf(stderr, "Not enough data for 2-byte CC encoding\n"); +#endif + break; + } + + data1 = current[1]; + data2 = current[2]; + current += 3; curbytes += 3; + + switch (cc_code) { + case 0xfe: + case 0xff: + odd_offset ^= 1; + if (odd_offset != selected_channel() >> 1) + break; + /* expect EIA-608 CC1/CC2 encoding */ + // FIXME check parity! + // Parity check omitted assuming we are reading from a DVD and therefore + // we should encounter no "transmission errors". + cc_decode_EIA608(data1 | (data2 << 8)); + break; + + case 0x00: + /* This seems to be just padding */ + break; + + case 0x01: + odd_offset = data2 >> 7; + break; + + default: +//#ifdef LOG_DEBUG + fprintf(stderr, "Unknown CC encoding: %x\n", cc_code); +//#endif + break; + } + } +} + + +void subcc_process_data(const uint8_t *inputdata, unsigned int len) +{ + if(!subcc_enabled) return; + if(!initialized) subcc_init(); + + subcc_decode(inputdata, len); +} diff --git a/sub/sub_cc.h b/sub/sub_cc.h new file mode 100644 index 0000000000..f5f6924057 --- /dev/null +++ b/sub/sub_cc.h @@ -0,0 +1,29 @@ +/* + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPLAYER_SUB_CC_H +#define MPLAYER_SUB_CC_H + +#include + +extern int subcc_enabled; + +void subcc_init(void); +void subcc_process_data(const uint8_t *inputdata, unsigned int len); + +#endif /* MPLAYER_SUB_CC_H */ diff --git a/sub/subreader.c b/sub/subreader.c new file mode 100644 index 0000000000..1f9294ec47 --- /dev/null +++ b/sub/subreader.c @@ -0,0 +1,2504 @@ +/* + * Subtitle reader with format autodetection + * + * Copyright (c) 2001 laaz + * Some code cleanup & realloc() by A'rpi/ESP-team + * + * This file is part of MPlayer. + * + * MPlayer is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * MPlayer is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with MPlayer; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include + +#include +#include + +#include "config.h" +#include "mp_msg.h" +#include "subreader.h" +#include "mpcommon.h" +#include "subassconvert.h" +#include "options.h" +#include "stream/stream.h" +#include "libavutil/common.h" +#include "libavutil/avstring.h" + +#ifdef CONFIG_ENCA +#include +#endif + +#define ERR ((void *) -1) + +#ifdef CONFIG_ICONV +#include +char *sub_cp=NULL; +#endif +#ifdef CONFIG_FRIBIDI +#include +char *fribidi_charset = NULL; ///character set that will be passed to FriBiDi +int flip_hebrew = 1; ///flip subtitles using fribidi +int fribidi_flip_commas = 0; ///flip comma when fribidi is used +#endif + +// Parameter struct for the format-specific readline functions +struct readline_args { + int utf16; + struct MPOpts *opts; +}; + +/* Maximal length of line of a subtitle */ +#define LINE_LEN 1000 +static float mpsub_position=0; +static float mpsub_multiplier=1.; +static int sub_slacktime = 20000; //20 sec + +int sub_no_text_pp=0; // 1 => do not apply text post-processing + // like {\...} elimination in SSA format. + +int sub_match_fuzziness=0; // level of sub name matching fuzziness + +/* Use the SUB_* constant defined in the header file */ +int sub_format=SUB_INVALID; +#ifdef CONFIG_SORTSUB +/* + Some subtitling formats, namely AQT and Subrip09, define the end of a + subtitle as the beginning of the following. Since currently we read one + subtitle at time, for these format we keep two global *subtitle, + previous_aqt_sub and previous_subrip09_sub, pointing to previous subtitle, + so we can change its end when we read current subtitle starting time. + When CONFIG_SORTSUB is defined, we use a single global unsigned long, + previous_sub_end, for both (and even future) formats, to store the end of + the previous sub: it is initialized to 0 in sub_read_file and eventually + modified by sub_read_aqt_line or sub_read_subrip09_line. + */ +unsigned long previous_sub_end; +#endif + +static int eol(char p) { + return p=='\r' || p=='\n' || p=='\0'; +} + +/* Remove leading and trailing space */ +static void trail_space(char *s) { + int i = 0; + while (isspace(s[i])) ++i; + if (i) strcpy(s, s + i); + i = strlen(s) - 1; + while (i > 0 && isspace(s[i])) s[i--] = '\0'; +} + +static char *stristr(const char *haystack, const char *needle) { + int len = 0; + const char *p = haystack; + + if (!(haystack && needle)) return NULL; + + len=strlen(needle); + while (*p != '\0') { + if (strncasecmp(p, needle, len) == 0) return (char*)p; + p++; + } + + return NULL; +} + +static void sami_add_line(subtitle *current, char *buffer, char **pos) { + char *p = *pos; + *p = 0; + trail_space(buffer); + if (*buffer && current->lines < SUB_MAX_TEXT) + current->text[current->lines++] = strdup(buffer); + *pos = buffer; +} + +static subtitle *sub_read_line_sami(stream_t* st, subtitle *current, + struct readline_args *args) +{ + int utf16 = args->utf16; + static char line[LINE_LEN+1]; + static char *s = NULL, *slacktime_s; + char text[LINE_LEN+1], *p=NULL, *q; + int state; + + current->lines = current->start = current->end = 0; + current->alignment = SUB_ALIGNMENT_BOTTOMCENTER; + state = 0; + + /* read the first line */ + if (!s) + if (!(s = stream_read_line(st, line, LINE_LEN, utf16))) return 0; + + do { + switch (state) { + + case 0: /* find "START=" or "Slacktime:" */ + slacktime_s = stristr (s, "Slacktime:"); + if (slacktime_s) + sub_slacktime = strtol (slacktime_s+10, NULL, 0) / 10; + + s = stristr (s, "Start="); + if (s) { + current->start = strtol (s + 6, &s, 0) / 10; + /* eat '>' */ + for (; *s != '>' && *s != '\0'; s++); + s++; + state = 1; continue; + } + break; + + case 1: /* find (optional) " TAG */ + if (s == '\0') + break; + s++; + continue; + + case 2: /* find ">" */ + if ((s = strchr (s, '>'))) { s++; state = 3; p = text; continue; } + break; + + case 3: /* get all text until '<' appears */ + if (*s == '\0') break; + else if (!strncasecmp (s, "
", 4)) { + sami_add_line(current, text, &p); + s += 4; + } + else if ((*s == '{') && !sub_no_text_pp) { state = 5; ++s; continue; } + else if (*s == '<') { state = 4; } + else if (!strncasecmp (s, " ", 6)) { *p++ = ' '; s += 6; } + else if (*s == '\t') { *p++ = ' '; s++; } + else if (*s == '\r' || *s == '\n') { s++; } + else *p++ = *s++; + + /* skip duplicated space */ + if (p > text + 2) if (*(p-1) == ' ' && *(p-2) == ' ') p--; + + continue; + + case 4: /* get current->end or skip */ + q = stristr (s, "Start="); + if (q) { + current->end = strtol (q + 6, &q, 0) / 10 - 1; + *p = '\0'; trail_space (text); + if (text[0] != '\0') + current->text[current->lines++] = strdup (text); + if (current->lines > 0) { state = 99; break; } + state = 0; continue; + } + s = strchr (s, '>'); + if (s) { s++; state = 3; continue; } + break; + case 5: /* get rid of {...} text, but read the alignment code */ + if ((*s == '\\') && (*(s + 1) == 'a') && !sub_no_text_pp) { + if (stristr(s, "\\a1") != NULL) { + current->alignment = SUB_ALIGNMENT_BOTTOMLEFT; + s = s + 3; + } + if (stristr(s, "\\a2") != NULL) { + current->alignment = SUB_ALIGNMENT_BOTTOMCENTER; + s = s + 3; + } else if (stristr(s, "\\a3") != NULL) { + current->alignment = SUB_ALIGNMENT_BOTTOMRIGHT; + s = s + 3; + } else if ((stristr(s, "\\a4") != NULL) || (stristr(s, "\\a5") != NULL) || (stristr(s, "\\a8") != NULL)) { + current->alignment = SUB_ALIGNMENT_TOPLEFT; + s = s + 3; + } else if (stristr(s, "\\a6") != NULL) { + current->alignment = SUB_ALIGNMENT_TOPCENTER; + s = s + 3; + } else if (stristr(s, "\\a7") != NULL) { + current->alignment = SUB_ALIGNMENT_TOPRIGHT; + s = s + 3; + } else if (stristr(s, "\\a9") != NULL) { + current->alignment = SUB_ALIGNMENT_MIDDLELEFT; + s = s + 3; + } else if (stristr(s, "\\a10") != NULL) { + current->alignment = SUB_ALIGNMENT_MIDDLECENTER; + s = s + 4; + } else if (stristr(s, "\\a11") != NULL) { + current->alignment = SUB_ALIGNMENT_MIDDLERIGHT; + s = s + 4; + } + } + if (*s == '}') state = 3; + ++s; + continue; + } + + /* read next line */ + if (state != 99 && !(s = stream_read_line (st, line, LINE_LEN, utf16))) { + if (current->start > 0) { + break; // if it is the last subtitle + } else { + return 0; + } + } + + } while (state != 99); + + // For the last subtitle + if (current->end <= 0) { + current->end = current->start + sub_slacktime; + sami_add_line(current, text, &p); + } + + return current; +} + + +static char *sub_readtext(char *source, char **dest) { + int len=0; + char *p=source; + +// printf("src=%p dest=%p \n",source,dest); + + while ( !eol(*p) && *p!= '|' ) { + p++,len++; + } + + *dest= malloc (len+1); + if (!dest) {return ERR;} + + strncpy(*dest, source, len); + (*dest)[len]=0; + + while (*p=='\r' || *p=='\n' || *p=='|') p++; + + if (*p) return p; // not-last text field + else return NULL; // last text field +} + +static subtitle *sub_read_line_microdvd(stream_t *st,subtitle *current, + struct readline_args *args) +{ + int utf16 = args->utf16; + char line[LINE_LEN+1]; + char line2[LINE_LEN+1]; + char *p, *next; + int i; + + do { + if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; + } while ((sscanf (line, + "{%ld}{}%[^\r\n]", + &(current->start), line2) < 2) && + (sscanf (line, + "{%ld}{%ld}%[^\r\n]", + &(current->start), &(current->end), line2) < 3)); + + if (args->opts->ass_enabled) { + subassconvert_microdvd(line2, line, LINE_LEN + 1); + p = line; + } else + p = line2; + + next=p, i=0; + while ((next =sub_readtext (next, &(current->text[i])))) { + if (current->text[i]==ERR) {return ERR;} + i++; + if (i>=SUB_MAX_TEXT) { mp_msg(MSGT_SUBREADER,MSGL_WARN,"Too many lines in a subtitle\n");current->lines=i;return current;} + } + current->lines= ++i; + + return current; +} + +static subtitle *sub_read_line_mpl2(stream_t *st,subtitle *current, + struct readline_args *args) +{ + int utf16 = args->utf16; + char line[LINE_LEN+1]; + char line2[LINE_LEN+1]; + char *p, *next; + int i; + + do { + if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; + } while ((sscanf (line, + "[%ld][%ld]%[^\r\n]", + &(current->start), &(current->end), line2) < 3)); + current->start *= 10; + current->end *= 10; + p=line2; + + next=p, i=0; + while ((next =sub_readtext (next, &(current->text[i])))) { + if (current->text[i]==ERR) {return ERR;} + i++; + if (i>=SUB_MAX_TEXT) { mp_msg(MSGT_SUBREADER,MSGL_WARN,"Too many lines in a subtitle\n");current->lines=i;return current;} + } + current->lines= ++i; + + return current; +} + +static subtitle *sub_read_line_subrip(stream_t* st, subtitle *current, + struct readline_args *args) +{ + int utf16 = args->utf16; + char line[LINE_LEN+1]; + int a1,a2,a3,a4,b1,b2,b3,b4; + char *p=NULL, *q=NULL; + int len; + + while (1) { + if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; + if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < 8) continue; + current->start = a1*360000+a2*6000+a3*100+a4; + current->end = b1*360000+b2*6000+b3*100+b4; + + if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; + + p=q=line; + for (current->lines=1; current->lines < SUB_MAX_TEXT; current->lines++) { + for (q=p,len=0; *p && *p!='\r' && *p!='\n' && *p!='|' && strncmp(p,"[br]",4); p++,len++); + current->text[current->lines-1]=malloc (len+1); + if (!current->text[current->lines-1]) return ERR; + strncpy (current->text[current->lines-1], q, len); + current->text[current->lines-1][len]='\0'; + if (!*p || *p=='\r' || *p=='\n') break; + if (*p=='|') p++; + else while (*p++!=']'); + } + break; + } + return current; +} + +static subtitle *sub_ass_read_line_subviewer(stream_t *st, subtitle *current, + struct readline_args *args) +{ + int utf16 = args->utf16; + int a1, a2, a3, a4, b1, b2, b3, b4, j = 0; + + while (!current->text[0]) { + char line[LINE_LEN + 1], full_line[LINE_LEN + 1], sep; + int i; + + /* Parse SubRip header */ + if (!stream_read_line(st, line, LINE_LEN, utf16)) + return NULL; + if (sscanf(line, "%d:%d:%d%[,.:]%d --> %d:%d:%d%[,.:]%d", + &a1, &a2, &a3, &sep, &a4, &b1, &b2, &b3, &sep, &b4) < 10) + continue; + + current->start = a1 * 360000 + a2 * 6000 + a3 * 100 + a4 / 10; + current->end = b1 * 360000 + b2 * 6000 + b3 * 100 + b4 / 10; + + /* Concat lines */ + full_line[0] = 0; + for (i = 0; i < SUB_MAX_TEXT; i++) { + int blank = 1, len = 0; + char *p; + + if (!stream_read_line(st, line, LINE_LEN, utf16)) + break; + + for (p = line; *p != '\n' && *p != '\r' && *p; p++, len++) + if (*p != ' ' && *p != '\t') + blank = 0; + + if (blank) + break; + + *p = 0; + + if (!(j + 1 + len < sizeof(full_line) - 1)) + break; + + if (j != 0) + full_line[j++] = '\n'; + strcpy(&full_line[j], line); + j += len; + } + + /* Use the ASS/SSA converter to transform the whole lines */ + if (full_line[0]) { + char converted_line[LINE_LEN + 1]; + subassconvert_subrip(full_line, converted_line, LINE_LEN + 1); + current->text[0] = strdup(converted_line); + current->lines = 1; + } + } + return current; +} + +static subtitle *sub_read_line_subviewer(stream_t *st,subtitle *current, + struct readline_args *args) +{ + int utf16 = args->utf16; + char line[LINE_LEN+1]; + int a1,a2,a3,a4,b1,b2,b3,b4; + char *p=NULL; + int i,len; + + if (args->opts->ass_enabled) + return sub_ass_read_line_subviewer(st, current, args); + while (!current->text[0]) { + if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; + if ((len=sscanf (line, "%d:%d:%d%[,.:]%d --> %d:%d:%d%[,.:]%d",&a1,&a2,&a3,(char *)&i,&a4,&b1,&b2,&b3,(char *)&i,&b4)) < 10) + continue; + current->start = a1*360000+a2*6000+a3*100+a4/10; + current->end = b1*360000+b2*6000+b3*100+b4/10; + for (i=0; itext[i]=malloc (len+1); + if (!current->text[i]) return ERR; + //strncpy (current->text[i], line, len); current->text[i][len]='\0'; + for(; j') { + skip=0; + continue; + } + if(line[j]=='<') { + skip=1; + continue; + } + if(skip) { + continue; + } + *curptr=line[j]; + curptr++; + } + *curptr='\0'; + + i++; + } else { + break; + } + } + current->lines=i; + } + return current; +} + +static subtitle *sub_read_line_subviewer2(stream_t *st,subtitle *current, + struct readline_args *args) +{ + int utf16 = args->utf16; + char line[LINE_LEN+1]; + int a1,a2,a3,a4; + char *p=NULL; + int i,len; + + while (!current->text[0]) { + if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; + if (line[0]!='{') + continue; + if ((len=sscanf (line, "{T %d:%d:%d:%d",&a1,&a2,&a3,&a4)) < 4) + continue; + current->start = a1*360000+a2*6000+a3*100+a4/10; + for (i=0; itext[i]=malloc (len+1); + if (!current->text[i]) return ERR; + strncpy (current->text[i], line, len); current->text[i][len]='\0'; + ++i; + } else { + break; + } + } + current->lines=i; + } + return current; +} + + +static subtitle *sub_read_line_vplayer(stream_t *st,subtitle *current, + struct readline_args *args) +{ + int utf16 = args->utf16; + char line[LINE_LEN+1]; + int a1,a2,a3; + char *p=NULL, *next,separator; + int i,len,plen; + + while (!current->text[0]) { + if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; + if ((len=sscanf (line, "%d:%d:%d%c%n",&a1,&a2,&a3,&separator,&plen)) < 4) + continue; + + if (!(current->start = a1*360000+a2*6000+a3*100)) + continue; + /* removed by wodzu + p=line; + // finds the body of the subtitle + for (i=0; i<3; i++){ + p=strchr(p,':'); + if (p==NULL) break; + ++p; + } + if (p==NULL) { + printf("SUB: Skipping incorrect subtitle line!\n"); + continue; + } + */ + // by wodzu: hey! this time we know what length it has! what is + // that magic for? it can't deal with space instead of third + // colon! look, what simple it can be: + p = &line[ plen ]; + + i=0; + if (*p!='|') { + // + next = p,i=0; + while ((next =sub_readtext (next, &(current->text[i])))) { + if (current->text[i]==ERR) {return ERR;} + i++; + if (i>=SUB_MAX_TEXT) { mp_msg(MSGT_SUBREADER,MSGL_WARN,"Too many lines in a subtitle\n");current->lines=i;return current;} + } + current->lines=i+1; + } + } + return current; +} + +static subtitle *sub_read_line_rt(stream_t *st,subtitle *current, + struct readline_args *args) +{ + int utf16 = args->utf16; + + //TODO: This format uses quite rich (sub/super)set of xhtml + // I couldn't check it since DTD is not included. + // WARNING: full XML parses can be required for proper parsing + char line[LINE_LEN+1]; + int a1,a2,a3,a4,b1,b2,b3,b4; + char *p=NULL,*next=NULL; + int i,len,plen; + + while (!current->text[0]) { + if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; + //TODO: it seems that format of time is not easily determined, it may be 1:12, 1:12.0 or 0:1:12.0 + //to describe the same moment in time. Maybe there are even more formats in use. + //if ((len=sscanf (line, "