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";
class ExplodeCommand extends ImageCommand {
params = {
amount: -1
};
static description = "Explodes an image";
static aliases = ["exp"];

View file

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

View file

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

View file

@ -1,57 +1,52 @@
#include <Magick++.h>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vips/vips8>
#include "common.h"
using namespace std;
using namespace Magick;
using namespace vips;
char *Explode(string type, string *outType, char *BufferData,
size_t BufferLength, ArgumentMap Arguments, size_t *DataSize) {
int amount = GetArgument<int>(Arguments, "amount");
int delay = GetArgumentWithFallback<int>(Arguments, "delay", 0);
bool implode = GetArgument<bool>(Arguments, "implode");
string basePath = GetArgument<string>(Arguments, "basePath");
Blob blob;
VOption *options = VImage::option();
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;
VImage in =
VImage::new_from_buffer(
BufferData, BufferLength, "",
type == "gif" ? options->set("n", -1)->set("access", "sequential")
: options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha()) in = in.bandjoin(255);
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) {
image.implode(amount);
image.magick(*outType);
blurred.push_back(image);
}
void *buf;
final.write_to_buffer(("." + *outType).c_str(), &buf, DataSize);
optimizeTransparency(blurred.begin(), blurred.end());
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;
return (char *)buf;
}