mirror of
https://github.com/mpv-player/mpv
synced 2024-12-12 18:06:18 +00:00
2c43d2b75a
Lots of dumb crap to do... something. Instead of adding yet another dumb helper, just use the main" sws_utils API in both callers. (Which, unfortunately, has been duplicated for glorious webp screenshots, despite the fact that webp is crap.) Good part: can enable zimg for screenshots (as far as needed). Bad part: uses "default" swscale parameters instead of HQ now.
49 lines
1.2 KiB
C
49 lines
1.2 KiB
C
#include <libavcodec/avcodec.h>
|
|
|
|
#include "common/common.h"
|
|
#include "mp_image.h"
|
|
#include "player/screenshot.h"
|
|
|
|
#include "image_loader.h"
|
|
|
|
struct mp_image *load_image_png_buf(void *buffer, size_t buffer_size, int imgfmt)
|
|
{
|
|
const AVCodec *codec = avcodec_find_decoder(AV_CODEC_ID_PNG);
|
|
if (!codec)
|
|
return NULL;
|
|
|
|
AVCodecContext *avctx = avcodec_alloc_context3(codec);
|
|
if (!avctx)
|
|
return NULL;
|
|
|
|
if (avcodec_open2(avctx, codec, NULL) < 0) {
|
|
avcodec_free_context(&avctx);
|
|
return NULL;
|
|
}
|
|
|
|
AVPacket *pkt = av_packet_alloc();
|
|
if (pkt) {
|
|
if (av_new_packet(pkt, buffer_size) >= 0)
|
|
memcpy(pkt->data, buffer, buffer_size);
|
|
}
|
|
|
|
// (There is only 1 outcome: either it takes it and decodes it, or not.)
|
|
avcodec_send_packet(avctx, pkt);
|
|
avcodec_send_packet(avctx, NULL);
|
|
|
|
av_packet_free(&pkt);
|
|
|
|
struct mp_image *res = NULL;
|
|
AVFrame *frame = av_frame_alloc();
|
|
if (frame && avcodec_receive_frame(avctx, frame) >= 0) {
|
|
struct mp_image *r = mp_image_from_av_frame(frame);
|
|
if (r)
|
|
res = convert_image(r, imgfmt, NULL, mp_null_log);
|
|
talloc_free(r);
|
|
}
|
|
av_frame_free(&frame);
|
|
|
|
avcodec_free_context(&avctx);
|
|
return res;
|
|
}
|