+/*
+ This retrieves the size of the video.
+ The best case is when the original video size is known, as we can then
+ scale images to match. In this case, since VLC autoscales, we want to
+ return the original size and let VLC scale everything.
+ if the original size is not known, then VLC can't resize, so we return
+ the size of the incoming video. If sizes in the Kate stream are in
+ relative units, it works fine. If they are absolute, you get what you
+ ask for. Images aren't rescaled.
+*/
+static void GetVideoSize( decoder_t *p_dec, int *w, int *h )
+{
+ /* searching for vout to get its size is frowned upon, so we don't and
+ use a default size if the original canvas size is not specified. */
+#if 1
+ decoder_sys_t *p_sys = p_dec->p_sys;
+ if( p_sys->ki.original_canvas_width > 0 && p_sys->ki.original_canvas_height > 0 )
+ {
+ *w = p_sys->ki.original_canvas_width;
+ *h = p_sys->ki.original_canvas_height;
+ msg_Dbg( p_dec, "original canvas %zu %zu\n",
+ p_sys->ki.original_canvas_width, p_sys->ki.original_canvas_height );
+ }
+ else
+ {
+ /* nothing, leave defaults */
+ msg_Dbg( p_dec, "original canvas size unknown\n");
+ }
+#else
+ /* keep this just in case it might be allowed one day ;) */
+ vout_thread_t *p_vout;
+ p_vout = vlc_object_find( (vlc_object_t*)p_dec, VLC_OBJECT_VOUT, FIND_CHILD );
+ if( p_vout )
+ {
+ decoder_sys_t *p_sys = p_dec->p_sys;
+ if( p_sys->ki.original_canvas_width > 0 && p_sys->ki.original_canvas_height > 0 )
+ {
+ *w = p_sys->ki.original_canvas_width;
+ *h = p_sys->ki.original_canvas_height;
+ }
+ else
+ {
+ *w = p_vout->fmt_in.i_width;
+ *h = p_vout->fmt_in.i_height;
+ }
+ msg_Dbg( p_dec, "video: in %d %d, out %d %d, original canvas %zu %zu\n",
+ p_vout->fmt_in.i_width, p_vout->fmt_in.i_height,
+ p_vout->fmt_out.i_width, p_vout->fmt_out.i_height,
+ p_sys->ki.original_canvas_width, p_sys->ki.original_canvas_height );
+ vlc_object_release( p_vout );
+ }
+#endif
+}
+
+#ifdef ENABLE_BITMAPS
+
+static void CreateKateBitmap( picture_t *pic, const kate_bitmap *bitmap )
+{
+ size_t y;
+
+ for( y=0; y<bitmap->height; ++y )
+ {
+ uint8_t *dest = pic->Y_PIXELS+pic->Y_PITCH*y;
+ const uint8_t *src = bitmap->pixels+y*bitmap->width;
+ memcpy( dest, src, bitmap->width );
+ }
+}
+
+static void CreateKatePalette( video_palette_t *fmt_palette, const kate_palette *palette )
+{
+ size_t n;
+
+ fmt_palette->i_entries = palette->ncolors;
+ for( n=0; n<palette->ncolors; ++n )
+ {
+ rgb_to_yuv(
+ &fmt_palette->palette[n][0], &fmt_palette->palette[n][1], &fmt_palette->palette[n][2],
+ palette->colors[n].r, palette->colors[n].g, palette->colors[n].b
+ );
+ fmt_palette->palette[n][3] = palette->colors[n].a;
+ }
+}
+
+#endif
+
+static void SetupText( decoder_t *p_dec, subpicture_t *p_spu, const kate_event *ev )
+{
+ decoder_sys_t *p_sys = p_dec->p_sys;
+
+ if( ev->text_encoding != kate_utf8 )
+ {
+ msg_Warn( p_dec, "Text isn't UTF-8, unsupported, ignored" );
+ return;
+ }
+
+ switch( ev->text_markup_type )
+ {
+ case kate_markup_none:
+ p_spu->p_region->psz_text = strdup( ev->text ); /* no leak, this actually gets killed by the core */
+ break;
+ case kate_markup_simple:
+ if( p_sys->b_formatted )
+ {
+ /* the HTML renderer expects a top level text tag pair */
+ char *buffer = NULL;
+ if( asprintf( &buffer, "<text>%s</text>", ev->text ) >= 0 )
+ {
+ p_spu->p_region->psz_html = buffer;
+ }
+ break;
+ }
+ /* if not formatted, we fall through */
+ default:
+ /* we don't know about this one, so remove markup and display as text */
+ {
+ char *copy = strdup( ev->text );
+ size_t len0 = strlen( copy ) + 1;
+ kate_text_remove_markup( ev->text_encoding, copy, &len0 );
+ p_spu->p_region->psz_text = copy;
+ }
+ break;
+ }
+}
+