Port explode/implode, add new playing messages

This commit is contained in:
Essem 2023-03-11 15:35:11 -06:00
parent a77dc5acf9
commit d236179639
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
4 changed files with 43 additions and 50 deletions

View file

@ -1,10 +1,6 @@
import ImageCommand from "../../classes/imageCommand.js"; import ImageCommand from "../../classes/imageCommand.js";
class ExplodeCommand extends ImageCommand { class ExplodeCommand extends ImageCommand {
params = {
amount: -1
};
static description = "Explodes an image"; static description = "Explodes an image";
static aliases = ["exp"]; static aliases = ["exp"];

View file

@ -2,7 +2,7 @@ import ImageCommand from "../../classes/imageCommand.js";
class ImplodeCommand extends ImageCommand { class ImplodeCommand extends ImageCommand {
params = { params = {
amount: 1 implode: true
}; };
static description = "Implodes an image"; static description = "Implodes an image";

View file

@ -158,7 +158,6 @@
"Item Asylum", "Item Asylum",
"TIC-80", "TIC-80",
"Ghetto Smosh", "Ghetto Smosh",
"brought to you by the DFS project",
"Splatoon 3", "Splatoon 3",
"changed", "changed",
"Chutes and Ladders", "Chutes and Ladders",
@ -195,6 +194,9 @@
"ANTONBLAST", "ANTONBLAST",
"[object Object]", "[object Object]",
"Xonotic", "Xonotic",
"Lario",
"Hi-Fi Rush",
"Calckey",
"The clock is ticking." "The clock is ticking."
] ]
} }

View file

@ -1,57 +1,52 @@
#include <Magick++.h> #include <vips/vips8>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include "common.h" #include "common.h"
using namespace std; using namespace std;
using namespace Magick; using namespace vips;
char *Explode(string type, string *outType, char *BufferData, char *Explode(string type, string *outType, char *BufferData,
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) { size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
int amount = GetArgument<int>(Arguments, "amount"); bool implode = GetArgument<bool>(Arguments, "implode");
int delay = GetArgumentWithFallback<int>(Arguments, "delay", 0); string basePath = GetArgument<string>(Arguments, "basePath");
Blob blob; VOption *options = VImage::option();
list<Image> frames; VImage in =
list<Image> coalesced; VImage::new_from_buffer(
list<Image> blurred; BufferData, BufferLength, "",
try { type == "gif" ? options->set("n", -1)->set("access", "sequential")
readImages(&frames, Blob(BufferData, BufferLength)); : options)
} catch (Magick::WarningCoder &warning) { .colourspace(VIPS_INTERPRETATION_sRGB);
cerr << "Coder Warning: " << warning.what() << endl; if (!in.has_alpha()) in = in.bandjoin(255);
} catch (Magick::Warning &warning) {
cerr << "Warning: " << warning.what() << endl; int width = in.width();
int pageHeight = vips_image_get_page_height(in.get_image());
int nPages = vips_image_get_n_pages(in.get_image());
string distortPath = basePath + "assets/images/" +
(implode ? "linearimplode.png" : "linearexplode.png");
VImage distort =
(VImage::new_from_file(distortPath.c_str())
.resize(width / 500.0, VImage::option()
->set("vscale", pageHeight / 500.0)
->set("kernel", VIPS_KERNEL_CUBIC)) /
65535);
VImage distortImage = (distort[0] * width).bandjoin(distort[1] * pageHeight);
vector<VImage> img;
for (int i = 0; i < nPages; i++) {
VImage img_frame =
type == "gif" ? in.crop(0, i * pageHeight, width, pageHeight) : in;
VImage mapped = img_frame.mapim(distortImage);
img.push_back(mapped);
} }
coalesceImages(&coalesced, frames.begin(), frames.end()); VImage final = VImage::arrayjoin(img, VImage::option()->set("across", 1));
final.set(VIPS_META_PAGE_HEIGHT, pageHeight);
for (Image &image : coalesced) { void *buf;
image.implode(amount); final.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
image.magick(*outType);
blurred.push_back(image);
}
optimizeTransparency(blurred.begin(), blurred.end()); return (char *)buf;
if (*outType == "gif") {
for (Image &image : blurred) {
image.quantizeDither(false);
image.quantize();
if (delay != 0) image.animationDelay(delay);
}
}
writeImages(blurred.begin(), blurred.end(), &blob);
*DataSize = blob.length();
// workaround because the data is tied to the blob
char *data = (char *)malloc(*DataSize);
memcpy(data, blob.data(), *DataSize);
return data;
} }