From cc05910f16a5ccd8e3dca26a89e9c3835cbdb645 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 4 Oct 2012 17:16:40 +0200 Subject: sub: cosmetics: move things around Move sub-bitmap definitions from dec_sub.h to sub.h. While it's a bit odd that OSD data structures are in a file named sub.h, it's definitely way too strange to have them in a file about subtitle decoding. (Maybe sub.h/.c and the sub/ directory should be split out and renamed "osd" at a later point.) Remove including ass_mp.h (and the libass headers) where possible. Remove typedefs for mp_eosd_res and sub_bitmaps structs. Store a mp_eosd_res struct in osd_state instead of just w/h. Note that sbtitles might be rendered using different sizes/margins when filters are involved (the subtitle renderer is not supposed to use the OSD res directly, and the "dim" member removed in the previous commit is something different). --- sub/dec_sub.h | 56 +++---------------------------------------------------- sub/osd_libass.c | 4 ++-- sub/sd_ass.c | 1 + sub/sd_lavc.c | 1 + sub/sub.c | 14 ++++++++------ sub/sub.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 70 insertions(+), 63 deletions(-) (limited to 'sub') diff --git a/sub/dec_sub.h b/sub/dec_sub.h index 442cd870d8..9cfe8d964c 100644 --- a/sub/dec_sub.h +++ b/sub/dec_sub.h @@ -4,61 +4,11 @@ #include #include +#include "sub.h" + struct sh_sub; -struct osd_state; struct ass_track; - -enum sub_bitmap_format { - SUBBITMAP_EMPTY = 0,// no bitmaps; always has num_parts==0 - SUBBITMAP_LIBASS, // A8, with a per-surface blend color (libass.color) - SUBBITMAP_RGBA, // B8G8R8A8, can be scaled - SUBBITMAP_OLD, // I8A8 (monochrome), premultiplied alpha - SUBBITMAP_OLD_PLANAR, // like previous, but bitmap points to old_osd_planar - - SUBBITMAP_COUNT -}; - -// For SUBBITMAP_OLD_PANAR -struct old_osd_planar { - unsigned char *bitmap; - unsigned char *alpha; -}; - -typedef struct mp_eosd_res { - int w, h; // screen dimensions, including black borders - int mt, mb, ml, mr; // borders (top, bottom, left, right) -} mp_eosd_res_t; - -struct sub_bitmap { - void *bitmap; - int stride; - int w, h; - int x, y; - // Note: not clipped, going outside the screen area is allowed - int dw, dh; - - union { - struct { - uint32_t color; - } libass; - }; -}; - -typedef struct sub_bitmaps { - int render_index; // for VO cache state (limited by MAX_OSD_PARTS) - - enum sub_bitmap_format format; - bool scaled; // if false, dw==w && dh==h - - struct sub_bitmap *parts; - int num_parts; - - // Provided for VOs with old code - struct ass_image *imgs; - - // Incremented on each change - int bitmap_id, bitmap_pos_id; -} mp_eosd_images_t; +struct MPOpts *opts; struct sub_render_params { double pts; diff --git a/sub/osd_libass.c b/sub/osd_libass.c index 811bc009f3..f3296c6091 100644 --- a/sub/osd_libass.c +++ b/sub/osd_libass.c @@ -196,7 +196,7 @@ static void update_progbar(struct osd_state *osd, struct osd_object *obj) // Assume the OSD bar takes 2/3 of the OSD width at PlayResY=288 and // FontSize=22 with an OSD aspect ratio of 16:9. Rescale as needed. // xxx can fail when unknown fonts are involved - double asp = (double)osd->w / osd->h; + double asp = (double)osd->res.w / osd->res.h; double scale = (asp / 1.77777) * (obj->osd_track->PlayResY / 288.0); style->ScaleX = style->ScaleY = scale; style->FontSize = 22.0; @@ -285,7 +285,7 @@ void osd_object_get_bitmaps(struct osd_state *osd, struct osd_object *obj, if (!obj->osd_track) return; - ass_set_frame_size(osd->osd_render, osd->w, osd->h); + ass_set_frame_size(osd->osd_render, osd->res.w, osd->res.h); mp_ass_render_frame(osd->osd_render, obj->osd_track, 0, &obj->parts_cache, out_imgs); talloc_steal(obj, obj->parts_cache); diff --git a/sub/sd_ass.c b/sub/sd_ass.c index fca47c557b..44c91c6fdc 100644 --- a/sub/sd_ass.c +++ b/sub/sd_ass.c @@ -28,6 +28,7 @@ #include "mp_msg.h" #include "libmpdemux/stheader.h" #include "sub.h" +#include "dec_sub.h" #include "ass_mp.h" #include "sd.h" #include "subassconvert.h" diff --git a/sub/sd_lavc.c b/sub/sd_lavc.c index 7f327957dd..a10ac5e18e 100644 --- a/sub/sd_lavc.c +++ b/sub/sd_lavc.c @@ -25,6 +25,7 @@ #include "sd.h" #include "spudec.h" // Current code still pushes subs directly to global spudec +#include "dec_sub.h" #include "sub.h" struct sd_lavc_priv { diff --git a/sub/sub.c b/sub/sub.c index 600ef6fae1..b2d9eb82fc 100644 --- a/sub/sub.c +++ b/sub/sub.c @@ -35,7 +35,7 @@ #include "mp_msg.h" #include "libvo/video_out.h" #include "sub.h" -#include "sub/ass_mp.h" +#include "dec_sub.h" #include "img_convert.h" #include "spudec.h" @@ -92,9 +92,11 @@ static struct osd_state *global_osd; static void osd_update_ext(struct osd_state *osd, struct mp_eosd_res res) { - if (osd->w != res.w || osd->h != res.h) { - osd->w = res.w; - osd->h = res.h; + struct mp_eosd_res old = osd->res; + if (old.w != res.w || old.h != res.h || old.ml != res.ml || old.mt != res.mt + || old.mr != res.mr || old.mb != res.mb) + { + osd->res = res; for (int n = 0; n < MAX_OSD_PARTS; n++) osd->objs[n]->force_redraw = true; } @@ -171,7 +173,7 @@ static bool render_object(struct osd_state *osd, struct osd_object *obj, if (obj->type == OSDTYPE_SPU) { *out_imgs = (struct sub_bitmaps) {0}; if (spu_visible(osd, obj)) - spudec_get_bitmap(vo_spudec, osd->w, osd->h, out_imgs); + spudec_get_bitmap(vo_spudec, osd->res.w, osd->res.h, out_imgs); // Normal change-detection (sub. dec. calls vo_osd_changed(OSDTYPE_SPU)) if (obj->force_redraw) { out_imgs->bitmap_id++; @@ -269,7 +271,7 @@ bool osd_draw_sub(struct osd_state *osd, struct sub_bitmaps *out_imgs, void draw_osd_with_eosd(struct vo *vo, struct osd_state *osd) { - mp_eosd_res_t dim = {0}; + struct mp_eosd_res dim = {0}; if (vo_control(vo, VOCTRL_GET_EOSD_RES, &dim) != VO_TRUE) return; diff --git a/sub/sub.h b/sub/sub.h index ed3010c1af..6a83036460 100644 --- a/sub/sub.h +++ b/sub/sub.h @@ -20,11 +20,64 @@ #define MPLAYER_SUB_H #include +#include #include "subreader.h" -#include "dec_sub.h" struct vo; +struct sub_render_params; + +enum sub_bitmap_format { + SUBBITMAP_EMPTY = 0,// no bitmaps; always has num_parts==0 + SUBBITMAP_LIBASS, // A8, with a per-surface blend color (libass.color) + SUBBITMAP_RGBA, // B8G8R8A8, can be scaled + SUBBITMAP_OLD, // I8A8 (monochrome), premultiplied alpha + SUBBITMAP_OLD_PLANAR, // like previous, but bitmap points to old_osd_planar + + SUBBITMAP_COUNT +}; + +// For SUBBITMAP_OLD_PANAR +struct old_osd_planar { + unsigned char *bitmap; + unsigned char *alpha; +}; + +struct sub_bitmap { + void *bitmap; + int stride; + int w, h; + int x, y; + // Note: not clipped, going outside the screen area is allowed + int dw, dh; + + union { + struct { + uint32_t color; + } libass; + }; +}; + +struct sub_bitmaps { + int render_index; // for VO cache state (limited by MAX_OSD_PARTS) + + enum sub_bitmap_format format; + bool scaled; // if false, dw==w && dh==h + + struct sub_bitmap *parts; + int num_parts; + + // Provided for VOs with old code + struct ass_image *imgs; + + // Incremented on each change + int bitmap_id, bitmap_pos_id; +}; + +struct mp_eosd_res { + int w, h; // screen dimensions, including black borders + int mt, mb, ml, mr; // borders (top, bottom, left, right) +}; enum mp_osdtype { OSDTYPE_SUB, @@ -71,7 +124,7 @@ struct osd_state { bool render_subs_in_filter; - int w, h; + struct mp_eosd_res res; char *osd_text; // OSDTYPE_OSD int progbar_type, progbar_value; // OSDTYPE_PROGBAR -- cgit v1.2.3