mrmBot-Matrix/natives/tile.cc

65 lines
1.6 KiB
C++
Raw Normal View History

#include <Magick++.h>
2022-12-28 06:20:17 +00:00
#include <cstring>
#include <iostream>
2020-07-23 00:54:58 +00:00
#include <list>
#include "common.h"
2020-07-23 00:54:58 +00:00
using namespace std;
using namespace Magick;
2022-12-28 06:20:17 +00:00
char *Tile(string *type, char *BufferData, size_t BufferLength,
ArgumentMap Arguments, size_t *DataSize) {
Blob blob;
2022-12-28 06:20:17 +00:00
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());
2022-12-28 06:20:17 +00:00
for (Image &image : coalesced) {
list<Image> duplicated;
Image appended;
list<Image> montage;
Image frame;
image.magick(*type);
for (int i = 0; i < 5; ++i) {
duplicated.push_back(image);
}
2022-12-28 06:20:17 +00:00
appendImages(&appended, duplicated.begin(), duplicated.end());
appended.repage();
for (int i = 0; i < 5; ++i) {
montage.push_back(appended);
}
2022-12-28 06:20:17 +00:00
appendImages(&frame, montage.begin(), montage.end(), true);
frame.repage();
frame.scale(Geometry("800x800>"));
frame.animationDelay(image.animationDelay());
mid.push_back(frame);
}
2020-07-23 00:54:58 +00:00
2022-12-28 06:20:17 +00:00
optimizeTransparency(mid.begin(), mid.end());
2020-07-23 00:54:58 +00:00
2022-12-28 06:20:17 +00:00
if (*type == "gif") {
for (Image &image : mid) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
2022-12-28 06:20:17 +00:00
}
2020-07-23 00:54:58 +00:00
2022-12-28 06:20:17 +00:00
writeImages(mid.begin(), mid.end(), &blob);
2020-07-23 00:54:58 +00:00
2022-12-28 06:20:17 +00:00
*DataSize = blob.length();
2022-06-28 03:50:53 +00:00
2022-12-28 06:20:17 +00:00
char *data = (char *)malloc(*DataSize);
memcpy(data, blob.data(), *DataSize);
return data;
2020-07-23 00:54:58 +00:00
}