summaryrefslogtreecommitdiffstats
path: root/video/image_loader.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2017-07-01 15:56:12 +0200
committerwm4 <wm4@nowhere>2017-07-01 15:56:12 +0200
commit91279390710954519be79cff8388873888bf2f42 (patch)
treee166303643359dba10aba888486b6cf642ead30d /video/image_loader.c
parentaee81828e2e627ca33e66f87428add220b06f7a7 (diff)
downloadmpv-91279390710954519be79cff8388873888bf2f42.tar.bz2
mpv-91279390710954519be79cff8388873888bf2f42.tar.xz
x11: load icon differently
Now it's sourced from the etc/ PNG files directly, instead of preprocessing them with imagemagick. Add some ad-hoc code to decode PNG files with libavcodec. At least we can drop the zlib code in exchange.
Diffstat (limited to 'video/image_loader.c')
-rw-r--r--video/image_loader.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/video/image_loader.c b/video/image_loader.c
new file mode 100644
index 0000000000..9efc8b7310
--- /dev/null
+++ b/video/image_loader.c
@@ -0,0 +1,48 @@
+#include <libavcodec/avcodec.h>
+
+#include "common/common.h"
+#include "mp_image.h"
+#include "image_writer.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, mp_null_log);
+ talloc_free(r);
+ }
+ av_frame_free(&frame);
+
+ avcodec_free_context(&avctx);
+ return res;
+}