1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-25 16:33:02 +00:00

img_convert: add function to scale RGBA OSD images

This commit is contained in:
wm4 2013-08-10 00:27:41 +02:00
parent 689a25003f
commit c7da4ba744
4 changed files with 50 additions and 1 deletions

View File

@ -142,6 +142,51 @@ bool osd_conv_blur_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs,
return true;
}
// If RGBA parts need scaling, scale them.
bool osd_scale_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs)
{
struct sub_bitmaps src = *imgs;
if (src.format != SUBBITMAP_RGBA && src.format != SUBBITMAP_RGBA_STR)
return false;
bool need_scale = false;
for (int n = 0; n < src.num_parts; n++) {
struct sub_bitmap *sb = &src.parts[n];
if (sb->w != sb->dw || sb->h != sb->dh)
need_scale = true;
}
if (!need_scale)
return false;
talloc_free(c->parts);
imgs->parts = c->parts = talloc_array(c, struct sub_bitmap, src.num_parts);
// Note: we scale all parts, since most likely all need scaling anyway, and
// to get a proper copy of all data in the imgs list.
for (int n = 0; n < src.num_parts; n++) {
struct sub_bitmap *d = &imgs->parts[n];
struct sub_bitmap *s = &src.parts[n];
struct mp_image src_image = {0};
mp_image_setfmt(&src_image, IMGFMT_BGRA);
mp_image_set_size(&src_image, s->w, s->h);
src_image.planes[0] = s->bitmap;
src_image.stride[0] = s->stride;
d->x = s->x;
d->y = s->y;
d->w = d->dw = s->dw;
d->h = d->dh = s->dh;
struct mp_image *image = mp_image_alloc(IMGFMT_BGRA, d->w, d->h);
talloc_steal(c->parts, image);
d->stride = image->stride[0];
d->bitmap = image->planes[0];
mp_image_swscale(image, &src_image, mp_sws_fast_flags);
}
return true;
}
static void rgba_to_gray(uint32_t *colors, size_t count)
{
for (int n = 0; n < count; n++) {

View File

@ -18,9 +18,9 @@ bool osd_conv_ass_to_rgba_str(struct osd_conv_cache *c, struct sub_bitmaps *imgs
// Sub postprocessing
bool osd_conv_blur_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs,
double gblur);
bool osd_scale_rgba(struct osd_conv_cache *c, struct sub_bitmaps *imgs);
bool osd_conv_idx_to_gray(struct osd_conv_cache *c, struct sub_bitmaps *imgs);
bool mp_sub_bitmaps_bb(struct sub_bitmaps *imgs, struct mp_rect *out_bb);
// Intentionally limit the maximum number of bounding rects to something low.

View File

@ -45,6 +45,9 @@ const int mp_sws_hq_flags = SWS_LANCZOS | SWS_FULL_CHR_H_INT |
SWS_FULL_CHR_H_INP | SWS_ACCURATE_RND |
SWS_BITEXACT;
// Fast, lossy.
const int mp_sws_fast_flags = SWS_BILINEAR;
// Set ctx parameters to global command line flags.
void mp_sws_set_from_cmdline(struct mp_sws_context *ctx)
{

View File

@ -14,6 +14,7 @@ struct mp_csp_details;
#define SWS_MIN_BYTE_ALIGN 16
extern const int mp_sws_hq_flags;
extern const int mp_sws_fast_flags;
bool mp_sws_supported_format(int imgfmt);