0
0
mirror of https://github.com/mpv-player/mpv.git synced 2024-09-19 19:42:24 +02:00

screenshot: support crop with --screenshot-sw

This commit is contained in:
Kacper Michajłow 2023-09-08 21:35:20 +02:00 committed by Dudemanguy
parent 49dfa1430b
commit 385719056e
2 changed files with 31 additions and 2 deletions

View File

@ -384,6 +384,19 @@ static struct mp_image *screenshot_get(struct MPContext *mpctx, int mode,
}
if (use_sw && image && window) {
if (mp_image_crop_valid(&image->params) &&
(mp_rect_w(image->params.crop) != image->w ||
mp_rect_h(image->params.crop) != image->h))
{
struct mp_image *nimage = mp_image_new_ref(image);
if (!nimage) {
MP_ERR(mpctx->screenshot_ctx, "mp_image_new_ref failed!\n");
return NULL;
}
mp_image_crop_rc(nimage, image->params.crop);
talloc_free(image);
image = nimage;
}
struct mp_osd_res res = osd_get_vo_res(mpctx->video_out->osd);
struct mp_osd_res image_res = osd_res_from_image_params(&image->params);
if (!osd_res_equals(res, image_res)) {

View File

@ -651,12 +651,25 @@ static struct mp_image *convert_image(struct mp_image *image, int destfmt,
mp_dbg(log, "Will convert image to %s\n", mp_imgfmt_to_name(p.imgfmt));
struct mp_image *src = image;
if (mp_image_crop_valid(&src->params) &&
(mp_rect_w(src->params.crop) != src->w ||
mp_rect_h(src->params.crop) != src->h))
{
src = mp_image_new_ref(src);
if (!src) {
mp_err(log, "mp_image_new_ref failed!\n");
return NULL;
}
mp_image_crop_rc(src, src->params.crop);
}
struct mp_image *dst = mp_image_alloc(p.imgfmt, p.w, p.h);
if (!dst) {
mp_err(log, "Out of memory.\n");
return NULL;
}
mp_image_copy_attributes(dst, image);
mp_image_copy_attributes(dst, src);
dst->params = p;
@ -664,9 +677,12 @@ static struct mp_image *convert_image(struct mp_image *image, int destfmt,
sws->log = log;
if (global)
mp_sws_enable_cmdline_opts(sws, global);
bool ok = mp_sws_scale(sws, dst, image) >= 0;
bool ok = mp_sws_scale(sws, dst, src) >= 0;
talloc_free(sws);
if (src != image)
talloc_free(src);
if (!ok) {
mp_err(log, "Error when converting image.\n");
talloc_free(dst);