sub: add function to draw OSD into an image

The osd_draw_on_image() function renders the full OSD into the provided
image.

It uses the mp_draw_sub_bitmaps() function added in the previous commit
to do the actual work.
This commit is contained in:
wm4 2012-10-07 03:26:46 +02:00
parent 0e72b0d5d3
commit c139cd2b93
2 changed files with 31 additions and 0 deletions

View File

@ -37,6 +37,7 @@
#include "sub.h"
#include "dec_sub.h"
#include "img_convert.h"
#include "draw_bmp.h"
#include "spudec.h"
@ -300,6 +301,30 @@ void draw_osd_with_eosd(struct vo *vo, struct osd_state *osd)
}
}
// Returns whether anything was drawn.
bool osd_draw_on_image(struct osd_state *osd, struct mp_image *dest,
struct mp_csp_details *dest_csp,
struct sub_render_params *sub_params)
{
static const bool formats[SUBBITMAP_COUNT] = {
[SUBBITMAP_LIBASS] = true,
[SUBBITMAP_RGBA] = true,
};
bool changed = false;
osd_update_ext(osd, sub_params->dim);
for (int n = 0; n < MAX_OSD_PARTS; n++) {
struct osd_object *obj = osd->objs[n];
if (obj->is_sub && osd->render_subs_in_filter)
continue;
struct sub_bitmaps imgs;
if (render_object(osd, obj, &imgs, sub_params, formats)) {
mp_draw_sub_bitmaps(dest, &imgs, dest_csp);
changed = true;
}
}
return changed;
}
void osd_draw_text_ext(struct osd_state *osd, int w, int h,
int ml, int mt, int mr, int mb, int unused0, int unused1,
void (*draw_alpha)(void *ctx, int x0, int y0, int w,

View File

@ -238,6 +238,12 @@ bool osd_draw_sub(struct osd_state *osd, struct sub_bitmaps *out_imgs,
struct sub_render_params *sub_params,
const bool formats[SUBBITMAP_COUNT]);
struct mp_image;
struct mp_csp_details;
bool osd_draw_on_image(struct osd_state *osd, struct mp_image *dest,
struct mp_csp_details *dest_csp,
struct sub_render_params *sub_params);
bool sub_bitmaps_bb(struct sub_bitmaps *imgs, int *x1, int *y1,
int *x2, int *y2);