mrmBot-Matrix/natives/circle.cc

53 lines
1.3 KiB
C++
Raw Normal View History

2022-11-27 20:52:40 +00:00
#include "common.h"
#include <Magick++.h>
2022-11-27 20:52:40 +00:00
#include <cstring>
#include <iostream>
#include <list>
2022-11-27 20:52:40 +00:00
#include <map>
#include <string>
using namespace std;
using namespace Magick;
2022-11-27 20:52:40 +00:00
char *Circle(string type, char *BufferData, size_t BufferLength,
2022-11-27 23:23:57 +00:00
map<string, ARG_TYPES> Arguments, size_t *DataSize) {
2022-11-27 20:52:40 +00:00
Blob blob;
list<Image> frames;
list<Image> coalesced;
list<Image> blurred;
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) {
image.rotationalBlur(10);
image.magick(type);
blurred.push_back(image);
}
optimizeTransparency(blurred.begin(), blurred.end());
if (type == "gif") {
for (Image &image : blurred) {
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
image.quantize();
}
2022-11-27 20:52:40 +00:00
}
2022-11-27 20:52:40 +00:00
writeImages(blurred.begin(), blurred.end(), &blob);
2022-06-28 03:50:53 +00:00
2022-11-27 20:52:40 +00:00
*DataSize = blob.length();
// workaround because the data is tied to the blob
char *data = (char *)malloc(*DataSize);
memcpy(data, blob.data(), *DataSize);
return data;
}