From 3365514951e9c07ec3a21bb3898e5796c214f8b7 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 28 Sep 2012 21:38:52 +0200 Subject: sub: allow rendering OSD in ASS image format directly, simplify Before this commit, the OSD was drawn using libass, but the resulting bitmaps were converted to the internal mplayer OSD format. We want to get rid of the old OSD format, because it's monochrome, and can't even be rendered directly using modern video output methods (like with OpenGL/Direct3D/VDPAU). Change it so that VOs can get the ASS images directly, without additional conversions. (This also has the consequence that the OSD can render colors now.) Currently, this is vo_gl3 only. The other VOs still use the old method. Also, the old OSD format is still used for all VOs with DVD subtitles (spudec). Rewrite sub.c. Remove all the awkward flags and bounding boxes and change detection things. It turns out that much of that isn't needed. Move code related to converting subtitle images to img_convert.c. (It has to be noted that all of these conversions were already done before in some places, and that the new code actually makes less use of them.) --- sub/spudec.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'sub/spudec.c') diff --git a/sub/spudec.c b/sub/spudec.c index 47e1676e2e..a58df60b17 100644 --- a/sub/spudec.c +++ b/sub/spudec.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include @@ -44,6 +45,7 @@ #include "spudec.h" #include "vobsub.h" +#include "sub.h" #include "mpcommon.h" /* Valid values for spu_aamode: @@ -57,7 +59,6 @@ int spu_aamode = 3; int spu_alignment = -1; float spu_gaussvar = 1.0; -extern int sub_pos; typedef struct spu_packet_t packet_t; struct spu_packet_t { @@ -123,6 +124,9 @@ typedef struct { unsigned int is_forced_sub; /* true if current subtitle is a forced subtitle */ struct palette_crop_cache palette_crop_cache; + + struct sub_bitmap borrowed_sub_part; + struct old_osd_planar borrowed_sub_image; } spudec_handle_t; static void spudec_queue_packet(spudec_handle_t *this, packet_t *packet) @@ -722,6 +726,40 @@ void spudec_set_forced_subs_only(void * const this, const unsigned int flag) } } +static void get_data(void *ctx, int x0,int y0, int w,int h, unsigned char* src, + unsigned char *srca, int stride) +{ + struct sub_bitmaps *bmp = ctx; + assert(bmp->num_parts == 0); + bmp->num_parts = 1; + struct sub_bitmap *s = &bmp->parts[0]; + struct old_osd_planar *p = s->bitmap; + // We know that the data stays valid until the next SPU related call + p->bitmap = src; + p->alpha = srca; + *s = (struct sub_bitmap) { + .bitmap = p, .stride = stride, + .x = x0, .y = y0, + .w = w, .h = h, + .dw = w, .dh = h, + }; +} + +void spudec_get_bitmap(void *this, int w, int h, struct sub_bitmaps *res) +{ + spudec_handle_t *spu = this; + *res = (struct sub_bitmaps) { + .format = SUBBITMAP_OLD_PLANAR, + .parts = &spu->borrowed_sub_part, + }; + res->parts[0].bitmap = &spu->borrowed_sub_image; + if (w == -1 && h == -1) { + spudec_draw(this, get_data, res); + } else { + spudec_draw_scaled(this, w, h, get_data, res); + } +} + 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; -- cgit v1.2.3