mrmBot-Matrix/natives/tile.cc

71 lines
1.8 KiB
C++
Raw Normal View History

#include <Magick++.h>
#include <cstring>
#include <iostream>
#include <list>
#include "common.h"
using namespace std;
using namespace Magick;
ArgumentMap Tile(string type, string *outType, char *BufferData, size_t BufferLength,
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> mid;
try {
readImages(&frames, Blob(BufferData, BufferLength));
} catch (Magick::WarningCoder &warning) {
cerr << "Coder Warning: " << warning.what() << endl;
} catch (Magick::Warning &warning) {
cerr << "Warning: " << warning.what() << endl;
}
coalesceImages(&coalesced, frames.begin(), frames.end());
for (Image &image : coalesced) {
list<Image> duplicated;
Image appended;
list<Image> montage;
Image frame;
image.magick(*outType);
for (int i = 0; i < 5; ++i) {
duplicated.push_back(image);
}
appendImages(&appended, duplicated.begin(), duplicated.end());
appended.repage();
for (int i = 0; i < 5; ++i) {
montage.push_back(appended);
}
appendImages(&frame, montage.begin(), montage.end(), true);
frame.repage();
frame.scale(Geometry("800x800>"));
frame.animationDelay(image.animationDelay());
mid.push_back(frame);
}
optimizeTransparency(mid.begin(), mid.end());
if (*outType == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
}
writeImages(mid.begin(), mid.end(), &blob);
*DataSize = blob.length();
char *data = (char *)malloc(*DataSize);
memcpy(data, blob.data(), *DataSize);
ArgumentMap output;
output["buf"] = data;
output["width"] = (int)mid.front().columns();
output["height"] = (int)mid.front().rows();
return output;
2020-07-23 00:54:58 +00:00
}