mrmBot-Matrix/natives/togif.cc

32 lines
803 B
C++
Raw Normal View History

2022-12-28 06:20:17 +00:00
#include "common.h"
#include <vips/vips8>
using namespace std;
using namespace vips;
2022-12-28 06:20:17 +00:00
char *ToGif(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
if (*type == "gif") {
vips_error_clear();
vips_thread_shutdown();
*DataSize = BufferLength;
return BufferData;
} else {
VOption *options = VImage::option()->set("access", "sequential");
VImage in = VImage::new_from_buffer(BufferData, BufferLength, "",
*type == "webp" ? options->set("n", -1)
: options);
2022-06-28 03:50:53 +00:00
2022-12-28 06:20:17 +00:00
void *buf;
in.write_to_buffer(".gif", &buf, DataSize);
*type = "gif";
vips_error_clear();
vips_thread_shutdown();
return (char *)buf;
}
}