2021-04-24 22:54:47 +00:00
|
|
|
#include <Magick++.h>
|
|
|
|
|
2022-12-28 06:20:17 +00:00
|
|
|
#include <cstring>
|
2021-10-23 18:58:19 +00:00
|
|
|
#include <iostream>
|
2020-07-23 20:49:34 +00:00
|
|
|
#include <list>
|
|
|
|
|
2022-12-28 23:01:50 +00:00
|
|
|
#include "common.h"
|
|
|
|
|
2020-07-23 20:49:34 +00:00
|
|
|
using namespace std;
|
|
|
|
using namespace Magick;
|
|
|
|
|
2023-03-09 01:36:39 +00:00
|
|
|
char *Wall(string type, string *outType, char *BufferData, size_t BufferLength,
|
2023-03-08 20:41:13 +00:00
|
|
|
[[maybe_unused]] ArgumentMap Arguments, size_t *DataSize) {
|
2022-12-28 06:20:17 +00:00
|
|
|
Blob blob;
|
2021-04-26 14:47:03 +00:00
|
|
|
|
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());
|
|
|
|
|
|
|
|
for (Image &image : coalesced) {
|
|
|
|
image.resize(Geometry("128x128"));
|
|
|
|
image.virtualPixelMethod(Magick::TileVirtualPixelMethod);
|
|
|
|
image.matteColor("none");
|
|
|
|
image.backgroundColor("none");
|
|
|
|
image.scale(Geometry("512x512"));
|
|
|
|
double arguments[16] = {0, 0, 57, 42, 0, 128, 63, 130,
|
|
|
|
128, 0, 140, 60, 128, 128, 140, 140};
|
|
|
|
image.distort(Magick::PerspectiveDistortion, 16, arguments);
|
|
|
|
image.scale(Geometry("800x800>"));
|
2023-03-09 01:36:39 +00:00
|
|
|
image.magick(*outType);
|
2022-12-28 06:20:17 +00:00
|
|
|
mid.push_back(image);
|
|
|
|
}
|
2020-07-23 20:49:34 +00:00
|
|
|
|
2022-12-28 06:20:17 +00:00
|
|
|
optimizeTransparency(mid.begin(), mid.end());
|
2020-07-23 20:49:34 +00:00
|
|
|
|
2023-03-09 01:36:39 +00:00
|
|
|
if (*outType == "gif") {
|
2022-12-28 06:20:17 +00:00
|
|
|
for (Image &image : mid) {
|
|
|
|
image.quantizeDitherMethod(FloydSteinbergDitherMethod);
|
|
|
|
image.quantize();
|
2021-04-24 22:54:47 +00:00
|
|
|
}
|
2022-12-28 06:20:17 +00:00
|
|
|
}
|
2020-07-23 20:49:34 +00:00
|
|
|
|
2022-12-28 06:20:17 +00:00
|
|
|
writeImages(mid.begin(), mid.end(), &blob);
|
2020-07-23 20:49:34 +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 20:49:34 +00:00
|
|
|
}
|