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).
This commit is contained in:
wm4 2012-10-04 17:16:40 +02:00
parent 05f4f00e24
commit cc05910f16
12 changed files with 76 additions and 72 deletions

View File

@ -35,6 +35,7 @@
#include "mp_image.h"
#include "vf.h"
#include "sub/sub.h"
#include "sub/dec_sub.h"
#include "libvo/fastmemcpy.h"

View File

@ -28,7 +28,6 @@
#include "bitmap_packer.h"
#include "mp_msg.h"
#include "mpcommon.h"
#include "sub/ass_mp.h"
#include "sub/dec_sub.h"
#include "fastmemcpy.h"

View File

@ -333,7 +333,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
return mpgl_osd_query_format(p->osd, *(int *)data)
? VO_TRUE : VO_NOTIMPL;
case VOCTRL_GET_EOSD_RES: {
mp_eosd_res_t *r = data;
struct mp_eosd_res *r = data;
r->w = vo->dwidth;
r->h = vo->dheight;
r->mt = r->mb = r->ml = r->mr = 0;

View File

@ -42,7 +42,6 @@
#include "gl_osd.h"
#include "aspect.h"
#include "fastmemcpy.h"
#include "sub/ass_mp.h"
//for gl_priv.use_yuv
#define MASK_ALL_YUV (~(1 << YUV_CONVERSION_NONE))
@ -1096,7 +1095,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
case VOCTRL_QUERY_EOSD_FORMAT:
return mpgl_osd_query_format(p->osd, *(int *)data) ? VO_TRUE : VO_NOTIMPL;
case VOCTRL_GET_EOSD_RES: {
mp_eosd_res_t *r = data;
struct mp_eosd_res *r = data;
r->w = vo->dwidth;
r->h = vo->dheight;
r->mt = r->mb = r->ml = r->mr = 0;

View File

@ -54,7 +54,6 @@
#include "filter_kernels.h"
#include "aspect.h"
#include "fastmemcpy.h"
#include "sub/ass_mp.h"
static const char vo_gl3_shaders[] =
// Generated from libvo/vo_gl3_shaders.glsl
@ -1689,7 +1688,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
draw_eosd(p, data);
return VO_TRUE;
case VOCTRL_GET_EOSD_RES: {
mp_eosd_res_t *r = data;
struct mp_eosd_res *r = data;
r->w = vo->dwidth;
r->h = vo->dheight;
r->ml = r->mr = p->border_x;

View File

@ -51,7 +51,6 @@
#include "libmpcodecs/vfcap.h"
#include "libmpcodecs/mp_image.h"
#include "osdep/timer.h"
#include "sub/ass_mp.h"
#include "bitmap_packer.h"
#define WRAP_ADD(x, a, m) ((a) < 0 \
@ -984,7 +983,7 @@ static void draw_eosd(struct vo *vo, int index)
}
}
static void generate_eosd(struct vo *vo, mp_eosd_images_t *imgs)
static void generate_eosd(struct vo *vo, struct sub_bitmaps *imgs)
{
struct vdpctx *vc = vo->priv;
struct vdp_functions *vdp = vc->vdp;
@ -1617,7 +1616,7 @@ static int control(struct vo *vo, uint32_t request, void *data)
if (!data)
return VO_FALSE;
if (status_ok(vo)) {
mp_eosd_images_t *imgs = data;
struct sub_bitmaps *imgs = data;
generate_eosd(vo, imgs);
draw_eosd(vo, imgs->render_index);
}

View File

@ -4,61 +4,11 @@
#include <stdbool.h>
#include <stdint.h>
#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;

View File

@ -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);

View File

@ -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"

View File

@ -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 {

View File

@ -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;

View File

@ -20,11 +20,64 @@
#define MPLAYER_SUB_H
#include <stdbool.h>
#include <stdint.h>
#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