2022-11-27 19:03:07 +00:00
|
|
|
#include "common.h"
|
|
|
|
|
2021-04-24 22:54:47 +00:00
|
|
|
#include <Magick++.h>
|
|
|
|
|
2022-11-27 20:52:40 +00:00
|
|
|
#include <cstring>
|
2021-10-23 18:58:19 +00:00
|
|
|
#include <iostream>
|
2020-07-12 15:14:39 +00:00
|
|
|
#include <list>
|
2022-11-27 20:52:40 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2020-07-12 15:14:39 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Magick;
|
|
|
|
|
2022-11-27 20:52:40 +00:00
|
|
|
char *Explode(string type, char *BufferData, size_t BufferLength,
|
2022-12-03 19:49:28 +00:00
|
|
|
ArgumentMap Arguments, size_t *DataSize) {
|
2022-11-27 20:52:40 +00:00
|
|
|
|
2022-12-03 19:49:28 +00:00
|
|
|
int amount = GetArgument<int>(Arguments, "amount");
|
|
|
|
int delay = GetArgumentWithFallback<int>(Arguments, "delay", 0);
|
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.implode(amount);
|
|
|
|
image.magick(type);
|
|
|
|
blurred.push_back(image);
|
|
|
|
}
|
|
|
|
|
|
|
|
optimizeTransparency(blurred.begin(), blurred.end());
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2022-11-27 20:52:40 +00:00
|
|
|
}
|
2020-07-12 15:14:39 +00:00
|
|
|
|
2022-11-27 20:52:40 +00:00
|
|
|
writeImages(blurred.begin(), blurred.end(), &blob);
|
2020-08-28 02:34:12 +00:00
|
|
|
|
2022-11-27 20:52:40 +00:00
|
|
|
*DataSize = blob.length();
|
2022-11-27 19:03:07 +00:00
|
|
|
|
2022-11-27 20:52:40 +00:00
|
|
|
// workaround because the data is tied to the blob
|
|
|
|
char *data = (char *)malloc(*DataSize);
|
|
|
|
memcpy(data, blob.data(), *DataSize);
|
|
|
|
return data;
|
2020-07-12 15:14:39 +00:00
|
|
|
}
|