2012-09-28 19:38:52 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2012-09-28 19:38:52 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2012-09-28 19:38:52 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2012-09-28 19:38:52 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2012-09-28 19:38:52 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2012-09-28 19:38:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
2019-10-31 10:24:20 +00:00
|
|
|
#include <limits.h>
|
2012-09-28 19:38:52 +00:00
|
|
|
|
2016-01-11 18:03:40 +00:00
|
|
|
#include "mpv_talloc.h"
|
2012-09-28 19:38:52 +00:00
|
|
|
|
2013-12-18 16:12:21 +00:00
|
|
|
#include "common/common.h"
|
2012-09-28 19:38:52 +00:00
|
|
|
#include "img_convert.h"
|
2013-11-24 11:58:06 +00:00
|
|
|
#include "osd.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "video/img_format.h"
|
|
|
|
#include "video/mp_image.h"
|
|
|
|
#include "video/sws_utils.h"
|
2012-09-28 19:38:52 +00:00
|
|
|
|
2016-06-17 19:54:12 +00:00
|
|
|
void mp_blur_rgba_sub_bitmap(struct sub_bitmap *d, double gblur)
|
2012-11-24 23:06:16 +00:00
|
|
|
{
|
2016-06-17 19:54:12 +00:00
|
|
|
struct mp_image *tmp1 = mp_image_alloc(IMGFMT_BGRA, d->w, d->h);
|
2023-11-23 19:46:25 +00:00
|
|
|
MP_HANDLE_OOM(tmp1);
|
|
|
|
{
|
2016-06-17 19:54:12 +00:00
|
|
|
struct mp_image s = {0};
|
|
|
|
mp_image_setfmt(&s, IMGFMT_BGRA);
|
|
|
|
mp_image_set_size(&s, d->w, d->h);
|
|
|
|
s.stride[0] = d->stride;
|
|
|
|
s.planes[0] = d->bitmap;
|
2012-11-24 23:06:16 +00:00
|
|
|
|
2016-06-17 19:54:12 +00:00
|
|
|
mp_image_copy(tmp1, &s);
|
video: introduce failure path for image allocations
Until now, failure to allocate image data resulted in a crash (i.e.
abort() was called). This was intentional, because it's pretty silly to
degrade playback, and in almost all situations, the OOM will probably
kill you anyway. (And then there's the standard Linux overcommit
behavior, which also will kill you at some point.)
But I changed my opinion, so here we go. This change does not affect
_all_ memory allocations, just image data. Now in most failure cases,
the output will just be skipped. For video filters, this coincidentally
means that failure is treated as EOF (because the playback core assumes
EOF if nothing comes out of the video filter chain). In other
situations, output might be in some way degraded, like skipping frames,
not scaling OSD, and such.
Functions whose return values changed semantics:
mp_image_alloc
mp_image_new_copy
mp_image_new_ref
mp_image_make_writeable
mp_image_setrefp
mp_image_to_av_frame_and_unref
mp_image_from_av_frame
mp_image_new_external_ref
mp_image_new_custom_ref
mp_image_pool_make_writeable
mp_image_pool_get
mp_image_pool_new_copy
mp_vdpau_mixed_frame_create
vf_alloc_out_image
vf_make_out_image_writeable
glGetWindowScreenshot
2014-06-17 20:43:43 +00:00
|
|
|
|
2016-06-18 10:08:17 +00:00
|
|
|
mp_image_sw_blur_scale(&s, tmp1, gblur);
|
2012-11-24 23:06:16 +00:00
|
|
|
}
|
2016-06-17 19:54:12 +00:00
|
|
|
talloc_free(tmp1);
|
2012-11-24 23:06:16 +00:00
|
|
|
}
|
2012-11-25 22:32:35 +00:00
|
|
|
|
2012-12-28 14:46:23 +00:00
|
|
|
bool mp_sub_bitmaps_bb(struct sub_bitmaps *imgs, struct mp_rect *out_bb)
|
|
|
|
{
|
|
|
|
struct mp_rect bb = {INT_MAX, INT_MAX, INT_MIN, INT_MIN};
|
|
|
|
for (int n = 0; n < imgs->num_parts; n++) {
|
|
|
|
struct sub_bitmap *p = &imgs->parts[n];
|
2019-10-31 10:24:20 +00:00
|
|
|
bb.x0 = MPMIN(bb.x0, p->x);
|
|
|
|
bb.y0 = MPMIN(bb.y0, p->y);
|
|
|
|
bb.x1 = MPMAX(bb.x1, p->x + p->dw);
|
|
|
|
bb.y1 = MPMAX(bb.y1, p->y + p->dh);
|
2012-12-28 14:46:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// avoid degenerate bounding box if empty
|
2019-10-31 10:24:20 +00:00
|
|
|
bb.x0 = MPMIN(bb.x0, bb.x1);
|
|
|
|
bb.y0 = MPMIN(bb.y0, bb.y1);
|
2012-12-28 14:46:23 +00:00
|
|
|
|
|
|
|
*out_bb = bb;
|
|
|
|
|
|
|
|
return bb.x0 < bb.x1 && bb.y0 < bb.y1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Merge bounding rectangles if they're closer than the given amount of pixels.
|
|
|
|
// Avoids having too many rectangles due to spacing between letter.
|
|
|
|
#define MERGE_RC_PIXELS 50
|
|
|
|
|
|
|
|
static void remove_intersecting_rcs(struct mp_rect *list, int *count)
|
|
|
|
{
|
|
|
|
int M = MERGE_RC_PIXELS;
|
|
|
|
bool changed = true;
|
|
|
|
while (changed) {
|
|
|
|
changed = false;
|
|
|
|
for (int a = 0; a < *count; a++) {
|
|
|
|
struct mp_rect *rc_a = &list[a];
|
|
|
|
for (int b = *count - 1; b > a; b--) {
|
|
|
|
struct mp_rect *rc_b = &list[b];
|
|
|
|
if (rc_a->x0 - M <= rc_b->x1 && rc_a->x1 + M >= rc_b->x0 &&
|
|
|
|
rc_a->y0 - M <= rc_b->y1 && rc_a->y1 + M >= rc_b->y0)
|
|
|
|
{
|
|
|
|
mp_rect_union(rc_a, rc_b);
|
|
|
|
MP_TARRAY_REMOVE_AT(list, *count, b);
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cluster the given subrectangles into a small numbers of bounding rectangles,
|
|
|
|
// and store them into list. E.g. when subtitles and toptitles are visible at
|
|
|
|
// the same time, there should be two bounding boxes, so that the video between
|
|
|
|
// the text is left untouched (need to resample less pixels -> faster).
|
|
|
|
// Returns number of rectangles added to out_rc_list (<= rc_list_count)
|
|
|
|
// NOTE: some callers assume that sub bitmaps are never split or partially
|
|
|
|
// covered by returned rectangles.
|
|
|
|
int mp_get_sub_bb_list(struct sub_bitmaps *sbs, struct mp_rect *out_rc_list,
|
|
|
|
int rc_list_count)
|
|
|
|
{
|
|
|
|
int M = MERGE_RC_PIXELS;
|
|
|
|
int num_rc = 0;
|
|
|
|
for (int n = 0; n < sbs->num_parts; n++) {
|
|
|
|
struct sub_bitmap *sb = &sbs->parts[n];
|
|
|
|
struct mp_rect bb = {sb->x, sb->y, sb->x + sb->dw, sb->y + sb->dh};
|
|
|
|
bool intersects = false;
|
|
|
|
for (int r = 0; r < num_rc; r++) {
|
|
|
|
struct mp_rect *rc = &out_rc_list[r];
|
|
|
|
if ((bb.x0 - M <= rc->x1 && bb.x1 + M >= rc->x0 &&
|
|
|
|
bb.y0 - M <= rc->y1 && bb.y1 + M >= rc->y0) ||
|
|
|
|
num_rc == rc_list_count)
|
|
|
|
{
|
|
|
|
mp_rect_union(rc, &bb);
|
|
|
|
intersects = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!intersects) {
|
|
|
|
out_rc_list[num_rc++] = bb;
|
|
|
|
remove_intersecting_rcs(out_rc_list, &num_rc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
remove_intersecting_rcs(out_rc_list, &num_rc);
|
|
|
|
return num_rc;
|
|
|
|
}
|