1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-23 16:36:56 +00:00

image_writer: move convert_image() to player/screenshot.c

This commit is contained in:
sfan5 2019-09-14 22:06:00 +02:00
parent 7cf288ec77
commit 8925f10962
5 changed files with 49 additions and 10 deletions

View File

@ -38,6 +38,7 @@
#include "video/mp_image_pool.h"
#include "video/out/vo.h"
#include "video/image_writer.h"
#include "video/sws_utils.h"
#include "sub/osd.h"
#include "video/csputils.h"
@ -387,6 +388,42 @@ static struct mp_image *screenshot_get(struct MPContext *mpctx, int mode,
return image;
}
struct mp_image *convert_image(struct mp_image *image, int destfmt,
struct mp_log *log)
{
int d_w, d_h;
mp_image_params_get_dsize(&image->params, &d_w, &d_h);
struct mp_image_params p = {
.imgfmt = destfmt,
.w = d_w,
.h = d_h,
.p_w = 1,
.p_h = 1,
};
mp_image_params_guess_csp(&p);
if (mp_image_params_equal(&p, &image->params))
return mp_image_new_ref(image);
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);
dst->params = p;
if (mp_image_swscale(dst, image, mp_sws_hq_flags) < 0) {
mp_err(log, "Error when converting image.\n");
talloc_free(dst);
return NULL;
}
return dst;
}
// mode is the same as in screenshot_get()
static struct mp_image *screenshot_get_rgb(struct MPContext *mpctx, int mode)
{

View File

@ -21,6 +21,8 @@
#include <stdbool.h>
struct MPContext;
struct mp_image;
struct mp_log;
// One time initialization at program start.
void screenshot_init(struct MPContext *mpctx);
@ -28,6 +30,12 @@ void screenshot_init(struct MPContext *mpctx);
// Called by the playback core code when a new frame is displayed.
void screenshot_flip(struct MPContext *mpctx);
/* Return the image converted to the given format. If the pixel aspect ratio is
* not 1:1, the image is scaled as well. Returns NULL on failure.
*/
struct mp_image *convert_image(struct mp_image *image, int destfmt,
struct mp_log *log);
// Handlers for the user-facing commands.
void cmd_screenshot(void *p);
void cmd_screenshot_to_file(void *p);

View File

@ -2,7 +2,7 @@
#include "common/common.h"
#include "mp_image.h"
#include "image_writer.h"
#include "player/screenshot.h"
#include "image_loader.h"

View File

@ -18,7 +18,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <setjmp.h>
#include <libavcodec/avcodec.h>
#include <libavutil/mem.h>
@ -27,6 +26,7 @@
#include "config.h"
#if HAVE_JPEG
#include <setjmp.h>
#include <jpeglib.h>
#endif
@ -291,8 +291,8 @@ int image_writer_format_from_ext(const char *ext)
return 0;
}
struct mp_image *convert_image(struct mp_image *image, int destfmt,
struct mp_log *log)
static struct mp_image *convert_image(struct mp_image *image, int destfmt,
struct mp_log *log)
{
int d_w, d_h;
mp_image_params_get_dsize(&image->params, &d_w, &d_h);

View File

@ -61,11 +61,5 @@ int image_writer_format_from_ext(const char *ext);
bool write_image(struct mp_image *image, const struct image_writer_opts *opts,
const char *filename, struct mp_log *log);
/* Return the image converted to the given format. If the pixel aspect ratio is
* not 1:1, the image is scaled as well. Returns NULL on failure.
*/
struct mp_image *convert_image(struct mp_image *image, int destfmt,
struct mp_log *log);
// Debugging helper.
void dump_png(struct mp_image *image, const char *filename, struct mp_log *log);