2022-11-27 19:03:07 +00:00
|
|
|
#include "common.h"
|
|
|
|
|
2021-04-24 22:54:47 +00:00
|
|
|
#include <Magick++.h>
|
|
|
|
|
2021-10-23 18:58:19 +00:00
|
|
|
#include <iostream>
|
2022-11-27 19:03:07 +00:00
|
|
|
#include <string>
|
|
|
|
#include <map>
|
2020-07-12 15:14:39 +00:00
|
|
|
#include <list>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Magick;
|
|
|
|
|
2022-11-27 19:03:07 +00:00
|
|
|
char* Explode(string type, char* BufferData, size_t BufferLength, map<string, string> Arguments, size_t* DataSize) {
|
2020-07-12 15:14:39 +00:00
|
|
|
|
2022-11-27 19:03:07 +00:00
|
|
|
int amount = stoi(Arguments.at("amount"));
|
|
|
|
int delay = MAP_HAS(Arguments, "delay") ? stoi(Arguments.at("delay")) : 0;
|
2021-04-26 14:47:03 +00:00
|
|
|
|
|
|
|
Blob blob;
|
|
|
|
|
|
|
|
list<Image> frames;
|
|
|
|
list<Image> coalesced;
|
|
|
|
list<Image> blurred;
|
2021-10-23 18:58:19 +00:00
|
|
|
try {
|
2022-11-27 19:03:07 +00:00
|
|
|
readImages(&frames, Blob(BufferData, BufferLength));
|
2021-10-23 18:58:19 +00:00
|
|
|
} catch (Magick::WarningCoder &warning) {
|
|
|
|
cerr << "Coder Warning: " << warning.what() << endl;
|
|
|
|
} catch (Magick::Warning &warning) {
|
|
|
|
cerr << "Warning: " << warning.what() << endl;
|
|
|
|
}
|
2021-04-26 14:47:03 +00:00
|
|
|
coalesceImages(&coalesced, frames.begin(), frames.end());
|
|
|
|
|
|
|
|
for (Image &image : coalesced) {
|
|
|
|
image.implode(amount);
|
|
|
|
image.magick(type);
|
|
|
|
blurred.push_back(image);
|
|
|
|
}
|
2020-07-12 15:14:39 +00:00
|
|
|
|
2021-04-26 14:47:03 +00:00
|
|
|
optimizeTransparency(blurred.begin(), blurred.end());
|
2020-07-12 15:14:39 +00:00
|
|
|
|
2021-04-26 14:47:03 +00:00
|
|
|
if (type == "gif") {
|
|
|
|
for (Image &image : blurred) {
|
|
|
|
image.quantizeDither(false);
|
|
|
|
image.quantize();
|
|
|
|
if (delay != 0) image.animationDelay(delay);
|
|
|
|
}
|
2021-04-24 22:54:47 +00:00
|
|
|
}
|
2020-07-12 15:14:39 +00:00
|
|
|
|
2021-04-26 14:47:03 +00:00
|
|
|
writeImages(blurred.begin(), blurred.end(), &blob);
|
2020-08-28 02:34:12 +00:00
|
|
|
|
2022-11-27 19:03:07 +00:00
|
|
|
*DataSize = blob.length();
|
|
|
|
|
|
|
|
return (char*) blob.data();
|
2020-07-12 15:14:39 +00:00
|
|
|
}
|